Skip to content

Commit 2189fca

Browse files
committed
Tag can be added from a new page.
1 parent ebc0e64 commit 2189fca

File tree

4 files changed

+161
-2
lines changed

4 files changed

+161
-2
lines changed

reactapp/src/AdminPage.jsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {Footer, Header, Section} from "./BasePage";
33
import React from "react";
44
import {Link, Redirect, useLocation} from "react-router-dom";
55
import {RemoveAdminToken} from "./api";
6+
import {AdminConfigSubMenu} from "./AdminTagPage";
67

78
export function AdminLogin() {
89
return (
@@ -148,11 +149,22 @@ export function AdminBC(props) {
148149
);
149150
}
150151

152+
function TagSubMenu(props) {
153+
const isHidden = !((props.activetab.toLowerCase() === "tags") || (props.activetab.toLowerCase() === "add"));
154+
return (
155+
<div className={isHidden ? "is-hidden" : "is-block"}>
156+
<ul>
157+
<MenuListElement name="Add" url={'/admin/tags/add'} active={props.activetab}/>
158+
</ul>
159+
</div>
160+
)
161+
}
162+
151163
export function AdminMenu(props) {
152164
return (
153165
<div>
154166
<ul className="menu-list">
155-
<MenuListElement name="Tags" url="/admin/tags" active={props.activetab} />
167+
<MenuListElement name="Tags" url="/admin/tags" active={props.activetab} children={<TagSubMenu name="Tags" url="/admin/tags/add" activetab={props.activetab} />} />
156168
<MenuListElement name="Captures" url="/admin/captures" active={props.activetab} />
157169
<MenuListElement name="Webhooks" url="/admin/webhooks" active={props.activetab} />
158170
</ul>

reactapp/src/AdminTagsAddPage.jsx

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
import AdminTagPage, {AdminTagBC, AdminTagMenu} from "./AdminTagPage";
2+
import {GetAdminToken, getData, handleErrors, postData} from "./api";
3+
import {AdminBC, AdminMenu, AdminPage, RedirectToLogin} from "./AdminPage";
4+
import {
5+
BulmaControl,
6+
Section,
7+
BulmaLabel,
8+
BulmaInput,
9+
BulmaCheckbox,
10+
BulmaRadio,
11+
BulmaField,
12+
BulmaSubmit, ErrorMessage
13+
} from "./BasePage";
14+
import React from "react";
15+
import {Redirect, withRouter} from "react-router-dom";
16+
import {AdminTagsBC} from "./AdminTagsListPage";
17+
18+
19+
class AdminTagsAddPage extends React.Component {
20+
constructor(props) {
21+
super(props);
22+
23+
GetAdminToken.call(this);
24+
25+
this.state = {serial: null, secretkey: null, description: null, fwversion: null, hwversion: null};
26+
27+
this.handleSubmit = this.handleSubmit.bind(this);
28+
this.handleChange = this.handleChange.bind(this);
29+
}
30+
31+
handleSubmit(event) {
32+
const admintoken = this.admintoken;
33+
const bearertoken = `Bearer ${admintoken}`;
34+
const extraheaders = {'Authorization': bearertoken};
35+
var payload = {};
36+
37+
if (this.state.serial) {
38+
payload.serial = this.state.serial;
39+
}
40+
41+
if (this.state.secretkey) {
42+
payload.secretkey = this.state.secretkey;
43+
}
44+
45+
if (this.state.description) {
46+
payload.description = this.state.description;
47+
}
48+
49+
if (this.state.fwversion) {
50+
payload.fwversion = this.state.fwversion;
51+
}
52+
53+
if (this.state.hwversion) {
54+
payload.hwversion = this.state.hwversion;
55+
}
56+
57+
if (event) {
58+
event.preventDefault();
59+
}
60+
61+
postData(process.env.REACT_APP_WSB_ORIGIN + '/api/admin/tags',
62+
payload,
63+
extraheaders)
64+
.then(handleErrors)
65+
.then(response => response.json())
66+
.then(json => {
67+
},
68+
(error) => {
69+
if (error) {
70+
this.setState({error: error});
71+
}
72+
});
73+
}
74+
75+
handleChange(event) {
76+
this.setState({[event.target.id]: event.target.value});
77+
}
78+
79+
render() {
80+
const activetab = 'Add';
81+
const error = this.state.error;
82+
if (error) {
83+
if (error.code ===401) {
84+
return <RedirectToLogin error={error} />
85+
}
86+
}
87+
return (
88+
<AdminPage bc={<AdminTagsAddBC />} menu={<AdminMenu activetab={activetab} />}>
89+
<ErrorMessage error={error} handleDismiss={this.handleDismiss} />
90+
<Section>
91+
<form onSubmit={this.handleSubmit} autoComplete="off">
92+
<BulmaField>
93+
<BulmaControl>
94+
<BulmaLabel>Serial</BulmaLabel>
95+
<BulmaInput id="serial" type="text" value={this.state.serial || ""} changeHandler={this.handleChange} maxLength={8}/>
96+
</BulmaControl>
97+
</BulmaField>
98+
<BulmaField>
99+
<BulmaControl>
100+
<BulmaLabel>Secret Key</BulmaLabel>
101+
<BulmaInput id="secretkey" type="text" value={this.state.secretkey || ""} changeHandler={this.handleChange} maxLength={16}/>
102+
</BulmaControl>
103+
</BulmaField>
104+
<BulmaField>
105+
<BulmaControl>
106+
<BulmaLabel>Firmware Version</BulmaLabel>
107+
<BulmaInput id="fwversion" type="text" value={this.state.fwversion || ""} changeHandler={this.handleChange}/>
108+
</BulmaControl>
109+
</BulmaField>
110+
<BulmaField>
111+
<BulmaControl>
112+
<BulmaLabel>Hardware Version</BulmaLabel>
113+
<BulmaInput id="hwversion" type="text" value={this.state.hwversion || ""} changeHandler={this.handleChange } />
114+
</BulmaControl>
115+
</BulmaField>
116+
<BulmaField>
117+
<BulmaControl>
118+
<BulmaLabel>Description</BulmaLabel>
119+
<BulmaInput id="description" type="text" value={this.state.description || ""} changeHandler={this.handleChange} />
120+
</BulmaControl>
121+
</BulmaField>
122+
<BulmaSubmit/>
123+
{/* https://jsfiddle.net/ndebellas/y4dLcqkx/ */}
124+
</form>
125+
</Section>
126+
</AdminPage>);
127+
128+
}
129+
}
130+
131+
function AdminTagsAddBC(props) {
132+
return(
133+
<AdminBC>
134+
<li><a href="/admin/tags" aria-current="page">Tags</a></li>
135+
<li className="is-active"><a href="#" aria-current="page">Add</a></li>
136+
</AdminBC>
137+
);
138+
}
139+
140+
141+
export default withRouter(AdminTagsAddPage);

reactapp/src/App.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import AdminConfigSerialPage from "./AdminConfigSerialPage";
2929
import AdminConfigNFCPage from "./AdminConfigNFCPage";
3030
import ConsumerConfigNFCPage from "./ConsumerConfigNFCPage";
3131
import ConsumerVersionPage from "./ConsumerVersionPage";
32+
import AdminTagsAddPage from "./AdminTagsAddPage";
3233

3334

3435
function App() {
@@ -87,6 +88,9 @@ function App() {
8788
<Route exact path="/admin/tags">
8889
<AdminTagsList />
8990
</Route>
91+
<Route exact path="/admin/tags/add">
92+
<AdminTagsAddPage />
93+
</Route>
9094
<Route exact path="/admin/tag/:id" render={props => (
9195
<Redirect to={`/admin/tag/${props.match.params.id}/simulate`} />
9296
)} />

reactapp/src/BasePage.jsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,16 @@ export function BulmaSubmit(props) {
6363
export function BulmaInput(props) {
6464
var readOnly = false;
6565
var disabled = false;
66+
const maxLength = props.maxLength || null;
6667
if (props.readOnly) {
6768
readOnly = true;
6869
}
6970
if (props.disabled) {
7071
disabled = true;
7172
}
73+
7274
return (
73-
<input className="input" id={props.id} type={props.type} value={props.value} disabled={disabled} onChange={props.changeHandler} readOnly={readOnly} />
75+
<input className="input" id={props.id} type={props.type} value={props.value} disabled={disabled} onChange={props.changeHandler} readOnly={readOnly} maxLength={maxLength}/>
7476
);
7577
}
7678

0 commit comments

Comments
 (0)