2023-09-21 07:00:08 +00:00
|
|
|
|
import { DoubleArrowRight } from "@icons/questionsPage/DoubleArrowRight";
|
2023-11-16 16:41:25 +00:00
|
|
|
|
import { DoubleTick } from "@icons/questionsPage/DoubleTick";
|
2023-09-21 07:00:08 +00:00
|
|
|
|
import { VectorQuestions } from "@icons/questionsPage/VectorQuestions";
|
2023-09-25 13:43:15 +00:00
|
|
|
|
import { DeleteIcon } from "@icons/questionsPage/deleteIcon";
|
2023-10-10 13:33:21 +00:00
|
|
|
|
import type { SxProps } from "@mui/material";
|
2023-11-16 16:41:25 +00:00
|
|
|
|
import {
|
2023-12-16 16:06:46 +00:00
|
|
|
|
Box, Button,
|
|
|
|
|
IconButton, Modal,
|
2023-11-16 16:41:25 +00:00
|
|
|
|
Tooltip,
|
|
|
|
|
Typography,
|
|
|
|
|
useMediaQuery,
|
|
|
|
|
useTheme,
|
|
|
|
|
} from "@mui/material";
|
2023-12-14 09:40:53 +00:00
|
|
|
|
import { copyQuestion, deleteQuestion, deleteQuestionWithTimeout, clearRuleForAll, updateQuestion, getQuestionByContentId } from "@root/questions/actions";
|
|
|
|
|
import { updateOpenBranchingPanel, updateDesireToOpenABranchingModal, } from "@root/uiTools/actions";
|
2023-11-16 16:41:25 +00:00
|
|
|
|
import MiniButtonSetting from "@ui_kit/MiniButtonSetting";
|
|
|
|
|
import { CopyIcon } from "../../assets/icons/questionsPage/CopyIcon";
|
|
|
|
|
import Branching from "../../assets/icons/questionsPage/branching";
|
|
|
|
|
import Clue from "../../assets/icons/questionsPage/clue";
|
|
|
|
|
import { HideIcon } from "../../assets/icons/questionsPage/hideIcon";
|
|
|
|
|
import SettingIcon from "../../assets/icons/questionsPage/settingIcon";
|
2023-11-29 13:49:52 +00:00
|
|
|
|
import type { AnyTypedQuizQuestion } from "../../model/questionTypes/shared";
|
2023-12-04 16:33:50 +00:00
|
|
|
|
import { useCurrentQuiz } from "@root/quizes/hooks";
|
2023-12-05 23:34:40 +00:00
|
|
|
|
import { enqueueSnackbar } from "notistack";
|
|
|
|
|
import { useQuestionsStore } from "@root/questions/store";
|
2023-12-14 16:50:02 +00:00
|
|
|
|
import { updateOpenedModalSettingsId } from "@root/uiTools/actions";
|
2023-12-13 10:55:57 +00:00
|
|
|
|
import { updateRootContentId } from "@root/quizes/actions";
|
2023-12-14 09:40:53 +00:00
|
|
|
|
import { useUiTools } from "@root/uiTools/store";
|
2023-12-16 16:06:46 +00:00
|
|
|
|
import {useState} from "react";
|
2023-12-27 07:25:30 +00:00
|
|
|
|
import { updateSomeWorkBackend } from "@root/uiTools/actions";
|
|
|
|
|
import { DeleteFunction } from "@utils/deleteFunc";
|
2023-03-15 22:56:53 +00:00
|
|
|
|
|
2023-03-18 21:35:09 +00:00
|
|
|
|
interface Props {
|
2023-11-16 16:41:25 +00:00
|
|
|
|
switchState: string;
|
|
|
|
|
SSHC: (data: string) => void;
|
2023-11-29 13:49:52 +00:00
|
|
|
|
question: AnyTypedQuizQuestion;
|
2023-11-16 16:41:25 +00:00
|
|
|
|
sx?: SxProps;
|
2023-03-18 21:35:09 +00:00
|
|
|
|
}
|
2023-03-15 22:56:53 +00:00
|
|
|
|
|
2023-09-22 07:26:07 +00:00
|
|
|
|
export default function ButtonsOptions({
|
2023-11-16 16:41:25 +00:00
|
|
|
|
SSHC,
|
|
|
|
|
switchState,
|
|
|
|
|
question,
|
2023-09-22 07:26:07 +00:00
|
|
|
|
}: Props) {
|
2023-11-16 16:41:25 +00:00
|
|
|
|
const theme = useTheme();
|
|
|
|
|
const isMobile = useMediaQuery(theme.breakpoints.down(790));
|
|
|
|
|
const isWrappMiniButtonSetting = useMediaQuery(theme.breakpoints.down(920));
|
2023-12-04 16:33:50 +00:00
|
|
|
|
const quiz = useCurrentQuiz();
|
2023-12-14 09:40:53 +00:00
|
|
|
|
const { questions } = useQuestionsStore.getState();
|
2023-12-16 16:06:46 +00:00
|
|
|
|
const [openDelete, setOpenDelete] = useState<boolean>(false);
|
2023-09-21 07:00:08 +00:00
|
|
|
|
|
2023-11-16 16:41:25 +00:00
|
|
|
|
const openedModal = () => {
|
2023-12-14 17:58:56 +00:00
|
|
|
|
updateOpenBranchingPanel(true);
|
|
|
|
|
updateDesireToOpenABranchingModal(question.content.id);
|
2023-11-16 16:41:25 +00:00
|
|
|
|
};
|
2023-09-20 17:39:17 +00:00
|
|
|
|
|
2023-11-16 16:41:25 +00:00
|
|
|
|
const buttonSetting: {
|
|
|
|
|
icon: JSX.Element;
|
|
|
|
|
title: string;
|
|
|
|
|
value: string;
|
|
|
|
|
myFunc?: any;
|
|
|
|
|
}[] = [
|
|
|
|
|
{
|
|
|
|
|
icon: (
|
|
|
|
|
<SettingIcon
|
|
|
|
|
color={
|
|
|
|
|
switchState === "setting" ? "#ffffff" : theme.palette.grey3.main
|
|
|
|
|
}
|
|
|
|
|
/>
|
|
|
|
|
),
|
|
|
|
|
title: "Настройки",
|
|
|
|
|
value: "setting",
|
|
|
|
|
},
|
2023-12-14 10:37:45 +00:00
|
|
|
|
// {
|
|
|
|
|
// icon: (
|
|
|
|
|
// <Clue
|
|
|
|
|
// color={switchState === "help" ? "#ffffff" : theme.palette.grey3.main}
|
|
|
|
|
// />
|
|
|
|
|
// ),
|
|
|
|
|
// title: "Подсказка",
|
|
|
|
|
// value: "help",
|
|
|
|
|
// },
|
2023-11-16 16:41:25 +00:00
|
|
|
|
{
|
|
|
|
|
icon: (
|
|
|
|
|
<Branching
|
|
|
|
|
color={
|
|
|
|
|
switchState === "branching" ? "#ffffff" : theme.palette.grey3.main
|
|
|
|
|
}
|
|
|
|
|
/>
|
|
|
|
|
),
|
|
|
|
|
title: "Ветвление",
|
|
|
|
|
value: "branching",
|
2023-12-05 23:34:40 +00:00
|
|
|
|
myFunc: (question) => {
|
2023-12-14 17:58:56 +00:00
|
|
|
|
updateOpenBranchingPanel(true);
|
2023-12-12 19:05:30 +00:00
|
|
|
|
updateDesireToOpenABranchingModal(question.content.id);
|
2023-12-05 23:34:40 +00:00
|
|
|
|
}
|
2023-11-16 16:41:25 +00:00
|
|
|
|
},
|
|
|
|
|
];
|
2023-09-21 07:00:08 +00:00
|
|
|
|
|
2023-11-16 16:41: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",
|
2023-10-13 13:42:28 +00:00
|
|
|
|
}}
|
2023-11-16 16:41:25 +00:00
|
|
|
|
>
|
|
|
|
|
{buttonSetting.map(({ icon, title, value, myFunc }) => (
|
|
|
|
|
<Box key={value}>
|
2023-12-27 08:42:10 +00:00
|
|
|
|
{value === "branching" ?
|
|
|
|
|
question.type === "page" || question.type === "text" || question.type === "date" || question.type === "number" ?
|
|
|
|
|
<></>
|
|
|
|
|
:
|
|
|
|
|
(
|
|
|
|
|
// <Tooltip
|
|
|
|
|
// arrow
|
|
|
|
|
// placement="right"
|
|
|
|
|
// componentsProps={{
|
|
|
|
|
// tooltip: {
|
|
|
|
|
// sx: {
|
|
|
|
|
// background: "#fff",
|
|
|
|
|
// borderRadius: "6px",
|
|
|
|
|
// color: "#9A9AAF",
|
|
|
|
|
// boxShadow: "0px 8px 24px rgba(210, 208, 225, 0.4)",
|
|
|
|
|
// "& .MuiTooltip-arrow": {
|
|
|
|
|
// color: "#FFF",
|
|
|
|
|
// },
|
|
|
|
|
// },
|
|
|
|
|
// },
|
|
|
|
|
// }}
|
|
|
|
|
// title={
|
|
|
|
|
// <Box>
|
|
|
|
|
// <Typography
|
|
|
|
|
// sx={{
|
|
|
|
|
// color: "#4D4D4D",
|
|
|
|
|
// fontWeight: "bold",
|
|
|
|
|
// fontSize: "14px",
|
|
|
|
|
// marginBottom: "10px",
|
|
|
|
|
// }}
|
|
|
|
|
// >
|
|
|
|
|
// Будет показан при условии
|
|
|
|
|
// </Typography>
|
|
|
|
|
// <Typography sx={{ fontWeight: "bold", fontSize: "12px" }}>
|
|
|
|
|
// Название
|
|
|
|
|
// </Typography>
|
|
|
|
|
// <Typography
|
|
|
|
|
// sx={{
|
|
|
|
|
// fontWeight: "bold",
|
|
|
|
|
// fontSize: "12px",
|
|
|
|
|
// marginBottom: "10px",
|
|
|
|
|
// }}
|
|
|
|
|
// >
|
|
|
|
|
// Условие 1, Условие 2
|
|
|
|
|
// </Typography>
|
|
|
|
|
// <Typography sx={{ color: "#7E2AEA", fontSize: "12px" }}>
|
|
|
|
|
// Все условия обязательны
|
|
|
|
|
// </Typography>
|
|
|
|
|
// </Box>
|
|
|
|
|
// }
|
|
|
|
|
// >
|
2023-11-16 16:41:25 +00:00
|
|
|
|
<MiniButtonSetting
|
|
|
|
|
key={title}
|
|
|
|
|
onClick={() => {
|
2023-12-12 19:05:30 +00:00
|
|
|
|
openedModal();
|
2023-12-08 11:53:41 +00:00
|
|
|
|
// SSHC(value);
|
|
|
|
|
// myFunc(question);
|
2023-11-16 16:41:25 +00:00
|
|
|
|
}}
|
|
|
|
|
sx={{
|
2023-12-17 22:34:22 +00:00
|
|
|
|
display: quiz.config.type === "form" ? "none" : "flex",
|
2023-11-16 16:41:25 +00:00
|
|
|
|
backgroundColor:
|
|
|
|
|
switchState === value
|
|
|
|
|
? theme.palette.brightPurple.main
|
|
|
|
|
: "transparent",
|
|
|
|
|
color:
|
|
|
|
|
switchState === value
|
|
|
|
|
? "#ffffff"
|
|
|
|
|
: theme.palette.grey3.main,
|
|
|
|
|
minWidth: isWrappMiniButtonSetting ? "30px" : "64px",
|
|
|
|
|
height: "30px",
|
|
|
|
|
"&:hover": {
|
|
|
|
|
color: theme.palette.grey3.main,
|
|
|
|
|
"& path": { stroke: theme.palette.grey3.main },
|
|
|
|
|
},
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{icon}
|
|
|
|
|
{isWrappMiniButtonSetting ? null : title}
|
|
|
|
|
</MiniButtonSetting>
|
2023-12-27 08:42:10 +00:00
|
|
|
|
// </Tooltip>
|
2023-11-16 16:41:25 +00:00
|
|
|
|
) : (
|
|
|
|
|
<>
|
|
|
|
|
<MiniButtonSetting
|
|
|
|
|
key={title}
|
|
|
|
|
onClick={() => {
|
|
|
|
|
SSHC(value);
|
|
|
|
|
myFunc();
|
|
|
|
|
}}
|
|
|
|
|
sx={{
|
|
|
|
|
backgroundColor:
|
|
|
|
|
switchState === value
|
|
|
|
|
? theme.palette.brightPurple.main
|
|
|
|
|
: "transparent",
|
|
|
|
|
color:
|
|
|
|
|
switchState === value
|
|
|
|
|
? "#ffffff"
|
|
|
|
|
: theme.palette.grey3.main,
|
|
|
|
|
minWidth: isWrappMiniButtonSetting ? "30px" : "64px",
|
|
|
|
|
height: "30px",
|
|
|
|
|
"&:hover": {
|
|
|
|
|
color: theme.palette.grey3.main,
|
|
|
|
|
"& path": { stroke: theme.palette.grey3.main },
|
|
|
|
|
},
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{icon}
|
|
|
|
|
{isWrappMiniButtonSetting ? null : title}
|
|
|
|
|
</MiniButtonSetting>
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
</Box>
|
|
|
|
|
))}
|
2023-12-27 08:42:10 +00:00
|
|
|
|
{/* <>
|
2023-11-16 16:41:25 +00:00
|
|
|
|
<MiniButtonSetting
|
|
|
|
|
onClick={undefined} // TODO
|
|
|
|
|
sx={{
|
|
|
|
|
minWidth: "30px",
|
|
|
|
|
height: "30px",
|
|
|
|
|
backgroundColor: "#FEDFD0",
|
|
|
|
|
}}
|
2023-10-13 11:28:51 +00:00
|
|
|
|
>
|
2023-11-16 16:41:25 +00:00
|
|
|
|
<DoubleTick style={{ color: "#FC712F", fontSize: "9px" }} />
|
|
|
|
|
</MiniButtonSetting>
|
|
|
|
|
<MiniButtonSetting
|
|
|
|
|
onClick={undefined} // TODO
|
|
|
|
|
sx={{
|
|
|
|
|
minWidth: "30px",
|
|
|
|
|
height: "30px",
|
|
|
|
|
backgroundColor: "#FEDFD0",
|
|
|
|
|
}}
|
2023-10-13 11:28:51 +00:00
|
|
|
|
>
|
2023-11-16 16:41:25 +00:00
|
|
|
|
<DoubleArrowRight style={{ color: "#FC712F", fontSize: "9px" }} />
|
|
|
|
|
</MiniButtonSetting>
|
|
|
|
|
<MiniButtonSetting
|
|
|
|
|
onClick={undefined} // TODO
|
|
|
|
|
sx={{
|
|
|
|
|
minWidth: "30px",
|
|
|
|
|
height: "30px",
|
|
|
|
|
backgroundColor: "#FEDFD0",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<VectorQuestions style={{ color: "#FC712F", fontSize: "9px" }} />
|
|
|
|
|
</MiniButtonSetting>
|
2023-12-27 08:42:10 +00:00
|
|
|
|
</> */}
|
2023-11-16 16:41:25 +00:00
|
|
|
|
</Box>
|
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
padding: "20px",
|
|
|
|
|
display: "flex",
|
2023-12-01 20:45:35 +00:00
|
|
|
|
gap: "6px",
|
2023-11-16 16:41:25 +00:00
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<IconButton sx={{ borderRadius: "6px", padding: "2px" }}>
|
|
|
|
|
<HideIcon style={{ color: "#4D4D4D" }} />
|
|
|
|
|
</IconButton>
|
|
|
|
|
<IconButton
|
|
|
|
|
sx={{ borderRadius: "6px", padding: "2px" }}
|
|
|
|
|
onClick={() => copyQuestion(question.id, question.quizId)}
|
2023-10-13 11:28:51 +00:00
|
|
|
|
>
|
2023-11-16 16:41:25 +00:00
|
|
|
|
<CopyIcon color={"#4D4D4D"} />
|
|
|
|
|
</IconButton>
|
|
|
|
|
<IconButton
|
|
|
|
|
sx={{ borderRadius: "6px", padding: "2px" }}
|
2023-12-12 19:05:30 +00:00
|
|
|
|
onClick={() => {
|
2023-12-16 16:06:46 +00:00
|
|
|
|
if(question.content.rule.parentId.length !== 0) {
|
|
|
|
|
setOpenDelete(true)
|
|
|
|
|
} else {
|
2023-12-27 07:25:30 +00:00
|
|
|
|
deleteQuestionWithTimeout(question.id, () => DeleteFunction(questions, question, quiz));
|
2023-12-16 16:06:46 +00:00
|
|
|
|
}
|
2023-12-11 10:08:54 +00:00
|
|
|
|
|
2023-11-16 16:41:25 +00:00
|
|
|
|
}}
|
2023-11-27 23:07:24 +00:00
|
|
|
|
data-cy="delete-question"
|
2023-11-16 16:41:25 +00:00
|
|
|
|
>
|
|
|
|
|
<DeleteIcon color={"#4D4D4D"} />
|
|
|
|
|
</IconButton>
|
2023-12-16 16:06:46 +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={() => {
|
2023-12-27 07:25:30 +00:00
|
|
|
|
deleteQuestionWithTimeout(question.id, () => DeleteFunction(questions, question, quiz));
|
2023-12-16 16:06:46 +00:00
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
Подтвердить
|
|
|
|
|
</Button>
|
|
|
|
|
</Box>
|
|
|
|
|
</Box>
|
|
|
|
|
</Modal>
|
2023-11-16 16:41:25 +00:00
|
|
|
|
</Box>
|
|
|
|
|
</Box>
|
|
|
|
|
);
|
2023-04-15 09:10:59 +00:00
|
|
|
|
}
|