Browse Source

feat: add QuestionAnswersProvider to manage local state and persistent synchronization for marriage section questions

master
sina_sajjadi 3 weeks ago
parent
commit
cee7cd816d
  1. 18
      src/components/questions/question-answer-storage.tsx

18
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,
};
}

Loading…
Cancel
Save