Добавлены route на страницы
This commit is contained in:
parent
bd4bcf5e9e
commit
30fb4d3e6a
@ -11,7 +11,7 @@ const Header = ({ routes }) => {
|
||||
const indexPageLink = routes.filter((route) => route.index === false).shift();
|
||||
const currentPage = routes.filter((route) => route.path === location.pathname)[0];
|
||||
if (currentUser) {
|
||||
routes = routes.filter((route) => !route.onlyNoAuthorized);
|
||||
routes = routes.filter((route) => !route.onlyNoAuthorized && route.onlyTeachers == null || route.onlyTeachers == currentUser.isTeacher);
|
||||
}
|
||||
else {
|
||||
routes = routes.filter((route) => !route.onlyAuthorized);
|
||||
|
0
src/hooks/StatementsHook.js
Normal file
0
src/hooks/StatementsHook.js
Normal file
@ -1,5 +1,28 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import UsersApiService from "../services/UsersApiService";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { useContext } from "react";
|
||||
import { CurrentUserContext } from "../contexts/CurrentUserContext";
|
||||
|
||||
export const useOnlyAuthorized = () => {
|
||||
const navigate = useNavigate();
|
||||
const { currentUser } = useContext(CurrentUserContext);
|
||||
useEffect(() => {
|
||||
if (!currentUser) {
|
||||
navigate("/auth");
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export const useOnlyTeachers = () => {
|
||||
const navigate = useNavigate();
|
||||
const { currentUser } = useContext(CurrentUserContext);
|
||||
useEffect(() => {
|
||||
if (!currentUser || !currentUser.isTeacher) {
|
||||
navigate("/auth");
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export const useUserByUsername = (username) => {
|
||||
const [usersRefresh, setUsersRefresh] = useState(false);
|
||||
|
24
src/main.jsx
24
src/main.jsx
@ -10,6 +10,9 @@ import MainPage from './pages/MainPage/MainPage.jsx'
|
||||
import AuthPage from './pages/AuthPage/AuthPage.jsx'
|
||||
import RegisterPage from './pages/RegisterPage/RegisterPage.jsx'
|
||||
import StatementsPage from './pages/StatementsPage/StatementsPage.jsx'
|
||||
import SubjectsPage from './pages/SubjectsPage/SubjectsPage.jsx'
|
||||
import GroupsPage from './pages/GroupsPage/GroupsPage.jsx'
|
||||
import StudentsPage from './pages/StudentsPage/StudentsPage.jsx'
|
||||
|
||||
const routes = [
|
||||
{
|
||||
@ -25,6 +28,27 @@ const routes = [
|
||||
onlyAuthorized: true,
|
||||
onlyTeachers: true
|
||||
},
|
||||
{
|
||||
path: '/groups',
|
||||
element: <GroupsPage />,
|
||||
title: 'Группы',
|
||||
onlyAuthorized: true,
|
||||
onlyTeachers: true
|
||||
},
|
||||
{
|
||||
path: '/students',
|
||||
element: <StudentsPage />,
|
||||
title: 'Студенты',
|
||||
onlyAuthorized: true,
|
||||
onlyTeachers: true
|
||||
},
|
||||
{
|
||||
path: '/subjects',
|
||||
element: <SubjectsPage />,
|
||||
title: 'Предметы',
|
||||
onlyAuthorized: true,
|
||||
onlyTeachers: true
|
||||
},
|
||||
{
|
||||
path: '/auth',
|
||||
element: <AuthPage />,
|
||||
|
13
src/pages/GroupsPage/GroupsPage.jsx
Normal file
13
src/pages/GroupsPage/GroupsPage.jsx
Normal file
@ -0,0 +1,13 @@
|
||||
import { useOnlyTeachers } from "../../hooks/UserHooks";
|
||||
|
||||
const GroupsPage = () => {
|
||||
useOnlyTeachers();
|
||||
|
||||
return (
|
||||
<>
|
||||
<h5>GroupsPage</h5>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default GroupsPage
|
@ -1,4 +1,8 @@
|
||||
import { useOnlyTeachers } from "../../hooks/UserHooks";
|
||||
|
||||
const StatementsPage = () => {
|
||||
useOnlyTeachers();
|
||||
|
||||
return (
|
||||
<>
|
||||
<h5>StatementsPage</h5>
|
||||
|
13
src/pages/StudentsPage/StudentsPage.jsx
Normal file
13
src/pages/StudentsPage/StudentsPage.jsx
Normal file
@ -0,0 +1,13 @@
|
||||
import { useOnlyTeachers } from "../../hooks/UserHooks";
|
||||
|
||||
const StudentsPage = () => {
|
||||
useOnlyTeachers();
|
||||
|
||||
return (
|
||||
<>
|
||||
<h5>StudentsPage</h5>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default StudentsPage;
|
13
src/pages/SubjectsPage/SubjectsPage.jsx
Normal file
13
src/pages/SubjectsPage/SubjectsPage.jsx
Normal file
@ -0,0 +1,13 @@
|
||||
import { useOnlyTeachers } from "../../hooks/UserHooks";
|
||||
|
||||
const SubjectsPage = () => {
|
||||
useOnlyTeachers();
|
||||
|
||||
return (
|
||||
<>
|
||||
<h5>SubjectsPage</h5>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default SubjectsPage
|
Loading…
Reference in New Issue
Block a user