Browse Source

fix(question-storage): only use option_id for choice questions so scalar number questions preserve numeric values

master
mortezaei 2 days ago
parent
commit
954cc10c60
  1. 31
      src/components/Componentes/question-answer-storage.tsx

31
src/components/Componentes/question-answer-storage.tsx

@ -261,7 +261,18 @@ function createPayload(
function fieldsToAnswers(fields: MarriageField[]) { function fieldsToAnswers(fields: MarriageField[]) {
return fields.reduce<QuestionAnswersByKey>((nextAnswers, field) => { return fields.reduce<QuestionAnswersByKey>((nextAnswers, field) => {
if (field.option_id !== undefined && field.option_id !== null) {
const isChoice =
field.type === "dropdown" ||
field.type === "radio" ||
field.type === "checkbox" ||
field.type === "scale";
if (
isChoice &&
field.option_id !== undefined &&
field.option_id !== null &&
(!Array.isArray(field.option_id) || field.option_id.length > 0 || field.type === "checkbox")
) {
nextAnswers[field.key] = { nextAnswers[field.key] = {
...field, ...field,
value: field.option_id, value: field.option_id,
@ -640,11 +651,27 @@ export function QuestionAnswersProvider({
if (question) { if (question) {
// Only update if there are no newer local dirty edits for this key // Only update if there are no newer local dirty edits for this key
if (!dirtyKeysRef.current.has(key)) { if (!dirtyKeysRef.current.has(key)) {
const isChoice =
question.type === "dropdown" ||
question.type === "radio" ||
question.type === "checkbox" ||
question.type === "scale";
const resolvedVal =
isChoice &&
answer.option_id !== undefined &&
answer.option_id !== null &&
(!Array.isArray(answer.option_id) ||
answer.option_id.length > 0 ||
question.type === "checkbox")
? answer.option_id
: answer.value;
nextAnswers[key] = { nextAnswers[key] = {
key, key,
label: question.title, label: question.title,
type: question.type, type: question.type,
value: answer.option_id ?? answer.value,
value: resolvedVal,
option_id: answer.option_id, option_id: answer.option_id,
} as MarriageField; } as MarriageField;
} }

Loading…
Cancel
Save