forked from WooTechnology/DINE-IN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAdditem.js
197 lines (182 loc) · 5.96 KB
/
Additem.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
import React , {useState} from 'react';
import { makeStyles } from '@material-ui/core/styles';
import Drawer from '@material-ui/core/Drawer';
import AppBar from '@material-ui/core/AppBar';
import CssBaseline from '@material-ui/core/CssBaseline';
import Toolbar from '@material-ui/core/Toolbar';
import List from '@material-ui/core/List';
import Typography from '@material-ui/core/Typography';
import ListItem from '@material-ui/core/ListItem';
import ListItemText from '@material-ui/core/ListItemText';
import Button from '@material-ui/core/Button';
import {deleteTokens} from './auth';
import ExpandLess from '@material-ui/icons/ExpandLess';
import ExpandMore from '@material-ui/icons/ExpandMore';
import Collapse from '@material-ui/core/Collapse';
import TextField from '@material-ui/core/TextField';
import Container from '@material-ui/core/Container';
import Paper from '@material-ui/core/Paper';
const drawerWidth = 240;
const useStyles = makeStyles(theme => ({
root: {
display: 'flex',
},
appBar: {
zIndex: theme.zIndex.drawer + 1,
},
drawer: {
width: drawerWidth,
flexShrink: 0,
},
drawerPaper: {
width: drawerWidth,
},
content: {
flexGrow: 1,
padding: theme.spacing(3),
},
toolbar: theme.mixins.toolbar,
}));
const logout = (e) => {
e.preventDefault();
deleteTokens();
window.location.replace('/');
}
const homepage = () => {
window.location.replace("/main")
}
const menupage = () => {
window.location.replace("/menu");
}
const paymentpage = () => {
window.location.replace("/payment")
}
const additem = () => {
window.location.replace("/add")
}
export default function ClippedDrawer(props) {
const classes = useStyles();
const [name , setName] = useState("");
const [id , setId] = useState(0);
const [description , setDescription] = useState("");
const [amount, setAmount] = useState(0);
const [open, setOpen] = useState(true);
const handleClick = () => {
setOpen(!open);
};
const onSubmit = (e) => {
e.preventDefault();
const data = { id, name, description, amount }
fetch('/menu_create', {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(data)
}).then( res => {
if(res.ok){
window.location.replace("/menu")
}
})
};
return (
<div className={classes.root}>
<CssBaseline />
<AppBar position="fixed" className={classes.appBar}>
<Toolbar>
<Typography variant="h6" noWrap>
Hotel App
</Typography>
<Button color="inherit" onClick={logout}>Logout</Button>
</Toolbar>
</AppBar>
<Drawer
className={classes.drawer}
variant="permanent"
classes={{
paper: classes.drawerPaper,
}}
>
<div className={classes.toolbar} />
<List>
<ListItem button>
<ListItemText primary="Order" onClick={homepage} />
</ListItem>
<ListItem button onClick={handleClick}>
<ListItemText primary="Menu" />
{open ? <ExpandLess /> : <ExpandMore />}
</ListItem>
<Collapse in={open} timeout="auto" unmountOnExit>
<List component="div" disablePadding>
<ListItem button className={classes.nested}>
<ListItemText primary="Menu List" onClick={menupage} />
</ListItem>
<ListItem button className={classes.nested}>
<ListItemText primary="Add Item" onClick={additem} />
</ListItem>
</List>
</Collapse>
<ListItem button>
<ListItemText primary="Profile" />
</ListItem>
</List>
</Drawer>
<main className={classes.content}>
<div className={classes.toolbar} />
<div component={Paper}>
<Container maxWidth="sm">
<h1>Add Item</h1>
<TextField
placeholder="Enter Id of Item"
label="Item Id"
value={id}
onChange={event => setId(event.target.value)}
variant="outlined"
fullWidth="true"
margin="normal"
/>
<br />
<TextField
placeholder="Enter Name of Item"
label="Name"
value={name}
onChange={event => setName(event.target.value)}
variant="outlined"
margin="normal"
fullWidth="true"
/>
<br />
<TextField
placeholder="Enter Description"
label="Description"
value={description}
onChange={event => setDescription(event.target.value)}
variant="outlined"
margin="normal"
fullWidth="true"
/>
<br />
<TextField
placeholder="Enter Price"
label="Amount"
value={amount}
onChange={event => setAmount(event.target.value)}
variant="outlined"
margin="normal"
fullWidth="true"
/>
<br />
<br/>
<br/>
<Button
color="primary"
variant="contained"
onClick={onSubmit}
>Add Item
</Button>
</Container>
</div>
</main>
</div>
);
}