source: frontend/src/Dashboard/Menu.js@ a26f6a1

Last change on this file since a26f6a1 was a26f6a1, checked in by Danilo <danilo.najkov@…>, 23 months ago

full auth flow

  • Property mode set to 100644
File size: 4.7 KB
Line 
1import React, {useEffect, useState} from 'react'
2import {Button, Form, Input, Card, notification} from "antd";
3import axios from "axios";
4import env from "../env";
5
6const Menu = props => {
7
8 const [loadingSave, setLoadingSave] = useState(false);
9 const [restaurant, setRestaurant] = useState({menu:[]});
10 const [loading, setLoading] = useState(true);
11
12 useEffect(()=> {
13 setLoading(true);
14 getRestaurant()
15 },[])
16
17 const getRestaurant = () => {
18 axios.get(env.api + 'Restaurants').then(res=>{
19 setRestaurant(res.data);
20 setLoadingSave(false);
21 setLoadingSave(false);
22 });
23 }
24
25 const addMenu = (data) => {
26 setLoadingSave(true);
27 axios.post(env.api + 'Menu/',{...data,price: parseInt(data.price)}, { headers: {Authorization: localStorage.getItem('Auth')}
28 }).then(res => {
29 notification['success']({
30 message: 'Успешно зачувано',
31 });
32 getRestaurant()
33 }).catch(er => {
34 notification['error']({
35 message: 'Се случи проблем при зачувување мени. Ве молиме пробајте повторно подоцна',
36 });
37 setLoadingSave(false);
38 console.log(er);
39 })
40 console.log(data)
41 }
42
43 const deleteMenu = (id) => {
44 axios.delete(env.api + 'Menu/'+id, {headers: {Authorization: localStorage.getItem('Auth')}
45 }).then(res => {
46 notification['success']({
47 message: 'Успешно избришано',
48 });
49 getRestaurant()
50 }).catch(er => {
51 notification['error']({
52 message: 'Се случи проблем при бришење мени. Ве молиме пробајте повторно подоцна',
53 });
54 console.log(er);
55 })
56 }
57
58 return(
59 <div style={{padding:'20px'}}>
60 <div style={{backgroundColor:'white'}}>
61 <div style={{
62 width: '100%',
63 height:'75px',
64 backgroundColor: 'white',
65 padding: '20px',
66 border: '1px solid lightgray'
67 }} >
68 <h2 style={{float: 'left'}}>Мени</h2>
69 </div>
70 <Form style={{padding:20}} onFinish={addMenu}>
71 <h2 style={{margin: '20px',marginTop: 0}}>Додади нов запис:</h2>
72 <Form.Item
73 label="Име"
74 name="title"
75
76 rules={[
77 {
78 required: true,
79 message: 'Ве молиме внесете име!',
80 },
81 ]}
82 >
83 <Input/>
84 </Form.Item>
85 <Form.Item
86 label="Опис"
87 name="description"
88
89 rules={[
90 {
91 required: true,
92 message: 'Ве молиме внесете опис!',
93 },
94 ]}
95 >
96 <Input/>
97 </Form.Item>
98 <Form.Item
99 label="Цена"
100 name="price"
101
102 rules={[
103 {
104 required: true,
105 message: 'Ве молиме внесете цена!',
106 },
107 ]}
108 >
109 <Input placeholder="Цена" type={'number'}/>
110 </Form.Item>
111 <Form.Item style={{textAlign: 'center'}}>
112 <Button type="primary" htmlType="submit" loading={loadingSave}>
113 Зачувај
114 </Button>
115 </Form.Item>
116 </Form>
117 </div>
118 <div style={{textAlign:'start'}}>
119 {restaurant.menu.map(el =>
120 <Card title={el.title} extra={<p style={{color:'red',cursor:'pointer'}} onClick={()=>deleteMenu(el.id)}>Избриши</p>} style={{ width: 300, display:'inline-block', margin:'10px' }} size="small">
121 <p>{el.description}</p>
122 <b>{el.price} ден.</b>
123 </Card>
124 )}
125 </div>
126 </div>
127 )
128}
129
130export default Menu;
Note: See TracBrowser for help on using the repository browser.