From cee7cd816d2c178085daf3658290de89ae8d6b45 Mon Sep 17 00:00:00 2001 From: sina_sajjadi Date: Thu, 2 Jul 2026 11:23:45 +0330 Subject: [PATCH] feat: add QuestionAnswersProvider to manage local state and persistent synchronization for marriage section questions --- .../questions/question-answer-storage.tsx | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/components/questions/question-answer-storage.tsx b/src/components/questions/question-answer-storage.tsx index 59bbe46..ac79fef 100644 --- a/src/components/questions/question-answer-storage.tsx +++ b/src/components/questions/question-answer-storage.tsx @@ -175,8 +175,15 @@ function getOrderedFields( return orderedFields; } -function getCurrentStep(fields: MarriageField[]) { - return fields.filter((field) => hasQuestionAnswerValue(field.value)).length; +function getCurrentStep(fields: MarriageField[], questions: readonly QuestionField[]) { + return questions.filter((question, index) => { + if (!question.required || question.logic?.dependsOn) { + return false; + } + const key = getQuestionFieldKey(question, index); + const field = fields.find((f) => f.key === key); + return field && hasQuestionAnswerValue(field.value); + }).length; } function createPayload( @@ -184,10 +191,13 @@ function createPayload( questions: readonly QuestionField[], ): UpdateMarriageSectionDataPayload { const fields = getOrderedFields(answers, questions); + const targetQuestions = questions.filter( + (q) => q.required && !q.logic?.dependsOn + ); return { - current_step: getCurrentStep(fields), - total_steps: questions.length, + current_step: getCurrentStep(fields, questions), + total_steps: targetQuestions.length, fields, }; }