From f2ad6b43bda5d8101623326868ca19246ea7393b Mon Sep 17 00:00:00 2001 From: Mikola Date: Fri, 15 Mar 2024 18:18:10 +0300 Subject: [PATCH] guardian routes --- src/App.jsx | 149 +----------------- src/api/request.js | 2 +- src/components/AuthBox/AuthBox.jsx | 1 + .../Common/AuthHeader/AuthHeader.jsx | 6 +- src/components/Navigation/Navigation.jsx | 2 +- .../ProfileHeader/ProfileHeader.jsx | 5 +- src/pages/Auth/Auth.jsx | 18 +-- src/pages/MainPage/MainPage.jsx | 36 +++++ .../PartnerСategories/PartnerСategories.jsx | 11 ++ src/pages/roles/DeveloperPage.jsx | 57 +++++++ src/pages/roles/GuestPage.jsx | 72 +++++++++ src/pages/roles/PartnerPage.jsx | 71 +++++++++ src/redux/outstaffingSlice.js | 2 +- 13 files changed, 267 insertions(+), 165 deletions(-) create mode 100644 src/pages/MainPage/MainPage.jsx create mode 100644 src/pages/roles/DeveloperPage.jsx create mode 100644 src/pages/roles/GuestPage.jsx create mode 100644 src/pages/roles/PartnerPage.jsx diff --git a/src/App.jsx b/src/App.jsx index b0aabcb1..8ff100d6 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -9,51 +9,8 @@ import { } from "react-router-dom"; import { getNotification } from "@redux/outstaffingSlice"; - -import { Article } from "@pages/Article/Article"; -import { Auth } from "@pages/Auth/Auth"; -import { AuthForCandidate } from "@pages/AuthForCandidate/AuthForCandidate"; -import { Blog } from "@pages/Blog/Blog"; -import CatalogSpecialists from "@pages/CatalogSpecialists/CatalogSpecialists"; -import { CompanyInfo } from "@pages/CompanyInfo/CompanyInfo"; -import { FormPage } from "@pages/FormPage/FormPage"; -import { Forms } from "@pages/Forms/Forms"; -import { FrequentlyAskedQuestion } from "@pages/FrequentlyAskedQuestion/FrequentlyAskedQuestion"; -import { FrequentlyAskedQuestions } from "@pages/FrequentlyAskedQuestions/FrequentlyAskedQuestions"; -import { Home } from "@pages/Home/Home"; -import { PartnerAddRequest } from "@pages/PartnerAddRequest/PartnerAddRequest"; -import { PartnerBid } from "@pages/PartnerBid/PartnerBid"; -import { PartnerEmployeeReport } from "@pages/PartnerEmployeeReport/PartnerEmployeeReport"; -import { PartnerEmployees } from "@pages/PartnerEmployees/PartnerEmployees"; -import { PartnerRequests } from "@pages/PartnerRequests/PartnerRequests"; -import { PartnerSettings } from "@pages/PartnerSettings/PartnerSettings"; -import { PartnerTreaties } from "@pages/PartnerTreaties/PartnerTreaties"; -import { PartnerCategories } from "@pages/PartnerСategories/PartnerСategories"; -import { Payouts } from "@pages/Payouts/Payouts"; -import { Profile } from "@pages/Profile/Profile"; -import { ProfileCandidate } from "@pages/ProfileCandidate/ProfileCandidate"; -import { ProjectTracker } from "@pages/ProjectTracker/ProjectTracker"; -import { PassingTests } from "@pages/Quiz/PassingTests"; -import { QuizPage } from "@pages/Quiz/QuizPage"; -import { QuizReportPage } from "@pages/Quiz/QuizReportPage"; -import { RegistrationForCandidate } from "@pages/RegistrationForCandidate/RegistrationForCandidate"; -import { RegistrationSetting } from "@pages/RegistrationSetting/RegistrationSetting"; -import { SingleReportPage } from "@pages/SingleReportPage/SingleReportPage"; -import Statistics from "@pages/Statistics/Statistics"; -import { Summary } from "@pages/Summary/Summary"; -import { Tracker } from "@pages/Tracker/Tracker"; -import { TrackerAuth } from "@pages/TrackerAuth/TrackerAuth"; -import { TrackerIntro } from "@pages/TrackerIntro/TrackerIntro"; -import { TrackerRegistration } from "@pages/TrackerRegistration/TrackerRegistration"; -import { ViewReport } from "@pages/ViewReport/ViewReport"; - -import { Calendar } from "@components/Calendar/Calendar"; -import { Candidate } from "@components/Candidate/Candidate"; -import { FreeDevelopers } from "@components/FreeDevelopers/FreeDevelopers"; -import { TicketFullScreen } from "@components/Modal/Tracker/TicketFullScreen/TicketFullScreen"; import { Notification } from "@components/Notification/Notification"; -import { ProfileCalendar } from "@components/ProfileCalendar/ProfileCalendar"; -import { ReportForm } from "@components/ReportForm/ReportForm"; +import { MainPage } from "@pages/MainPage/MainPage"; import "assets/fonts/stylesheet.css"; import "assets/global.scss"; @@ -64,109 +21,7 @@ const App = () => { <> - } /> - } /> - } /> - } /> - } - /> - } /> - } - /> - } - /> - - } /> - } - > - } - /> - - } /> - } - /> - - }> - }> - } - /> - } - /> - - } /> - } /> - } /> - - } /> - - - } /> - } /> - } /> - } /> - } - /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } - /> - } /> - - } /> - } /> - } /> - - - } - /> - - - - } /> - - - } /> + } /> {notification.show && } diff --git a/src/api/request.js b/src/api/request.js index 4c07b441..d7615cbc 100644 --- a/src/api/request.js +++ b/src/api/request.js @@ -41,7 +41,7 @@ export const apiRequest = ( if (response.data?.redirect || response.status === 401) { window.location.replace("/auth"); localStorage.clear(); - // dispatch(auth(false)); + store.dispatch(auth(false)); store.dispatch(setProfileInfo({})); } return resolve(response); diff --git a/src/components/AuthBox/AuthBox.jsx b/src/components/AuthBox/AuthBox.jsx index 27c5bf67..8ebf1394 100644 --- a/src/components/AuthBox/AuthBox.jsx +++ b/src/components/AuthBox/AuthBox.jsx @@ -70,6 +70,7 @@ export const AuthBox = ({ title }) => { dispatch(setUserInfo(res)); dispatch(loading(false)); dispatch(setRole("ROLE_PARTNER")); + navigate("/profile"); } }); } diff --git a/src/components/Common/AuthHeader/AuthHeader.jsx b/src/components/Common/AuthHeader/AuthHeader.jsx index c39b072d..19e8ebac 100644 --- a/src/components/Common/AuthHeader/AuthHeader.jsx +++ b/src/components/Common/AuthHeader/AuthHeader.jsx @@ -24,9 +24,9 @@ export const AuthHeader = () => { Главная -
  • - Кабинет разработчика -
  • + {/*
  • */} + {/* Кабинет разработчика*/} + {/*
  • */}
  • Трекер
  • diff --git a/src/components/Navigation/Navigation.jsx b/src/components/Navigation/Navigation.jsx index eb4baac8..80d0a184 100644 --- a/src/components/Navigation/Navigation.jsx +++ b/src/components/Navigation/Navigation.jsx @@ -81,7 +81,7 @@ export const Navigation = () => { { }); }, []); - const handler = () => { - setIsLoggingOut(true); + const handler = (e) => { + e.preventDefault() localStorage.clear(); dispatch(auth(false)); - setIsLoggingOut(false); navigate("/auth"); dispatch(setProfileInfo({})); }; diff --git a/src/pages/Auth/Auth.jsx b/src/pages/Auth/Auth.jsx index 663be1c3..42cf790e 100644 --- a/src/pages/Auth/Auth.jsx +++ b/src/pages/Auth/Auth.jsx @@ -19,16 +19,16 @@ import cross from "assets/images/cross.png"; import "./auth.scss"; export const Auth = () => { - const isAuth = useSelector(selectAuth); - let navigate = useNavigate(); + // const isAuth = useSelector(selectAuth); + // let navigate = useNavigate(); + // + // const getToken = localStorage.getItem("auth_token"); - const getToken = localStorage.getItem("auth_token"); - - useEffect(() => { - if (isAuth || getToken) { - navigate("/profile"); - } - }, [getToken]); + // useEffect(() => { + // if (isAuth || getToken) { + // navigate("/profile"); + // } + // }, [getToken]); return (
    diff --git a/src/pages/MainPage/MainPage.jsx b/src/pages/MainPage/MainPage.jsx new file mode 100644 index 00000000..870b818d --- /dev/null +++ b/src/pages/MainPage/MainPage.jsx @@ -0,0 +1,36 @@ +import React from "react"; +import { useMemo } from "react"; +import { PartnerPage } from "@pages/roles/PartnerPage"; +import { DeveloperPage } from "@pages/roles/DeveloperPage"; +import { GuestPage } from "@pages/roles/GuestPage"; +import { useSelector } from "react-redux"; +import { selectAuth } from "@redux/outstaffingSlice"; + +export const MainPage = () => { + const roleId = localStorage.getItem("role_status") + const isAuth = useSelector(selectAuth); + const user_roles = { + developer: 4, + partner: 18 + } + + const CurrentRolePage = useMemo( + () => getRolePage(Number(roleId)), + [isAuth] + ); + + function getRolePage(roleId) { + switch (roleId) { + case user_roles.developer: + return DeveloperPage; + case user_roles.partner: + return PartnerPage; + default: + return GuestPage; + } + } + + return( + + ) +} diff --git a/src/pages/PartnerСategories/PartnerСategories.jsx b/src/pages/PartnerСategories/PartnerСategories.jsx index 5abf140f..d69da8cf 100644 --- a/src/pages/PartnerСategories/PartnerСategories.jsx +++ b/src/pages/PartnerСategories/PartnerСategories.jsx @@ -64,6 +64,17 @@ export const PartnerCategories = () => { }, { label: "Резюме", + renderCell: (item) => ( + + Резюме + + ) + }, + { + label: "Отчет", renderCell: (item) => ( { + return( + + } + > + } + /> + + + } /> + } /> + } /> + } + /> + } /> + } /> + } /> + } /> + } /> + } /> + + } /> + } /> + } /> + + + } /> + + ) +} diff --git a/src/pages/roles/GuestPage.jsx b/src/pages/roles/GuestPage.jsx new file mode 100644 index 00000000..8b783bab --- /dev/null +++ b/src/pages/roles/GuestPage.jsx @@ -0,0 +1,72 @@ +import React from "react"; +import { Navigate, Route, Routes } from "react-router-dom"; +import { TrackerIntro } from "@pages/TrackerIntro/TrackerIntro"; +import { TrackerAuth } from "@pages/TrackerAuth/TrackerAuth"; +import { Forms } from "@pages/Forms/Forms"; +import { TrackerRegistration } from "@pages/TrackerRegistration/TrackerRegistration"; +import { CompanyInfo } from "@pages/CompanyInfo/CompanyInfo"; +import { RegistrationSetting } from "@pages/RegistrationSetting/RegistrationSetting"; +import CatalogSpecialists from "@pages/CatalogSpecialists/CatalogSpecialists"; +import { FreeDevelopers } from "@components/FreeDevelopers/FreeDevelopers"; +import { AuthForCandidate } from "@pages/AuthForCandidate/AuthForCandidate"; +import { RegistrationForCandidate } from "@pages/RegistrationForCandidate/RegistrationForCandidate"; +import { FrequentlyAskedQuestions } from "@pages/FrequentlyAskedQuestions/FrequentlyAskedQuestions"; +import { Blog } from "@pages/Blog/Blog"; +import { Article } from "@pages/Article/Article"; +import { FrequentlyAskedQuestion } from "@pages/FrequentlyAskedQuestion/FrequentlyAskedQuestion"; +import { SingleReportPage } from "@pages/SingleReportPage/SingleReportPage"; +import { ProfileCandidate } from "@pages/ProfileCandidate/ProfileCandidate"; +import { Auth } from "@pages/Auth/Auth"; + +export const GuestPage = () => { + return( + + } /> + } /> + } /> + } /> + } /> + } + /> + } /> + } + /> + } + /> + } /> + } /> + } + /> + + }> + }> + } + /> + } + /> + + } /> + + } /> + + + ) +} diff --git a/src/pages/roles/PartnerPage.jsx b/src/pages/roles/PartnerPage.jsx new file mode 100644 index 00000000..2626d60b --- /dev/null +++ b/src/pages/roles/PartnerPage.jsx @@ -0,0 +1,71 @@ +import React from "react"; +import { Navigate, Route, Routes } from "react-router-dom"; +import { Candidate } from "@components/Candidate/Candidate"; +import { FormPage } from "@pages/FormPage/FormPage"; +import { Calendar } from "@components/Calendar/Calendar"; +import { ProjectTracker } from "@pages/ProjectTracker/ProjectTracker"; +import { TicketFullScreen } from "@components/Modal/Tracker/TicketFullScreen/TicketFullScreen"; +import { Profile } from "@pages/Profile/Profile"; +import { Home } from "@pages/Home/Home"; +import { ViewReport } from "@pages/ViewReport/ViewReport"; +import { Tracker } from "@pages/Tracker/Tracker"; +import Statistics from "@pages/Statistics/Statistics"; +import { PartnerRequests } from "@pages/PartnerRequests/PartnerRequests"; +import { PartnerAddRequest } from "@pages/PartnerAddRequest/PartnerAddRequest"; +import { PartnerBid } from "@pages/PartnerBid/PartnerBid"; +import { PartnerCategories } from "@pages/PartnerСategories/PartnerСategories"; +import { PartnerEmployeeReport } from "@pages/PartnerEmployeeReport/PartnerEmployeeReport"; +import { PartnerTreaties } from "@pages/PartnerTreaties/PartnerTreaties"; +import { PartnerEmployees } from "@pages/PartnerEmployees/PartnerEmployees"; +import { PartnerSettings } from "@pages/PartnerSettings/PartnerSettings"; + +export const PartnerPage = () => { + return( + + } /> + } /> + } /> + + } + > + } + /> + + + } /> + } /> + } + /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } + /> + } /> + } + /> + + } /> + + ) +} diff --git a/src/redux/outstaffingSlice.js b/src/redux/outstaffingSlice.js index be040a7b..c6becf0d 100644 --- a/src/redux/outstaffingSlice.js +++ b/src/redux/outstaffingSlice.js @@ -6,7 +6,7 @@ const initialState = { filteredCandidates: null, selectedItems: [], currentCandidate: {}, - auth: false, + auth: null, positionId: null, profileInfo: {}, reportsDates: "",