|
@@ -1,5 +1,5 @@
|
|
|
import React from 'react';
|
|
import React from 'react';
|
|
|
-import { createBrowserRouter, Navigate } from 'react-router';
|
|
|
|
|
|
|
+import { createBrowserRouter, Navigate, useParams } from 'react-router';
|
|
|
import { ProtectedRoute } from './components/ProtectedRoute';
|
|
import { ProtectedRoute } from './components/ProtectedRoute';
|
|
|
import { ErrorPage } from './components/ErrorPage';
|
|
import { ErrorPage } from './components/ErrorPage';
|
|
|
import { NotFoundPage } from './components/NotFoundPage';
|
|
import { NotFoundPage } from './components/NotFoundPage';
|
|
@@ -19,6 +19,32 @@ import ExamAdmin from './components/Exam/ExamAdmin';
|
|
|
import ExamCard from './components/Exam/ExamCard';
|
|
import ExamCard from './components/Exam/ExamCard';
|
|
|
import MemberPage from './pages/MemberPage';
|
|
import MemberPage from './pages/MemberPage';
|
|
|
import { MainLayout } from './layouts/MainLayout';
|
|
import { MainLayout } from './layouts/MainLayout';
|
|
|
|
|
+import { getGlobalConfig } from '../utils/utils';
|
|
|
|
|
+import { UserType } from '@/server/modules/users/user.enum';
|
|
|
|
|
+import { useAuth } from './hooks/AuthProvider';
|
|
|
|
|
+
|
|
|
|
|
+const PublicClassroomPage = () => <ClassroomPage />;
|
|
|
|
|
+const PrivateClassroomPage = () => <ClassroomPage />;
|
|
|
|
|
+const RouteClassroomPage = () => {
|
|
|
|
|
+ let params = useParams()
|
|
|
|
|
+ if( params.classId == getGlobalConfig('PUBLIC_CHATROOM_ID'))
|
|
|
|
|
+ return <PublicClassroomPage />
|
|
|
|
|
+ else
|
|
|
|
|
+ return <PrivateClassroomPage />
|
|
|
|
|
+}
|
|
|
|
|
+const HomeClassroomPage = () => {
|
|
|
|
|
+ const { user } = useAuth();
|
|
|
|
|
+
|
|
|
|
|
+ const getUrl = (classId = '') => {
|
|
|
|
|
+ if (user?.userType === UserType.TEACHER) {
|
|
|
|
|
+ return `/mobile/classroom/${classId}/${UserType.TEACHER}`;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return `/mobile/classroom/${classId}/${UserType.STUDENT}`;
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ return <Navigate to={getUrl(getGlobalConfig('PUBLIC_CHATROOM_ID'))} replace />
|
|
|
|
|
+};
|
|
|
|
|
|
|
|
export const router = createBrowserRouter([
|
|
export const router = createBrowserRouter([
|
|
|
{
|
|
{
|
|
@@ -47,7 +73,7 @@ export const router = createBrowserRouter([
|
|
|
children: [
|
|
children: [
|
|
|
{
|
|
{
|
|
|
path: '',
|
|
path: '',
|
|
|
- element: <StockHomePage />
|
|
|
|
|
|
|
+ element: <HomeClassroomPage />
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
path: 'member',
|
|
path: 'member',
|
|
@@ -55,7 +81,7 @@ export const router = createBrowserRouter([
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
path: 'classroom/:classId/:role',
|
|
path: 'classroom/:classId/:role',
|
|
|
- element: <ProtectedRoute><ClassroomPage /></ProtectedRoute>,
|
|
|
|
|
|
|
+ element: <ProtectedRoute><RouteClassroomPage /></ProtectedRoute>,
|
|
|
errorElement: <ErrorPage />
|
|
errorElement: <ErrorPage />
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|