source: frontend/src/Dashboard/ToDo.js@ d86edb7

Last change on this file since d86edb7 was d86edb7, checked in by Danilo <danilo.najkov@…>, 2 years ago

small fix

  • Property mode set to 100644
File size: 10.1 KB
RevLine 
[a569b7c]1import React, {useEffect, useState} from 'react'
2import {
3 Button,
4 Card,
5 DatePicker,
6 Dropdown,
7 Form,
8 Input,
9 List, Menu,
10 Modal,
11 notification,
12 Rate,
13 Select, Space,
14 Spin,
15 Tooltip
16} from "antd";
17import moment from "moment";
18import axios from "axios";
19import env from "../env";
20import AddNewReservation from "./AddNewReservation";
21import {DownOutlined} from "@ant-design/icons";
22
23const ToDo = ({}) => {
24
25 const [loading, setLoading] = useState(true);
26 const [todoItems, setToDoItems] = useState([]);
27 const [newTodoVisible, setNewTodoVisible] = useState(false);
28 const [saveNewTodoLoading, setSaveNewTodoLoading] = useState(false)
29 const [restaurant, setRestaurant] = useState({reviews:[]})
30 const [showReview, setShowReview] = useState(null);
31 const [sortSelect, setSortSelect] = useState('date')
32
33 useEffect(()=> {
34 setLoading(true);
35 getToDos()
36 getRestaurant()
37 },[])
38
39 const getToDos = () => {
40 setSortSelect(type=> {
41 axios.get(env.api + 'ToDo', {
42 params: {sortBy: type},
43 headers: {Authorization: localStorage.getItem('Auth')}
44 }).then(res => {
45 console.log(res.data)
46 setToDoItems(res.data);
47 setLoading(false);
48 });
[d86edb7]49 return type
[a569b7c]50 })
51 }
52
53 const updateSort = (type)=>{
54 setSortSelect(type);
55 getToDos();
56 }
57
58 const createToDo = (data) => {
59 console.log(data)
60 setSaveNewTodoLoading(true);
61 axios.post(env.api + 'ToDo', data, {headers:{Authorization:localStorage.getItem('Auth')}}).then(res=>{
62 setSaveNewTodoLoading(false);
63 setNewTodoVisible(false);
64 getToDos()
65 });
66 }
67
68
69 const getRestaurant = () => {
70 axios.get(env.api + 'Restaurants').then(res=>{
71 setRestaurant(res.data);
72 setLoading(false);
73 });
74 }
75
76 const changeStatus = (id, newStatus) => {
77 axios.put(env.api + 'ToDo/'+id, {}, {params:{newStatus:newStatus}, headers:{Authorization:localStorage.getItem('Auth')}}).then(res=>{
78 getToDos()
79 });
80 }
81
82 return(
83 <div style={{padding: '20px',textAlign:'center'}}>
84 <div style={{
85 width: '100%',
86 backgroundColor: 'white',
87 padding: '20px',
88 height:'75px',
89 border: '1px solid lightgray'
90 }} id={'expandMain'}>
91 <h2 style={{float: 'left'}}>ToDo листа</h2>
92 <Button style={{float:'right'}} type={'primary'} onClick={()=>setNewTodoVisible(true)}>Внеси нов запис</Button>
93 <div style={{float:'right', marginRight:'20px'}}>
94 <span style={{marginRight:'5px'}}>Начин на подредување:</span>
95 <Select
96 defaultValue="date"
97 style={{
98 width: 120,
99 }}
100 onChange={(el)=>updateSort(el)}
101 >
102 <Select.Option value="date">Датум</Select.Option>
103 <Select.Option value="priority">Приоритет</Select.Option>
104 </Select>
105 </div>
106 </div>
107 {loading ? <Spin style={{margin: '20px', textAlign:'center'}}/> :
108 <div style={{textAlign:'start'}}>
109 <List dataSource={todoItems} itemLayout={'horizontal'} locale={{emptyText:'Немате направено ToDo'}}
110 renderItem={item => (
111 <Card title={item.title} style={{width:'98%',backgroundColor:'white',margin:'1%'}}
112 actions={
113 item.status == 0 ?
114 [<a style={{color:'#1890ff'}} onClick={()=>changeStatus(item.id,1)}>Започни</a>, <a style={{color:'red'}} onClick={()=>changeStatus(item.id,3)}>Отфрли</a>]
115 : item.status == 1 ? [<a style={{color:'green'}} onClick={()=>changeStatus(item.id,2)}>Заврши</a>, <a style={{color:'red'}} onClick={()=>changeStatus(item.id,3)}>Отфрли</a>]
116 : []}
117 extra={<div style={{textAlign:'end'}}>
118 {
119 item.status == 0 ? [<span style={{color:'#1890ff'}}>Ново</span>] :
120 item.status == 1 ? [<span style={{color:'orange'}}>Започнато</span>] :
121 item.status == 2 ? [<span style={{color:'green'}}>Завршено</span>] :
122 item.status == 3 ? [<span style={{color:'red'}}>Отфрлено</span>] : ''
123 }
124 <br/>
125 <span style={{color:'gray'}}>{moment(item.createdAt).format("DD.MM.yyyy")}</span>
126 </div>}
127 >
128 <p>{item.description}</p>
129 <div style={{borderTop:'1px solid rgb(242, 242, 242)', marginBottom:'15px'}}/>
130 <span style={{float:'left'}}>{item.linkedReview ? <p onClick={() => setShowReview(item.linkedReview)}>Поврзана оценка: <span style={{textDecoration:'underline', cursor:'pointer'}}>{item.linkedReview.id +' - '+ item.linkedReview.title}</span></p> : <></>}</span>
131 <span style={{float:'right'}}>Приоритет: {item.priority}</span>
132 </Card>
133 )}/>
134 </div>
135
136 }
137 <Modal
138 style={{top: 20}}
139 width={'700px'}
140 title="Нова ToDo"
141 footer={[
142 <Button form="newToDoForm" key="submit" htmlType="submit" type={'primary'} loading={saveNewTodoLoading}>
143 Прати
144 </Button>
145 ]}
146 onCancel={()=>setNewTodoVisible(false)}
147 visible={newTodoVisible}>
148 <div>
149 <Form onFinish={createToDo}
150 id={'newToDoForm'}
151 onFinishFailed={()=>
152 notification['error']({
153 message: 'Ве молиме поправете ги сите грешки пред зачувување!',
154 })}>
155 <Form.Item
156 label="Наслов"
157 name="title"
158 rules={[
159 {
160 required: true,
161 message: 'Ве молиме внесете наслов!',
162 },
163 ]}
164 >
165 <Input/>
166 </Form.Item>
167 <Form.Item
168 label="Опис"
169 name="description"
170 rules={[
171 {
172 required: true,
173 message: 'Ве молиме внесете опис!',
174 },
175 ]}
176 >
177 <Input.TextArea rows={4}/>
178 </Form.Item>
179 <Form.Item
180 label="Приоритет"
181 name="priority"
182 rules={[
183 {
184 required: true,
185 message: 'Ве молиме внесете приоритет!',
186 },
187 {
188 regex: new RegExp('^[1-9]\\d*$'),
189 message: 'Ве молиме внесете позитивен број!',
190 },
191 ]}
192 >
193 <Input type={'number'}/>
194 </Form.Item>
195 <Form.Item
196 label="Поврзана оценка"
197 name="reviewId"
198 >
199 <Select>
200 {restaurant.reviews.map(el =>(
201 <Select.Option value={el.id}>{el.id +" - "+ el.title}</Select.Option>
202 ))}
203 </Select>
204 </Form.Item>
205 </Form>
206 </div>
207 </Modal>
208 <Modal
209 style={{top: '10%', padding:'0'}}
210 bodyStyle={{backgroundColor:'rgb(242, 242, 242)'}}
211 width={'700px'}
212 title="Поврзана оценка"
213 footer={[
214 <Button onClick={()=>setShowReview(null)}>
215 Затвори
216 </Button>
217 ]}
218 onCancel={()=>setShowReview(null)}
219 visible={showReview != null}>
220 <div style={{backgroundColor:'rgb(242, 242, 242)'}}>
221 {showReview ?
222 <Card title={showReview.title} >
223 <p>{showReview.description}</p>
224 <Rate disabled value={showReview.stars}/>
225 <p style={{color: 'gray'}}>{moment(showReview.createdAt).format("DD.MM.yyyy")}</p>
226 </Card>
227 :<></>}
228 </div>
229 </Modal>
230 </div>
231 )
232}
233export default ToDo;
Note: See TracBrowser for help on using the repository browser.