source: frontend/src/Dashboard/Restaurant.js@ 13f1472

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

full auth flow

  • Property mode set to 100644
File size: 5.9 KB
Line 
1import React,{useState, useEffect} from 'react';
2import {Form, Upload, Spin, message, Modal, Button, Input, notification} from "antd";
3import {PlusOutlined} from "@ant-design/icons";
4import axios from 'axios';
5import env from "../env";
6
7const Restaurant = props => {
8 const [loadingSave, setLoadingSave] = useState(false);
9 const [loadingLoad, setLoadingLoad] = useState(true);
10 const [restaurant, setRestaurant] = useState({});
11
12 useEffect(()=> {
13 setLoadingLoad(true);
14 getRestaurant()
15 },[])
16
17 const getRestaurant = () => {
18 axios.get(env.api + 'Restaurants').then(res=>{
19 setRestaurant(res.data);
20 setLoadingLoad(false);
21 setLoadingSave(false);
22 });
23 }
24 const beforeUpload = (file) => {
25 const isJpgOrPng = file.type === 'image/jpeg' || file.type === 'image/png';
26 if (!isJpgOrPng) {
27 message.error('Сликата мора да е формат jpg или png');
28 }
29 if(isJpgOrPng) setLoadingSave(true);
30 return isJpgOrPng;
31 }
32 const uploadChanged = (ev) =>{
33 if(ev.file.status == 'done'){
34 getRestaurant()
35 }
36 }
37 const submitEdit = (form) => {
38 setLoadingSave(true);
39 axios.put(env.api + 'Restaurants/',{...form}, { headers: {Authorization: localStorage.getItem('Auth')}
40 }).then(res => {
41 notification['success']({
42 message: 'Успешно зачувано',
43 });
44 setLoadingSave(false);
45 }).catch(er => {
46 notification['error']({
47 message: 'Се случи проблем при менување контакт информации. Ве молиме пробајте повторно подоцна',
48 });
49 setLoadingSave(false);
50 console.log(er);
51 })
52 console.log(form)
53 }
54 return(
55 <div style={{padding:'20px'}}>
56 <div style={{backgroundColor:'white'}}>
57 <div style={{
58 width: '100%',
59 height:'75px',
60 backgroundColor: 'white',
61 padding: '20px',
62 border: '1px solid lightgray'
63 }} >
64 <h2 style={{float: 'left'}}>Ресторан</h2>
65 </div>
66 {loadingLoad ? <Spin size="large"/> :
67 <div style={{padding:'20px'}}>
68 <Upload
69 name="file"
70 onChange={uploadChanged}
71 showUploadList={false}
72 beforeUpload={beforeUpload}
73 style={{maxWidth: '90%', height: '200px', overflow: 'hidden'}}
74 action={env.api+'Restaurants/upload'}
75 >
76 {restaurant.base64Image != "data:image/png;base64," ? <img style={{cursor: 'pointer'}} src={restaurant.base64Image} alt="avatar"
77 height='200px'/> : <div style={{cursor:'pointer',margin: 15,border:'1px solid gray',padding: 5}}><PlusOutlined /><div style={{ marginTop: 8}}>Додади слика</div></div>}
78 </Upload>
79 <div style={{textAlign: 'start', width: '100%', marginTop:'10px'}}>
80 <Form onFinish={submitEdit}
81 onFinishFailed={() => Modal.error({title: "Ве молиме пополнете ги задолжителните полиња"})}
82 initialValues={{...restaurant}}>
83 <Form.Item
84 label="Име на локал"
85 name="name"
86
87 rules={[
88 {
89 required: true,
90 message: 'Ве молиме внесете име на локалот!',
91 },
92 ]}
93 >
94 <Input/>
95 </Form.Item>
96 <Form.Item
97 label="Адреса"
98 name="address"
99 rules={[
100 {
101 required: true,
102 message: 'Ве молиме внесете адреса!',
103 },
104 ]}
105 >
106 <Input/>
107 </Form.Item>
108 <Form.Item
109 label="Телефон"
110 name="phone"
111 rules={[
112 {
113 required: true,
114 message: 'Ве молиме внесете телефон!',
115 },
116 ]}
117 >
118 <Input placeholder='ex. 070123456'/>
119 </Form.Item>
120 <Form.Item style={{textAlign: 'center'}}>
121 <Button type="primary" htmlType="submit" loading={loadingSave}>
122 Зачувај
123 </Button>
124 </Form.Item>
125 </Form>
126 </div>
127 </div>
128 }
129 </div>
130 </div>
131 )
132}
133export default Restaurant;
Note: See TracBrowser for help on using the repository browser.