2023-09-19 11:41:38 +00:00
|
|
|
|
import { useState, useRef, useEffect } from "react";
|
2023-09-06 13:20:12 +00:00
|
|
|
|
import { useParams } from "react-router-dom";
|
2023-03-30 18:39:59 +00:00
|
|
|
|
import {
|
2023-04-15 09:10:59 +00:00
|
|
|
|
Box,
|
|
|
|
|
Button,
|
2023-08-24 20:53:27 +00:00
|
|
|
|
Chip,
|
2023-04-15 09:10:59 +00:00
|
|
|
|
FormControl,
|
|
|
|
|
FormControlLabel,
|
|
|
|
|
IconButton,
|
|
|
|
|
Link,
|
|
|
|
|
Modal,
|
|
|
|
|
Radio,
|
|
|
|
|
RadioGroup,
|
|
|
|
|
Typography,
|
|
|
|
|
useTheme,
|
2023-03-30 18:39:59 +00:00
|
|
|
|
} from "@mui/material";
|
2023-08-24 20:53:27 +00:00
|
|
|
|
import {
|
|
|
|
|
questionStore,
|
|
|
|
|
resetSomeField,
|
|
|
|
|
updateQuestionsList,
|
|
|
|
|
} from "@root/questions";
|
2023-08-15 14:04:01 +00:00
|
|
|
|
import { Select } from "./Select";
|
2023-08-24 20:53:27 +00:00
|
|
|
|
|
2023-05-10 17:35:30 +00:00
|
|
|
|
import DeleteIcon from "@icons/questionsPage/deleteIcon";
|
2023-05-03 23:25:35 +00:00
|
|
|
|
import RadioCheck from "@ui_kit/RadioCheck";
|
|
|
|
|
import RadioIcon from "@ui_kit/RadioIcon";
|
2023-08-15 14:04:01 +00:00
|
|
|
|
import InfoIcon from "@icons/Info";
|
2023-03-30 18:39:59 +00:00
|
|
|
|
|
2023-08-24 20:53:27 +00:00
|
|
|
|
type BranchingQuestionsProps = {
|
|
|
|
|
totalIndex: number;
|
|
|
|
|
};
|
|
|
|
|
|
2023-08-16 12:00:35 +00:00
|
|
|
|
const ACTIONS = ["Показать", "Скрыть"];
|
2023-08-24 20:53:27 +00:00
|
|
|
|
const STIPULATIONS = ["Условие 1", "Условие 2", "Условие 3"];
|
|
|
|
|
const ANSWERS = ["Ответ 1", "Ответ 2", "Ответ 3"];
|
2023-08-16 12:00:35 +00:00
|
|
|
|
const CONDITIONS = [
|
|
|
|
|
"Все условия обязательны",
|
|
|
|
|
"Обязательно хотя бы одно условие",
|
|
|
|
|
];
|
|
|
|
|
|
2023-08-24 20:53:27 +00:00
|
|
|
|
export default function BranchingQuestions({
|
|
|
|
|
totalIndex,
|
|
|
|
|
}: BranchingQuestionsProps) {
|
2023-09-19 11:41:38 +00:00
|
|
|
|
const [title, setTitle] = useState<string>("Заголовок работа");
|
|
|
|
|
const [titleInputWidth, setTitleInputWidth] = useState<number>(0);
|
2023-09-06 13:20:12 +00:00
|
|
|
|
const quizId = Number(useParams().quizId);
|
2023-08-24 20:53:27 +00:00
|
|
|
|
const { openedModalSettings, listQuestions } = questionStore();
|
2023-07-30 15:35:40 +00:00
|
|
|
|
const theme = useTheme();
|
2023-09-19 11:41:38 +00:00
|
|
|
|
const titleRef = useRef<HTMLDivElement>(null);
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
setTitleInputWidth(titleRef.current?.offsetWidth || 0);
|
|
|
|
|
}, [title]);
|
2023-07-14 18:29:09 +00:00
|
|
|
|
|
|
|
|
|
const handleClose = () => {
|
2023-07-30 15:35:40 +00:00
|
|
|
|
resetSomeField({ openedModalSettings: "" });
|
|
|
|
|
};
|
2023-03-30 18:39:59 +00:00
|
|
|
|
|
2023-04-15 09:10:59 +00:00
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<Modal
|
2023-07-14 18:29:09 +00:00
|
|
|
|
open={Boolean(openedModalSettings)}
|
2023-07-14 12:21:03 +00:00
|
|
|
|
onClose={handleClose}
|
2023-04-15 09:10:59 +00:00
|
|
|
|
aria-labelledby="modal-modal-title"
|
|
|
|
|
aria-describedby="modal-modal-description"
|
|
|
|
|
>
|
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
position: "absolute" as "absolute",
|
2023-08-15 12:20:09 +00:00
|
|
|
|
overflow: "hidden",
|
2023-04-15 09:10:59 +00:00
|
|
|
|
top: "50%",
|
|
|
|
|
left: "50%",
|
|
|
|
|
transform: "translate(-50%, -50%)",
|
|
|
|
|
maxWidth: "620px",
|
|
|
|
|
width: "100%",
|
|
|
|
|
bgcolor: "background.paper",
|
|
|
|
|
borderRadius: "12px",
|
|
|
|
|
boxShadow: 24,
|
|
|
|
|
p: 0,
|
|
|
|
|
}}
|
|
|
|
|
>
|
2023-08-15 12:20:09 +00:00
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
boxSizing: "border-box",
|
|
|
|
|
background: "#F2F3F7",
|
|
|
|
|
padding: "25px",
|
|
|
|
|
height: "70px",
|
|
|
|
|
display: "flex",
|
|
|
|
|
}}
|
|
|
|
|
>
|
2023-09-19 11:41:38 +00:00
|
|
|
|
<Box sx={{ color: "#9A9AAF" }}>
|
|
|
|
|
<Typography component="span">(</Typography>
|
|
|
|
|
<Box sx={{ display: "inline" }}>
|
|
|
|
|
<Typography
|
|
|
|
|
ref={titleRef}
|
|
|
|
|
sx={{
|
|
|
|
|
position: "absolute",
|
|
|
|
|
opacity: 0,
|
|
|
|
|
zIndex: "-100",
|
|
|
|
|
whiteSpace: "pre",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{title}
|
|
|
|
|
</Typography>
|
|
|
|
|
<input
|
|
|
|
|
type="text"
|
|
|
|
|
value={title}
|
|
|
|
|
onChange={({ target }) => setTitle(target.value)}
|
|
|
|
|
style={{
|
|
|
|
|
width: titleInputWidth,
|
|
|
|
|
outline: "none",
|
|
|
|
|
background: "transparent",
|
|
|
|
|
border: "none",
|
|
|
|
|
fontSize: "18px",
|
|
|
|
|
minWidth: "150px",
|
|
|
|
|
maxWidth: "500px",
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
</Box>
|
|
|
|
|
<Typography component="span">)</Typography>
|
|
|
|
|
</Box>
|
2023-08-15 12:20:09 +00:00
|
|
|
|
<InfoIcon width={24} height={24} />
|
|
|
|
|
</Box>
|
2023-04-15 09:10:59 +00:00
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
padding: "20px",
|
|
|
|
|
display: "flex",
|
|
|
|
|
flexDirection: "column",
|
|
|
|
|
gap: "30px",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
display: "flex",
|
|
|
|
|
gap: "20px",
|
|
|
|
|
alignItems: "center",
|
|
|
|
|
}}
|
|
|
|
|
>
|
2023-08-15 14:04:01 +00:00
|
|
|
|
<Select
|
2023-08-16 12:00:35 +00:00
|
|
|
|
items={ACTIONS}
|
2023-08-24 20:53:27 +00:00
|
|
|
|
activeItemIndex={
|
2023-09-06 13:20:12 +00:00
|
|
|
|
listQuestions[quizId][totalIndex].content.rule.show ? 0 : 1
|
2023-08-24 20:53:27 +00:00
|
|
|
|
}
|
2023-08-15 14:04:01 +00:00
|
|
|
|
sx={{ maxWidth: "140px" }}
|
2023-08-24 20:53:27 +00:00
|
|
|
|
onChange={(action) => {
|
2023-09-06 13:20:12 +00:00
|
|
|
|
const clonContent = listQuestions[quizId][totalIndex].content;
|
2023-08-24 20:53:27 +00:00
|
|
|
|
clonContent.rule.show = action === ACTIONS[0];
|
2023-09-06 13:20:12 +00:00
|
|
|
|
updateQuestionsList(quizId, totalIndex, {
|
|
|
|
|
content: clonContent,
|
|
|
|
|
});
|
2023-08-24 20:53:27 +00:00
|
|
|
|
}}
|
2023-08-15 14:04:01 +00:00
|
|
|
|
/>
|
2023-08-15 12:20:09 +00:00
|
|
|
|
<Typography sx={{ color: theme.palette.grey2.main }}>
|
|
|
|
|
если в ответе на вопрос
|
|
|
|
|
</Typography>
|
2023-04-15 09:10:59 +00:00
|
|
|
|
</Box>
|
2023-09-06 13:20:12 +00:00
|
|
|
|
{listQuestions[quizId][totalIndex].content.rule.reqs.map(
|
2023-08-24 20:53:27 +00:00
|
|
|
|
(request, index) => (
|
2023-08-15 12:20:09 +00:00
|
|
|
|
<Box
|
2023-08-24 20:53:27 +00:00
|
|
|
|
key={index}
|
2023-08-15 12:20:09 +00:00
|
|
|
|
sx={{
|
2023-08-24 20:53:27 +00:00
|
|
|
|
padding: "20px",
|
|
|
|
|
borderRadius: "8px",
|
|
|
|
|
height: "100%",
|
|
|
|
|
bgcolor: "#F2F3F7",
|
2023-08-15 12:20:09 +00:00
|
|
|
|
}}
|
|
|
|
|
>
|
2023-08-24 20:53:27 +00:00
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
display: "flex",
|
|
|
|
|
justifyContent: "space-between",
|
|
|
|
|
alignItems: "center",
|
|
|
|
|
pb: "5px",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Typography sx={{ color: "#4D4D4D", fontWeight: "500" }}>
|
|
|
|
|
Условие 1
|
|
|
|
|
</Typography>
|
|
|
|
|
<IconButton
|
|
|
|
|
sx={{ borderRadius: "6px", padding: "2px" }}
|
|
|
|
|
onClick={() => {
|
2023-09-06 13:20:12 +00:00
|
|
|
|
const clonContent =
|
|
|
|
|
listQuestions[quizId][totalIndex].content;
|
2023-08-24 20:53:27 +00:00
|
|
|
|
|
|
|
|
|
clonContent.rule.reqs.splice(index, 1);
|
2023-09-06 13:20:12 +00:00
|
|
|
|
updateQuestionsList(quizId, totalIndex, {
|
2023-08-24 20:53:27 +00:00
|
|
|
|
content: clonContent,
|
|
|
|
|
});
|
2023-08-16 12:00:35 +00:00
|
|
|
|
}}
|
2023-08-15 14:04:01 +00:00
|
|
|
|
>
|
2023-08-24 20:53:27 +00:00
|
|
|
|
<DeleteIcon color={"#4D4D4D"} />
|
|
|
|
|
</IconButton>
|
|
|
|
|
</Box>
|
|
|
|
|
<Select
|
|
|
|
|
empty
|
2023-08-25 11:18:25 +00:00
|
|
|
|
activeItemIndex={request.id ? Number(request.id) : -1}
|
2023-08-24 20:53:27 +00:00
|
|
|
|
items={STIPULATIONS}
|
|
|
|
|
onChange={(stipulation) => {
|
2023-09-06 13:20:12 +00:00
|
|
|
|
const clonContent =
|
|
|
|
|
listQuestions[quizId][totalIndex].content;
|
2023-08-24 20:53:27 +00:00
|
|
|
|
|
|
|
|
|
clonContent.rule.reqs[index] = {
|
|
|
|
|
id: String(
|
|
|
|
|
STIPULATIONS.findIndex((item) =>
|
|
|
|
|
item.includes(stipulation)
|
|
|
|
|
)
|
|
|
|
|
),
|
|
|
|
|
vars: request.vars,
|
|
|
|
|
};
|
|
|
|
|
|
2023-09-06 13:20:12 +00:00
|
|
|
|
updateQuestionsList(quizId, totalIndex, {
|
|
|
|
|
content: clonContent,
|
|
|
|
|
});
|
2023-08-24 20:53:27 +00:00
|
|
|
|
}}
|
|
|
|
|
sx={{ marginBottom: "15px" }}
|
|
|
|
|
/>
|
|
|
|
|
{request.id && (
|
|
|
|
|
<>
|
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
display: "flex",
|
|
|
|
|
alignItems: "center",
|
|
|
|
|
pb: "10px",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Typography
|
|
|
|
|
sx={{ color: "#4D4D4D", fontWeight: "500" }}
|
|
|
|
|
>
|
|
|
|
|
Дан ответ
|
|
|
|
|
</Typography>
|
|
|
|
|
<Typography sx={{ color: "#7E2AEA", pl: "10px" }}>
|
|
|
|
|
(Укажите один или несколько вариантов)
|
|
|
|
|
</Typography>
|
|
|
|
|
</Box>
|
|
|
|
|
<Select
|
|
|
|
|
empty
|
|
|
|
|
activeItemIndex={-1}
|
|
|
|
|
items={ANSWERS}
|
|
|
|
|
onChange={(answer) => {
|
2023-09-06 13:20:12 +00:00
|
|
|
|
const clonContent =
|
|
|
|
|
listQuestions[quizId][totalIndex].content;
|
2023-08-24 20:53:27 +00:00
|
|
|
|
const answerItemIndex = ANSWERS.findIndex(
|
|
|
|
|
(answerItem) => answerItem === answer
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
!clonContent.rule.reqs[index].vars.includes(
|
|
|
|
|
answerItemIndex
|
|
|
|
|
)
|
|
|
|
|
) {
|
2023-09-06 13:20:12 +00:00
|
|
|
|
listQuestions[quizId][totalIndex].content.rule.reqs[
|
2023-08-24 20:53:27 +00:00
|
|
|
|
index
|
|
|
|
|
].vars.push(answerItemIndex);
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-06 13:20:12 +00:00
|
|
|
|
updateQuestionsList(quizId, totalIndex, {
|
2023-08-24 20:53:27 +00:00
|
|
|
|
content: clonContent,
|
|
|
|
|
});
|
|
|
|
|
}}
|
|
|
|
|
sx={{
|
|
|
|
|
marginBottom: "10px",
|
|
|
|
|
".MuiSelect-select.MuiInputBase-input": {
|
|
|
|
|
color: "transparent",
|
|
|
|
|
},
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
display: "flex",
|
|
|
|
|
gap: "10px",
|
|
|
|
|
}}
|
|
|
|
|
>
|
2023-09-06 13:20:12 +00:00
|
|
|
|
{listQuestions[quizId][totalIndex].content.rule.reqs[
|
2023-08-24 20:53:27 +00:00
|
|
|
|
index
|
|
|
|
|
].vars.map((item, varIndex) => (
|
|
|
|
|
<Chip
|
|
|
|
|
key={varIndex}
|
|
|
|
|
label={ANSWERS[item]}
|
|
|
|
|
variant="outlined"
|
|
|
|
|
onDelete={() => {
|
|
|
|
|
const clonContent =
|
2023-09-06 13:20:12 +00:00
|
|
|
|
listQuestions[quizId][totalIndex].content;
|
2023-08-24 20:53:27 +00:00
|
|
|
|
const removedItemIndex = clonContent.rule.reqs[
|
|
|
|
|
index
|
|
|
|
|
].vars.findIndex((varItem) => varItem === item);
|
|
|
|
|
|
|
|
|
|
clonContent.rule.reqs[index].vars.splice(
|
|
|
|
|
removedItemIndex,
|
|
|
|
|
1
|
|
|
|
|
);
|
|
|
|
|
|
2023-09-06 13:20:12 +00:00
|
|
|
|
updateQuestionsList(quizId, totalIndex, {
|
2023-08-24 20:53:27 +00:00
|
|
|
|
content: clonContent,
|
|
|
|
|
});
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
))}
|
|
|
|
|
</Box>
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
</Box>
|
|
|
|
|
)
|
2023-04-15 09:10:59 +00:00
|
|
|
|
)}
|
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
display: "flex",
|
|
|
|
|
flexDirection: "column",
|
|
|
|
|
alignItems: "baseline",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Link
|
|
|
|
|
variant="body2"
|
2023-08-15 12:20:09 +00:00
|
|
|
|
sx={{
|
|
|
|
|
color: theme.palette.brightPurple.main,
|
|
|
|
|
marginBottom: "10px",
|
|
|
|
|
}}
|
2023-08-24 20:53:27 +00:00
|
|
|
|
onClick={() => {
|
2023-09-06 13:20:12 +00:00
|
|
|
|
const clonContent = listQuestions[quizId][totalIndex].content;
|
2023-08-24 20:53:27 +00:00
|
|
|
|
clonContent.rule.reqs.push({ id: "", vars: [] });
|
2023-09-06 13:20:12 +00:00
|
|
|
|
updateQuestionsList(quizId, totalIndex, {
|
|
|
|
|
content: clonContent,
|
|
|
|
|
});
|
2023-08-24 20:53:27 +00:00
|
|
|
|
}}
|
2023-04-15 09:10:59 +00:00
|
|
|
|
>
|
|
|
|
|
Добавить условие
|
|
|
|
|
</Link>
|
|
|
|
|
<FormControl>
|
|
|
|
|
<RadioGroup
|
|
|
|
|
aria-labelledby="demo-controlled-radio-buttons-group"
|
2023-09-07 07:48:19 +00:00
|
|
|
|
value={
|
|
|
|
|
listQuestions[quizId][totalIndex].content.rule.or ? 1 : 0
|
2023-08-28 11:16:00 +00:00
|
|
|
|
}
|
2023-09-07 07:48:19 +00:00
|
|
|
|
onChange={(_, value) => {
|
2023-09-06 13:20:12 +00:00
|
|
|
|
const clonContent =
|
|
|
|
|
listQuestions[quizId][totalIndex].content;
|
2023-09-07 07:48:19 +00:00
|
|
|
|
clonContent.rule.or = Boolean(Number(value));
|
2023-09-06 13:20:12 +00:00
|
|
|
|
updateQuestionsList(quizId, totalIndex, {
|
|
|
|
|
content: clonContent,
|
|
|
|
|
});
|
2023-08-24 20:53:27 +00:00
|
|
|
|
}}
|
2023-04-15 09:10:59 +00:00
|
|
|
|
>
|
2023-08-16 12:00:35 +00:00
|
|
|
|
{CONDITIONS.map((condition, index) => (
|
|
|
|
|
<FormControlLabel
|
2023-08-24 20:53:27 +00:00
|
|
|
|
key={index}
|
2023-08-16 12:00:35 +00:00
|
|
|
|
sx={{ color: theme.palette.grey2.main }}
|
|
|
|
|
value={index}
|
|
|
|
|
control={
|
|
|
|
|
<Radio
|
|
|
|
|
checkedIcon={<RadioCheck />}
|
|
|
|
|
icon={<RadioIcon />}
|
|
|
|
|
/>
|
|
|
|
|
}
|
|
|
|
|
label={condition}
|
|
|
|
|
/>
|
|
|
|
|
))}
|
2023-04-15 09:10:59 +00:00
|
|
|
|
</RadioGroup>
|
|
|
|
|
</FormControl>
|
|
|
|
|
</Box>
|
|
|
|
|
<Box sx={{ display: "flex", justifyContent: "end", gap: "10px" }}>
|
2023-08-15 12:20:09 +00:00
|
|
|
|
<Button
|
|
|
|
|
variant="outlined"
|
|
|
|
|
onClick={handleClose}
|
2023-08-16 12:00:35 +00:00
|
|
|
|
sx={{ width: "100%", maxWidth: "130px" }}
|
2023-08-15 12:20:09 +00:00
|
|
|
|
>
|
2023-04-15 09:10:59 +00:00
|
|
|
|
Отмена
|
2023-05-10 17:35:30 +00:00
|
|
|
|
</Button>
|
2023-08-15 12:20:09 +00:00
|
|
|
|
<Button
|
|
|
|
|
variant="contained"
|
2023-08-16 12:00:35 +00:00
|
|
|
|
sx={{ width: "100%", maxWidth: "130px" }}
|
|
|
|
|
onClick={handleClose}
|
2023-08-15 12:20:09 +00:00
|
|
|
|
>
|
|
|
|
|
Готово
|
|
|
|
|
</Button>
|
2023-04-15 09:10:59 +00:00
|
|
|
|
</Box>
|
|
|
|
|
</Box>
|
|
|
|
|
</Box>
|
|
|
|
|
</Modal>
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
}
|