@@ -292,35 +292,23 @@ export function InstructionsWizard({ onClose, selectedFileId }: InstructionsWiza
292292 [ dynamicSteps ]
293293 )
294294
295- const currentStep = wizardSteps [ currentStepIndex ]
296- const currentQuestion = currentStep ?. questions [ currentQuestionIndex ]
295+ const currentStep = wizardSteps [ currentStepIndex ] ?? null
296+ const currentQuestion = currentStep ?. questions [ currentQuestionIndex ] ?? null
297297
298298 const totalQuestions = useMemo (
299299 ( ) => wizardSteps . reduce ( ( count , step ) => count + step . questions . length , 0 ) ,
300300 [ wizardSteps ]
301301 )
302302
303- if ( ! currentStep || ! currentQuestion ) {
304- return null
305- }
306-
307- const currentAnswerValue = responses [ currentQuestion . id ]
308-
309- const isAnswerSelected = ( value : string ) => {
310- if ( currentQuestion . allowMultiple ) {
311- return Array . isArray ( currentAnswerValue ) && currentAnswerValue . includes ( value )
312- }
313-
314- return currentAnswerValue === value
315- }
303+ const currentAnswerValue = currentQuestion ? responses [ currentQuestion . id ] : undefined
316304
317305 const defaultAnswer = useMemo (
318- ( ) => currentQuestion . answers . find ( ( answer ) => answer . isDefault ) ,
306+ ( ) => currentQuestion ? .answers . find ( ( answer ) => answer . isDefault ) ?? null ,
319307 [ currentQuestion ]
320308 )
321309
322310 const isDefaultSelected = useMemo ( ( ) => {
323- if ( ! defaultAnswer ) {
311+ if ( ! currentQuestion || ! defaultAnswer ) {
324312 return false
325313 }
326314
@@ -329,10 +317,11 @@ export function InstructionsWizard({ onClose, selectedFileId }: InstructionsWiza
329317 }
330318
331319 return currentAnswerValue === defaultAnswer . value
332- } , [ currentAnswerValue , currentQuestion . allowMultiple , defaultAnswer ] )
320+ } , [ currentAnswerValue , currentQuestion , defaultAnswer ] )
333321
334322 const canUseDefault = Boolean (
335323 ! isComplete &&
324+ currentQuestion &&
336325 defaultAnswer &&
337326 ! defaultAnswer . disabled &&
338327 ( ! isDefaultSelected || currentQuestion . allowMultiple )
@@ -342,6 +331,18 @@ export function InstructionsWizard({ onClose, selectedFileId }: InstructionsWiza
342331 ? `Use default (${ defaultAnswer . label } )`
343332 : "Use default"
344333
334+ if ( ! currentStep || ! currentQuestion ) {
335+ return null
336+ }
337+
338+ const isAnswerSelected = ( value : string ) => {
339+ if ( currentQuestion . allowMultiple ) {
340+ return Array . isArray ( currentAnswerValue ) && currentAnswerValue . includes ( value )
341+ }
342+
343+ return currentAnswerValue === value
344+ }
345+
345346 const advanceToNextQuestion = ( ) => {
346347 const isLastQuestionInStep = currentQuestionIndex === currentStep . questions . length - 1
347348 const isLastStep = currentStepIndex === wizardSteps . length - 1
0 commit comments