2024-02-29 11:23:52 +00:00
|
|
|
|
import { QuestionType } from "@model/question/question";
|
2023-09-18 10:22:09 +00:00
|
|
|
|
import {
|
2023-12-31 02:53:25 +00:00
|
|
|
|
Box,
|
|
|
|
|
Button,
|
|
|
|
|
IconButton,
|
|
|
|
|
Modal,
|
|
|
|
|
Typography,
|
|
|
|
|
useMediaQuery,
|
|
|
|
|
useTheme,
|
2023-09-18 10:22:09 +00:00
|
|
|
|
} from "@mui/material";
|
2023-12-31 02:53:25 +00:00
|
|
|
|
import {
|
|
|
|
|
copyQuestion,
|
|
|
|
|
deleteQuestion,
|
|
|
|
|
deleteQuestionWithTimeout,
|
|
|
|
|
} from "@root/questions/actions";
|
2024-02-25 11:12:41 +00:00
|
|
|
|
import { useQuestionsStore } from "@root/questions/store";
|
|
|
|
|
import { useCurrentQuiz } from "@root/quizes/hooks";
|
|
|
|
|
import { updateDesireToOpenABranchingModal } from "@root/uiTools/actions";
|
2023-11-15 18:38:02 +00:00
|
|
|
|
import MiniButtonSetting from "@ui_kit/MiniButtonSetting";
|
|
|
|
|
import { ReallyChangingModal } from "@ui_kit/Modal/ReallyChangingModal/ReallyChangingModal";
|
2024-02-25 11:12:41 +00:00
|
|
|
|
import { DeleteFunction } from "@utils/deleteFunc";
|
2024-02-29 11:23:52 +00:00
|
|
|
|
import { memo, useState } from "react";
|
2023-09-25 13:43:15 +00:00
|
|
|
|
import { CopyIcon } from "../../assets/icons/questionsPage/CopyIcon";
|
2023-11-15 18:38:02 +00:00
|
|
|
|
import Branching from "../../assets/icons/questionsPage/branching";
|
2023-09-25 13:43:15 +00:00
|
|
|
|
import { DeleteIcon } from "../../assets/icons/questionsPage/deleteIcon";
|
2023-05-03 19:21:00 +00:00
|
|
|
|
import ImgIcon from "../../assets/icons/questionsPage/imgIcon";
|
2023-11-15 18:38:02 +00:00
|
|
|
|
import SettingIcon from "../../assets/icons/questionsPage/settingIcon";
|
2023-09-21 07:00:08 +00:00
|
|
|
|
|
2023-03-30 18:39:59 +00:00
|
|
|
|
interface Props {
|
2023-12-31 02:53:25 +00:00
|
|
|
|
switchState: string;
|
|
|
|
|
SSHC: (data: string) => void;
|
2024-01-05 07:07:06 +00:00
|
|
|
|
openBranchingPage: boolean;
|
|
|
|
|
setOpenBranchingPage: (a: boolean) => void;
|
2024-02-29 11:23:52 +00:00
|
|
|
|
questionId: string;
|
|
|
|
|
questionType: QuestionType;
|
|
|
|
|
questionContentId: string;
|
|
|
|
|
questionHasParent: boolean;
|
2023-03-30 18:39:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-02-29 11:23:52 +00:00
|
|
|
|
const ButtonsOptionsAndPict = memo<Props>(function ({
|
2023-12-31 02:53:25 +00:00
|
|
|
|
SSHC,
|
|
|
|
|
switchState,
|
2024-01-05 07:07:06 +00:00
|
|
|
|
openBranchingPage,
|
|
|
|
|
setOpenBranchingPage,
|
2024-02-29 11:23:52 +00:00
|
|
|
|
questionId,
|
|
|
|
|
questionType,
|
|
|
|
|
questionContentId,
|
|
|
|
|
questionHasParent,
|
|
|
|
|
}) {
|
2023-12-31 02:53:25 +00:00
|
|
|
|
const [buttonHover, setButtonHover] = useState<string>("");
|
|
|
|
|
const [openedReallyChangingModal, setOpenedReallyChangingModal] =
|
|
|
|
|
useState<boolean>(false);
|
|
|
|
|
const theme = useTheme();
|
|
|
|
|
const isMobile = useMediaQuery(theme.breakpoints.down(790));
|
|
|
|
|
const isIconMobile = useMediaQuery(theme.breakpoints.down(1050));
|
|
|
|
|
const quiz = useCurrentQuiz();
|
|
|
|
|
const [openDelete, setOpenDelete] = useState<boolean>(false);
|
2024-02-29 11:23:52 +00:00
|
|
|
|
const isQuestionFirst = useQuestionsStore(
|
|
|
|
|
(state) => state.questions[0]?.id === questionId,
|
|
|
|
|
);
|
2023-12-16 16:06:46 +00:00
|
|
|
|
|
2024-02-29 11:23:52 +00:00
|
|
|
|
if (!quiz) return null;
|
2023-08-16 13:29:28 +00:00
|
|
|
|
|
2023-12-31 02:53:25 +00:00
|
|
|
|
return (
|
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
display: "flex",
|
|
|
|
|
alignItems: "center",
|
|
|
|
|
justifyContent: "space-between",
|
|
|
|
|
width: "100%",
|
|
|
|
|
background: "#f2f3f7",
|
|
|
|
|
height: isMobile ? "92px" : "70px",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
padding: isMobile ? " 3px 12px 11px" : "20px",
|
|
|
|
|
display: "flex",
|
|
|
|
|
flexWrap: isMobile ? "wrap" : "nowrap",
|
|
|
|
|
gap: "6px",
|
|
|
|
|
maxWidth: isMobile ? "200px" : undefined,
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<MiniButtonSetting
|
|
|
|
|
onMouseEnter={() => setButtonHover("setting")}
|
|
|
|
|
onMouseLeave={() => setButtonHover("")}
|
|
|
|
|
onClick={() => {
|
|
|
|
|
SSHC("setting");
|
|
|
|
|
}}
|
|
|
|
|
sx={{
|
|
|
|
|
maxWidth: "104px",
|
|
|
|
|
minWidth: isIconMobile ? "30px" : "64px",
|
|
|
|
|
height: "30px",
|
|
|
|
|
backgroundColor:
|
|
|
|
|
switchState === "setting"
|
|
|
|
|
? theme.palette.brightPurple.main
|
|
|
|
|
: "transparent",
|
|
|
|
|
color:
|
|
|
|
|
switchState === "setting" ? "#ffffff" : theme.palette.grey3.main,
|
|
|
|
|
"&:hover": {
|
|
|
|
|
color:
|
|
|
|
|
switchState === "setting" ? theme.palette.grey3.main : null,
|
|
|
|
|
},
|
|
|
|
|
}}
|
2023-11-15 18:38:02 +00:00
|
|
|
|
>
|
2023-12-31 02:53:25 +00:00
|
|
|
|
<SettingIcon
|
|
|
|
|
color={
|
|
|
|
|
buttonHover === "setting"
|
|
|
|
|
? theme.palette.grey3.main
|
|
|
|
|
: switchState === "setting"
|
|
|
|
|
? "#ffffff"
|
|
|
|
|
: theme.palette.grey3.main
|
|
|
|
|
}
|
|
|
|
|
/>
|
|
|
|
|
{isIconMobile ? null : "Настройки"}
|
|
|
|
|
</MiniButtonSetting>
|
2024-02-29 11:23:52 +00:00
|
|
|
|
{questionType !== "text" && (
|
2023-12-31 02:53:25 +00:00
|
|
|
|
<MiniButtonSetting
|
2024-02-29 11:23:52 +00:00
|
|
|
|
onMouseEnter={() => setButtonHover("branching")}
|
2023-12-31 02:53:25 +00:00
|
|
|
|
onMouseLeave={() => setButtonHover("")}
|
|
|
|
|
onClick={() => {
|
2024-02-29 11:23:52 +00:00
|
|
|
|
setOpenBranchingPage(true);
|
|
|
|
|
updateDesireToOpenABranchingModal(questionContentId);
|
2023-12-31 02:53:25 +00:00
|
|
|
|
}}
|
|
|
|
|
sx={{
|
2024-02-29 11:23:52 +00:00
|
|
|
|
display: quiz.config.type === "form" ? "none" : "flex",
|
2023-12-31 02:53:25 +00:00
|
|
|
|
height: "30px",
|
2024-02-29 11:23:52 +00:00
|
|
|
|
maxWidth: "103px",
|
2023-12-31 02:53:25 +00:00
|
|
|
|
minWidth: isIconMobile ? "30px" : "64px",
|
|
|
|
|
backgroundColor:
|
2024-02-29 11:23:52 +00:00
|
|
|
|
switchState === "branching"
|
2023-12-31 02:53:25 +00:00
|
|
|
|
? theme.palette.brightPurple.main
|
|
|
|
|
: "transparent",
|
|
|
|
|
color:
|
2024-02-29 11:23:52 +00:00
|
|
|
|
switchState === "branching"
|
|
|
|
|
? "#ffffff"
|
|
|
|
|
: theme.palette.grey3.main,
|
2023-12-31 02:53:25 +00:00
|
|
|
|
"&:hover": {
|
|
|
|
|
color:
|
2024-02-29 11:23:52 +00:00
|
|
|
|
switchState === "branching" ? theme.palette.grey3.main : null,
|
2023-12-31 02:53:25 +00:00
|
|
|
|
},
|
|
|
|
|
}}
|
|
|
|
|
>
|
2024-02-29 11:23:52 +00:00
|
|
|
|
<Branching
|
2023-12-31 02:53:25 +00:00
|
|
|
|
color={
|
2024-02-29 11:23:52 +00:00
|
|
|
|
buttonHover === "branching"
|
2023-12-31 02:53:25 +00:00
|
|
|
|
? theme.palette.grey3.main
|
2024-02-29 11:23:52 +00:00
|
|
|
|
: switchState === "branching"
|
2023-12-31 02:53:25 +00:00
|
|
|
|
? "#ffffff"
|
|
|
|
|
: theme.palette.grey3.main
|
|
|
|
|
}
|
|
|
|
|
/>
|
2024-02-29 11:23:52 +00:00
|
|
|
|
{isIconMobile ? null : "Ветвление"}
|
2023-12-31 02:53:25 +00:00
|
|
|
|
</MiniButtonSetting>
|
2024-02-29 11:23:52 +00:00
|
|
|
|
)}
|
|
|
|
|
<MiniButtonSetting
|
|
|
|
|
onMouseEnter={() => setButtonHover("image")}
|
|
|
|
|
onMouseLeave={() => setButtonHover("")}
|
|
|
|
|
onClick={() => {
|
|
|
|
|
SSHC("image");
|
|
|
|
|
}}
|
|
|
|
|
sx={{
|
|
|
|
|
height: "30px",
|
|
|
|
|
maxWidth: "123px",
|
|
|
|
|
minWidth: isIconMobile ? "30px" : "64px",
|
|
|
|
|
backgroundColor:
|
|
|
|
|
switchState === "image"
|
|
|
|
|
? theme.palette.brightPurple.main
|
|
|
|
|
: "transparent",
|
|
|
|
|
color:
|
|
|
|
|
switchState === "image" ? "#ffffff" : theme.palette.grey3.main,
|
|
|
|
|
"&:hover": {
|
|
|
|
|
color: switchState === "image" ? theme.palette.grey3.main : null,
|
|
|
|
|
},
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<ImgIcon
|
|
|
|
|
color={
|
|
|
|
|
buttonHover === "image"
|
|
|
|
|
? theme.palette.grey3.main
|
|
|
|
|
: switchState === "image"
|
|
|
|
|
? "#ffffff"
|
|
|
|
|
: theme.palette.grey3.main
|
|
|
|
|
}
|
|
|
|
|
/>
|
|
|
|
|
{isIconMobile ? null : "Изображение"}
|
|
|
|
|
</MiniButtonSetting>
|
2023-12-31 02:53:25 +00:00
|
|
|
|
</Box>
|
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
padding: "20px",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<IconButton
|
|
|
|
|
sx={{ borderRadius: "6px" }}
|
2024-02-29 11:23:52 +00:00
|
|
|
|
onClick={() => copyQuestion(questionId, quiz.backendId)}
|
2023-12-31 02:53:25 +00:00
|
|
|
|
>
|
|
|
|
|
<CopyIcon style={{ color: "#4D4D4D" }} />
|
|
|
|
|
</IconButton>
|
2024-02-29 11:23:52 +00:00
|
|
|
|
{(quiz?.config.type !== "form" || !isQuestionFirst) && (
|
2024-01-12 09:35:50 +00:00
|
|
|
|
<IconButton
|
|
|
|
|
sx={{ borderRadius: "6px", padding: "2px" }}
|
|
|
|
|
onClick={() => {
|
2024-02-29 11:23:52 +00:00
|
|
|
|
if (questionType === null) {
|
|
|
|
|
deleteQuestion(questionId);
|
2024-01-12 09:35:50 +00:00
|
|
|
|
}
|
2024-02-29 11:23:52 +00:00
|
|
|
|
if (questionHasParent) {
|
2024-01-12 09:35:50 +00:00
|
|
|
|
setOpenDelete(true);
|
|
|
|
|
} else {
|
2024-02-29 11:23:52 +00:00
|
|
|
|
deleteQuestionWithTimeout(questionId, () =>
|
|
|
|
|
DeleteFunction(questionId),
|
2024-01-12 09:35:50 +00:00
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}}
|
|
|
|
|
data-cy="delete-question"
|
|
|
|
|
>
|
|
|
|
|
<DeleteIcon style={{ color: "#4D4D4D" }} />
|
|
|
|
|
</IconButton>
|
|
|
|
|
)}
|
2023-12-31 02:53:25 +00:00
|
|
|
|
<Modal open={openDelete} onClose={() => setOpenDelete(false)}>
|
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
position: "absolute",
|
|
|
|
|
top: "50%",
|
|
|
|
|
left: "50%",
|
|
|
|
|
transform: "translate(-50%, -50%)",
|
|
|
|
|
padding: "30px",
|
|
|
|
|
borderRadius: "10px",
|
|
|
|
|
background: "#FFFFFF",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Typography variant="h6" sx={{ textAlign: "center" }}>
|
|
|
|
|
Вы удаляете вопрос, участвующий в ветвлении. Все его потомки
|
|
|
|
|
потеряют данные ветвления. Вы уверены, что хотите удалить вопрос?
|
|
|
|
|
</Typography>
|
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
marginTop: "30px",
|
|
|
|
|
display: "flex",
|
|
|
|
|
justifyContent: "center",
|
|
|
|
|
gap: "15px",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Button
|
|
|
|
|
variant="contained"
|
|
|
|
|
sx={{ minWidth: "150px" }}
|
|
|
|
|
onClick={() => setOpenDelete(false)}
|
|
|
|
|
>
|
|
|
|
|
Отмена
|
|
|
|
|
</Button>
|
|
|
|
|
<Button
|
|
|
|
|
variant="contained"
|
|
|
|
|
sx={{ minWidth: "150px" }}
|
|
|
|
|
onClick={() => {
|
2024-02-29 11:23:52 +00:00
|
|
|
|
deleteQuestionWithTimeout(questionId, () =>
|
|
|
|
|
DeleteFunction(questionId),
|
2023-12-31 02:53:25 +00:00
|
|
|
|
);
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
Подтвердить
|
|
|
|
|
</Button>
|
2023-11-15 18:38:02 +00:00
|
|
|
|
</Box>
|
2023-12-31 02:53:25 +00:00
|
|
|
|
</Box>
|
|
|
|
|
</Modal>
|
|
|
|
|
</Box>
|
|
|
|
|
<ReallyChangingModal
|
|
|
|
|
opened={openedReallyChangingModal}
|
|
|
|
|
onClose={() => setOpenedReallyChangingModal(false)}
|
|
|
|
|
/>
|
|
|
|
|
</Box>
|
|
|
|
|
);
|
2024-02-29 11:23:52 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
ButtonsOptionsAndPict.displayName = "ButtonsOptionsAndPict";
|
|
|
|
|
|
|
|
|
|
export default ButtonsOptionsAndPict;
|