fix: not allow new logic jump until previous filled & do not allow saving survey until atleast 2 fields are filled

This commit is contained in:
ShubhamPalriwala
2023-08-31 20:57:45 +05:30
parent b7d4885e51
commit bca1e0e926
2 changed files with 25 additions and 0 deletions
@@ -20,6 +20,7 @@ import {
import { QuestionMarkCircleIcon, TrashIcon } from "@heroicons/react/24/solid";
import { ChevronDown, SplitIcon } from "lucide-react";
import { useMemo } from "react";
import { toast } from "react-hot-toast";
import { BsArrowDown, BsArrowReturnRight } from "react-icons/bs";
interface LogicEditorProps {
@@ -141,6 +142,17 @@ export default function LogicEditor({
};
const addLogic = () => {
if (question.logic && question.logic?.length >= 0) {
const hasUndefinedLogic = question.logic.some(
(logic) =>
logic.condition === undefined && logic.value === undefined && logic.destination === undefined
);
if (hasUndefinedLogic) {
toast.error("Please fill the existing logic jump first!");
return;
}
}
const newLogic: Logic[] = !question.logic ? [] : question.logic;
newLogic.push({
condition: undefined,
@@ -115,6 +115,19 @@ export default function SurveyMenuBar({
return false;
}
for (const question of survey.questions) {
for (const logic of question.logic || []) {
const validFields = ["condition", "destination", "value"].filter(
(field) => logic[field] !== undefined
).length;
if (validFields < 2) {
toast.error("Please fill all the opened Logic Jumps or delete them!");
return false;
}
}
}
/*
Check whether the count for autocomplete responses is not less
than the current count of accepted response and also it is not set to 0