frontPanel/src/pages/Questions/DraggableList/ChooseAnswerModal.tsx

138 lines
5.3 KiB
TypeScript
Raw Normal View History

2023-09-20 12:42:14 +00:00
import {
2023-11-14 20:15:52 +00:00
Box,
Button,
ClickAwayListener,
2023-11-14 20:15:52 +00:00
Grow,
MenuItem,
MenuList,
2023-11-14 20:15:52 +00:00
Modal,
Paper,
Popper,
Typography,
2023-11-14 20:15:52 +00:00
useTheme,
2023-09-20 12:42:14 +00:00
} from "@mui/material";
import { useState } from "react";
2023-09-20 12:42:14 +00:00
import { BUTTON_TYPE_QUESTIONS } from "../TypeQuestions";
import type { RefObject } from "react";
import type { AnyQuizQuestion } from "../../../model/questionTypes/shared";
import { QuestionType } from "@model/question/question";
2023-09-20 12:42:14 +00:00
type ChooseAnswerModalProps = {
2023-11-14 20:15:52 +00:00
open: boolean;
onClose: () => void;
anchorRef: RefObject<HTMLDivElement>;
question: AnyQuizQuestion;
switchState: string;
2023-09-20 12:42:14 +00:00
};
export const ChooseAnswerModal = ({
2023-11-14 20:15:52 +00:00
open,
onClose,
anchorRef,
question,
switchState,
2023-09-20 12:42:14 +00:00
}: ChooseAnswerModalProps) => {
2023-11-14 20:15:52 +00:00
const [openModal, setOpenModal] = useState<boolean>(false);
const [selectedValue, setSelectedValue] = useState<QuestionType>("text");
2023-11-14 20:15:52 +00:00
const theme = useTheme();
2023-09-20 12:42:14 +00:00
2023-11-14 20:15:52 +00:00
return (
<>
<Popper
placement="right-start"
open={open}
anchorEl={anchorRef.current}
transition
>
{({ TransitionProps }) => (
<Grow {...TransitionProps}>
<Paper>
<ClickAwayListener onClickAway={onClose}>
<MenuList autoFocusItem={open}>
{BUTTON_TYPE_QUESTIONS.map(({ icon, title, value }) => (
<MenuItem
key={value}
sx={{ display: "flex", gap: "10px" }}
{...(value !== switchState && {
onClick: () => {
onClose();
setOpenModal(true);
setSelectedValue(value);
},
})}
>
<Box>{icon}</Box>
<Typography
sx={{
color:
value === switchState
? theme.palette.brightPurple.main
: theme.palette.grey2.main,
}}
>
{title}
</Typography>
</MenuItem>
))}
</MenuList>
</ClickAwayListener>
</Paper>
</Grow>
)}
</Popper>
<Modal open={openModal} onClose={() => setOpenModal(false)}>
<Box
sx={{
position: "absolute",
top: "50%",
left: "50%",
transform: "translate(-50%, -50%)",
padding: "30px",
borderRadius: "10px",
background: "#FFFFFF",
}}
>
<Typography variant="h6">
Все настройки, кроме заголовка вопроса будут сброшены
</Typography>
<Box
2023-09-28 09:35:25 +00:00
sx={{
2023-11-14 20:15:52 +00:00
marginTop: "30px",
display: "flex",
justifyContent: "center",
gap: "15px",
2023-09-28 09:35:25 +00:00
}}
2023-11-14 20:15:52 +00:00
>
<Button
variant="contained"
sx={{ minWidth: "150px" }}
onClick={() => setOpenModal(false)}
>
Отмена
</Button>
<Button
variant="contained"
sx={{ minWidth: "150px" }}
onClick={() => { // TODO
// setOpenModal(false);
2023-09-20 12:42:14 +00:00
2023-11-14 20:15:52 +00:00
// const question = { ...listQuestions[quizId][totalIndex] };
2023-10-03 14:03:57 +00:00
2023-11-14 20:15:52 +00:00
// removeQuestionForce(quizId, question.id);
// createQuestion(quizId, selectedValue, totalIndex);
// updateQuestionsList<QuizQuestionBase>(quizId, totalIndex, {
// title: question.title,
// expanded: question.expanded,
// });
}}
>
Подтвердить
</Button>
</Box>
</Box>
</Modal>
</>
);
2023-09-20 12:42:14 +00:00
};