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

327 lines
10 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-09-18 12:34:41 +00:00
import {
Box,
Button,
Typography,
Tooltip,
useMediaQuery,
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-09-20 09:07:33 +00:00
import { useDebouncedCallback } from "use-debounce";
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";
2023-10-03 14:03:57 +00:00
import type { QuizQuestionImages } from "../../../model/questionTypes/images";
interface Props {
2023-10-04 11:35:02 +00:00
Icon: (props: { color: string }) => JSX.Element;
// Icon: React.ElementType;
2023-04-15 09:10:59 +00:00
isActive?: boolean;
onClick: () => void;
}
2023-08-28 09:31:34 +00:00
type SettingOpytionsPictProps = {
totalIndex: number;
};
2023-10-04 11:35:02 +00:00
type Proportion = "1:1" | "2:1" | "1:2";
type ProportionItem = {
value: Proportion;
icon: (props: { color: string }) => JSX.Element;
};
const PROPORTIONS: ProportionItem[] = [
2023-08-28 09:31:34 +00:00
{ 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();
2023-09-15 12:37:12 +00:00
2023-04-15 09:10:59 +00:00
return (
<Button
2023-04-15 09:10:59 +00:00
onClick={onClick}
variant="outlined"
2023-09-18 12:34:41 +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",
2023-09-25 13:43:15 +00:00
2023-04-15 09:10:59 +00:00
borderRadius: 0,
border: "none",
2023-09-18 12:34:41 +00:00
color: isActive
? theme.palette.brightPurple.main
: theme.palette.grey2.main,
2023-04-15 09:10:59 +00:00
p: "7px",
2023-09-25 13:43:15 +00:00
width: "40px",
height: "40px",
2023-04-15 09:10:59 +00:00
minWidth: 0,
"& .MuiButton-startIcon": {
mr: 0,
ml: 0,
},
"&:hover": {
2023-04-23 08:39:34 +00:00
border: "none",
2023-09-18 12:34:41 +00:00
borderColor: isActive
? theme.palette.brightPurple.main
: theme.palette.grey2.main,
2023-04-15 09:10:59 +00:00
},
}}
/>
);
}
2023-09-18 12:34:41 +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-09-15 12:37:12 +00:00
const theme = useTheme();
2023-09-25 13:43:15 +00:00
const isTablet = useMediaQuery(theme.breakpoints.down(985));
2023-09-15 12:37:12 +00:00
const isMobile = useMediaQuery(theme.breakpoints.down(790));
2023-10-03 14:03:57 +00:00
const question = listQuestions[quizId][totalIndex] as QuizQuestionImages;
2023-09-25 13:43:15 +00:00
const isFigmaTablte = useMediaQuery(theme.breakpoints.down(990));
2023-09-20 09:07:33 +00:00
const debounced = useDebouncedCallback((value) => {
2023-10-04 11:35:02 +00:00
updateQuestionsList<QuizQuestionImages>(quizId, totalIndex, {
2023-10-03 14:03:57 +00:00
content: { ...question.content, innerName: value },
2023-09-20 09:07:33 +00:00
});
}, 1000);
2023-08-28 09:31:34 +00:00
useEffect(() => {
2023-10-03 14:03:57 +00:00
if (!question.content.xy) {
2023-08-28 09:31:34 +00:00
updateProportions("1:1");
}
}, []);
2023-10-04 11:35:02 +00:00
const updateProportions = (proportions: Proportion) => {
updateQuestionsList<QuizQuestionImages>(quizId, totalIndex, {
2023-10-03 14:03:57 +00:00
content: { ...question.content, xy: proportions },
});
2023-08-28 09:31:34 +00:00
};
2023-04-15 09:10:59 +00:00
return (
<>
2023-09-08 13:42:52 +00:00
<Box
sx={{
display: "flex",
justifyContent: "space-between",
2023-09-15 12:37:12 +00:00
flexDirection: isTablet ? "column" : null,
2023-09-25 13:43:15 +00:00
marginRight: isFigmaTablte ? (isMobile ? "0" : "0px") : "30px",
2023-09-08 13:42:52 +00:00
}}
>
2023-09-25 13:43:15 +00:00
<Box
sx={{
pt: isMobile ? "25px" : "20px",
pb: isMobile ? "25px" : "20px",
pl: "20px",
pr: isFigmaTablte ? (isMobile ? "20px" : "0px") : "28px",
display: "flex",
flexDirection: "column",
gap: "14px",
width: "100%",
}}
>
<Box sx={{ pb: isMobile ? "11px" : "6px" }}>
2023-10-05 14:03:54 +00:00
<Typography
sx={{
fontWeight: "500",
fontSize: "18px",
color: " #4D4D4D",
mb: isMobile ? "10px" : "14px",
}}
>
2023-09-25 13:43:15 +00:00
Пропорции
</Typography>
<Box
sx={{
display: "flex",
gap: "10px",
}}
>
{PROPORTIONS.map(({ value, icon }, index) => (
<SelectIconButton
key={index}
onClick={() => updateProportions(value)}
2023-10-05 14:03:54 +00:00
isActive={question.content.xy === value}
2023-09-25 13:43:15 +00:00
Icon={icon}
/>
))}
</Box>
2023-04-15 09:10:59 +00:00
</Box>
2023-09-15 12:37:12 +00:00
2023-10-05 14:03:54 +00:00
<Typography
sx={{ fontWeight: "500", fontSize: "18px", color: " #4D4D4D" }}
>
2023-09-18 12:34:41 +00:00
Настройки ответов
</Typography>
2023-08-28 09:31:34 +00:00
<CustomCheckbox
2023-09-21 07:00:08 +00:00
sx={{ display: "block", mr: isMobile ? "0px" : "16px" }}
2023-08-28 09:31:34 +00:00
label={"Можно несколько"}
2023-10-03 14:03:57 +00:00
checked={question.content.multi}
2023-09-07 14:14:48 +00:00
handleChange={({ target }) =>
2023-10-04 11:35:02 +00:00
updateQuestionsList<QuizQuestionImages>(quizId, totalIndex, {
2023-10-03 14:03:57 +00:00
content: { ...question.content, multi: target.checked },
2023-08-28 09:31:34 +00:00
})
}
/>
2023-10-05 14:03:54 +00:00
{question.content.xy !== "1:1" &&
question.content.format !== "masonry" && (
2023-09-25 12:35:12 +00:00
<CustomCheckbox
sx={{ display: "block", mr: isMobile ? "0px" : "16px" }}
label={"Большие картинки"}
2023-10-05 14:03:54 +00:00
checked={question.content.largeCheck}
2023-09-25 12:35:12 +00:00
handleChange={({ target }) =>
2023-10-05 14:03:54 +00:00
updateQuestionsList<QuizQuestionImages>(quizId, totalIndex, {
2023-09-25 12:35:12 +00:00
content: {
2023-10-05 14:03:54 +00:00
...question.content,
2023-09-25 12:35:12 +00:00
largeCheck: target.checked,
},
})
}
/>
)}
2023-09-07 14:14:48 +00:00
<CustomCheckbox
2023-09-21 07:00:08 +00:00
sx={{ display: "block", mr: isMobile ? "0px" : "16px" }}
2023-09-07 14:14:48 +00:00
label={'Вариант "свой ответ"'}
2023-10-03 14:03:57 +00:00
checked={question.content.own}
2023-09-07 14:14:48 +00:00
handleChange={({ target }) =>
2023-10-04 11:35:02 +00:00
updateQuestionsList<QuizQuestionImages>(quizId, totalIndex, {
2023-10-03 14:03:57 +00:00
content: { ...question.content, own: target.checked },
2023-08-28 09:31:34 +00:00
})
}
/>
2023-04-15 09:10:59 +00:00
</Box>
2023-09-25 13:43:15 +00:00
<Box
sx={{
2023-10-05 14:03:54 +00:00
pt: isMobile ? "25px" : "20px",
pb: isMobile ? "25px" : "20px",
pl: "20px",
pr: isFigmaTablte ? (isMobile ? "20px" : "0px") : "28px",
2023-09-25 13:43:15 +00:00
display: "flex",
flexDirection: "column",
2023-10-05 14:03:54 +00:00
gap: "14px",
2023-09-25 13:43:15 +00:00
width: "100%",
}}
>
2023-04-15 09:10:59 +00:00
<Box
sx={{
2023-10-05 14:03:54 +00:00
marginBottom: "5px",
opacity: question.content.xy !== "1:1" ? 1 : 0,
2023-10-06 19:28:30 +00:00
display: isTablet
? question.content.xy === "1:1"
? "none"
: "block"
: "block",
2023-04-15 09:10:59 +00:00
}}
>
2023-10-05 14:03:54 +00:00
<Typography
2023-09-25 13:43:15 +00:00
sx={{
2023-10-05 14:03:54 +00:00
marginBottom: "15px",
fontWeight: "500",
fontSize: "18px",
color: " #4D4D4D",
2023-09-25 13:43:15 +00:00
}}
>
2023-10-05 14:03:54 +00:00
Формат
</Typography>
2023-04-15 09:10:59 +00:00
<SelectIconButton
2023-08-28 09:31:34 +00:00
onClick={() =>
2023-10-04 11:35:02 +00:00
updateQuestionsList<QuizQuestionImages>(quizId, totalIndex, {
2023-10-03 14:03:57 +00:00
content: { ...question.content, format: "carousel" },
2023-08-28 09:31:34 +00:00
})
}
2023-10-03 14:03:57 +00:00
isActive={question.content.format === "carousel"}
2023-08-28 09:31:34 +00:00
Icon={FormatIcon2}
/>
<SelectIconButton
onClick={() =>
2023-10-04 11:35:02 +00:00
updateQuestionsList<QuizQuestionImages>(quizId, totalIndex, {
2023-10-03 14:03:57 +00:00
content: { ...question.content, format: "masonry" },
2023-08-28 09:31:34 +00:00
})
}
2023-10-03 14:03:57 +00:00
isActive={question.content.format === "masonry"}
2023-04-15 09:10:59 +00:00
Icon={FormatIcon1}
/>
</Box>
2023-10-05 14:03:54 +00:00
<Typography
sx={{ fontWeight: "500", fontSize: "18px", color: " #4D4D4D" }}
>
2023-09-18 12:34:41 +00:00
Настройки вопросов
</Typography>
2023-09-07 14:14:48 +00:00
<CustomCheckbox
2023-10-03 14:41:12 +00:00
sx={{ alignItems: isMobile ? "flex-start" : "" }}
2023-09-07 14:14:48 +00:00
label={"Необязательный вопрос"}
2023-10-03 14:03:57 +00:00
checked={question.content.required}
2023-09-07 14:14:48 +00:00
handleChange={({ target }) =>
2023-10-04 11:35:02 +00:00
updateQuestionsList<QuizQuestionImages>(quizId, totalIndex, {
2023-10-03 14:03:57 +00:00
content: { ...question.content, required: target.checked },
2023-09-07 14:14:48 +00:00
})
}
/>
2023-10-03 14:03:57 +00:00
<Box
sx={{
width: isMobile ? "90%" : "auto",
display: "flex",
alignItems: "center",
}}
>
2023-09-07 14:14:48 +00:00
<CustomCheckbox
2023-10-06 19:28:30 +00:00
sx={{
height: isMobile ? "100%" : "26px",
alignItems: isMobile ? "flex-start" : "center",
}}
2023-09-07 14:14:48 +00:00
label={"Внутреннее название вопроса"}
2023-10-03 14:03:57 +00:00
checked={question.content.innerNameCheck}
2023-09-07 14:14:48 +00:00
handleChange={({ target }) =>
2023-10-04 11:35:02 +00:00
updateQuestionsList<QuizQuestionImages>(quizId, totalIndex, {
2023-09-07 14:14:48 +00:00
content: {
2023-10-03 14:03:57 +00:00
...question.content,
2023-09-07 14:14:48 +00:00
innerNameCheck: target.checked,
innerName: "",
},
})
}
/>
2023-09-18 12:34:41 +00:00
<Tooltip
title="Будет отображаться как заголовок вопроса в приходящих заявках."
placement="top"
>
<Box>
<InfoIcon />
</Box>
</Tooltip>
2023-09-07 14:14:48 +00:00
</Box>
2023-10-03 14:03:57 +00:00
{question.content.innerNameCheck && (
2023-09-07 14:14:48 +00:00
<CustomTextField
placeholder={"Внутреннее описание вопроса"}
2023-10-03 14:03:57 +00:00
text={question.content.innerName}
2023-09-20 09:07:33 +00:00
onChange={({ target }) => debounced(target.value)}
2023-09-07 14:14:48 +00:00
/>
)}
2023-04-15 09:10:59 +00:00
</Box>
</Box>
</>
);
}