Skip to content

Commit 6c1cb37

Browse files
committed
tidy
1 parent 2ca4e45 commit 6c1cb37

1 file changed

Lines changed: 29 additions & 48 deletions

File tree

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

Lines changed: 29 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -89,20 +89,14 @@ const NhsSdeAccessStepper = () => {
8989
}
9090
})();
9191

92-
const circleFor = (index: number): CircleState =>
93-
index < activeStep
94-
? STEP_STATE.COMPLETE
95-
: index === activeStep
96-
? STEP_STATE.ACTIVE
97-
: STEP_STATE.PENDING;
98-
99-
const step1State: CircleState = cdsApproved
100-
? STEP_STATE.COMPLETE
101-
: STEP_STATE.LOCKED;
102-
const step2State = circleFor(2);
103-
const step3State = circleFor(3);
104-
const step4State = circleFor(4);
105-
const step5State = circleFor(5);
92+
const circleFor = (index: number): CircleState => {
93+
if (index === 1) {
94+
return cdsApproved ? STEP_STATE.COMPLETE : STEP_STATE.LOCKED;
95+
}
96+
if (index < activeStep) return STEP_STATE.COMPLETE;
97+
if (index === activeStep) return STEP_STATE.ACTIVE;
98+
return STEP_STATE.PENDING;
99+
};
106100

107101
const badge =
108102
cdsApproved && approvalRequested
@@ -150,18 +144,12 @@ const NhsSdeAccessStepper = () => {
150144
};
151145

152146
const steps: {
153-
label: string;
154-
state: CircleState;
155147
titleKey: string;
156-
muted: boolean;
157-
extra?: ReactNode;
148+
extra?: (state: CircleState) => ReactNode;
158149
}[] = [
159150
{
160-
label: "1",
161-
state: step1State,
162151
titleKey: "step1Title",
163-
muted: false,
164-
extra: (
152+
extra: () => (
165153
<>
166154
{!cdsApproved && (
167155
<Typography
@@ -188,11 +176,8 @@ const NhsSdeAccessStepper = () => {
188176
),
189177
},
190178
{
191-
label: "2",
192-
state: step2State,
193179
titleKey: "step2Title",
194-
muted: step2State === STEP_STATE.PENDING,
195-
extra: step2State === STEP_STATE.ACTIVE && (
180+
extra: state => state === STEP_STATE.ACTIVE && (
196181
<>
197182
<Box
198183
sx={{
@@ -246,11 +231,8 @@ const NhsSdeAccessStepper = () => {
246231
),
247232
},
248233
{
249-
label: "3",
250-
state: step3State,
251234
titleKey: "step3Title",
252-
muted: step3State === STEP_STATE.PENDING,
253-
extra: step3State === STEP_STATE.ACTIVE && (
235+
extra: state => state === STEP_STATE.ACTIVE && (
254236
<>
255237
<Typography color={colors.grey600} sx={{ mt: 1, mb: 2 }}>
256238
{t("step3Text")}
@@ -263,16 +245,10 @@ const NhsSdeAccessStepper = () => {
263245
),
264246
},
265247
{
266-
label: "4",
267-
state: step4State,
268248
titleKey: "step4Title",
269-
muted: step4State === STEP_STATE.PENDING,
270249
},
271250
{
272-
label: "5",
273-
state: step5State,
274251
titleKey: "step5Title",
275-
muted: step5State === STEP_STATE.PENDING,
276252
},
277253
];
278254

@@ -307,18 +283,23 @@ const NhsSdeAccessStepper = () => {
307283
</Box>
308284
)}
309285

310-
{steps.map((step, i) => (
311-
<StepNode
312-
key={step.label}
313-
circleState={step.state}
314-
label={step.label}
315-
isLast={i === steps.length - 1}>
316-
<StepTitle muted={step.muted}>
317-
{t(step.titleKey)}
318-
</StepTitle>
319-
{step.extra}
320-
</StepNode>
321-
))}
286+
{steps.map((step, i) => {
287+
const label = `${i + 1}`;
288+
const state = circleFor(i + 1);
289+
return (
290+
<StepNode
291+
key={label}
292+
circleState={state}
293+
label={label}
294+
isLast={i === steps.length - 1}>
295+
<StepTitle
296+
muted={state === STEP_STATE.PENDING}>
297+
{t(step.titleKey)}
298+
</StepTitle>
299+
{step.extra && step.extra(state)}
300+
</StepNode>
301+
);
302+
})}
322303
</>
323304
)}
324305
</Paper>

0 commit comments

Comments
 (0)