Files

169 lines
7.3 KiB
TypeScript

import { redirect, type RouteObject } from "react-router-dom";
import { AssessmentAttemptPage, AssessmentPage } from "../../pages/assessment";
import { AssessmentResultPage, AssessmentResultsPage } from "../../pages/assessment-result";
import { LoginPage, RegisterPage, VerifyEmailPage } from "../../pages/auth";
import {
CandidateInvitationPage,
CandidateInvitationsPage,
} from "../../pages/candidate-invitations";
import { CandidateOnboardingPage } from "../../pages/candidate-onboarding";
import { CompanyPage } from "../../pages/company";
import { EmployerInvitationsPage } from "../../pages/employer-invitations";
import { PrivacyPage, PublicPrivacyPage } from "../../pages/privacy";
import { TermsPage } from "../../pages/terms";
import { SessionGate } from "../../entities/session";
import { MatchesPage } from "../../pages/matches";
import { InvitationComposePage } from "../../pages/invitation-compose";
import { JuryGuidePage } from "../../pages/jury-guide";
import { NotFoundPage } from "../../pages/not-found";
import { NeedEditorPage } from "../../pages/need-editor";
import { NeedListPage } from "../../pages/needs";
import { CandidateNotificationsPage, EmployerNotificationsPage } from "../../pages/notifications";
import { ProfilePage } from "../../pages/profile";
import { QuestionnairePage } from "../../pages/questionnaire";
import { StatusPage } from "../../pages/status";
import {
CreateSupportCasePage,
ManualAssessmentPage,
SupportCaseDetailPage,
SupportCasesPage,
} from "../../pages/support-cases";
import { WelcomePage } from "../../pages/welcome";
import { paths, standMode, type StandMode } from "../../shared/config";
import { CandidateShell } from "../../widgets/candidate-shell";
import { EmployerShell } from "../../widgets/employer-shell";
import { PublicShell } from "../../widgets/public-shell";
import { RootLayout } from "../ui/root-layout";
import { RouteErrorPage } from "../ui/route-error-page";
import { CandidateHomeRoute } from "./candidate-home-route";
import { SupportRoute } from "./support-route";
/**
* Route tree with public pages and role-specific cabinets. Protected shells
* restore the server session before they render any cabinet child. The jury
* guide and the demonstration banner exist only in a demo build; elsewhere
* the guide path answers with the not-found page.
*/
export function createRoutes(stand: StandMode = standMode): RouteObject[] {
return [
{
element: <RootLayout />,
errorElement: <RouteErrorPage />,
children: [
{
element: <PublicShell />,
children: [
{ index: true, element: <WelcomePage demoStand={stand.demo} /> },
{ path: paths.login, element: <LoginPage /> },
{ path: paths.register, element: <RegisterPage /> },
{ path: paths.verifyEmail, element: <VerifyEmailPage /> },
{ path: paths.support, element: <SupportRoute /> },
{ path: paths.status, element: <StatusPage /> },
{ path: paths.terms, element: <TermsPage demoStand={stand.demo} /> },
{ path: paths.privacy, element: <PublicPrivacyPage demoStand={stand.demo} /> },
...(stand.demo ? [{ path: paths.demoGuide, element: <JuryGuidePage /> }] : []),
{ path: "*", element: <NotFoundPage /> },
],
},
{
path: paths.candidate.root,
element: <CandidateShell />,
children: [
{
element: <SessionGate scenario="candidate" />,
children: [
{ index: true, element: <CandidateHomeRoute /> },
{ path: paths.candidate.onboarding, element: <CandidateOnboardingPage /> },
{
path: paths.candidate.profile,
element: <ProfilePage />,
},
{
path: paths.candidate.questionnaire,
element: <QuestionnairePage />,
},
{
path: paths.candidate.assessment,
element: <AssessmentPage />,
},
{
path: `${paths.candidate.assessment}/:attemptId`,
element: <AssessmentAttemptPage />,
},
{ path: paths.candidate.results, element: <AssessmentResultsPage /> },
{
path: `${paths.candidate.results}/:attemptId`,
element: <AssessmentResultPage />,
},
{ path: paths.candidate.invitations, element: <CandidateInvitationsPage /> },
{
path: `${paths.candidate.invitations}/:invitationId`,
element: <CandidateInvitationPage />,
},
{ path: paths.candidate.notifications, element: <CandidateNotificationsPage /> },
{
path: paths.candidate.privacy,
element: <PrivacyPage />,
},
{ path: paths.candidate.supportCases, element: <SupportCasesPage /> },
{ path: paths.candidate.supportNew, element: <CreateSupportCasePage /> },
{ path: paths.candidate.supportManual, element: <ManualAssessmentPage /> },
{
path: `${paths.candidate.supportCases}/:caseId`,
element: <SupportCaseDetailPage />,
},
{
path: "*",
element: (
<NotFoundPage homePath={paths.candidate.root} homeLabel="В кабинет кандидата" />
),
},
],
},
],
},
{
path: paths.employer.root,
element: <EmployerShell />,
children: [
{
element: <SessionGate scenario="employer" />,
children: [
{ index: true, loader: () => redirect(paths.employer.company) },
{
path: paths.employer.company,
element: <CompanyPage />,
},
{ path: paths.employer.needs, element: <NeedListPage /> },
{ path: `${paths.employer.needs}/new`, element: <NeedEditorPage /> },
{ path: `${paths.employer.needs}/:needId`, element: <NeedEditorPage /> },
{ path: paths.employer.supportCases, element: <SupportCasesPage /> },
{ path: paths.employer.supportNew, element: <CreateSupportCasePage /> },
{
path: `${paths.employer.supportCases}/:caseId`,
element: <SupportCaseDetailPage />,
},
{ path: paths.employer.candidates, element: <MatchesPage /> },
{ path: paths.employer.invitations, element: <EmployerInvitationsPage /> },
{ path: paths.employer.invitationNew, element: <InvitationComposePage /> },
{ path: paths.employer.notifications, element: <EmployerNotificationsPage /> },
{
path: "*",
element: (
<NotFoundPage
homePath={paths.employer.company}
homeLabel="В кабинет работодателя"
/>
),
},
],
},
],
},
],
},
];
}
export const routes: RouteObject[] = createRoutes();