summaryrefslogtreecommitdiff
path: root/src/app/AuthenticatedApp.js
diff options
context:
space:
mode:
authorLeonardo Murça <106257713+leomurca@users.noreply.github.com>2023-02-07 20:40:41 -0300
committerGitHub <noreply@github.com>2023-02-07 20:40:41 -0300
commit8eca8b79ce4bfc40f8416309cbcfe397ed935ec4 (patch)
treeca4152122b67605e76f7a53ed1a14402255b23aa /src/app/AuthenticatedApp.js
parente3de3c8e5fe06f7d14b2dc99a8b6aadc3b9bf18a (diff)
parentc1f1286c86a47b87abcca55cbd0177d2a9c92fcd (diff)
Merge pull request #20 from leomurca/feature/professor_classroomHEADmain
Feature/professor classroom
Diffstat (limited to 'src/app/AuthenticatedApp.js')
-rw-r--r--src/app/AuthenticatedApp.js41
1 files changed, 18 insertions, 23 deletions
diff --git a/src/app/AuthenticatedApp.js b/src/app/AuthenticatedApp.js
index 80d66be..b4a9412 100644
--- a/src/app/AuthenticatedApp.js
+++ b/src/app/AuthenticatedApp.js
@@ -1,22 +1,20 @@
-import { Navigate, Route, Routes, useNavigate } from 'react-router-dom';
+import { lazy } from 'react';
+import { useNavigate } from 'react-router-dom';
import { Container } from '@mui/system';
-import { useUser } from '../context/user';
import { useAuthState } from '../context/auth';
+import { useUser } from '../context/user';
import MainMenu from '../components/MainMenu';
-import Home from '../screens/Home';
-import Information from '../screens/Information';
-import Calendar from '../screens/Calendar';
import useLayoutType from '../hooks/useLayoutType';
import Toolbar from '../components/Toolbar';
-import Classroom from '../screens/Classroom';
-import Assignment from '../screens/Assignment';
-import Profile from '../screens/Profile';
import { avatarMenuOptions, menuOptions } from './data';
import styles from './styles';
+const StudentRoutes = lazy(() => import('./StudentRoutes'));
+const ProfessorRoutes = lazy(() => import('./ProfessorRoutes'));
+
function AuthenticatedApp() {
const navigate = useNavigate();
const { state } = useUser();
@@ -24,6 +22,17 @@ function AuthenticatedApp() {
const layoutType = useLayoutType();
const { container, toolbar } = styles[layoutType];
+ const routeResolver = role => {
+ switch (role) {
+ case 'STUDENT':
+ return <StudentRoutes />;
+ case 'PROFESSOR':
+ return <ProfessorRoutes />;
+ default:
+ return null;
+ }
+ };
+
return (
state &&
state.user && (
@@ -43,21 +52,7 @@ function AuthenticatedApp() {
options={menuOptions(state.pathname)}
layoutType={layoutType}
/>
- <Routes>
- <Route path="/home" element={<Home />} />
- <Route path="/info" element={<Information />} />
- <Route path="/calendar" element={<Calendar />} />
- <Route path="/profile" element={<Profile />} />
- <Route path="/class">
- <Route path=":id" element={<Classroom />} />
- </Route>
- <Route path="/assignment">
- <Route path=":id" element={<Assignment />} />
- </Route>
- <Route path="/login" element={<Navigate to="/home" />} />
- <Route path="/register" element={<Navigate to="/home" />} />
- <Route path="/" element={<Navigate to="/home" />} />
- </Routes>
+ {routeResolver(state.user.role)}
</Container>
</>
)