- Timestamp:
- 08/09/22 16:09:32 (2 years ago)
- Branches:
- master
- Children:
- a569b7c
- Parents:
- 899b19d
- Location:
- frontend/src
- Files:
-
- 4 added
- 8 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
frontend/src/App.js
r899b19d ra26f6a1 6 6 import {Spin} from "antd"; 7 7 import React, {useEffect, useState} from "react"; 8 import {Login, Register} from "./ auth";8 import {Login, Register} from "./Auth/auth"; 9 9 import Dashboard from "./Dashboard"; 10 10 import Reservations from "./Dashboard/Reservations"; … … 13 13 import Menu from "./Dashboard/Menu"; 14 14 import Review from "./Dashboard/Review"; 15 import Confirm from "./Auth/Confirm"; 16 import SendConfirm from "./Auth/SendConfirm"; 17 import SendReset from "./Auth/SendReset"; 18 import Reset from "./Auth/Reset"; 15 19 16 20 17 21 function App() { 18 22 const [user, setUser] = useState(undefined) 19 const [loading, setLoading] = useState( false)23 const [loading, setLoading] = useState(true) 20 24 useEffect(()=>{ 21 25 getUser() … … 24 28 const getUser = () => { 25 29 setLoading(true) 26 axios.get(env.api+'Users/authed',{headers:{Authorization: sessionStorage.getItem('Auth')}}).then(res=>{27 console.log( !res.data)30 axios.get(env.api+'Users/authed',{headers:{Authorization:localStorage.getItem('Auth')}}).then(res=>{ 31 console.log(res.data) 28 32 setUser(res.data) 29 33 setLoading(false) … … 32 36 const logout = () => { 33 37 setUser(undefined); 34 sessionStorage.removeItem('Auth');38 localStorage.removeItem('Auth'); 35 39 window.location.replace('/') 36 40 } … … 48 52 <Route path="/login" element={loading ? <Spin /> : !user ? <Login setUser={setUser}/> : <Navigate to="/dashboard" replace={true} />}/> 49 53 <Route path="/register" element={loading ? <Spin /> : !user ? <Register setUser={setUser}/> : <Navigate to="/dashboard" replace={true} />}/> 54 <Route path="/reset-password" element={loading ? <Spin /> : <SendReset/>}/> 55 <Route path="/reset" element={loading ? <Spin /> : <Reset/>}/> 56 <Route path="/confirm" element={loading ? <Spin /> : <Confirm setUser={setUser} user={user}/>}/> 57 <Route path="/confirm-email" element={loading ? <Spin /> : <SendConfirm setUser={setUser} user={user}/>}/> 50 58 <Route path="/" element={<FrontPage user={user} logout={logout}/>}/> 51 59 </Routes> -
frontend/src/Auth/auth.js
r899b19d ra26f6a1 4 4 import { UserOutlined, LockOutlined } from '@ant-design/icons'; 5 5 import axios from "axios"; 6 import '. /App.css'7 import env from ". /env";6 import '../App.css' 7 import env from "../env"; 8 8 9 9 const setAuthCookie = (token) => { 10 sessionStorage.setItem('Auth','Bearer '+token)10 localStorage.setItem('Auth','Bearer '+token) 11 11 } 12 12 … … 103 103 setUser(res.data) 104 104 setLoading(false) 105 history( res.data.isAdmin ? '/dashboard' : '/')105 history('/confirm-email') 106 106 }) 107 107 } -
frontend/src/Dashboard.js
r899b19d ra26f6a1 11 11 const history = useNavigate() 12 12 const logout = () => { 13 sessionStorage.removeItem('Auth');13 localStorage.removeItem('Auth'); 14 14 setUser(false) 15 15 } -
frontend/src/Dashboard/Menu.js
r899b19d ra26f6a1 25 25 const addMenu = (data) => { 26 26 setLoadingSave(true); 27 axios.post(env.api + 'Menu/',{...data,price: parseInt(data.price)}, { headers: {Authorization: sessionStorage.getItem('Auth')}27 axios.post(env.api + 'Menu/',{...data,price: parseInt(data.price)}, { headers: {Authorization: localStorage.getItem('Auth')} 28 28 }).then(res => { 29 29 notification['success']({ … … 42 42 43 43 const deleteMenu = (id) => { 44 axios.delete(env.api + 'Menu/'+id, {headers: {Authorization: sessionStorage.getItem('Auth')}44 axios.delete(env.api + 'Menu/'+id, {headers: {Authorization: localStorage.getItem('Auth')} 45 45 }).then(res => { 46 46 notification['success']({ -
frontend/src/Dashboard/Reservations.js
r899b19d ra26f6a1 26 26 from: date[0].format('YYYY-MM-DDThh:mm:ss') + 'Z', 27 27 to: date[1].format('YYYY-MM-DDThh:mm:ss') + 'Z' 28 }, headers: {Authorization: sessionStorage.getItem('Auth')}28 }, headers: {Authorization: localStorage.getItem('Auth')} 29 29 }).then(res => { 30 30 axios.get(env.api + 'Reservations/new', { 31 headers: {Authorization: sessionStorage.getItem('Auth')}31 headers: {Authorization: localStorage.getItem('Auth')} 32 32 }).then(newres=>{ 33 33 setNewReservations(newres.data); … … 54 54 params: { 55 55 status: newStatus 56 }, headers: {Authorization: sessionStorage.getItem('Auth')}56 }, headers: {Authorization: localStorage.getItem('Auth')} 57 57 }).then(res => { 58 58 getReservations() … … 68 68 params: { 69 69 tableId: ev.target.value == '' ? 0 : ev.target.value 70 }, headers: {Authorization: sessionStorage.getItem('Auth')}70 }, headers: {Authorization: localStorage.getItem('Auth')} 71 71 }).then(res => { 72 72 console.log("success"); -
frontend/src/Dashboard/Restaurant.js
r899b19d ra26f6a1 37 37 const submitEdit = (form) => { 38 38 setLoadingSave(true); 39 axios.put(env.api + 'Restaurants/',{...form}, { headers: {Authorization: sessionStorage.getItem('Auth')}39 axios.put(env.api + 'Restaurants/',{...form}, { headers: {Authorization: localStorage.getItem('Auth')} 40 40 }).then(res => { 41 41 notification['success']({ -
frontend/src/Dashboard/Review.js
r899b19d ra26f6a1 1 1 import React, {useEffect, useState} from 'react' 2 import {Button, Card, Input, List, Rate, Spin, Tooltip} from "antd";2 import {Button, Card, Input, List, notification, Rate, Spin, Tooltip} from "antd"; 3 3 import axios from "axios"; 4 4 import env from "../env"; … … 12 12 setLoading(true); 13 13 getRestaurant() 14 console.log(props.user) 14 15 },[]) 15 16 useEffect(()=> { … … 36 37 {props.front ? 37 38 (props.user? 38 <Button style={{float:'right'}} type={'primary'} onClick={()=>props. setVisible(true)}>Внеси оценка</Button>39 <Button style={{float:'right'}} type={'primary'} onClick={()=>props.user.isConfirmed ? props.setVisible(true) : notification['error']({message: <p>Мора да го потврдите вашиот мејл за да оставите оценка. <a href={'/confirm-email'}>Потврдете го тука</a></p>})}>Внеси оценка</Button> 39 40 : <Tooltip title={'Мора да се најавите за да оставите оценка'}><Button style={{float:'right'}} disabled type={'primary'} onClick={()=>props.setVisible(true)}>Внеси оценка</Button></Tooltip>) 40 41 : '' -
frontend/src/FrontPage.js
r899b19d ra26f6a1 1 1 import React, {useState, useEffect} from 'react' 2 2 import {Header} from "./Header"; 3 import { useNavigate} from "react-router-dom";3 import {Link, useNavigate} from "react-router-dom"; 4 4 import {Button, Card, DatePicker, Form, Image, Input, Modal, notification, Rate, Spin} from "antd"; 5 5 import placeholderImage from '../src/Assets/placeholder.png' … … 26 26 },[]) 27 27 28 useEffect(()=>{ 29 if(user && !user.isConfirmed) { 30 notification['warning']({ 31 message: <p>Вашиот емаил не е потврден. <a href={'/confirm-email'}>Потврдете го тука</a></p> 32 }); 33 } 34 },[user]) 35 28 36 const saveNewReview = data =>{ 29 37 setSaveModalLoading(true) 30 axios.post(env.api + 'Reviews',data,{ headers: {Authorization: sessionStorage.getItem('Auth')}}).then(res=>{38 axios.post(env.api + 'Reviews',data,{ headers: {Authorization: localStorage.getItem('Auth')}}).then(res=>{ 31 39 setNewReviewModal(false) 32 40 setSaveModalLoading(false) -
frontend/src/index.js
r899b19d ra26f6a1 6 6 const root = ReactDOM.createRoot(document.getElementById('root')); 7 7 root.render( 8 <React.StrictMode>9 8 <App /> 10 </React.StrictMode>11 9 );
Note:
See TracChangeset
for help on using the changeset viewer.