Skip to content

Commit 0452244

Browse files
authored
Merge pull request #172 from GlorianB/fix/stepper-sync
Fixes stepper unsynchronized with step's content
2 parents 2943dd4 + c285840 commit 0452244

2 files changed

Lines changed: 32 additions & 5 deletions

File tree

src/hooks/useRsiInitialStep.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { useCallback } from "react"
2+
import { StepType } from "../steps/UploadFlow"
3+
4+
export const useRsiInitialStep = (step: StepType) => {
5+
const steps = ["uploadStep", "selectHeaderStep", "matchColumnsStep", "validationStep"] as const
6+
7+
const getInitialStep = useCallback((step: StepType) => {
8+
switch (step) {
9+
case StepType.upload:
10+
return 0
11+
case StepType.selectSheet:
12+
return 0
13+
case StepType.selectHeader:
14+
return 1
15+
case StepType.matchColumns:
16+
return 2
17+
case StepType.validateData:
18+
return 3
19+
default:
20+
return 0
21+
}
22+
}, [])
23+
24+
return { steps, initialStep: getInitialStep(step) }
25+
}

src/steps/Steps.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1-
import { UploadFlow } from "./UploadFlow"
1+
import { UploadFlow, StepType } from "./UploadFlow"
22
import { ModalHeader } from "@chakra-ui/react"
33
import { useSteps, Step, Steps as Stepper } from "chakra-ui-steps"
44
import { CgCheck } from "react-icons/cg"
55
import { useRsi } from "../hooks/useRsi"
6+
import { useRsiInitialStep } from "../hooks/useRsiInitialStep"
67

78
const CheckIcon = ({ color }: { color: string }) => <CgCheck size="2.25rem" color={color} />
89

9-
const steps = ["uploadStep", "selectHeaderStep", "matchColumnsStep", "validationStep"] as const
10-
1110
export const Steps = () => {
12-
const { translations } = useRsi()
11+
const { initialStepState, translations } = useRsi()
12+
13+
const { steps, initialStep } = useRsiInitialStep(initialStepState?.type || StepType.upload)
14+
1315
const { nextStep, activeStep } = useSteps({
14-
initialStep: 0,
16+
initialStep,
1517
})
1618

1719
return (

0 commit comments

Comments
 (0)