2023-12-01 19:56:13 +00:00
|
|
|
import { Box, Modal, Button, Typography } from "@mui/material";
|
|
|
|
import { useQuestionsStore } from "@root/questions/store";
|
2023-12-04 13:36:30 +00:00
|
|
|
import { AnyTypedQuizQuestion } from "@model/questionTypes/shared";
|
2023-12-01 19:56:13 +00:00
|
|
|
|
|
|
|
interface Props {
|
|
|
|
openedModalQuestions: boolean;
|
2023-12-04 13:36:30 +00:00
|
|
|
setModalQuestionTargetContentId: (contentId: string) => void;
|
|
|
|
setOpenedModalQuestions: (open: boolean) => void;
|
2023-12-01 19:56:13 +00:00
|
|
|
}
|
|
|
|
|
2023-12-04 13:36:30 +00:00
|
|
|
export const BranchingQuestionsModal = ({
|
|
|
|
openedModalQuestions,
|
|
|
|
setOpenedModalQuestions,
|
|
|
|
setModalQuestionTargetContentId,
|
|
|
|
}: Props) => {
|
2023-12-14 13:36:00 +00:00
|
|
|
const trashQuestions = useQuestionsStore().questions;
|
|
|
|
const questions = trashQuestions.filter(
|
|
|
|
(question) => question.type !== "result"
|
|
|
|
);
|
2023-12-01 19:56:13 +00:00
|
|
|
|
|
|
|
const handleClose = () => {
|
|
|
|
setOpenedModalQuestions(false);
|
|
|
|
};
|
|
|
|
|
2023-12-04 13:36:30 +00:00
|
|
|
const typedQuestions: AnyTypedQuizQuestion[] = questions.filter(
|
2023-12-20 14:18:01 +00:00
|
|
|
(question) =>
|
|
|
|
question.type &&
|
|
|
|
!question.content.rule.parentId &&
|
|
|
|
question.type !== "result"
|
2023-12-04 13:36:30 +00:00
|
|
|
) as AnyTypedQuizQuestion[];
|
|
|
|
|
2023-12-20 14:18:01 +00:00
|
|
|
if (typedQuestions.length === 0) return <></>;
|
|
|
|
|
2023-12-01 19:56:13 +00:00
|
|
|
return (
|
|
|
|
<Modal open={openedModalQuestions} onClose={handleClose}>
|
|
|
|
<Box
|
|
|
|
sx={{
|
|
|
|
position: "absolute",
|
2023-12-17 22:34:22 +00:00
|
|
|
overflow: "auto",
|
2023-12-01 19:56:13 +00:00
|
|
|
top: "50%",
|
|
|
|
left: "50%",
|
|
|
|
transform: "translate(-50%, -50%)",
|
|
|
|
maxWidth: "620px",
|
|
|
|
width: "100%",
|
|
|
|
bgcolor: "background.paper",
|
|
|
|
borderRadius: "12px",
|
|
|
|
boxShadow: 24,
|
|
|
|
padding: "30px 0",
|
2023-12-20 14:18:01 +00:00
|
|
|
height: "80vh",
|
2023-12-01 19:56:13 +00:00
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Box sx={{ margin: "0 auto", maxWidth: "350px" }}>
|
2023-12-04 13:36:30 +00:00
|
|
|
{typedQuestions.map((question) => (
|
2023-12-01 19:56:13 +00:00
|
|
|
<Button
|
|
|
|
key={question.content.id}
|
|
|
|
onClick={() => {
|
2023-12-04 13:36:30 +00:00
|
|
|
setModalQuestionTargetContentId(question.content.id);
|
2023-12-01 19:56:13 +00:00
|
|
|
handleClose();
|
|
|
|
}}
|
|
|
|
sx={{
|
|
|
|
width: "100%",
|
|
|
|
cursor: "pointer",
|
|
|
|
display: "flex",
|
|
|
|
justifyContent: "space-between",
|
|
|
|
alignItems: "center",
|
|
|
|
padding: "12px",
|
|
|
|
background: "#FFFFFF",
|
|
|
|
borderRadius: "8px",
|
|
|
|
marginBottom: "20px",
|
|
|
|
boxShadow: "0px 10px 30px #e7e7e7",
|
2023-12-14 13:36:00 +00:00
|
|
|
backgroundImage: `url("data:image/svg+xml,%3csvg width='100%25' height='100%25' xmlns='http://www.w3.org/2000/svg'%3e%3crect width='100%25' height='100%25' fill='none' rx='8' ry='8' stroke='rgb(154, 154, 175)' strokeWidth='2' stroke-dasharray='8 8' stroke-dashoffset='0' strokeLinecap='square'/%3e%3c/svg%3e");
|
2023-12-01 19:56:13 +00:00
|
|
|
border-radius: 8px;`,
|
|
|
|
"&:last-child": { marginBottom: 0 },
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Typography
|
|
|
|
sx={{
|
|
|
|
width: "100%",
|
|
|
|
color: "#000",
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{question.title || "нет заголовка"}
|
|
|
|
</Typography>
|
|
|
|
</Button>
|
|
|
|
))}
|
|
|
|
</Box>
|
|
|
|
</Box>
|
|
|
|
</Modal>
|
|
|
|
);
|
|
|
|
};
|