2023-08-25 08:29:42 +00:00
|
|
|
|
import {
|
2023-11-16 16:41:25 +00:00
|
|
|
|
Box,
|
|
|
|
|
FormControl,
|
|
|
|
|
FormControlLabel,
|
|
|
|
|
Radio,
|
|
|
|
|
RadioGroup,
|
|
|
|
|
Tooltip,
|
|
|
|
|
Typography,
|
|
|
|
|
useMediaQuery,
|
|
|
|
|
useTheme,
|
2023-08-25 08:29:42 +00:00
|
|
|
|
} from "@mui/material";
|
2023-11-27 23:07:24 +00:00
|
|
|
|
import { setQuestionInnerName, updateQuestion } from "@root/questions/actions";
|
2023-03-31 15:48:49 +00:00
|
|
|
|
import CustomCheckbox from "@ui_kit/CustomCheckbox";
|
2023-09-08 13:42:52 +00:00
|
|
|
|
import CustomTextField from "@ui_kit/CustomTextField";
|
2023-09-12 11:06:39 +00:00
|
|
|
|
import CheckedIcon from "@ui_kit/RadioCheck";
|
|
|
|
|
import CheckIcon from "@ui_kit/RadioIcon";
|
2023-11-16 16:41:25 +00:00
|
|
|
|
import { useDebouncedCallback } from "use-debounce";
|
2023-05-03 19:21:00 +00:00
|
|
|
|
import InfoIcon from "../../../assets/icons/InfoIcon";
|
2023-10-03 14:03:57 +00:00
|
|
|
|
import type { QuizQuestionText } from "../../../model/questionTypes/text";
|
|
|
|
|
|
2023-11-16 16:41:25 +00:00
|
|
|
|
|
2023-08-25 08:29:42 +00:00
|
|
|
|
type SettingTextFieldProps = {
|
2023-11-16 16:41:25 +00:00
|
|
|
|
question: QuizQuestionText;
|
2023-08-25 08:29:42 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
type Answer = {
|
2023-11-16 16:41:25 +00:00
|
|
|
|
name: string;
|
|
|
|
|
value: "single" | "multi";
|
2023-08-25 08:29:42 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const ANSWER_TYPES: Answer[] = [
|
2023-11-16 16:41:25 +00:00
|
|
|
|
{ name: "Однострочное", value: "single" },
|
|
|
|
|
{ name: "Многострочное", value: "multi" },
|
2023-08-25 08:29:42 +00:00
|
|
|
|
];
|
|
|
|
|
|
2023-10-30 10:46:55 +00:00
|
|
|
|
export default function SettingTextField({
|
2023-11-16 16:41:25 +00:00
|
|
|
|
question,
|
2023-10-30 10:46:55 +00:00
|
|
|
|
}: SettingTextFieldProps) {
|
2023-11-16 16:41:25 +00:00
|
|
|
|
const theme = useTheme();
|
|
|
|
|
const isWrappColumn = useMediaQuery(theme.breakpoints.down(980));
|
|
|
|
|
const isMobile = useMediaQuery(theme.breakpoints.down(790));
|
|
|
|
|
const isFigmaTablte = useMediaQuery(theme.breakpoints.down(990));
|
2023-09-25 13:43:15 +00:00
|
|
|
|
|
2023-11-16 16:41:25 +00:00
|
|
|
|
const debounced = useDebouncedCallback((value) => {
|
|
|
|
|
setQuestionInnerName(question.id, value);
|
2023-11-27 23:07:24 +00:00
|
|
|
|
}, 200);
|
2023-08-25 08:29:42 +00:00
|
|
|
|
|
2023-11-16 16:41:25 +00:00
|
|
|
|
return (
|
|
|
|
|
<Box
|
2023-10-30 10:46:55 +00:00
|
|
|
|
sx={{
|
2023-11-16 16:41:25 +00:00
|
|
|
|
display: "flex",
|
|
|
|
|
justifyContent: "space-between",
|
|
|
|
|
flexDirection: isWrappColumn ? "column" : null,
|
|
|
|
|
marginRight: isFigmaTablte ? "0px" : "32px",
|
2023-08-25 08:29:42 +00:00
|
|
|
|
}}
|
2023-11-16 16:41:25 +00:00
|
|
|
|
>
|
|
|
|
|
<Box
|
2023-09-12 11:06:39 +00:00
|
|
|
|
sx={{
|
2023-11-16 16:41:25 +00:00
|
|
|
|
pt: isMobile ? "25px" : "20px",
|
|
|
|
|
pb: isMobile ? "25px" : "20px",
|
|
|
|
|
pl: "20px",
|
2023-09-12 11:06:39 +00:00
|
|
|
|
}}
|
2023-11-16 16:41:25 +00:00
|
|
|
|
>
|
|
|
|
|
<Typography
|
|
|
|
|
sx={{
|
|
|
|
|
fontWeight: "500",
|
|
|
|
|
fontSize: "18px",
|
|
|
|
|
color: " #4D4D4D",
|
|
|
|
|
marginBottom: "14px",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
Настройки ответов
|
|
|
|
|
</Typography>
|
|
|
|
|
<FormControl>
|
|
|
|
|
<RadioGroup
|
|
|
|
|
sx={{
|
|
|
|
|
display: "flex",
|
|
|
|
|
flexDirection: "column",
|
|
|
|
|
gap: "14px",
|
|
|
|
|
width: "100%",
|
|
|
|
|
}}
|
|
|
|
|
aria-labelledby="demo-controlled-radio-buttons-group"
|
|
|
|
|
name="controlled-radio-buttons-group"
|
|
|
|
|
value={ANSWER_TYPES.findIndex(
|
|
|
|
|
({ value }) => question.content.answerType === value
|
|
|
|
|
)}
|
|
|
|
|
onChange={({ target }: React.ChangeEvent<HTMLInputElement>) => {
|
2023-11-27 23:07:24 +00:00
|
|
|
|
updateQuestion(question.id, question => {
|
2023-11-16 16:41:25 +00:00
|
|
|
|
if (question.type !== "text") return;
|
|
|
|
|
|
|
|
|
|
question.content.answerType = ANSWER_TYPES[Number(target.value)].value;
|
|
|
|
|
});
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{ANSWER_TYPES.map(({ name }, index) => (
|
|
|
|
|
<FormControlLabel
|
|
|
|
|
key={index}
|
|
|
|
|
sx={{
|
|
|
|
|
height: "26px",
|
|
|
|
|
color: theme.palette.grey2.main,
|
|
|
|
|
"& .MuiRadio-root": { padding: "8px 9px" },
|
|
|
|
|
}}
|
|
|
|
|
value={index}
|
|
|
|
|
control={
|
|
|
|
|
<Radio icon={<CheckIcon />} checkedIcon={<CheckedIcon />} />
|
|
|
|
|
}
|
|
|
|
|
label={name}
|
|
|
|
|
/>
|
|
|
|
|
))}
|
|
|
|
|
</RadioGroup>
|
|
|
|
|
</FormControl>
|
|
|
|
|
<CustomCheckbox
|
|
|
|
|
sx={{
|
|
|
|
|
display: isMobile ? "flex" : "block",
|
|
|
|
|
mr: isMobile ? "0px" : "16px",
|
|
|
|
|
marginTop: "15px",
|
|
|
|
|
alignItems: isMobile ? "flex-end" : "center",
|
|
|
|
|
}}
|
|
|
|
|
label={"Только числа"}
|
|
|
|
|
checked={question.content.onlyNumbers}
|
|
|
|
|
handleChange={({ target }) => {
|
2023-11-27 23:07:24 +00:00
|
|
|
|
updateQuestion(question.id, question => {
|
2023-11-16 16:41:25 +00:00
|
|
|
|
if (question.type !== "text") return;
|
|
|
|
|
|
|
|
|
|
question.content.onlyNumbers = target.checked;
|
|
|
|
|
});
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
</Box>
|
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
pt: isMobile ? "0px" : "20px",
|
|
|
|
|
pb: "20px",
|
|
|
|
|
pl: isFigmaTablte ? (isWrappColumn ? "20px" : "34px") : "20px",
|
|
|
|
|
pr: "20px",
|
|
|
|
|
display: "flex",
|
|
|
|
|
flexDirection: "column",
|
|
|
|
|
gap: "14px",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Typography
|
|
|
|
|
sx={{
|
|
|
|
|
height: isMobile ? "18px" : "auto",
|
|
|
|
|
fontWeight: "500",
|
|
|
|
|
fontSize: "18px",
|
|
|
|
|
color: " #4D4D4D",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
Настройки вопросов
|
|
|
|
|
</Typography>
|
|
|
|
|
<CustomCheckbox
|
|
|
|
|
sx={{
|
|
|
|
|
display: isMobile ? "flex" : "block",
|
|
|
|
|
mr: isMobile ? "0px" : "16px",
|
|
|
|
|
alignItems: isMobile ? "flex-end" : "center",
|
|
|
|
|
}}
|
|
|
|
|
label={"Автозаполнение адреса"}
|
|
|
|
|
checked={question.content.autofill}
|
|
|
|
|
handleChange={({ target }) => {
|
2023-11-27 23:07:24 +00:00
|
|
|
|
updateQuestion(question.id, question => {
|
2023-11-16 16:41:25 +00:00
|
|
|
|
question.content.autofill = target.checked;
|
|
|
|
|
});
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
<CustomCheckbox
|
|
|
|
|
sx={{
|
|
|
|
|
display: isMobile ? "flex" : "block",
|
|
|
|
|
mr: isMobile ? "0px" : "16px",
|
|
|
|
|
alignItems: isMobile ? "flex-end" : "center",
|
|
|
|
|
}}
|
|
|
|
|
label={"Необязательный вопрос"}
|
|
|
|
|
checked={!question.required}
|
|
|
|
|
handleChange={(e) => {
|
2023-11-27 23:07:24 +00:00
|
|
|
|
updateQuestion(question.id, question => {
|
2023-11-16 16:41:25 +00:00
|
|
|
|
question.required = !e.target.checked;
|
|
|
|
|
});
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
width: isMobile ? "90%" : "auto",
|
|
|
|
|
display: "flex",
|
|
|
|
|
alignItems: "center",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<CustomCheckbox
|
|
|
|
|
sx={{
|
|
|
|
|
alignItems: isMobile ? "flex-start" : "center",
|
|
|
|
|
display: isMobile ? "flex" : "block",
|
|
|
|
|
mr: isMobile ? "0px" : "16px",
|
|
|
|
|
height: isMobile ? "100%" : "26px",
|
|
|
|
|
}}
|
|
|
|
|
label={"Внутреннее название вопроса"}
|
|
|
|
|
checked={question.content.innerNameCheck}
|
|
|
|
|
handleChange={({ target }) => {
|
2023-11-27 23:07:24 +00:00
|
|
|
|
updateQuestion(question.id, question => {
|
2023-11-16 16:41:25 +00:00
|
|
|
|
question.content.innerNameCheck = target.checked;
|
|
|
|
|
question.content.innerName = target.checked
|
|
|
|
|
? question.content.innerName
|
|
|
|
|
: "";
|
|
|
|
|
});
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
<Tooltip
|
|
|
|
|
title="Будет отображаться как заголовок вопроса в приходящих заявках."
|
|
|
|
|
placement="top"
|
|
|
|
|
>
|
|
|
|
|
<Box>
|
|
|
|
|
<InfoIcon />
|
|
|
|
|
</Box>
|
|
|
|
|
</Tooltip>
|
|
|
|
|
</Box>
|
|
|
|
|
{question.content.innerNameCheck && (
|
|
|
|
|
<CustomTextField
|
|
|
|
|
placeholder={"Развёрнутое описание вопроса"}
|
|
|
|
|
text={question.content.innerName}
|
|
|
|
|
onChange={({ target }) => debounced(target.value)}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
2023-09-18 12:34:41 +00:00
|
|
|
|
</Box>
|
2023-09-08 13:42:52 +00:00
|
|
|
|
</Box>
|
2023-11-16 16:41:25 +00:00
|
|
|
|
);
|
2023-08-25 08:29:42 +00:00
|
|
|
|
}
|