Changeset cc4db18 for frontend/src/Dashboard
- Timestamp:
- 07/06/22 13:13:35 (2 years ago)
- Branches:
- master
- Children:
- 899b19d
- Parents:
- d76b7ee
- Location:
- frontend/src/Dashboard
- Files:
-
- 2 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
frontend/src/Dashboard/Reservations.js
rd76b7ee rcc4db18 1 1 import React, {useEffect, useState} from 'react' 2 import {Button, Modal, DatePicker, List, notification } from "antd";2 import {Button, Modal, DatePicker, List, notification, Input} from "antd"; 3 3 import AddNewReservation from "./AddNewReservation"; 4 4 import moment from 'moment' … … 13 13 const [date, setDate] = useState([moment().startOf('day'), moment().add(24,'hours')]); 14 14 const [reservations, setReservations] = useState([]) 15 const [newReservations, setNewReservations] = useState([]) 15 16 const [loadingReservations, setLoadingReservations] = useState(true) 16 17 … … 26 27 to: date[1].format('YYYY-MM-DDThh:mm:ss') + 'Z' 27 28 }, headers: {Authorization: sessionStorage.getItem('Auth')} 28 }) 29 .then(res => { 29 }).then(res => { 30 axios.get(env.api + 'Reservations/new', { 31 headers: {Authorization: sessionStorage.getItem('Auth')} 32 }).then(newres=>{ 33 setNewReservations(newres.data); 30 34 setReservations(res.data); 31 console.log(res.data)32 35 setLoadingReservations(false) 33 }).catch(er => { 36 }) 37 }).catch(er => { 34 38 setLoadingReservations(false) 35 39 notification['error']({ 36 40 message: 'Се случи проблем при додавање резервација. Ве молиме пробајте повторно подоцна', 37 41 }); 38 39 42 console.log(er); 40 43 }); … … 48 51 const changeReservationStatus = (id, newStatus) => { 49 52 console.log(id) 50 axios.put(env.api + 'Reservations/'+id ,{}, {53 axios.put(env.api + 'Reservations/'+id+'/status',{}, { 51 54 params: { 52 55 status: newStatus … … 59 62 }); 60 63 console.log(er); 61 }); 62 } 64 }) 65 } 66 const changeTable = (ev, item) => { 67 axios.put(env.api + 'Reservations/'+item.id+'/table',{}, { 68 params: { 69 tableId: ev.target.value == '' ? 0 : ev.target.value 70 }, headers: {Authorization: sessionStorage.getItem('Auth')} 71 }).then(res => { 72 console.log("success"); 73 }).catch(er => { 74 notification['error']({ 75 message: 'Се случи проблем при менување резервација. Ве молиме пробајте повторно подоцна', 76 }); 77 console.log(er); 78 }) 79 setNewReservations(old =>{ 80 const newRes = old.indexOf(item); 81 if(newRes == -1) return old; 82 const copy = [...old]; 83 copy[newRes].table = ev.target.value; 84 return copy; 85 }) 86 setReservations(old =>{ 87 const newRes = old.indexOf(item); 88 if(newRes == -1) return old; 89 const copy = [...old]; 90 copy[newRes].table = ev.target.value; 91 return copy; 92 }) 93 } 94 63 95 const ReservationType = [ 'Кратко', 'Долго', 'Настан' ]; 64 96 const ReservationPlace = [ 'Внатре', 'Надвор' ]; … … 84 116 border: '1px solid lightgray' 85 117 }} > 118 <h3 style={{float: 'left'}}>Нови резервации</h3> 119 </div> 120 <List loading={loadingReservations} dataSource={newReservations} itemLayout={'horizontal'} locale={{emptyText:'Немате нови резервации'}} 121 renderItem={item => ( 122 <List.Item 123 actions={ 124 item.reservationStatus == 0 ? 125 [<a onClick={()=>changeReservationStatus(item.id,ReservationStatus[1])}>Прифати</a>, <a style={{color:'red'}} onClick={()=>changeReservationStatus(item.id,ReservationStatus[2])}>Отфрли</a>] 126 : item.reservationStatus == 1 ? [<span style={{color:'green'}}>Прифатено</span>] : [<span style={{color:'red'}}>Отфрлено</span>]}> 127 <div style={{display:'flex',flexDirection:'row',justifyContent:'space-between',width:'100%', padding:'10px'}}> 128 <div style={{textAlign:'start', width:'200px'}}> 129 <div><b>Име:</b> {item.contactName}</div> 130 <div><b>Број:</b> {item.contactNumber}</div> 131 </div> 132 <div style={{marginTop:'10px'}}> 133 Маса: <Input style={{ width: '60px' }} type={'number'} value={item.table == 0 ? '' : item.table} onChange={(ev)=>changeTable(ev,item)}/> 134 </div> 135 <div> 136 <div><b>Луѓе:</b> {item.persons}</div> 137 <div>{ReservationPlace[item.reservationPlace]}, {ReservationType[item.reservationType]}</div> 138 </div> 139 <div> 140 <div style={{marginTop:'10px'}}>{moment(item.startDate).format('hh:mm DD/MM/YY')}</div> 141 </div> 142 </div> 143 </List.Item> 144 )}/> 145 </div> 146 <div style={{marginTop:'20px', backgroundColor:'white'}}> 147 <div style={{ 148 width: '100%', 149 height:'75px', 150 backgroundColor: 'white', 151 padding: '20px', 152 border: '1px solid lightgray' 153 }} > 86 154 <h3 style={{float: 'left'}}>Сите резервации</h3> 87 155 <RangePicker … … 89 157 style={{float:'right'}} 90 158 ranges={{ 159 'Наредни 3 часа': [moment(), moment().add(3,'hours')], 91 160 'Следни 24 часа': [moment().startOf('day'), moment().add(24,'hours')], 92 161 'Овој месец': [moment().startOf('month'), moment().endOf('month')], … … 96 165 /> 97 166 </div> 98 <List loading={loadingReservations} dataSource={reservations} itemLayout={'horizontal'} 167 <List loading={loadingReservations} dataSource={reservations} itemLayout={'horizontal'} locale={{emptyText:'Нема резервации за овој период'}} 99 168 renderItem={item => ( 100 169 <List.Item … … 107 176 <div><b>Име:</b> {item.contactName}</div> 108 177 <div><b>Број:</b> {item.contactNumber}</div> 178 </div> 179 <div style={{marginTop:'10px'}}> 180 Маса: <Input style={{ width: '60px' }} type={'number'} value={item.table == 0 ? '' : item.table} onChange={(ev)=>changeTable(ev,item)}/> 109 181 </div> 110 182 <div>
Note:
See TracChangeset
for help on using the changeset viewer.