2023-08-25 11:18:25 +00:00
|
|
|
|
import { useState, useEffect } from "react";
|
2023-08-24 09:09:43 +00:00
|
|
|
|
import { Box, Typography } from "@mui/material";
|
2023-03-15 22:56:53 +00:00
|
|
|
|
import CustomCheckbox from "@ui_kit/CustomCheckbox";
|
2023-05-03 19:21:00 +00:00
|
|
|
|
import InfoIcon from "../../../assets/icons/InfoIcon";
|
2023-07-11 10:43:04 +00:00
|
|
|
|
import * as React from "react";
|
|
|
|
|
import CustomTextField from "@ui_kit/CustomTextField";
|
2023-08-24 09:09:43 +00:00
|
|
|
|
import { questionStore, updateQuestionsList } from "@root/questions";
|
2023-03-15 22:56:53 +00:00
|
|
|
|
|
2023-08-25 11:18:25 +00:00
|
|
|
|
import type { ChangeEvent } from "react";
|
|
|
|
|
|
2023-07-11 10:43:04 +00:00
|
|
|
|
interface Props {
|
2023-08-24 09:09:43 +00:00
|
|
|
|
totalIndex: number;
|
2023-07-11 10:43:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-08-24 09:09:43 +00:00
|
|
|
|
export default function ResponseSettings({ totalIndex }: Props) {
|
2023-08-25 11:18:25 +00:00
|
|
|
|
const [checked, setChecked] = useState(false);
|
2023-08-24 09:09:43 +00:00
|
|
|
|
const { listQuestions } = questionStore();
|
2023-08-25 11:18:25 +00:00
|
|
|
|
|
|
|
|
|
const handleChange = (event: ChangeEvent<HTMLInputElement>) => {
|
|
|
|
|
setChecked(event.target.checked);
|
2023-08-24 09:09:43 +00:00
|
|
|
|
};
|
2023-03-15 22:56:53 +00:00
|
|
|
|
|
2023-08-25 11:18:25 +00:00
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (listQuestions[totalIndex].content.innerName.length) {
|
|
|
|
|
setChecked(true);
|
|
|
|
|
}
|
|
|
|
|
}, []);
|
|
|
|
|
|
2023-08-24 09:09:43 +00:00
|
|
|
|
return (
|
|
|
|
|
<Box sx={{ display: "flex" }}>
|
|
|
|
|
<Box sx={{ padding: "20px", display: "flex", flexDirection: "column" }}>
|
|
|
|
|
<Typography>Настройки ответов</Typography>
|
|
|
|
|
<CustomCheckbox
|
|
|
|
|
label={"Длинный текстовый ответ"}
|
|
|
|
|
checked={listQuestions[totalIndex].content.large}
|
|
|
|
|
handleChange={(e) => {
|
|
|
|
|
let clonContent = listQuestions[totalIndex].content;
|
|
|
|
|
clonContent.large = e.target.checked;
|
|
|
|
|
updateQuestionsList(totalIndex, { content: clonContent });
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
<CustomCheckbox
|
|
|
|
|
label={"Можно несколько"}
|
|
|
|
|
checked={listQuestions[totalIndex].content.multi}
|
|
|
|
|
handleChange={(e) => {
|
|
|
|
|
let clonContent = listQuestions[totalIndex].content;
|
|
|
|
|
clonContent.multi = e.target.checked;
|
|
|
|
|
updateQuestionsList(totalIndex, { content: clonContent });
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
<CustomCheckbox
|
|
|
|
|
label={'Вариант "свой ответ"'}
|
|
|
|
|
checked={listQuestions[totalIndex].content.own}
|
|
|
|
|
handleChange={(e) => {
|
|
|
|
|
let clonContent = listQuestions[totalIndex].content;
|
|
|
|
|
clonContent.own = e.target.checked;
|
|
|
|
|
updateQuestionsList(totalIndex, { content: clonContent });
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
</Box>
|
|
|
|
|
<Box sx={{ padding: "20px", display: "flex", flexDirection: "column" }}>
|
|
|
|
|
<Typography>Настройки вопросов</Typography>
|
|
|
|
|
<CustomCheckbox
|
|
|
|
|
label={"Необязательный вопрос"}
|
|
|
|
|
checked={!listQuestions[totalIndex].required}
|
|
|
|
|
handleChange={(e) => {
|
|
|
|
|
updateQuestionsList(totalIndex, { required: !e.target.checked });
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
<Box sx={{ display: "flex" }}>
|
|
|
|
|
<CustomCheckbox
|
|
|
|
|
label={"Внутреннее название вопроса"}
|
2023-08-25 11:18:25 +00:00
|
|
|
|
checked={checked}
|
2023-08-24 09:09:43 +00:00
|
|
|
|
handleChange={handleChange}
|
|
|
|
|
/>{" "}
|
|
|
|
|
<InfoIcon />
|
2023-03-15 22:56:53 +00:00
|
|
|
|
</Box>
|
2023-08-25 11:18:25 +00:00
|
|
|
|
{checked && (
|
2023-08-24 09:09:43 +00:00
|
|
|
|
<CustomTextField
|
|
|
|
|
placeholder={"Развёрнутое описание вопроса"}
|
2023-08-25 11:18:25 +00:00
|
|
|
|
text={listQuestions[totalIndex].content.innerName}
|
|
|
|
|
onChange={({ target }) => {
|
2023-08-24 09:09:43 +00:00
|
|
|
|
let clonContent = listQuestions[totalIndex].content;
|
2023-08-25 11:18:25 +00:00
|
|
|
|
clonContent.innerName = target.value;
|
2023-08-24 09:09:43 +00:00
|
|
|
|
updateQuestionsList(totalIndex, { content: clonContent });
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
</Box>
|
|
|
|
|
</Box>
|
|
|
|
|
);
|
|
|
|
|
}
|