1 | import './App.css';
|
---|
2 | import {Route, BrowserRouter as Router, Navigate, Routes} from "react-router-dom";
|
---|
3 | import axios from 'axios'
|
---|
4 | import env from './env'
|
---|
5 |
|
---|
6 | import {Spin} from "antd";
|
---|
7 | import React, {useEffect, useState} from "react";
|
---|
8 | import {Login, Register} from "./auth";
|
---|
9 | import Dashboard from "./Dashboard";
|
---|
10 | import Reservations from "./Dashboard/Reservations";
|
---|
11 | import FrontPage from "./FrontPage";
|
---|
12 |
|
---|
13 |
|
---|
14 | function App() {
|
---|
15 | const [user, setUser] = useState(false)
|
---|
16 | const [loading, setLoading] = useState(false)
|
---|
17 | useEffect(()=>{
|
---|
18 | getUser()
|
---|
19 | },[])
|
---|
20 |
|
---|
21 | const getUser = () => {
|
---|
22 | setLoading(true)
|
---|
23 | axios.get(env.api+'Users/authed',{headers:{Authorization:sessionStorage.getItem('Auth')}}).then(res=>{
|
---|
24 | console.log(!res.data)
|
---|
25 | setUser(res.data)
|
---|
26 | setLoading(false)
|
---|
27 | })
|
---|
28 | }
|
---|
29 | return (
|
---|
30 | <div style={{textAlign:'center'}}>
|
---|
31 | <Router>
|
---|
32 | <Routes>
|
---|
33 | <Route path="/dashboard" element={loading ? <Spin /> : user ?<Dashboard setUser={setUser}/> : <Navigate to="/login" replace={true} />}>
|
---|
34 | <Route path="/dashboard" element={'edit restaurant'}/>
|
---|
35 | <Route path="/dashboard/menu" element={'menu'}/>
|
---|
36 | <Route path="/dashboard/reservations" element={<Reservations/>}/>
|
---|
37 | <Route path="/dashboard/reviews" element={'reviews'}/>
|
---|
38 | <Route path="/dashboard/todo" element={'todo'}/>
|
---|
39 | </Route>
|
---|
40 | <Route path="/login" element={loading ? <Spin /> : !user ? <Login setUser={setUser}/> : <Navigate to="/dashboard" replace={true} />}/>
|
---|
41 | <Route path="/register" element={loading ? <Spin /> : !user ? <Register setUser={setUser}/> : <Navigate to="/dashboard" replace={true} />}/>
|
---|
42 | <Route path="/" element={<FrontPage/>}/>
|
---|
43 | </Routes>
|
---|
44 | </Router>
|
---|
45 | </div>
|
---|
46 | );
|
---|
47 | }
|
---|
48 |
|
---|
49 | export default App;
|
---|