2023-12-31 02:53:25 +00:00
|
|
|
|
import { Box } from "@mui/material";
|
2023-12-13 23:34:34 +00:00
|
|
|
|
import { useEffect, useRef, useLayoutEffect } from "react";
|
2023-12-31 02:53:25 +00:00
|
|
|
|
import {
|
|
|
|
|
deleteQuestion,
|
|
|
|
|
clearRuleForAll,
|
|
|
|
|
updateQuestion,
|
|
|
|
|
createResult,
|
|
|
|
|
} from "@root/questions/actions";
|
|
|
|
|
import { updateOpenedModalSettingsId } from "@root/uiTools/actions";
|
|
|
|
|
import { updateRootContentId } from "@root/quizes/actions";
|
|
|
|
|
import { useCurrentQuiz } from "@root/quizes/hooks";
|
|
|
|
|
import { useQuestionsStore } from "@root/questions/store";
|
2023-11-29 15:45:15 +00:00
|
|
|
|
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-31 02:53:25 +00:00
|
|
|
|
setOpenedModalQuestions: (open: boolean) => void;
|
|
|
|
|
modalQuestionTargetContentId: string;
|
2023-12-01 08:12:59 +00:00
|
|
|
|
}
|
2023-12-31 02:53:25 +00:00
|
|
|
|
export const FirstNodeField = ({
|
|
|
|
|
setOpenedModalQuestions,
|
|
|
|
|
modalQuestionTargetContentId,
|
|
|
|
|
}: Props) => {
|
|
|
|
|
const quiz = useCurrentQuiz();
|
2023-12-13 23:34:34 +00:00
|
|
|
|
|
2023-12-31 02:53:25 +00:00
|
|
|
|
useLayoutEffect(() => {
|
|
|
|
|
updateOpenedModalSettingsId();
|
|
|
|
|
updateRootContentId(quiz.id, "");
|
|
|
|
|
clearRuleForAll();
|
|
|
|
|
}, []);
|
2023-12-13 23:34:34 +00:00
|
|
|
|
|
2023-12-31 02:53:25 +00:00
|
|
|
|
const { questions } = useQuestionsStore();
|
|
|
|
|
const { dragQuestionContentId } = useUiTools();
|
|
|
|
|
const Container = useRef<HTMLDivElement | null>(null);
|
2023-12-13 23:34:34 +00:00
|
|
|
|
|
2023-12-31 02:53:25 +00:00
|
|
|
|
const modalOpen = () => setOpenedModalQuestions(true);
|
2023-12-13 23:34:34 +00:00
|
|
|
|
|
2023-12-31 02:53:25 +00:00
|
|
|
|
const newRootNode = () => {
|
|
|
|
|
if (quiz) {
|
|
|
|
|
if (dragQuestionContentId) {
|
|
|
|
|
updateRootContentId(quiz?.id, dragQuestionContentId);
|
|
|
|
|
updateQuestion(
|
|
|
|
|
dragQuestionContentId,
|
|
|
|
|
(question) => (question.content.rule.parentId = "root"),
|
|
|
|
|
);
|
|
|
|
|
createResult(quiz?.backendId, dragQuestionContentId);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
enqueueSnackbar("Нет информации о взятом опросе");
|
2023-11-29 15:45:15 +00:00
|
|
|
|
}
|
2023-12-31 02:53:25 +00:00
|
|
|
|
};
|
2023-11-29 15:45:15 +00:00
|
|
|
|
|
2023-12-31 02:53:25 +00:00
|
|
|
|
useEffect(() => {
|
|
|
|
|
Container.current?.addEventListener("mouseup", newRootNode);
|
|
|
|
|
Container.current?.addEventListener("click", modalOpen);
|
|
|
|
|
return () => {
|
|
|
|
|
Container.current?.removeEventListener("mouseup", newRootNode);
|
|
|
|
|
Container.current?.removeEventListener("click", modalOpen);
|
|
|
|
|
};
|
|
|
|
|
}, [dragQuestionContentId]);
|
2023-12-01 19:56:13 +00:00
|
|
|
|
|
2023-12-31 02:53:25 +00:00
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (quiz) {
|
|
|
|
|
if (modalQuestionTargetContentId) {
|
|
|
|
|
updateRootContentId(quiz?.id, modalQuestionTargetContentId);
|
|
|
|
|
updateQuestion(
|
|
|
|
|
modalQuestionTargetContentId,
|
|
|
|
|
(question) => (question.content.rule.parentId = "root"),
|
|
|
|
|
);
|
|
|
|
|
createResult(quiz?.backendId, modalQuestionTargetContentId);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
enqueueSnackbar("Нет информации о взятом опросе");
|
|
|
|
|
}
|
|
|
|
|
}, [modalQuestionTargetContentId]);
|
2023-12-04 13:33:43 +00:00
|
|
|
|
|
2023-12-31 02:53:25 +00:00
|
|
|
|
return (
|
|
|
|
|
<Box
|
|
|
|
|
ref={Container}
|
|
|
|
|
sx={{
|
|
|
|
|
height: "100%",
|
|
|
|
|
width: "100%",
|
|
|
|
|
backgroundColor: "#f2f3f7",
|
|
|
|
|
display: "flex",
|
|
|
|
|
alignItems: "center",
|
|
|
|
|
justifyContent: "center",
|
|
|
|
|
color: "#4d4d4d",
|
|
|
|
|
fontSize: "50px",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
+
|
|
|
|
|
</Box>
|
|
|
|
|
);
|
|
|
|
|
};
|