-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Right now there is a bug that overrides the submitted practice results for multiple-choice questions. More specifically, when users submit their selected answers by clicking the Check Answer button. Their answers are evaluated and feedback is displayed. In the background their results (selection) is saved in the sessionStorage and in the database.
Now for some reason, the respective practice result for the multiple-choice question is overridden once users press the Continue button or essentially navigate away from the current multiple-choice question. Preliminary analysis showed, that the results state resets the user-selection from e.g.
['some-id', null, 'some-id', null]to
[undefined, undefined, undefined, undefined]More specifically debugging indicated that this state-reset happens, when the question is switched, thus the question.id and question.type has changed. Right now the reset-logic within the RenderPracticeQuestion has been reverted to this:
const RHFForm = useRHF(
QuestionInputSchema,
{
defaultValues: () => ({ question_id: question.id, type: question.type }),
},
{ serverAction: EvaluateAnswer, initialActionState: { success: false } },
)
const {
...
} = RHFForm
//* Handle reseting form inputs when question changes
useEffect(() => {
if (form.watch('type') === question.type && form.watch('question_id') === question.id) return
else {
console.log('Resetting form due to question change...', { question_id: question.id, type: question.type as Any })
//* When the question is changed reset the form (and set the new question id and type)
console.log(
'Resetting form before',
results.find((q) => q.question_id === '1b6e0db1-e81a-4d06-8faf-2b419a85a542'),
)
form.reset({ question_id: question.id, type: question.type as Any })
console.log(
'Resetting form after',
results.find((q) => q.question_id === '1b6e0db1-e81a-4d06-8faf-2b419a85a542'),
form.getValues(),
)
return
}
}, [question.id, question.type])to investigate this problem more easily. Note that his issue appears in both the previously used reset-logic (the one used to debug) and the refactored reset-logic by making the form a controlled form, see (4d05778c).
Metadata
Metadata
Assignees
Labels
Type
Projects
Status