initial commit
This commit is contained in:
@@ -0,0 +1,112 @@
|
||||
import React from 'react';
|
||||
import { Routes, Route, Navigate } from 'react-router-dom';
|
||||
import { useParticipant } from '../contexts/ParticipantContext';
|
||||
import { useAdmin } from '../contexts/AdminContext';
|
||||
|
||||
// Pages
|
||||
import Hub from '../pages/Hub';
|
||||
import EventLanding from '../pages/EventLanding';
|
||||
import LessonView from '../pages/LessonView';
|
||||
import ParticipantProgress from '../pages/ParticipantProgress';
|
||||
import AdminLogin from '../pages/admin/AdminLogin';
|
||||
import AdminDashboard from '../pages/admin/AdminDashboard';
|
||||
import EventManagement from '../pages/admin/EventManagement';
|
||||
import LessonConfiguration from '../pages/admin/LessonConfiguration';
|
||||
import ParticipantData from '../pages/admin/ParticipantData';
|
||||
|
||||
// Protected route for participants
|
||||
const ParticipantRoute = ({ children }) => {
|
||||
const { isAuthenticated, loading } = useParticipant();
|
||||
|
||||
if (loading) {
|
||||
return <div className="loading">Loading...</div>;
|
||||
}
|
||||
|
||||
return isAuthenticated ? children : <Navigate to="/" />;
|
||||
};
|
||||
|
||||
// Protected route for admin
|
||||
const AdminRoute = ({ children }) => {
|
||||
const { isAuthenticated, loading } = useAdmin();
|
||||
|
||||
if (loading) {
|
||||
return <div className="loading">Loading...</div>;
|
||||
}
|
||||
|
||||
return isAuthenticated ? children : <Navigate to="/admin/login" />;
|
||||
};
|
||||
|
||||
const AppRoutes = () => {
|
||||
return (
|
||||
<Routes>
|
||||
{/* Public routes */}
|
||||
<Route path="/" element={<Hub />} />
|
||||
<Route path="/admin/login" element={<AdminLogin />} />
|
||||
|
||||
{/* Participant routes */}
|
||||
<Route
|
||||
path="/event"
|
||||
element={
|
||||
<ParticipantRoute>
|
||||
<EventLanding />
|
||||
</ParticipantRoute>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path="/lesson/:eventLessonId"
|
||||
element={
|
||||
<ParticipantRoute>
|
||||
<LessonView />
|
||||
</ParticipantRoute>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path="/progress"
|
||||
element={
|
||||
<ParticipantRoute>
|
||||
<ParticipantProgress />
|
||||
</ParticipantRoute>
|
||||
}
|
||||
/>
|
||||
|
||||
{/* Admin routes */}
|
||||
<Route
|
||||
path="/admin"
|
||||
element={
|
||||
<AdminRoute>
|
||||
<AdminDashboard />
|
||||
</AdminRoute>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path="/admin/events"
|
||||
element={
|
||||
<AdminRoute>
|
||||
<EventManagement />
|
||||
</AdminRoute>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path="/admin/events/:eventId/lessons"
|
||||
element={
|
||||
<AdminRoute>
|
||||
<LessonConfiguration />
|
||||
</AdminRoute>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path="/admin/events/:eventId/participants"
|
||||
element={
|
||||
<AdminRoute>
|
||||
<ParticipantData />
|
||||
</AdminRoute>
|
||||
}
|
||||
/>
|
||||
|
||||
{/* 404 */}
|
||||
<Route path="*" element={<Navigate to="/" />} />
|
||||
</Routes>
|
||||
);
|
||||
};
|
||||
|
||||
export default AppRoutes;
|
||||
Reference in New Issue
Block a user