- Timestamp:
- 07/10/22 10:27:45 (2 years ago)
- Branches:
- master
- Children:
- a26f6a1
- Parents:
- cc4db18
- Location:
- frontend/src
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
frontend/src/App.js
rcc4db18 r899b19d 1 1 import './App.css'; 2 import {Route, BrowserRouter as Router, Navigate, Routes } from "react-router-dom";2 import {Route, BrowserRouter as Router, Navigate, Routes, useNavigate} from "react-router-dom"; 3 3 import axios from 'axios' 4 4 import env from './env' … … 12 12 import Restaurant from "./Dashboard/Restaurant"; 13 13 import Menu from "./Dashboard/Menu"; 14 import Review from "./Dashboard/Review"; 14 15 15 16 16 17 function App() { 17 const [user, setUser] = useState( false)18 const [user, setUser] = useState(undefined) 18 19 const [loading, setLoading] = useState(false) 19 20 useEffect(()=>{ … … 29 30 }) 30 31 } 32 const logout = () => { 33 setUser(undefined); 34 sessionStorage.removeItem('Auth'); 35 window.location.replace('/') 36 } 31 37 return ( 32 38 <div style={{textAlign:'center'}}> 33 39 <Router> 34 40 <Routes> 35 <Route path="/dashboard" element={loading ? <Spin /> : user ? <Dashboard setUser={setUser}/>: <Navigate to="/login" replace={true} />}>41 <Route path="/dashboard" element={loading ? <Spin /> : user ? (user.isAdmin ? <Dashboard setUser={setUser}/> : <Navigate to="/" replace={true} />) : <Navigate to="/login" replace={true} />}> 36 42 <Route path="/dashboard" element={<Restaurant/>}/> 37 43 <Route path="/dashboard/menu" element={<Menu/>}/> 38 44 <Route path="/dashboard/reservations" element={<Reservations/>}/> 39 <Route path="/dashboard/reviews" element={ 'reviews'}/>45 <Route path="/dashboard/reviews" element={<Review/>}/> 40 46 <Route path="/dashboard/todo" element={'todo'}/> 41 47 </Route> 42 48 <Route path="/login" element={loading ? <Spin /> : !user ? <Login setUser={setUser}/> : <Navigate to="/dashboard" replace={true} />}/> 43 49 <Route path="/register" element={loading ? <Spin /> : !user ? <Register setUser={setUser}/> : <Navigate to="/dashboard" replace={true} />}/> 44 <Route path="/" element={<FrontPage />}/>50 <Route path="/" element={<FrontPage user={user} logout={logout}/>}/> 45 51 </Routes> 46 52 </Router> -
frontend/src/FrontPage.js
rcc4db18 r899b19d 2 2 import {Header} from "./Header"; 3 3 import {useNavigate} from "react-router-dom"; 4 import {Button, Card, Image, Modal, Spin} from "antd";4 import {Button, Card, DatePicker, Form, Image, Input, Modal, notification, Rate, Spin} from "antd"; 5 5 import placeholderImage from '../src/Assets/placeholder.png' 6 6 import AddNewReservation from "./Dashboard/AddNewReservation"; 7 7 import axios from "axios"; 8 8 import env from "./env"; 9 import Review from "./Dashboard/Review"; 9 10 10 const FrontPage = ({ }) => {11 const FrontPage = ({user, logout}) => { 11 12 const [restaurant, setRestaurant] = useState({name:'Sample Restaurant name', address: 'Sample street 1', city:'Sample'}); 12 13 const [newReservationModal, setNewReservationModal] = useState(false); 13 14 const [saveModalLoading, setSaveModalLoading] = useState(false); 15 const [newReviewModal, setNewReviewModal] = useState(false); 14 16 const [loading, setLoading] = useState(true); 17 const [refreshToggle, setRefreshToggle] = useState(false); 15 18 const history = useNavigate(); 16 19 … … 23 26 },[]) 24 27 28 const saveNewReview = data =>{ 29 setSaveModalLoading(true) 30 axios.post(env.api + 'Reviews',data,{ headers: {Authorization: sessionStorage.getItem('Auth')}}).then(res=>{ 31 setNewReviewModal(false) 32 setSaveModalLoading(false) 33 notification['success']({ 34 message: 'Успешно зачувано', 35 }); 36 setRefreshToggle(ref => !ref); 37 }).catch(err=>{ 38 setSaveModalLoading(false) 39 notification['error']({ 40 message: 'Се случи проблем при зачувување', 41 }); 42 }); 43 } 44 25 45 return( 26 46 <div> 27 <Header onClickButton={ ()=>history('/login')} buttonText={'Логирајсе'}/>47 <Header onClickButton={!user?()=>history('/login'):logout} buttonText={!user?'Најави се':'Одјави се'}/> 28 48 {loading ? <Spin style={{margin: 20}}/> : 29 49 <div style={{ … … 69 89 </div> 70 90 <div style={{textAlign: 'start', backgroundColor: '#F2F2F2'}}> 71 <h2 style={{textAlign:'center',paddingTop:'20px'}}>Мени</h2> 91 <div style={{ 92 width: '100%', 93 height:'75px', 94 backgroundColor: 'white', 95 padding: '20px', 96 border: '1px solid lightgray' 97 }} > 98 <h2 style={{float: 'left'}}>Мени</h2> 99 </div> 72 100 {restaurant.menu.map(el => 73 <Card title={el.title} style={{ width: 280, display:'inline-block', margin:'10px' }} size="small">101 <Card key={el.id} title={el.title} style={{ width: 280, display:'inline-block', margin:'10px' }} size="small"> 74 102 <p>{el.description}</p> 75 103 <b>{el.price} ден.</b> 76 104 </Card> 77 105 )} 106 <Review user={user} front refresh={refreshToggle} setVisible={setNewReviewModal}/> 78 107 </div> 79 108 </div> … … 92 121 <AddNewReservation setModalSaveLoading={setSaveModalLoading} setModalVisible={setNewReservationModal} /> 93 122 </Modal> 123 <Modal 124 style={{top: 20}} 125 width={'700px'} 126 title="Нова оценка" 127 footer={[ 128 <Button form="newReviewForm" key="submit" htmlType="submit" type={'primary'} loading={saveModalLoading}> 129 Прати 130 </Button> 131 ]} 132 onCancel={()=>setNewReviewModal(false)} 133 visible={newReviewModal}> 134 <Form onFinish={saveNewReview} 135 id={'newReviewForm'} 136 onFinishFailed={()=> 137 notification['error']({ 138 message: 'Ве молиме поправете ги сите грешки пред зачувување!', 139 })}> 140 <Form.Item 141 label="Наслов" 142 name="title" 143 rules={[ 144 { 145 required: true, 146 message: 'Ве молиме внесете наслов!', 147 }, 148 ]} 149 > 150 <Input/> 151 </Form.Item> 152 <Form.Item 153 label="Опис" 154 name="description" 155 rules={[ 156 { 157 required: true, 158 message: 'Ве молиме внесете опис!', 159 }, 160 ]} 161 > 162 <Input.TextArea rows={4}/> 163 </Form.Item> 164 <Form.Item 165 label="Оценка" 166 name="stars" 167 rules={[ 168 { 169 required: true, 170 message: 'Ве молиме внесете оценка!', 171 }, 172 ]} 173 > 174 <Rate/> 175 </Form.Item> 176 </Form> 177 </Modal> 94 178 </div> 95 96 179 ) 97 180 } 98 99 181 export default FrontPage; -
frontend/src/auth.js
rcc4db18 r899b19d 21 21 setAuthCookie(res.data.token) 22 22 console.log(res.data.token) 23 setUser( true)23 setUser(res.data) 24 24 setLoading(false) 25 history( '/dashboard')25 history(res.data.isAdmin ? '/dashboard' : '/') 26 26 }).catch(el => { 27 27 Modal.error({ … … 101 101 axios.post(env.api+'Users/register',{email: attr.email, password: attr.password}).then(res => { 102 102 setAuthCookie(res.data.token) 103 setUser( true)103 setUser(res.data) 104 104 setLoading(false) 105 history( '/dashboard')105 history(res.data.isAdmin ? '/dashboard' : '/') 106 106 }) 107 107 }
Note:
See TracChangeset
for help on using the changeset viewer.