This repository was archived by the owner on Feb 10, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCheckerRouter.tsx
93 lines (84 loc) · 2.42 KB
/
CheckerRouter.tsx
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
"use client";
import { useEffect } from "react";
import { match, P } from "ts-pattern";
import { Hex } from "viem";
import { useCheckerContext } from "@/features/checker/store/hooks/useCheckerContext";
import { Step } from "@/types";
import { useInitialize } from "~checker/hooks";
import {
ApplicationEvaluationOverviewPage,
ReviewApplicationsPage,
SubmitApplicationEvaluationPage,
SubmitFinalEvaluationPage,
} from "~checker/pages";
import { CheckerRoute } from "~checker/store";
import { EvaluationBody, ReviewBody } from "~checker/types";
export interface CheckerRouterProps {
address: Hex;
poolId: string;
chainId: number;
setEvaluationBody: (body: EvaluationBody) => void;
isSuccess: boolean;
isEvaluating: boolean;
isError: boolean;
steps: Step[];
setReviewBody: (reviewBody: ReviewBody | null) => void;
isReviewing: boolean;
}
export const CheckerRouter = ({
address,
poolId,
chainId,
setEvaluationBody,
isSuccess,
isEvaluating,
isError,
steps,
setReviewBody,
isReviewing,
}: CheckerRouterProps) => {
useInitialize({ address, poolId, chainId });
const { route } = useCheckerContext();
// When route changes scroll to top
useEffect(() => {
window.scrollTo(0, 0);
}, [route]);
return match(route)
.with({ id: CheckerRoute.ReviewApplications }, () => <ReviewApplicationsPage />)
.with(
{ id: CheckerRoute.ApplicationEvaluationOverview, projectId: P.string.minLength(1) },
({ projectId }) => (
<ApplicationEvaluationOverviewPage
chainId={chainId}
poolId={poolId}
applicationId={projectId}
address={address}
/>
),
)
.with(
{ id: CheckerRoute.SubmitApplicationEvaluation, projectId: P.string.minLength(1) },
({ projectId }) => {
return (
<SubmitApplicationEvaluationPage
setEvaluationBody={setEvaluationBody}
isSuccess={isSuccess}
isEvaluating={isEvaluating}
isError={isError}
applicationId={projectId}
chainId={chainId}
poolId={poolId}
address={address}
/>
);
},
)
.with({ id: CheckerRoute.SubmitFinalEvaluation }, () => (
<SubmitFinalEvaluationPage
steps={steps}
setReviewBody={setReviewBody}
isReviewing={isReviewing}
/>
))
.otherwise(() => <div>{`Route Not Found: ${JSON.stringify(route)}`}</div>);
};