diff --git a/apps/web/modules/survey/editor/components/conditional-logic.test.tsx b/apps/web/modules/survey/editor/components/conditional-logic.test.tsx index 4f2b6dc0af..beb4ab04fa 100755 --- a/apps/web/modules/survey/editor/components/conditional-logic.test.tsx +++ b/apps/web/modules/survey/editor/components/conditional-logic.test.tsx @@ -241,4 +241,40 @@ describe("ConditionalLogic", () => { expect(screen.getAllByTestId("logic-editor").length).toBe(2); }); + + test("should clear logicFallback when logic array is empty and logicFallback exists (useEffect)", () => { + const mockUpdateQuestion = vi.fn(); + const mockQuestion: TSurveyQuestion = { + id: "testQuestionId", + type: TSurveyQuestionTypeEnum.OpenText, + headline: { default: "Test Question" }, + required: false, + inputType: "text", + charLimit: { enabled: false }, + logic: [], // Empty logic array + logicFallback: "someTarget", // Has logicFallback but no logic + }; + const mockSurvey = { + id: "testSurveyId", + name: "Test Survey", + type: "link", + createdAt: new Date(), + updatedAt: new Date(), + environmentId: "testEnvId", + status: "inProgress", + questions: [mockQuestion], + endings: [], + } as unknown as TSurvey; + + render( + + ); + + expect(mockUpdateQuestion).toHaveBeenCalledWith(0, { logicFallback: undefined }); + }); }); diff --git a/apps/web/modules/survey/editor/components/conditional-logic.tsx b/apps/web/modules/survey/editor/components/conditional-logic.tsx index 3cf95ae3de..c0d2553f09 100644 --- a/apps/web/modules/survey/editor/components/conditional-logic.tsx +++ b/apps/web/modules/survey/editor/components/conditional-logic.tsx @@ -27,7 +27,7 @@ import { SplitIcon, TrashIcon, } from "lucide-react"; -import { useMemo } from "react"; +import { useEffect, useMemo } from "react"; import { TSurvey, TSurveyLogic, TSurveyQuestion } from "@formbricks/types/surveys/types"; interface ConditionalLogicProps { @@ -117,6 +117,12 @@ export function ConditionalLogic({ }; const [parent] = useAutoAnimate(); + useEffect(() => { + if (question.logic?.length === 0 && question.logicFallback) { + updateQuestion(questionIdx, { logicFallback: undefined }); + } + }, [question.logic, questionIdx, question.logicFallback, updateQuestion]); + return (