2022-11-17 13:33:59 +01:00
|
|
|
import React, { useEffect } from 'react';
|
2022-11-20 17:39:39 +01:00
|
|
|
import { BrowserRouter, Navigate, Route, Routes} from 'react-router-dom';
|
2022-11-17 13:33:59 +01:00
|
|
|
|
|
|
|
import './css/App.css';
|
|
|
|
import Home from './pages/Home';
|
|
|
|
import ErrorBoundary from './util/ErrorBoundary';
|
|
|
|
import Sidebar, { SidebarMenu } from './components/Sidebar';
|
|
|
|
import UserControls from './components/UserControls';
|
|
|
|
import { useLoginContext } from './structures/UserContext';
|
|
|
|
import Login from './pages/Login';
|
|
|
|
import { fetchUser } from './util/Util';
|
2022-11-20 17:39:39 +01:00
|
|
|
import PrivateRoute from './structures/PrivateRoute';
|
|
|
|
import { UnauthedRoute } from './structures/UnauthedRoute';
|
|
|
|
import Users from './pages/Users';
|
|
|
|
import Admin from './pages/Admin';
|
2022-11-15 19:33:00 +01:00
|
|
|
|
|
|
|
function App() {
|
2022-11-17 13:33:59 +01:00
|
|
|
|
|
|
|
const [user] = useLoginContext();
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
fetchUser();
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
const menuItems = [
|
2022-11-20 17:39:39 +01:00
|
|
|
{ to: '/home', label: 'Home' },
|
2022-11-17 13:33:59 +01:00
|
|
|
{ to: '/users', label: 'Users' },
|
|
|
|
{ to: '/admin', label: 'Admin' }
|
2022-11-17 22:11:52 +01:00
|
|
|
|
2022-11-17 13:33:59 +01:00
|
|
|
];
|
|
|
|
|
2022-11-15 19:33:00 +01:00
|
|
|
return (
|
2022-11-17 13:33:59 +01:00
|
|
|
<div className='app'>
|
|
|
|
|
|
|
|
<header>
|
|
|
|
<UserControls />
|
2022-11-15 19:33:00 +01:00
|
|
|
</header>
|
2022-11-17 13:33:59 +01:00
|
|
|
|
2022-11-20 17:39:39 +01:00
|
|
|
<div className='background'>
|
2022-11-17 13:33:59 +01:00
|
|
|
|
|
|
|
<BrowserRouter>
|
|
|
|
|
2022-11-20 17:39:39 +01:00
|
|
|
{user ?
|
2022-11-17 13:33:59 +01:00
|
|
|
<Sidebar>
|
|
|
|
SIDEBAR
|
2022-11-20 17:39:39 +01:00
|
|
|
<SidebarMenu menuItems={menuItems} />
|
2022-11-17 13:33:59 +01:00
|
|
|
</Sidebar>
|
2022-11-20 17:39:39 +01:00
|
|
|
: null}
|
2022-11-17 13:33:59 +01:00
|
|
|
|
|
|
|
<div className='main-content'>
|
|
|
|
<ErrorBoundary>
|
|
|
|
<Routes>
|
2022-11-20 17:39:39 +01:00
|
|
|
<Route path='/home/*' element={<PrivateRoute><Home /></PrivateRoute >} />
|
|
|
|
<Route path='/users/*' element={<PrivateRoute><Users /></PrivateRoute >} />
|
|
|
|
<Route path='/admin/*' element={<PrivateRoute><Admin /></PrivateRoute >} />
|
|
|
|
<Route path='/login/*' element={<UnauthedRoute><Login /></UnauthedRoute>} />
|
|
|
|
<Route path='*' element={<Navigate to='/home' />} />
|
2022-11-17 13:33:59 +01:00
|
|
|
</Routes>
|
|
|
|
</ErrorBoundary>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
</BrowserRouter>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
2022-11-15 19:33:00 +01:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default App;
|