2023-12-26 12:57:44 +00:00
|
|
|
|
import { useEffect, useRef, useState } from "react";
|
|
|
|
|
// import { useBlocker } from "react-router-dom";
|
|
|
|
|
import {
|
|
|
|
|
Box,
|
|
|
|
|
Button,
|
|
|
|
|
Typography,
|
|
|
|
|
Paper,
|
|
|
|
|
Modal,
|
|
|
|
|
TextField,
|
|
|
|
|
} from "@mui/material";
|
2023-11-20 17:22:13 +00:00
|
|
|
|
import { incrementCurrentStep } from "@root/quizes/actions";
|
|
|
|
|
import CustomWrapper from "@ui_kit/CustomWrapper";
|
|
|
|
|
import { DescriptionForm } from "./DescriptionForm/DescriptionForm";
|
|
|
|
|
import { ResultListForm } from "./ResultListForm";
|
|
|
|
|
import { SettingForm } from "./SettingForm";
|
2023-12-07 22:56:31 +00:00
|
|
|
|
import { WhenCard } from "./cards/WhenCard";
|
2023-12-10 17:15:55 +00:00
|
|
|
|
import { ResultCard, checkEmptyData } from "./cards/ResultCard";
|
2023-12-07 22:56:31 +00:00
|
|
|
|
import { EmailSettingsCard } from "./cards/EmailSettingsCard";
|
2023-12-19 23:08:33 +00:00
|
|
|
|
import { useCurrentQuiz } from "@root/quizes/hooks";
|
2023-12-09 21:04:26 +00:00
|
|
|
|
import { useQuestionsStore } from "@root/questions/store";
|
2023-12-21 08:29:51 +00:00
|
|
|
|
import { deleteQuestion } from "@root/questions/actions";
|
2023-12-09 21:04:26 +00:00
|
|
|
|
import { QuizQuestionResult } from "@model/questionTypes/result";
|
2023-12-07 22:56:31 +00:00
|
|
|
|
|
2023-12-26 12:57:44 +00:00
|
|
|
|
import IconPlus from "@icons/IconPlus";
|
|
|
|
|
import Info from "@icons/Info";
|
|
|
|
|
import Plus from "@icons/Plus";
|
|
|
|
|
import ArrowLeft from "@icons/questionsPage/arrowLeft";
|
|
|
|
|
|
2023-12-07 22:56:31 +00:00
|
|
|
|
export const ResultSettings = () => {
|
2023-12-19 23:08:33 +00:00
|
|
|
|
const { questions } = useQuestionsStore();
|
|
|
|
|
const quiz = useCurrentQuiz();
|
2023-12-26 12:57:44 +00:00
|
|
|
|
const results = useQuestionsStore().questions.filter(
|
2023-12-31 02:53:25 +00:00
|
|
|
|
(q): q is QuizQuestionResult => q.type === "result",
|
2023-12-26 12:57:44 +00:00
|
|
|
|
);
|
2023-12-19 23:08:33 +00:00
|
|
|
|
const [quizExpand, setQuizExpand] = useState(true);
|
|
|
|
|
const [resultContract, setResultContract] = useState(true);
|
2023-12-26 12:57:44 +00:00
|
|
|
|
const [triggerExit, setTriggerExit] = useState<{
|
|
|
|
|
follow: boolean;
|
|
|
|
|
path: string;
|
|
|
|
|
}>({ follow: false, path: "" });
|
|
|
|
|
const [openNotificationModal, setOpenNotificationModal] =
|
|
|
|
|
useState<boolean>(true);
|
2023-12-10 17:15:55 +00:00
|
|
|
|
const isReadyToLeaveRef = useRef(true);
|
2023-12-26 12:57:44 +00:00
|
|
|
|
// const blocker = useBlocker(false);
|
2023-12-24 15:03:46 +00:00
|
|
|
|
|
2023-12-19 23:08:33 +00:00
|
|
|
|
useEffect(
|
|
|
|
|
function calcIsReadyToLeave() {
|
|
|
|
|
let isReadyToLeave = true;
|
|
|
|
|
results.forEach((result) => {
|
|
|
|
|
if (checkEmptyData({ resultData: result })) {
|
|
|
|
|
isReadyToLeave = false;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
isReadyToLeaveRef.current = isReadyToLeave;
|
|
|
|
|
},
|
2023-12-31 02:53:25 +00:00
|
|
|
|
[results],
|
2023-12-19 23:08:33 +00:00
|
|
|
|
);
|
2023-12-09 22:03:53 +00:00
|
|
|
|
|
2023-12-11 10:08:54 +00:00
|
|
|
|
useEffect(() => {
|
2023-12-19 23:08:33 +00:00
|
|
|
|
return () => {
|
2023-12-26 12:57:44 +00:00
|
|
|
|
if (!isReadyToLeaveRef.current && window.location.pathname !== "/edit") {
|
|
|
|
|
setOpenNotificationModal(true);
|
|
|
|
|
}
|
2023-12-19 23:08:33 +00:00
|
|
|
|
};
|
2023-12-10 17:15:55 +00:00
|
|
|
|
}, []);
|
2023-12-11 10:08:54 +00:00
|
|
|
|
|
2023-12-26 12:57:44 +00:00
|
|
|
|
const cnsl = results.filter((q) => q.content.usage);
|
|
|
|
|
|
|
|
|
|
const shouldBlock = true; // Replace this
|
|
|
|
|
|
|
|
|
|
// useEffect(() => {
|
|
|
|
|
// if (shouldBlock) {
|
|
|
|
|
// blocker.proceed?.()
|
|
|
|
|
// }
|
|
|
|
|
// }, [shouldBlock]);
|
|
|
|
|
|
|
|
|
|
const leavePage = (leave: boolean) => {
|
|
|
|
|
if (leave) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setOpenNotificationModal(false);
|
|
|
|
|
};
|
2023-12-22 23:58:34 +00:00
|
|
|
|
|
2023-04-15 09:10:59 +00:00
|
|
|
|
return (
|
2023-10-16 14:23:44 +00:00
|
|
|
|
<Box sx={{ maxWidth: "796px" }}>
|
2023-12-19 23:08:33 +00:00
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
display: "flex",
|
|
|
|
|
alignItems: "center",
|
|
|
|
|
margin: "60px 0 40px 0",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Typography variant="h5">Настройки результатов</Typography>
|
2023-04-15 09:10:59 +00:00
|
|
|
|
<Info />
|
|
|
|
|
<Button
|
|
|
|
|
disableRipple
|
|
|
|
|
sx={{
|
|
|
|
|
ml: "auto",
|
|
|
|
|
width: "73px",
|
|
|
|
|
height: "19px",
|
|
|
|
|
color: "#7E2AEA",
|
|
|
|
|
textDecoration: "underline",
|
|
|
|
|
fontSize: "16px",
|
|
|
|
|
"&:hover": {
|
|
|
|
|
background: "none",
|
|
|
|
|
textDecoration: "underline",
|
|
|
|
|
},
|
|
|
|
|
}}
|
|
|
|
|
variant="text"
|
2023-12-07 22:56:31 +00:00
|
|
|
|
onClick={() => setQuizExpand(!quizExpand)}
|
2023-04-15 09:10:59 +00:00
|
|
|
|
>
|
|
|
|
|
Свернуть
|
|
|
|
|
</Button>
|
|
|
|
|
</Box>
|
2023-12-07 22:56:31 +00:00
|
|
|
|
|
|
|
|
|
<WhenCard quizExpand={quizExpand} />
|
2023-12-26 12:57:44 +00:00
|
|
|
|
{quiz.config.resultInfo.when === "email" && (
|
|
|
|
|
<EmailSettingsCard quizExpand={quizExpand} />
|
|
|
|
|
)}
|
2023-12-07 22:56:31 +00:00
|
|
|
|
|
2023-12-26 12:57:44 +00:00
|
|
|
|
<Box
|
|
|
|
|
sx={{ display: "flex", alignItems: "center", mb: "15px", mt: "15px" }}
|
|
|
|
|
>
|
2023-04-15 09:10:59 +00:00
|
|
|
|
<Typography variant="p1" sx={{ color: "#4D4D4D", fontSize: "14px" }}>
|
|
|
|
|
Создайте результат
|
|
|
|
|
</Typography>
|
|
|
|
|
<Button
|
|
|
|
|
disableRipple
|
|
|
|
|
sx={{
|
|
|
|
|
ml: "auto",
|
|
|
|
|
height: "19px",
|
|
|
|
|
color: "#7E2AEA",
|
|
|
|
|
textDecoration: "underline",
|
|
|
|
|
fontSize: "16px",
|
|
|
|
|
|
|
|
|
|
"&:hover": {
|
|
|
|
|
background: "none",
|
|
|
|
|
textDecoration: "underline",
|
|
|
|
|
},
|
|
|
|
|
}}
|
|
|
|
|
variant="text"
|
2023-12-07 22:56:31 +00:00
|
|
|
|
onClick={() => setResultContract(!resultContract)}
|
2023-04-15 09:10:59 +00:00
|
|
|
|
>
|
|
|
|
|
Развернуть все
|
|
|
|
|
</Button>
|
|
|
|
|
</Box>
|
|
|
|
|
|
2023-12-22 23:58:34 +00:00
|
|
|
|
{cnsl.map((resultQuestion) => (
|
2023-12-26 12:57:44 +00:00
|
|
|
|
<ResultCard
|
|
|
|
|
resultContract={resultContract}
|
|
|
|
|
resultData={resultQuestion}
|
|
|
|
|
key={resultQuestion.id}
|
|
|
|
|
/>
|
2023-12-19 23:08:33 +00:00
|
|
|
|
))}
|
2023-12-09 22:03:53 +00:00
|
|
|
|
<Modal
|
|
|
|
|
open={false}
|
|
|
|
|
// onClose={handleClose}
|
|
|
|
|
aria-labelledby="modal-modal-title"
|
|
|
|
|
aria-describedby="modal-modal-description"
|
|
|
|
|
>
|
|
|
|
|
<></>
|
|
|
|
|
</Modal>
|
2023-04-15 09:10:59 +00:00
|
|
|
|
</Box>
|
|
|
|
|
);
|
2023-04-23 08:39:34 +00:00
|
|
|
|
};
|