mirror of
https://github.com/formbricks/formbricks.git
synced 2025-12-30 18:30:32 -06:00
fix: logicfallback cleanup backport (#6603)
This commit is contained in:
@@ -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(
|
||||
<ConditionalLogic
|
||||
localSurvey={mockSurvey}
|
||||
question={mockQuestion}
|
||||
questionIdx={0}
|
||||
updateQuestion={mockUpdateQuestion}
|
||||
/>
|
||||
);
|
||||
|
||||
expect(mockUpdateQuestion).toHaveBeenCalledWith(0, { logicFallback: undefined });
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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 (
|
||||
<div className="mt-4" ref={parent}>
|
||||
<Label className="flex gap-2">
|
||||
|
||||
Reference in New Issue
Block a user