mirror of
https://github.com/hazemKrimi/crimson-quirks-ui.git
synced 2026-05-01 18:20:28 +00:00
Update app routing
This commit is contained in:
+26
-7
@@ -1,27 +1,45 @@
|
|||||||
import { useEffect } from 'react';
|
import { useEffect } from 'react';
|
||||||
import { Switch } from 'react-router-dom';
|
import { Switch } from 'react-router-dom';
|
||||||
import { ProtectedRoute, AuthRoute } from './components';
|
import { useReactiveVar } from '@apollo/client';
|
||||||
import { tokenVar } from './graphql/state';
|
import { ProtectedRoute, AuthRoute, Navbar, Sidebar } from './components';
|
||||||
|
import { roleVar, tokenVar } from './graphql/state';
|
||||||
import {
|
import {
|
||||||
AdditionalInfo,
|
AdditionalInfo,
|
||||||
ForgotPassword,
|
ForgotPassword,
|
||||||
Login,
|
Login,
|
||||||
RecoverAccount,
|
RecoverAccount,
|
||||||
Signup,
|
Signup,
|
||||||
Main,
|
Project,
|
||||||
|
Settings,
|
||||||
} from './pages';
|
} from './pages';
|
||||||
|
|
||||||
const App = () => {
|
const App = () => {
|
||||||
useEffect(() => {
|
const token = useReactiveVar(tokenVar);
|
||||||
const token = localStorage.getItem('token');
|
const role = useReactiveVar(roleVar);
|
||||||
|
|
||||||
if (token) tokenVar(token);
|
useEffect(() => {
|
||||||
|
const localStorageToken = localStorage.getItem('token');
|
||||||
|
|
||||||
|
if (localStorageToken) tokenVar(localStorageToken);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
<>
|
||||||
|
{token && (
|
||||||
|
<>
|
||||||
|
<Navbar withSidebar={role !== 'admin'} />
|
||||||
|
{role !== 'admin' && <Sidebar />}
|
||||||
|
</>
|
||||||
|
)}
|
||||||
<Switch>
|
<Switch>
|
||||||
<ProtectedRoute path='/' exact>
|
<ProtectedRoute path='/' exact>
|
||||||
<Main />
|
<Project />
|
||||||
|
</ProtectedRoute>
|
||||||
|
<ProtectedRoute path='/project' exact>
|
||||||
|
<Project />
|
||||||
|
</ProtectedRoute>
|
||||||
|
<ProtectedRoute path='/settings' exact>
|
||||||
|
<Settings />
|
||||||
</ProtectedRoute>
|
</ProtectedRoute>
|
||||||
<AuthRoute path='/login' exact>
|
<AuthRoute path='/login' exact>
|
||||||
<Login />
|
<Login />
|
||||||
@@ -39,6 +57,7 @@ const App = () => {
|
|||||||
<RecoverAccount />
|
<RecoverAccount />
|
||||||
</AuthRoute>
|
</AuthRoute>
|
||||||
</Switch>
|
</Switch>
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user