frontPanel/src/pages/Questions/OwnTextField/settingTextField.tsx

81 lines
2.4 KiB
TypeScript
Raw Normal View History

2023-08-25 08:29:42 +00:00
import {
Box,
FormControl,
FormControlLabel,
Radio,
RadioGroup,
Typography,
useTheme,
} from "@mui/material";
import CustomCheckbox from "@ui_kit/CustomCheckbox";
2023-08-25 08:29:42 +00:00
import { questionStore, updateQuestionsList } from "@root/questions";
import InfoIcon from "../../../assets/icons/InfoIcon";
2023-08-25 08:29:42 +00:00
type SettingTextFieldProps = {
totalIndex: number;
};
type Answer = {
name: string;
2023-08-28 08:20:09 +00:00
value: "single" | "multi" | "number";
2023-08-25 08:29:42 +00:00
};
const ANSWER_TYPES: Answer[] = [
{ name: "Односточное", value: "single" },
{ name: "Многострочное", value: "multi" },
{ name: "Только числа", value: "number" },
];
export default function SettingTextField({
totalIndex,
}: SettingTextFieldProps) {
const { listQuestions } = questionStore();
const theme = useTheme();
return (
<Box sx={{ display: "flex" }}>
<Box sx={{ padding: "20px" }}>
<Typography>Настройки ответов</Typography>
<FormControl>
<RadioGroup
aria-labelledby="demo-controlled-radio-buttons-group"
name="controlled-radio-buttons-group"
value={ANSWER_TYPES.findIndex(
2023-08-28 08:20:09 +00:00
({ value }) => listQuestions[totalIndex].content[value]
2023-08-25 08:29:42 +00:00
)}
onChange={({ target }: React.ChangeEvent<HTMLInputElement>) => {
2023-08-28 08:20:09 +00:00
const clonContent = {
...listQuestions[totalIndex].content,
single: false,
multi: false,
number: false,
[ANSWER_TYPES[Number(target.value)].value]: true,
};
2023-08-25 08:29:42 +00:00
updateQuestionsList(totalIndex, { content: clonContent });
}}
>
{ANSWER_TYPES.map(({ name }, index) => (
<FormControlLabel
key={index}
sx={{ color: theme.palette.grey2.main }}
value={index}
control={<Radio />}
label={name}
/>
))}
</RadioGroup>
</FormControl>
</Box>
<Box sx={{ padding: "20px" }}>
<Typography>Настройки вопросов</Typography>
<CustomCheckbox label={"Автозаполнение адреса"} />
<CustomCheckbox label={"Необязательный вопрос"} />
<CustomCheckbox label={"Внутреннее название вопроса"} /> <InfoIcon />
</Box>
</Box>
);
}