frontPanel/src/pages/Questions/OptionsPicture/settingOpytionsPict.tsx

243 lines
7.8 KiB
TypeScript
Raw Normal View History

2023-08-28 09:31:34 +00:00
import { useEffect } from "react";
2023-09-06 13:20:12 +00:00
import { useParams } from "react-router-dom";
2023-08-28 09:31:34 +00:00
import { Box, Button, Typography, useTheme } from "@mui/material";
import CustomCheckbox from "@ui_kit/CustomCheckbox";
2023-09-07 14:14:48 +00:00
import CustomTextField from "@ui_kit/CustomTextField";
2023-08-28 09:31:34 +00:00
import { questionStore, updateQuestionsList } from "@root/questions";
import InfoIcon from "../../../assets/icons/InfoIcon";
import FormatIcon2 from "../../../assets/icons/questionsPage/FormatIcon2";
import FormatIcon1 from "../../../assets/icons/questionsPage/FormatIcon1";
import ProportionsIcon11 from "../../../assets/icons/questionsPage/ProportionsIcon11";
import ProportionsIcon21 from "../../../assets/icons/questionsPage/ProportionsIcon21";
import ProportionsIcon12 from "../../../assets/icons/questionsPage/ProportionsIcon12";
interface Props {
2023-04-15 09:10:59 +00:00
Icon: React.ElementType;
isActive?: boolean;
onClick: () => void;
}
2023-08-28 09:31:34 +00:00
type SettingOpytionsPictProps = {
totalIndex: number;
};
const PROPORTIONS = [
{ value: "1:1", icon: ProportionsIcon11 },
{ value: "2:1", icon: ProportionsIcon21 },
{ value: "1:2", icon: ProportionsIcon12 },
];
2023-04-15 09:10:59 +00:00
export function SelectIconButton({ Icon, isActive = false, onClick }: Props) {
const theme = useTheme();
return (
<Button
2023-04-15 09:10:59 +00:00
onClick={onClick}
variant="outlined"
2023-08-28 09:31:34 +00:00
startIcon={
<Icon
color={
isActive
? theme.palette.navbarbg.main
: theme.palette.brightPurple.main
}
/>
}
2023-04-15 09:10:59 +00:00
sx={{
backgroundColor: isActive ? theme.palette.brightPurple.main : "#eee4fc",
borderRadius: 0,
border: "none",
2023-08-28 09:31:34 +00:00
color: isActive
? theme.palette.brightPurple.main
: theme.palette.grey2.main,
2023-04-15 09:10:59 +00:00
p: "7px",
width: "auto",
minWidth: 0,
"& .MuiButton-startIcon": {
mr: 0,
ml: 0,
},
"&:hover": {
2023-04-23 08:39:34 +00:00
border: "none",
2023-08-28 09:31:34 +00:00
borderColor: isActive
? theme.palette.brightPurple.main
: theme.palette.grey2.main,
2023-04-15 09:10:59 +00:00
},
}}
/>
);
}
2023-08-28 09:31:34 +00:00
export default function SettingOpytionsPict({
totalIndex,
}: SettingOpytionsPictProps) {
2023-09-06 13:20:12 +00:00
const quizId = Number(useParams().quizId);
2023-08-28 09:31:34 +00:00
const { listQuestions } = questionStore();
2023-08-28 09:31:34 +00:00
useEffect(() => {
2023-09-06 13:20:12 +00:00
if (!listQuestions[quizId][totalIndex].content.xy) {
2023-08-28 09:31:34 +00:00
updateProportions("1:1");
}
}, []);
const updateProportions = (proportions: string) => {
2023-09-06 13:20:12 +00:00
const clonContent = listQuestions[quizId][totalIndex].content;
2023-08-28 09:31:34 +00:00
clonContent.xy = proportions;
2023-09-06 13:20:12 +00:00
updateQuestionsList(quizId, totalIndex, { content: clonContent });
2023-08-28 09:31:34 +00:00
};
2023-04-15 09:10:59 +00:00
return (
<>
<Box sx={{ display: "flex" }}>
<Box sx={{ padding: "20px" }}>
<Typography sx={{ marginBottom: "15px" }}>Пропорции</Typography>
<Box
sx={{
display: "flex",
gap: "10px",
marginBottom: "20px",
}}
>
2023-08-28 09:31:34 +00:00
{PROPORTIONS.map(({ value, icon }, index) => (
<SelectIconButton
key={index}
onClick={() => updateProportions(value)}
2023-09-06 13:20:12 +00:00
isActive={
listQuestions[quizId][totalIndex].content.xy === value
}
2023-08-28 09:31:34 +00:00
Icon={icon}
/>
))}
2023-04-15 09:10:59 +00:00
</Box>
2023-08-28 09:31:34 +00:00
<Typography sx={{ marginBottom: "15px" }}>
Настройки ответов
</Typography>
<CustomCheckbox
2023-09-07 14:14:48 +00:00
sx={{ display: "block" }}
2023-08-28 09:31:34 +00:00
label={"Можно несколько"}
2023-09-06 13:20:12 +00:00
checked={listQuestions[quizId][totalIndex].content.multi}
2023-09-07 14:14:48 +00:00
handleChange={({ target }) =>
2023-09-06 13:20:12 +00:00
updateQuestionsList(quizId, totalIndex, {
2023-08-28 09:31:34 +00:00
content: {
2023-09-06 13:20:12 +00:00
...listQuestions[quizId][totalIndex].content,
2023-09-07 14:14:48 +00:00
multi: target.checked,
2023-08-28 09:31:34 +00:00
},
})
}
/>
<CustomCheckbox
label={"Большие картинки"}
2023-09-06 13:20:12 +00:00
checked={listQuestions[quizId][totalIndex].content.largeCheck}
2023-09-07 14:14:48 +00:00
handleChange={({ target }) =>
2023-09-06 13:20:12 +00:00
updateQuestionsList(quizId, totalIndex, {
2023-08-28 09:31:34 +00:00
content: {
2023-09-06 13:20:12 +00:00
...listQuestions[quizId][totalIndex].content,
2023-09-07 14:14:48 +00:00
largeCheck: target.checked,
},
})
}
/>
<CustomCheckbox
label={'Вариант "свой ответ"'}
checked={listQuestions[quizId][totalIndex].content.own}
handleChange={({ target }) =>
updateQuestionsList(quizId, totalIndex, {
content: {
...listQuestions[quizId][totalIndex].content,
own: target.checked,
2023-08-28 09:31:34 +00:00
},
})
}
/>
2023-04-15 09:10:59 +00:00
</Box>
<Box sx={{ padding: "20px" }}>
<Typography sx={{ marginBottom: "15px" }}>Форма</Typography>
<Box
sx={{
display: "flex",
gap: "10px",
marginBottom: "20px",
}}
>
<SelectIconButton
2023-08-28 09:31:34 +00:00
onClick={() =>
2023-09-06 13:20:12 +00:00
updateQuestionsList(quizId, totalIndex, {
2023-08-28 09:31:34 +00:00
content: {
2023-09-06 13:20:12 +00:00
...listQuestions[quizId][totalIndex].content,
2023-08-28 09:31:34 +00:00
format: "carousel",
},
})
}
2023-09-06 13:20:12 +00:00
isActive={
listQuestions[quizId][totalIndex].content.format === "carousel"
}
2023-08-28 09:31:34 +00:00
Icon={FormatIcon2}
/>
<SelectIconButton
onClick={() =>
2023-09-06 13:20:12 +00:00
updateQuestionsList(quizId, totalIndex, {
2023-08-28 09:31:34 +00:00
content: {
2023-09-06 13:20:12 +00:00
...listQuestions[quizId][totalIndex].content,
2023-08-28 09:31:34 +00:00
format: "masonry",
},
})
}
2023-09-06 13:20:12 +00:00
isActive={
listQuestions[quizId][totalIndex].content.format === "masonry"
}
2023-04-15 09:10:59 +00:00
Icon={FormatIcon1}
/>
</Box>
2023-08-28 09:31:34 +00:00
<Typography sx={{ marginBottom: "15px" }}>
Настройки вопросов
</Typography>
2023-09-07 14:14:48 +00:00
<CustomCheckbox
label={"Необязательный вопрос"}
checked={listQuestions[quizId][totalIndex].content.required}
handleChange={({ target }) =>
updateQuestionsList(quizId, totalIndex, {
content: {
...listQuestions[quizId][totalIndex].content,
required: target.checked,
},
})
}
/>
<Box sx={{ display: "flex" }}>
<CustomCheckbox
sx={{ width: "100%" }}
label={"Внутреннее название вопроса"}
checked={listQuestions[quizId][totalIndex].content.innerNameCheck}
handleChange={({ target }) =>
updateQuestionsList(quizId, totalIndex, {
content: {
...listQuestions[quizId][totalIndex].content,
innerNameCheck: target.checked,
innerName: "",
},
})
}
/>
<InfoIcon />
</Box>
{listQuestions[quizId][totalIndex].content.innerNameCheck && (
<CustomTextField
placeholder={"Внутреннее описание вопроса"}
text={listQuestions[quizId][totalIndex].content.innerName}
onChange={({ target }) => {
let clonContent = listQuestions[quizId][totalIndex].content;
clonContent.innerName = target.value;
updateQuestionsList(quizId, totalIndex, {
content: clonContent,
});
}}
/>
)}
2023-04-15 09:10:59 +00:00
</Box>
</Box>
</>
);
}