File size: 3,434 Bytes
62c0f7a
ce153ff
5ecce33
ce153ff
5ecce33
9b39693
62c0f7a
 
 
0f20d79
2136ee7
3e4ac0f
96232bb
01f53a6
 
ce153ff
5ecce33
62c0f7a
5ecce33
 
 
 
1410e38
ce153ff
bd128b1
62c0f7a
bd128b1
 
 
 
 
 
01f53a6
 
 
 
 
 
 
 
c6e39c8
 
 
 
 
 
 
 
 
5ecce33
 
 
62c0f7a
5ecce33
 
62c0f7a
5ecce33
3e4ac0f
5ecce33
 
 
 
 
 
9b39693
 
 
 
 
 
 
 
5ecce33
 
 
62c0f7a
bd128b1
 
 
 
 
 
 
 
 
01f53a6
 
 
 
 
 
 
 
 
 
 
62c0f7a
 
 
 
 
 
 
 
0f20d79
 
 
 
 
 
 
 
2136ee7
 
 
 
 
 
 
 
96232bb
 
 
c6e39c8
96232bb
c6e39c8
96232bb
 
bd128b1
5ecce33
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
// frontend/src/App.jsx
import React from "react";
import { Routes, Route, Navigate } from "react-router-dom";
import LoginPage from "./pages/Login";
import StudentDashboard from "./pages/StudentDashboard";
import StudentExams from "./pages/StudentExams";
import AdminLogin from "./pages/AdminLogin";
import AdminDashboard from "./pages/AdminDashboard";
import AdminMembers from "./pages/AdminMembers";
import AdminClasses from "./pages/AdminClasses";
import AdminExams from "./pages/AdminExams";
import InviteAcceptance from "./pages/InviteAcceptance";
import StudentProfile from "./pages/StudentProfile";
import CoachLogin from "./pages/CoachLogin";
import CoachDashboard from "./pages/CoachDashboard";

function RequireStudent({ children }) {
  const stored = localStorage.getItem("karateStudent");
  if (!stored) {
    return <Navigate to="/login" replace />;
  }
  return children;
}

function RequireAdmin({ children }) {
  const stored = sessionStorage.getItem("admin");
  if (!stored) {
    return <Navigate to="/admin/login" replace />;
  }
  return children;
}

function RequireCoach({ children }) {
  const stored = localStorage.getItem("karateCoach");
  if (!stored) {
    return <Navigate to="/coach/login" replace />;
  }
  return children;
}

function RequireAdminOrCoach({ children }) {
  const storedAdmin = sessionStorage.getItem("admin");
  const storedCoach = localStorage.getItem("karateCoach");
  if (!storedAdmin && !storedCoach) {
    return <Navigate to="/login" replace />;
  }
  return children;
}

export default function App() {
  return (
    <Routes>
      {/* Root goes to student login for now */}
      <Route path="/" element={<Navigate to="/login" replace />} />

      {/* Student auth */}
      <Route path="/login" element={<LoginPage />} />
      <Route path="/invite/:token" element={<InviteAcceptance />} />
      <Route
        path="/student"
        element={
          <RequireStudent>
            <StudentDashboard />
          </RequireStudent>
        }
      />
      <Route
        path="/student/exams"
        element={
          <RequireStudent>
            <StudentExams />
          </RequireStudent>
        }
      />

      {/* Admin auth */}
      <Route path="/admin/login" element={<AdminLogin />} />
      <Route
        path="/admin"
        element={
          <RequireAdmin>
            <AdminDashboard />
          </RequireAdmin>
        }
      />
      
      {/* Coach auth */}
      <Route path="/coach/login" element={<CoachLogin />} />
      <Route
        path="/coach"
        element={
          <RequireCoach>
            <CoachDashboard />
          </RequireCoach>
        }
      />
      <Route
        path="/admin/members"
        element={
          <RequireAdmin>
            <AdminMembers />
          </RequireAdmin>
        }
      />
      <Route
        path="/admin/classes"
        element={
          <RequireAdmin>
            <AdminClasses />
          </RequireAdmin>
        }
      />
      <Route
        path="/admin/exams"
        element={
          <RequireAdmin>
            <AdminExams />
          </RequireAdmin>
        }
      />
      <Route
        path="/admin/students/:id"
        element={
          <RequireAdminOrCoach>
            <StudentProfile />
          </RequireAdminOrCoach>
        }
      />

      {/* Fallback */}
      <Route path="*" element={<Navigate to="/login" replace />} />
    </Routes>
  );
}