frontPanel/src/pages/Questions/BranchingQuestionsModal/index.tsx

91 lines
2.9 KiB
TypeScript
Raw Normal View History

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";
interface Props {
openedModalQuestions: boolean;
2023-12-04 13:36:30 +00:00
setModalQuestionTargetContentId: (contentId: string) => void;
setOpenedModalQuestions: (open: boolean) => void;
}
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"
);
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 <></>;
return (
<Modal open={openedModalQuestions} onClose={handleClose}>
<Box
sx={{
position: "absolute",
overflow: "auto",
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",
}}
>
<Box sx={{ margin: "0 auto", maxWidth: "350px" }}>
2023-12-04 13:36:30 +00:00
{typedQuestions.map((question) => (
<Button
key={question.content.id}
onClick={() => {
2023-12-04 13:36:30 +00:00
setModalQuestionTargetContentId(question.content.id);
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");
border-radius: 8px;`,
"&:last-child": { marginBottom: 0 },
}}
>
<Typography
sx={{
width: "100%",
color: "#000",
}}
>
{question.title || "нет заголовка"}
</Typography>
</Button>
))}
</Box>
</Box>
</Modal>
);
};