2024-05-29 16:41:41 +00:00
|
|
|
|
import { Box, FormControlLabel, Radio, RadioGroup, Typography, useMediaQuery, useTheme } from "@mui/material";
|
2024-02-26 15:56:07 +00:00
|
|
|
|
import { updateQuestion } from "@root/questions/actions";
|
2023-03-31 15:48:49 +00:00
|
|
|
|
import CustomCheckbox from "@ui_kit/CustomCheckbox";
|
2023-10-03 14:03:57 +00:00
|
|
|
|
import type { QuizQuestionText } from "../../../model/questionTypes/text";
|
2024-02-29 11:23:52 +00:00
|
|
|
|
import { memo } from "react";
|
2024-05-29 16:41:41 +00:00
|
|
|
|
import RadioCheck from "@ui_kit/RadioCheck";
|
|
|
|
|
|
import RadioIcon from "@ui_kit/RadioIcon";
|
2023-10-03 14:03:57 +00:00
|
|
|
|
|
2024-05-29 16:41:41 +00:00
|
|
|
|
type Answer = "single" | "multi" | "numberOnly";
|
2023-08-25 08:29:42 +00:00
|
|
|
|
|
2024-05-29 16:41:41 +00:00
|
|
|
|
type AnswerItem = {
|
2023-12-31 02:53:25 +00:00
|
|
|
|
name: string;
|
2024-05-29 16:41:41 +00:00
|
|
|
|
value: Answer;
|
2023-08-25 08:29:42 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
2024-05-29 16:41:41 +00:00
|
|
|
|
const ANSWER_TYPES: AnswerItem[] = [
|
2023-12-31 02:53:25 +00:00
|
|
|
|
{ name: "Однострочное", value: "single" },
|
|
|
|
|
|
{ name: "Многострочное", value: "multi" },
|
2024-05-29 16:41:41 +00:00
|
|
|
|
{ name: "Только числа", value: "numberOnly" },
|
2023-08-25 08:29:42 +00:00
|
|
|
|
];
|
|
|
|
|
|
|
2024-05-29 16:41:41 +00:00
|
|
|
|
type SettingTextFieldProps = {
|
|
|
|
|
|
questionId: string;
|
|
|
|
|
|
isRequired: boolean;
|
|
|
|
|
|
isAutofill: boolean;
|
|
|
|
|
|
answerType: Answer;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const SettingTextField = memo<SettingTextFieldProps>(function ({ questionId, isRequired, isAutofill, answerType }) {
|
2023-12-31 02:53:25 +00:00
|
|
|
|
const theme = useTheme();
|
|
|
|
|
|
const isWrappColumn = useMediaQuery(theme.breakpoints.down(980));
|
|
|
|
|
|
const isMobile = useMediaQuery(theme.breakpoints.down(790));
|
2024-05-29 16:41:41 +00:00
|
|
|
|
const isTablet = useMediaQuery(theme.breakpoints.down(900));
|
2023-12-31 02:53:25 +00:00
|
|
|
|
const isFigmaTablte = useMediaQuery(theme.breakpoints.down(990));
|
2023-09-25 13:43:15 +00:00
|
|
|
|
|
2023-12-31 02:53:25 +00:00
|
|
|
|
return (
|
|
|
|
|
|
<Box
|
|
|
|
|
|
sx={{
|
|
|
|
|
|
display: "flex",
|
|
|
|
|
|
justifyContent: "space-between",
|
2024-05-29 16:41:41 +00:00
|
|
|
|
flexDirection: isTablet ? "column" : "row",
|
|
|
|
|
|
marginRight: isFigmaTablte ? (isMobile ? "0" : "0px") : "30px",
|
|
|
|
|
|
pb: "20px",
|
|
|
|
|
|
pl: "20px",
|
|
|
|
|
|
pt: isTablet ? "5px" : "0px",
|
2023-12-31 02:53:25 +00:00
|
|
|
|
}}
|
|
|
|
|
|
>
|
|
|
|
|
|
<Box
|
|
|
|
|
|
sx={{
|
2024-05-29 16:41:41 +00:00
|
|
|
|
boxSizing: "border-box",
|
|
|
|
|
|
pt: "20px",
|
|
|
|
|
|
pr: isFigmaTablte ? "19px" : "20px",
|
|
|
|
|
|
display: "flex",
|
|
|
|
|
|
flexDirection: "column",
|
|
|
|
|
|
gap: "14px",
|
|
|
|
|
|
width: "100%",
|
|
|
|
|
|
}}
|
|
|
|
|
|
>
|
|
|
|
|
|
<Typography
|
|
|
|
|
|
sx={{
|
|
|
|
|
|
height: isMobile ? "18px" : "auto",
|
|
|
|
|
|
fontWeight: "500",
|
|
|
|
|
|
fontSize: "18px",
|
|
|
|
|
|
color: " #4D4D4D",
|
|
|
|
|
|
}}
|
|
|
|
|
|
>
|
|
|
|
|
|
Настройки ответов
|
|
|
|
|
|
</Typography>
|
|
|
|
|
|
<RadioGroup
|
|
|
|
|
|
value={answerType}
|
|
|
|
|
|
onChange={(event) => {
|
|
|
|
|
|
updateQuestion<QuizQuestionText>(questionId, (question) => {
|
|
|
|
|
|
question.content.answerType = event.target.value as Answer;
|
|
|
|
|
|
});
|
|
|
|
|
|
}}
|
|
|
|
|
|
sx={{
|
|
|
|
|
|
display: "flex",
|
|
|
|
|
|
flexDirection: "column",
|
|
|
|
|
|
}}
|
|
|
|
|
|
>
|
|
|
|
|
|
{ANSWER_TYPES.map((answerTypeItem, index) => (
|
|
|
|
|
|
<FormControlLabel
|
|
|
|
|
|
value={answerTypeItem.value}
|
|
|
|
|
|
control={<Radio checkedIcon={<RadioCheck />} icon={<RadioIcon />} />}
|
|
|
|
|
|
label={answerTypeItem.name}
|
|
|
|
|
|
sx={{
|
|
|
|
|
|
color: theme.palette.grey2.main,
|
|
|
|
|
|
}}
|
|
|
|
|
|
/>
|
|
|
|
|
|
))}
|
|
|
|
|
|
</RadioGroup>
|
|
|
|
|
|
</Box>
|
|
|
|
|
|
<Box
|
|
|
|
|
|
sx={{
|
|
|
|
|
|
boxSizing: "border-box",
|
2024-01-04 15:18:29 +00:00
|
|
|
|
pt: "20px",
|
2024-05-29 16:41:41 +00:00
|
|
|
|
pr: isFigmaTablte ? "19px" : "20px",
|
2023-12-31 02:53:25 +00:00
|
|
|
|
display: "flex",
|
|
|
|
|
|
flexDirection: "column",
|
|
|
|
|
|
gap: "14px",
|
2024-05-29 16:41:41 +00:00
|
|
|
|
width: "100%",
|
2023-12-31 02:53:25 +00:00
|
|
|
|
}}
|
|
|
|
|
|
>
|
|
|
|
|
|
<Typography
|
|
|
|
|
|
sx={{
|
|
|
|
|
|
height: isMobile ? "18px" : "auto",
|
|
|
|
|
|
fontWeight: "500",
|
|
|
|
|
|
fontSize: "18px",
|
|
|
|
|
|
color: " #4D4D4D",
|
|
|
|
|
|
}}
|
|
|
|
|
|
>
|
|
|
|
|
|
Настройки вопросов
|
|
|
|
|
|
</Typography>
|
2024-05-29 16:41:41 +00:00
|
|
|
|
<CustomCheckbox
|
|
|
|
|
|
dataCy="checkbox-optional-autofill"
|
|
|
|
|
|
sx={{
|
|
|
|
|
|
display: isMobile ? "flex" : "block",
|
|
|
|
|
|
mr: isMobile ? "0px" : "16px",
|
|
|
|
|
|
alignItems: isMobile ? "flex-end" : "center",
|
|
|
|
|
|
}}
|
|
|
|
|
|
label={"Автозаполнение адреса"}
|
|
|
|
|
|
checked={isAutofill}
|
|
|
|
|
|
handleChange={(e) => {
|
|
|
|
|
|
updateQuestion<QuizQuestionText>(questionId, (question) => {
|
|
|
|
|
|
question.content.autofill = e.target.checked;
|
|
|
|
|
|
});
|
|
|
|
|
|
}}
|
|
|
|
|
|
/>
|
2023-12-31 02:53:25 +00:00
|
|
|
|
<CustomCheckbox
|
2024-01-10 10:43:04 +00:00
|
|
|
|
dataCy="checkbox-optional-question"
|
2023-12-31 02:53:25 +00:00
|
|
|
|
sx={{
|
|
|
|
|
|
display: isMobile ? "flex" : "block",
|
|
|
|
|
|
mr: isMobile ? "0px" : "16px",
|
|
|
|
|
|
alignItems: isMobile ? "flex-end" : "center",
|
|
|
|
|
|
}}
|
|
|
|
|
|
label={"Необязательный вопрос"}
|
2024-02-29 11:23:52 +00:00
|
|
|
|
checked={!isRequired}
|
2023-12-31 02:53:25 +00:00
|
|
|
|
handleChange={(e) => {
|
2024-02-29 11:23:52 +00:00
|
|
|
|
updateQuestion<QuizQuestionText>(questionId, (question) => {
|
2023-12-31 02:53:25 +00:00
|
|
|
|
question.content.required = !e.target.checked;
|
|
|
|
|
|
});
|
|
|
|
|
|
}}
|
|
|
|
|
|
/>
|
|
|
|
|
|
</Box>
|
|
|
|
|
|
</Box>
|
|
|
|
|
|
);
|
2024-02-29 11:23:52 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
SettingTextField.displayName = "SettingTextField";
|
|
|
|
|
|
|
|
|
|
|
|
export default SettingTextField;
|