2023-11-29 15:45:15 +00:00
|
|
|
|
import { Box } from "@mui/material"
|
2023-12-13 23:34:34 +00:00
|
|
|
|
import { useEffect, useRef, useLayoutEffect } from "react";
|
2023-12-14 16:50:02 +00:00
|
|
|
|
import { deleteQuestion, clearRuleForAll, updateQuestion } from "@root/questions/actions"
|
|
|
|
|
import { updateOpenedModalSettingsId } from "@root/uiTools/actions"
|
2023-12-03 10:48:00 +00:00
|
|
|
|
import { updateRootContentId } from "@root/quizes/actions"
|
2023-12-04 13:33:43 +00:00
|
|
|
|
import { useCurrentQuiz } from "@root/quizes/hooks"
|
2023-11-29 15:45:15 +00:00
|
|
|
|
import { useQuestionsStore } from "@root/questions/store"
|
|
|
|
|
import { enqueueSnackbar } from "notistack";
|
2023-12-14 09:40:53 +00:00
|
|
|
|
import { useUiTools } from "@root/uiTools/store";
|
2023-11-29 15:45:15 +00:00
|
|
|
|
|
2023-12-01 08:12:59 +00:00
|
|
|
|
interface Props {
|
2023-12-01 19:56:13 +00:00
|
|
|
|
setOpenedModalQuestions: (open: boolean) => void;
|
|
|
|
|
modalQuestionTargetContentId: string;
|
2023-12-01 08:12:59 +00:00
|
|
|
|
}
|
2023-12-01 19:56:13 +00:00
|
|
|
|
export const FirstNodeField = ({ setOpenedModalQuestions, modalQuestionTargetContentId }: Props) => {
|
2023-11-29 15:45:15 +00:00
|
|
|
|
const quiz = useCurrentQuiz();
|
2023-12-13 23:34:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
useLayoutEffect(() => {
|
|
|
|
|
updateOpenedModalSettingsId()
|
2023-12-14 17:58:56 +00:00
|
|
|
|
updateRootContentId(quiz.id, "")
|
|
|
|
|
clearRuleForAll()
|
2023-12-13 23:34:34 +00:00
|
|
|
|
}, [])
|
|
|
|
|
|
|
|
|
|
|
2023-12-14 09:40:53 +00:00
|
|
|
|
const { questions } = useQuestionsStore()
|
|
|
|
|
const { dragQuestionContentId } = useUiTools()
|
2023-12-04 13:33:43 +00:00
|
|
|
|
const Container = useRef<HTMLDivElement | null>(null);
|
2023-11-29 15:45:15 +00:00
|
|
|
|
|
2023-12-01 19:56:13 +00:00
|
|
|
|
const modalOpen = () => setOpenedModalQuestions(true)
|
2023-11-29 15:45:15 +00:00
|
|
|
|
|
|
|
|
|
const newRootNode = () => {
|
|
|
|
|
if (quiz) {
|
2023-12-01 19:56:13 +00:00
|
|
|
|
if (dragQuestionContentId) {
|
2023-12-03 10:48:00 +00:00
|
|
|
|
updateRootContentId(quiz?.id, dragQuestionContentId)
|
2023-12-01 19:56:13 +00:00
|
|
|
|
updateQuestion(dragQuestionContentId, (question) => question.content.rule.parentId = "root")
|
2023-12-12 15:44:18 +00:00
|
|
|
|
//если были результаты - удалить
|
|
|
|
|
questions.forEach((q) => {
|
|
|
|
|
if (q.type === 'result') deleteQuestion(q.id)
|
|
|
|
|
})
|
|
|
|
|
|
2023-11-29 15:45:15 +00:00
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
enqueueSnackbar("Нет информации о взятом опроснике")
|
|
|
|
|
}
|
2023-12-04 13:33:43 +00:00
|
|
|
|
|
2023-11-29 15:45:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
Container.current?.addEventListener("mouseup", newRootNode)
|
2023-12-01 19:56:13 +00:00
|
|
|
|
Container.current?.addEventListener("click", modalOpen)
|
|
|
|
|
return () => {
|
|
|
|
|
Container.current?.removeEventListener("mouseup", newRootNode)
|
|
|
|
|
Container.current?.removeEventListener("click", modalOpen)
|
|
|
|
|
}
|
2023-12-02 13:51:37 +00:00
|
|
|
|
}, [dragQuestionContentId])
|
2023-11-29 15:45:15 +00:00
|
|
|
|
|
2023-12-01 19:56:13 +00:00
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (quiz) {
|
|
|
|
|
|
2023-12-02 13:51:37 +00:00
|
|
|
|
if (modalQuestionTargetContentId) {
|
2023-12-03 10:48:00 +00:00
|
|
|
|
updateRootContentId(quiz?.id, modalQuestionTargetContentId)
|
2023-12-01 19:56:13 +00:00
|
|
|
|
updateQuestion(modalQuestionTargetContentId, (question) => question.content.rule.parentId = "root")
|
2023-12-12 15:44:18 +00:00
|
|
|
|
//если были результаты - удалить
|
|
|
|
|
questions.forEach((q) => {
|
|
|
|
|
if (q.type === 'result') deleteQuestion(q.id)
|
|
|
|
|
})
|
2023-12-01 19:56:13 +00:00
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
enqueueSnackbar("Нет информации о взятом опроснике")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}, [modalQuestionTargetContentId])
|
|
|
|
|
|
2023-12-04 13:33:43 +00:00
|
|
|
|
|
2023-11-29 15:45:15 +00:00
|
|
|
|
return (
|
|
|
|
|
<Box
|
|
|
|
|
ref={Container}
|
|
|
|
|
sx={{
|
|
|
|
|
height: "100%",
|
|
|
|
|
width: "100%",
|
|
|
|
|
backgroundColor: "#f2f3f7",
|
|
|
|
|
display: "flex",
|
|
|
|
|
alignItems: "center",
|
|
|
|
|
justifyContent: "center",
|
|
|
|
|
color: "#4d4d4d",
|
|
|
|
|
fontSize: "50px"
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
+
|
|
|
|
|
</Box>
|
|
|
|
|
)
|
|
|
|
|
}
|