2025-01-11 02:22:14 -05:00
|
|
|
import React from 'react';
|
2025-02-21 14:48:21 -05:00
|
|
|
import { useEffect, useState } from 'react';
|
|
|
|
|
import { Routes, Route, Navigate, useLocation } from 'react-router-dom';
|
2024-03-29 20:08:34 -04:00
|
|
|
|
|
|
|
|
// Page main
|
|
|
|
|
import Home from './pages/Home/Home';
|
|
|
|
|
|
|
|
|
|
// Pages espace enseignant
|
|
|
|
|
import Dashboard from './pages/Teacher/Dashboard/Dashboard';
|
|
|
|
|
import Share from './pages/Teacher/Share/Share';
|
2025-02-21 14:48:21 -05:00
|
|
|
import Register from './pages/AuthManager/providers/SimpleLogin/Register';
|
|
|
|
|
import ResetPassword from './pages/AuthManager/providers/SimpleLogin/ResetPassword';
|
2024-03-29 20:08:34 -04:00
|
|
|
import ManageRoom from './pages/Teacher/ManageRoom/ManageRoom';
|
|
|
|
|
import QuizForm from './pages/Teacher/EditorQuiz/EditorQuiz';
|
|
|
|
|
|
|
|
|
|
// Pages espace étudiant
|
|
|
|
|
import JoinRoom from './pages/Student/JoinRoom/JoinRoom';
|
|
|
|
|
|
2025-02-21 14:48:21 -05:00
|
|
|
// Pages authentification selection
|
|
|
|
|
import AuthDrawer from './pages/AuthManager/AuthDrawer';
|
|
|
|
|
|
2024-03-29 20:08:34 -04:00
|
|
|
// Header/Footer import
|
|
|
|
|
import Header from './components/Header/Header';
|
|
|
|
|
import Footer from './components/Footer/Footer';
|
|
|
|
|
|
|
|
|
|
import ApiService from './services/ApiService';
|
2025-02-21 14:48:21 -05:00
|
|
|
import OAuthCallback from './pages/AuthManager/callback/AuthCallback';
|
|
|
|
|
|
2025-03-16 00:52:22 -04:00
|
|
|
import Users from './pages/Admin/Users';
|
|
|
|
|
import Images from './pages/Admin/Images';
|
|
|
|
|
import Stats from './pages/Admin/Stats';
|
|
|
|
|
|
|
|
|
|
|
2025-02-21 14:48:21 -05:00
|
|
|
const App: React.FC = () => {
|
|
|
|
|
const [isAuthenticated, setIsAuthenticated] = useState(ApiService.isLoggedIn());
|
|
|
|
|
const [isTeacherAuthenticated, setIsTeacherAuthenticated] = useState(ApiService.isLoggedInTeacher());
|
2025-04-02 20:40:36 -04:00
|
|
|
const [isAdmin, setIsAdmin] = useState(false);
|
2025-02-21 14:48:21 -05:00
|
|
|
const [isRoomRequireAuthentication, setRoomsRequireAuth] = useState(null);
|
|
|
|
|
const location = useLocation();
|
|
|
|
|
|
|
|
|
|
// Check login status every time the route changes
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
const checkLoginStatus = () => {
|
|
|
|
|
setIsAuthenticated(ApiService.isLoggedIn());
|
|
|
|
|
setIsTeacherAuthenticated(ApiService.isLoggedInTeacher());
|
2025-04-02 20:40:36 -04:00
|
|
|
setIsAdmin(ApiService.isAdmin());
|
2025-02-21 14:48:21 -05:00
|
|
|
};
|
2024-03-29 20:08:34 -04:00
|
|
|
|
2025-02-21 14:48:21 -05:00
|
|
|
const fetchAuthenticatedRooms = async () => {
|
|
|
|
|
const data = await ApiService.getRoomsRequireAuth();
|
|
|
|
|
setRoomsRequireAuth(data);
|
|
|
|
|
};
|
2024-03-29 20:08:34 -04:00
|
|
|
|
2025-02-21 14:48:21 -05:00
|
|
|
checkLoginStatus();
|
|
|
|
|
fetchAuthenticatedRooms();
|
|
|
|
|
}, [location]);
|
|
|
|
|
|
|
|
|
|
const handleLogout = () => {
|
|
|
|
|
ApiService.logout();
|
|
|
|
|
setIsAuthenticated(false);
|
|
|
|
|
setIsTeacherAuthenticated(false);
|
|
|
|
|
};
|
2024-03-29 20:08:34 -04:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="content">
|
2025-04-02 20:40:36 -04:00
|
|
|
<Header isLoggedIn={isAuthenticated} isAdmin={isAdmin} handleLogout={handleLogout} />
|
2024-03-29 20:08:34 -04:00
|
|
|
<div className="app">
|
|
|
|
|
<main>
|
|
|
|
|
<Routes>
|
|
|
|
|
{/* Page main */}
|
|
|
|
|
<Route path="/" element={<Home />} />
|
|
|
|
|
|
|
|
|
|
{/* Pages espace enseignant */}
|
2025-02-21 14:48:21 -05:00
|
|
|
<Route
|
|
|
|
|
path="/teacher/dashboard"
|
|
|
|
|
element={isTeacherAuthenticated ? <Dashboard /> : <Navigate to="/login" />}
|
|
|
|
|
/>
|
|
|
|
|
<Route
|
|
|
|
|
path="/teacher/share/:id"
|
|
|
|
|
element={isTeacherAuthenticated ? <Share /> : <Navigate to="/login" />}
|
|
|
|
|
/>
|
|
|
|
|
<Route
|
|
|
|
|
path="/teacher/editor-quiz/:id"
|
|
|
|
|
element={isTeacherAuthenticated ? <QuizForm /> : <Navigate to="/login" />}
|
|
|
|
|
/>
|
|
|
|
|
<Route
|
2025-03-06 09:47:27 -05:00
|
|
|
path="/teacher/manage-room/:quizId/:roomName"
|
2025-02-21 14:48:21 -05:00
|
|
|
element={isTeacherAuthenticated ? <ManageRoom /> : <Navigate to="/login" />}
|
|
|
|
|
/>
|
2024-03-29 20:08:34 -04:00
|
|
|
|
|
|
|
|
{/* Pages espace étudiant */}
|
2025-02-21 14:48:21 -05:00
|
|
|
<Route
|
|
|
|
|
path="/student/join-room"
|
|
|
|
|
element={( !isRoomRequireAuthentication || isAuthenticated ) ? <JoinRoom /> : <Navigate to="/login" />}
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
{/* Pages authentification */}
|
|
|
|
|
<Route path="/login" element={<AuthDrawer />} />
|
|
|
|
|
|
|
|
|
|
{/* Pages enregistrement */}
|
|
|
|
|
<Route path="/register" element={<Register />} />
|
|
|
|
|
|
|
|
|
|
{/* Pages rest password */}
|
|
|
|
|
<Route path="/resetPassword" element={<ResetPassword />} />
|
|
|
|
|
|
|
|
|
|
{/* Pages authentification sélection */}
|
|
|
|
|
<Route path="/auth/callback" element={<OAuthCallback />} />
|
2025-03-16 00:52:22 -04:00
|
|
|
|
|
|
|
|
<Route path="/admin/stats" element={<Stats />} />
|
|
|
|
|
<Route path="/admin/images" element={<Images />} />
|
|
|
|
|
<Route path="/admin/users" element={<Users />} />
|
|
|
|
|
|
2024-03-29 20:08:34 -04:00
|
|
|
</Routes>
|
|
|
|
|
</main>
|
|
|
|
|
</div>
|
2025-02-21 14:48:21 -05:00
|
|
|
<Footer />
|
2024-03-29 20:08:34 -04:00
|
|
|
</div>
|
|
|
|
|
);
|
2025-02-21 14:48:21 -05:00
|
|
|
};
|
2024-03-29 20:08:34 -04:00
|
|
|
|
|
|
|
|
export default App;
|