Skip to content

Commit 7fc463c

Browse files
committed
tidy
1 parent fc10521 commit 7fc463c

1 file changed

Lines changed: 68 additions & 41 deletions

File tree

src/app/[locale]/account/profile/cohort-discovery-request/components/NhsSdeAccessStepper/NhsSdeAccessStepper.tsx

Lines changed: 68 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use client";
22

3-
import { useState } from "react";
3+
import { ReactNode, useState } from "react";
44
import { useTranslations } from "next-intl";
55
import Button from "@/components/Button";
66
import Link from "@/components/Link";
@@ -36,13 +36,61 @@ const NhsSdeAccessStepper = () => {
3636
const loading = userLoading || statusLoading || !hasFetched;
3737
const cdsApproved = requestStatus === "APPROVED";
3838

39-
const step1State: CircleState = cdsApproved
40-
? STEP_STATE.COMPLETE
41-
: STEP_STATE.LOCKED;
42-
const step2State: CircleState = STEP_STATE.LOCKED;
43-
const step3State: CircleState = STEP_STATE.LOCKED;
44-
const step4State: CircleState = STEP_STATE.LOCKED;
45-
const step5State: CircleState = STEP_STATE.LOCKED;
39+
const steps: {
40+
label: string;
41+
state: CircleState;
42+
titleKey: string;
43+
muted: boolean;
44+
extra?: ReactNode;
45+
}[] = [
46+
{
47+
label: "1",
48+
state: cdsApproved ? STEP_STATE.COMPLETE : STEP_STATE.LOCKED,
49+
titleKey: "step1Title",
50+
muted: false,
51+
extra: cdsApproved
52+
? applied
53+
? (
54+
<Typography color={colors.grey600} sx={{ mt: 1 }}>
55+
{t("appliedText")}
56+
</Typography>
57+
)
58+
: (
59+
<Button
60+
variant="outlined"
61+
color="secondary"
62+
sx={{ mt: 1 }}
63+
onClick={() => setApplied(true)}>
64+
{t("applyButton")}
65+
</Button>
66+
)
67+
: undefined,
68+
},
69+
{
70+
label: "2",
71+
state: STEP_STATE.LOCKED,
72+
titleKey: "step2Title",
73+
muted: true,
74+
},
75+
{
76+
label: "3",
77+
state: STEP_STATE.LOCKED,
78+
titleKey: "step3Title",
79+
muted: true,
80+
},
81+
{
82+
label: "4",
83+
state: STEP_STATE.LOCKED,
84+
titleKey: "step4Title",
85+
muted: true,
86+
},
87+
{
88+
label: "5",
89+
state: STEP_STATE.LOCKED,
90+
titleKey: "step5Title",
91+
muted: true,
92+
},
93+
];
4694

4795
return (
4896
<Paper sx={{ bgcolor: "white", p: { mobile: 3, laptop: 4 } }}>
@@ -65,39 +113,18 @@ const NhsSdeAccessStepper = () => {
65113
</Typography>
66114
) : (
67115
<>
68-
<StepNode circleState={step1State} label="1">
69-
<StepTitle>{t("step1Title")}</StepTitle>
70-
{cdsApproved && !applied && (
71-
<Button
72-
variant="outlined"
73-
color="secondary"
74-
sx={{ mt: 1 }}
75-
onClick={() => setApplied(true)}>
76-
{t("applyButton")}
77-
</Button>
78-
)}
79-
{cdsApproved && applied && (
80-
<Typography color={colors.grey600} sx={{ mt: 1 }}>
81-
{t("appliedText")}
82-
</Typography>
83-
)}
84-
</StepNode>
85-
86-
<StepNode circleState={step2State} label="2">
87-
<StepTitle muted>{t("step2Title")}</StepTitle>
88-
</StepNode>
89-
90-
<StepNode circleState={step3State} label="3">
91-
<StepTitle muted>{t("step3Title")}</StepTitle>
92-
</StepNode>
93-
94-
<StepNode circleState={step4State} label="4">
95-
<StepTitle muted>{t("step4Title")}</StepTitle>
96-
</StepNode>
97-
98-
<StepNode circleState={step5State} label="5" isLast>
99-
<StepTitle muted>{t("step5Title")}</StepTitle>
100-
</StepNode>
116+
{steps.map((step, i) => (
117+
<StepNode
118+
key={step.label}
119+
circleState={step.state}
120+
label={step.label}
121+
isLast={i === steps.length - 1}>
122+
<StepTitle muted={step.muted}>
123+
{t(step.titleKey)}
124+
</StepTitle>
125+
{step.extra}
126+
</StepNode>
127+
))}
101128
</>
102129
)}
103130
</Paper>

0 commit comments

Comments
 (0)