@@ -41,12 +41,12 @@ export type StepState =
4141 }
4242
4343interface Props {
44- nextStep : ( ) => void
44+ state : StepState
45+ onNext : ( v : StepState ) => void
46+ onBack : ( ) => void
4547}
4648
47- export const UploadFlow = ( { nextStep } : Props ) => {
48- const { initialStepState } = useRsi ( )
49- const [ state , setState ] = useState < StepState > ( initialStepState || { type : StepType . upload } )
49+ export const UploadFlow = ( { state, onNext, onBack } : Props ) => {
5050 const [ uploadedFile , setUploadedFile ] = useState < File | null > ( null )
5151 const { maxRecords, translations, uploadStepHook, selectHeaderStepHook, matchColumnsStepHook } = useRsi ( )
5252 const toast = useToast ( )
@@ -78,16 +78,15 @@ export const UploadFlow = ({ nextStep }: Props) => {
7878 }
7979 try {
8080 const mappedWorkbook = await uploadStepHook ( mapWorkbook ( workbook ) )
81- setState ( {
81+ onNext ( {
8282 type : StepType . selectHeader ,
8383 data : mappedWorkbook ,
8484 } )
85- nextStep ( )
8685 } catch ( e ) {
8786 errorToast ( ( e as Error ) . message )
8887 }
8988 } else {
90- setState ( { type : StepType . selectSheet , workbook } )
89+ onNext ( { type : StepType . selectSheet , workbook } )
9190 }
9291 } }
9392 />
@@ -103,15 +102,15 @@ export const UploadFlow = ({ nextStep }: Props) => {
103102 }
104103 try {
105104 const mappedWorkbook = await uploadStepHook ( mapWorkbook ( state . workbook , sheetName ) )
106- setState ( {
105+ onNext ( {
107106 type : StepType . selectHeader ,
108107 data : mappedWorkbook ,
109108 } )
110- nextStep ( )
111109 } catch ( e ) {
112110 errorToast ( ( e as Error ) . message )
113111 }
114112 } }
113+ onBack = { onBack }
115114 />
116115 )
117116 case StepType . selectHeader :
@@ -121,16 +120,16 @@ export const UploadFlow = ({ nextStep }: Props) => {
121120 onContinue = { async ( ...args ) => {
122121 try {
123122 const { data, headerValues } = await selectHeaderStepHook ( ...args )
124- setState ( {
123+ onNext ( {
125124 type : StepType . matchColumns ,
126125 data,
127126 headerValues,
128127 } )
129- nextStep ( )
130128 } catch ( e ) {
131129 errorToast ( ( e as Error ) . message )
132130 }
133131 } }
132+ onBack = { onBack }
134133 />
135134 )
136135 case StepType . matchColumns :
@@ -141,19 +140,19 @@ export const UploadFlow = ({ nextStep }: Props) => {
141140 onContinue = { async ( values , rawData , columns ) => {
142141 try {
143142 const data = await matchColumnsStepHook ( values , rawData , columns )
144- setState ( {
143+ onNext ( {
145144 type : StepType . validateData ,
146145 data,
147146 } )
148- nextStep ( )
149147 } catch ( e ) {
150148 errorToast ( ( e as Error ) . message )
151149 }
152150 } }
151+ onBack = { onBack }
153152 />
154153 )
155154 case StepType . validateData :
156- return < ValidationStep initialData = { state . data } file = { uploadedFile ! } />
155+ return < ValidationStep initialData = { state . data } file = { uploadedFile ! } onBack = { onBack } />
157156 default :
158157 return < Progress isIndeterminate />
159158 }
0 commit comments