diff --git a/apps/web/app/(app)/(survey-editor)/environments/[environmentId]/surveys/[surveyId]/edit/components/AdvancedLogicEditorActions.tsx b/apps/web/app/(app)/(survey-editor)/environments/[environmentId]/surveys/[surveyId]/edit/components/AdvancedLogicEditorActions.tsx index f99bc112a1..ce2e6d6088 100644 --- a/apps/web/app/(app)/(survey-editor)/environments/[environmentId]/surveys/[surveyId]/edit/components/AdvancedLogicEditorActions.tsx +++ b/apps/web/app/(app)/(survey-editor)/environments/[environmentId]/surveys/[surveyId]/edit/components/AdvancedLogicEditorActions.tsx @@ -107,7 +107,7 @@ export function AdvancedLogicEditorActions({ options={ action.objective === "calculate" ? getActionVariableOptions(localSurvey) - : getActionTargetOptions(localSurvey, questionIdx) + : getActionTargetOptions(action, localSurvey, questionIdx) } selected={action.objective === "calculate" ? action.variableId : action.target} onChangeValue={(val: string) => { diff --git a/apps/web/app/(app)/(survey-editor)/environments/[environmentId]/surveys/[surveyId]/edit/components/HiddenFieldsCard.tsx b/apps/web/app/(app)/(survey-editor)/environments/[environmentId]/surveys/[surveyId]/edit/components/HiddenFieldsCard.tsx index b21fafaba9..ad892e0219 100644 --- a/apps/web/app/(app)/(survey-editor)/environments/[environmentId]/surveys/[surveyId]/edit/components/HiddenFieldsCard.tsx +++ b/apps/web/app/(app)/(survey-editor)/environments/[environmentId]/surveys/[surveyId]/edit/components/HiddenFieldsCard.tsx @@ -1,5 +1,6 @@ "use client"; +import { findHiddenFieldUsedInLogic } from "@/app/(app)/(survey-editor)/environments/[environmentId]/surveys/[surveyId]/edit/lib/util"; import * as Collapsible from "@radix-ui/react-collapsible"; import { useState } from "react"; import { toast } from "react-hot-toast"; @@ -64,6 +65,25 @@ export const HiddenFieldsCard = ({ }); }; + const handleDeleteHiddenField = (fieldId: string) => { + const quesIdx = findHiddenFieldUsedInLogic(localSurvey, fieldId); + + if (quesIdx !== -1) { + toast.error( + `${fieldId} is used in logic of question ${quesIdx + 1}. Please remove it from logic first.` + ); + return; + } + + updateSurvey( + { + enabled: true, + fieldIds: localSurvey.hiddenFields?.fieldIds?.filter((q) => q !== fieldId), + }, + fieldId + ); + }; + return (