diff --git a/src/pages/Questions/BranchingMap/CsComponent.tsx b/src/pages/Questions/BranchingMap/CsComponent.tsx index 61a431f8..3ecb1118 100644 --- a/src/pages/Questions/BranchingMap/CsComponent.tsx +++ b/src/pages/Questions/BranchingMap/CsComponent.tsx @@ -125,9 +125,11 @@ function CsComponent({ const parentQuestion = getQuestionByContentId(parentNodeContentId) //Нельзя добавлять больше 1 ребёнка вопросам типа страница, ползунок, своё поле для ввода и дата - if (parentQuestion?.type === "date" || parentQuestion?.type === "text" || parentQuestion?.type === "number" || parentQuestion?.type === "page" + if ((parentQuestion?.type === "date" || parentQuestion?.type === "text" || parentQuestion?.type === "number" || parentQuestion?.type === "page") && parentQuestion.content.rule.children.length === 1 ) { + console.log(parentQuestion.content.rule.children) + console.log("parentQuestion.content.rule.children.length === 1",parentQuestion.content.rule.children.length === 1) enqueueSnackbar("у вопроса этого типа может быть только 1 потомок") return } diff --git a/src/pages/Questions/DraggableList/ChooseAnswerModal.tsx b/src/pages/Questions/DraggableList/ChooseAnswerModal.tsx index 5e067917..e95abc0b 100644 --- a/src/pages/Questions/DraggableList/ChooseAnswerModal.tsx +++ b/src/pages/Questions/DraggableList/ChooseAnswerModal.tsx @@ -12,11 +12,13 @@ import { Typography, useTheme, } from "@mui/material"; -import { changeQuestionType } from "@root/questions/actions"; +import { changeQuestionType, updateQuestion } from "@root/questions/actions"; import type { RefObject } from "react"; import { useState } from "react"; import type { AnyTypedQuizQuestion, UntypedQuizQuestion } from "../../../model/questionTypes/shared"; import { BUTTON_TYPE_QUESTIONS } from "../TypeQuestions"; +import { useQuestionsStore } from "@root/questions/store"; +import { updateSomeWorkBackend } from "@root/uiTools/actions"; type ChooseAnswerModalProps = { @@ -36,6 +38,7 @@ export const ChooseAnswerModal = ({ }: ChooseAnswerModalProps) => { const [openModal, setOpenModal] = useState(false); const [selectedValue, setSelectedValue] = useState("text"); + const { questions } = useQuestionsStore() const theme = useTheme(); return ( @@ -94,8 +97,8 @@ export const ChooseAnswerModal = ({ background: "#FFFFFF", }} > - - Все настройки, кроме заголовка вопроса будут сброшены
+ + Все настройки, кроме заголовка вопроса будут сброшены
(вопрос всё ещё будет участвовать в ветвлении, но его условия будут сброшены)
{ + onClick={async () => { + + updateSomeWorkBackend(true) setOpenModal(false); + const clearQuestions = [] as string[]; + + //записываем потомков , а их результаты удаляем + const getChildren = (parentQuestion: any) => { + questions.forEach((targetQuestion) => { + if (targetQuestion.type !== null && targetQuestion.content.rule.parentId === parentQuestion.content.id) {//если у вопроса совпал родитель с родителем => он потомок, в кучу его + if (targetQuestion.type !== "result" && targetQuestion.type !== null) { + if (!clearQuestions.includes(targetQuestion.content.id)) clearQuestions.push(targetQuestion.content.id); + getChildren(targetQuestion); //и ищем его потомков + } + } + }); + }; + getChildren(question); + + updateQuestion(question.id, q => { + q.content.rule.parentId = ""; + q.content.rule.main = []; + q.content.rule.children = []; + q.content.rule.default = ""; + }); + //чистим потомков от инфы ветвления + await Promise.allSettled( + clearQuestions.map((id) => { + updateQuestion(id, question => { + question.content.rule.parentId = ""; + question.content.rule.main = []; + question.content.rule.children = []; + question.content.rule.default = ""; + }); + }) + ) changeQuestionType(question.id, selectedValue); + updateSomeWorkBackend(false) }} > Подтвердить diff --git a/src/pages/startPage/EditPage.tsx b/src/pages/startPage/EditPage.tsx index 3ff301e3..397c6f17 100755 --- a/src/pages/startPage/EditPage.tsx +++ b/src/pages/startPage/EditPage.tsx @@ -40,6 +40,7 @@ import { updateCanCreatePublic, updateModalInfoWhyCantCreate, setShowConfirmLeaveModal, + updateSomeWorkBackend, } from "@root/uiTools/actions"; import { BranchingPanel } from "../Questions/BranchingPanel"; import { useQuestionsStore } from "@root/questions/store"; @@ -123,6 +124,7 @@ export default function EditPage() { resetEditConfig(); cleanQuestions(); updateModalInfoWhyCantCreate(false); + updateSomeWorkBackend(false) }, [] ); diff --git a/src/utils/deleteFunc.ts b/src/utils/deleteFunc.ts index 5158f2ce..27098b9d 100644 --- a/src/utils/deleteFunc.ts +++ b/src/utils/deleteFunc.ts @@ -33,6 +33,7 @@ export const DeleteFunction = async (questions: any, question: any, quiz: any) = clearQuestions.map((id) => { updateQuestion(id, question => { question.content.rule.parentId = ""; + question.content.rule.children = []; question.content.rule.main = []; question.content.rule.default = ""; });