2023-12-29 13:32:57 +00:00
|
|
|
import { quizApi } from "@api/quiz";
|
2023-12-30 00:29:13 +00:00
|
|
|
import {Box, IconButton, useMediaQuery, useTheme} from "@mui/material";
|
2023-12-29 13:32:57 +00:00
|
|
|
import {
|
|
|
|
resetEditConfig,
|
|
|
|
setQuizes,
|
|
|
|
updateQuiz,
|
|
|
|
setCurrentStep,
|
|
|
|
} from "@root/quizes/actions";
|
|
|
|
import { useCurrentQuiz } from "@root/quizes/hooks";
|
|
|
|
import { useQuizStore } from "@root/quizes/store";
|
|
|
|
import Sidebar from "@ui_kit/Sidebar";
|
|
|
|
import { enqueueSnackbar } from "notistack";
|
2023-12-30 00:29:13 +00:00
|
|
|
import React, { useEffect, useState } from "react";
|
2023-12-29 13:32:57 +00:00
|
|
|
import { useNavigate } from "react-router-dom";
|
|
|
|
import { useDebouncedCallback } from "use-debounce";
|
2023-12-30 00:29:13 +00:00
|
|
|
import { SidebarMobile } from "../startPage/Sidebar/SidebarMobile";
|
2023-12-29 13:32:57 +00:00
|
|
|
import {
|
|
|
|
cleanQuestions,
|
|
|
|
createResult,
|
|
|
|
setQuestions,
|
|
|
|
} from "@root/questions/actions";
|
|
|
|
import {
|
|
|
|
updateCanCreatePublic,
|
|
|
|
updateModalInfoWhyCantCreate,
|
|
|
|
setShowConfirmLeaveModal,
|
|
|
|
updateSomeWorkBackend,
|
|
|
|
} from "@root/uiTools/actions";
|
|
|
|
import { useQuestionsStore } from "@root/questions/store";
|
|
|
|
import { questionApi } from "@api/question";
|
|
|
|
import { useUiTools } from "@root/uiTools/store";
|
|
|
|
|
|
|
|
import { clearUserData } from "@root/user";
|
|
|
|
import { clearAuthToken } from "@frontend/kitui";
|
|
|
|
import { logout } from "@api/auth";
|
|
|
|
import { AnyTypedQuizQuestion } from "@model/questionTypes/shared";
|
2023-12-30 00:29:13 +00:00
|
|
|
import { ModalInfoWhyCantCreate } from "../startPage/ModalInfoWhyCantCreate";
|
|
|
|
import { ConfirmLeaveModal } from "../startPage/ConfirmLeaveModal";
|
2023-12-29 13:32:57 +00:00
|
|
|
import { checkQuestionHint } from "@utils/checkQuestionHint";
|
2023-12-30 00:29:13 +00:00
|
|
|
import { Header } from "../startPage/Header";
|
|
|
|
import {DesignFilling} from "./DesignFilling";
|
|
|
|
import {toggleQuizPreview} from "@root/quizPreview";
|
|
|
|
import VisibilityIcon from "@mui/icons-material/Visibility";
|
|
|
|
import {createPortal} from "react-dom";
|
|
|
|
import QuizPreview from "@ui_kit/QuizPreview/QuizPreview";
|
2023-12-29 13:32:57 +00:00
|
|
|
|
|
|
|
export const DesignPage = () => {
|
|
|
|
const quiz = useCurrentQuiz();
|
|
|
|
const { editQuizId } = useQuizStore();
|
|
|
|
const { questions } = useQuestionsStore();
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
const getData = async () => {
|
|
|
|
const quizes = await quizApi.getList();
|
|
|
|
setQuizes(quizes);
|
2023-12-30 00:29:13 +00:00
|
|
|
if (editQuizId) {
|
|
|
|
const questions = await questionApi.getList({ quiz_id: editQuizId });
|
|
|
|
setQuestions(questions);
|
|
|
|
}
|
2023-12-29 13:32:57 +00:00
|
|
|
};
|
|
|
|
getData();
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
const { showConfirmLeaveModal } = useUiTools();
|
|
|
|
const theme = useTheme();
|
|
|
|
const navigate = useNavigate();
|
|
|
|
const currentStep = useQuizStore((state) => state.currentStep);
|
|
|
|
const isMobile = useMediaQuery(theme.breakpoints.down(660));
|
|
|
|
const [mobileSidebar, setMobileSidebar] = useState<boolean>(false);
|
|
|
|
const [nextStep, setNextStep] = useState<number>(0);
|
|
|
|
|
|
|
|
useEffect(
|
|
|
|
() => () => {
|
|
|
|
cleanQuestions();
|
|
|
|
updateModalInfoWhyCantCreate(false);
|
|
|
|
updateSomeWorkBackend(false);
|
|
|
|
},
|
|
|
|
[]
|
|
|
|
);
|
2023-12-29 14:48:53 +00:00
|
|
|
|
2023-12-29 13:32:57 +00:00
|
|
|
useEffect(() => {
|
2023-12-29 14:48:53 +00:00
|
|
|
if (editQuizId === null) navigate("/list");
|
2023-12-30 00:29:13 +00:00
|
|
|
|
2023-12-29 14:48:53 +00:00
|
|
|
}, [navigate, editQuizId]);
|
2023-12-29 13:32:57 +00:00
|
|
|
|
|
|
|
const followNewPage = () => {
|
|
|
|
setShowConfirmLeaveModal(false);
|
|
|
|
setCurrentStep(nextStep);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const changePage = (index: number) => {
|
|
|
|
if (currentStep === 2) {
|
|
|
|
setNextStep(index);
|
|
|
|
setShowConfirmLeaveModal(true);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
setCurrentStep(index);
|
|
|
|
};
|
|
|
|
|
2023-12-29 14:48:53 +00:00
|
|
|
console.log(quiz)
|
|
|
|
if (!quiz) return <></>;
|
2023-12-29 13:32:57 +00:00
|
|
|
return (
|
|
|
|
<>
|
2023-12-29 14:06:53 +00:00
|
|
|
<Header setMobileSidebar={setMobileSidebar} />
|
2023-12-30 00:29:13 +00:00
|
|
|
<Box sx={{ display: "flex", flexDirection: isMobile ? "column" : "row" }}>
|
2023-12-29 13:32:57 +00:00
|
|
|
{isMobile ? (
|
|
|
|
<SidebarMobile open={mobileSidebar} changePage={changePage} />
|
|
|
|
) : (
|
|
|
|
<Sidebar changePage={changePage} />
|
|
|
|
)}
|
2023-12-30 00:29:13 +00:00
|
|
|
<DesignFilling/>
|
|
|
|
{createPortal(<QuizPreview />, document.body)}
|
2023-12-29 13:32:57 +00:00
|
|
|
</Box>
|
|
|
|
<ModalInfoWhyCantCreate />
|
|
|
|
<ConfirmLeaveModal
|
|
|
|
open={showConfirmLeaveModal}
|
|
|
|
follow={followNewPage}
|
|
|
|
cancel={() => setShowConfirmLeaveModal(false)}
|
|
|
|
/>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|