diff --git a/apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/edit/MultipleChoiceMultiForm.tsx b/apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/edit/MultipleChoiceMultiForm.tsx index 5c0e99f7bf..e086541663 100644 --- a/apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/edit/MultipleChoiceMultiForm.tsx +++ b/apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/edit/MultipleChoiceMultiForm.tsx @@ -53,16 +53,28 @@ export default function MultipleChoiceMultiForm({ }, }; - const updateChoice = (choiceIdx: number, updatedAttributes: any) => { - const newChoices = !question.choices - ? [] - : question.choices.map((choice, idx) => { - if (idx === choiceIdx) { - return { ...choice, ...updatedAttributes }; - } - return choice; - }); - updateQuestion(questionIdx, { choices: newChoices }); + const updateChoice = (choiceIdx: number, updatedAttributes: { label: string }) => { + const newLabel = updatedAttributes.label; + const oldLabel = question.choices[choiceIdx].label; + let newChoices: any[] = []; + if (question.choices) { + newChoices = question.choices.map((choice, idx) => { + if (idx !== choiceIdx) return choice; + return { ...choice, ...updatedAttributes }; + }); + } + + let newLogic: any[] = []; + question.logic?.forEach((logic) => { + let newL: string | string[] | undefined = logic.value; + if (Array.isArray(logic.value)) { + newL = logic.value.map((value) => (value === oldLabel ? newLabel : value)); + } else { + newL = logic.value === oldLabel ? newLabel : logic.value; + } + newLogic.push({ ...logic, value: newL }); + }); + updateQuestion(questionIdx, { choices: newChoices, logic: newLogic }); }; const addChoice = (choiceIdx?: number) => { diff --git a/apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/edit/MultipleChoiceSingleForm.tsx b/apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/edit/MultipleChoiceSingleForm.tsx index a91188f36f..db5bf4a460 100644 --- a/apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/edit/MultipleChoiceSingleForm.tsx +++ b/apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/edit/MultipleChoiceSingleForm.tsx @@ -53,16 +53,28 @@ export default function MultipleChoiceSingleForm({ }, }; - const updateChoice = (choiceIdx: number, updatedAttributes: any) => { - const newChoices = !question.choices - ? [] - : question.choices.map((choice, idx) => { - if (idx === choiceIdx) { - return { ...choice, ...updatedAttributes }; - } - return choice; - }); - updateQuestion(questionIdx, { choices: newChoices }); + const updateChoice = (choiceIdx: number, updatedAttributes: { label: string }) => { + const newLabel = updatedAttributes.label; + const oldLabel = question.choices[choiceIdx].label; + let newChoices: any[] = []; + if (question.choices) { + newChoices = question.choices.map((choice, idx) => { + if (idx !== choiceIdx) return choice; + return { ...choice, ...updatedAttributes }; + }); + } + + let newLogic: any[] = []; + question.logic?.forEach((logic) => { + let newL: string | string[] | undefined = logic.value; + if (Array.isArray(logic.value)) { + newL = logic.value.map((value) => (value === oldLabel ? newLabel : value)); + } else { + newL = logic.value === oldLabel ? newLabel : logic.value; + } + newLogic.push({ ...logic, value: newL }); + }); + updateQuestion(questionIdx, { choices: newChoices, logic: newLogic }); }; const addChoice = (choiceIdx?: number) => {