frontPanel/src/pages/Questions/PageOptions/PageOptions.tsx

127 lines
4.1 KiB
TypeScript
Raw Normal View History

2023-09-05 13:54:41 +00:00
import { useState } from "react";
2023-04-15 09:10:59 +00:00
import { Box, Typography, useTheme } from "@mui/material";
import ButtonsOptions from "../ButtonsOptions";
import CustomTextField from "@ui_kit/CustomTextField";
import AddImage from "../../../assets/icons/questionsPage/addImage";
import AddVideofile from "../../../assets/icons/questionsPage/addVideofile";
import SwitchPageOptions from "./switchPageOptions";
2023-09-05 13:54:41 +00:00
import { questionStore, updateQuestionsList } from "@root/questions";
import { UploadImageModal } from "../UploadImage/UploadImageModal";
import { UploadVideoModal } from "../UploadVideoModal";
2023-04-15 09:10:59 +00:00
type Props = {
disableInput?: boolean;
2023-08-12 08:31:21 +00:00
totalIndex: number;
2023-04-15 09:10:59 +00:00
};
export default function PageOptions({ disableInput, totalIndex }: Props) {
2023-09-05 13:54:41 +00:00
const [openImageModal, setOpenImageModal] = useState<boolean>(false);
const [openVideoModal, setOpenVideoModal] = useState<boolean>(false);
const [switchState, setSwitchState] = useState("setting");
const { listQuestions } = questionStore();
2023-04-15 09:10:59 +00:00
const theme = useTheme();
2023-09-05 13:54:41 +00:00
2023-04-15 09:10:59 +00:00
const SSHC = (data: string) => {
setSwitchState(data);
};
2023-09-05 13:54:41 +00:00
2023-04-15 09:10:59 +00:00
return (
<>
<Box
sx={{
width: "100%",
maxWidth: "640px",
display: "flex",
padding: "20px",
flexDirection: "column",
gap: "20px",
}}
>
<Box sx={{ display: disableInput ? "none" : "" }}>
2023-09-05 13:54:41 +00:00
<CustomTextField
placeholder={"Можно добавить текст"}
text={listQuestions[totalIndex].content.text}
onChange={({ target }) => {
const clonContent = listQuestions[totalIndex].content;
clonContent.text = target.value;
updateQuestionsList(totalIndex, { content: clonContent });
}}
/>
2023-04-15 09:10:59 +00:00
</Box>
<Box sx={{ display: "flex", alignItems: "center", gap: "12px" }}>
2023-09-05 13:54:41 +00:00
<Box
onClick={() => setOpenImageModal(true)}
2023-04-15 09:10:59 +00:00
sx={{
2023-09-05 13:54:41 +00:00
cursor: "pointer",
display: "flex",
alignItems: "center",
gap: "10px",
2023-04-15 09:10:59 +00:00
}}
>
2023-09-05 13:54:41 +00:00
<AddImage />
<Typography
sx={{
fontWeight: 400,
fontSize: "16px",
lineHeight: "18.96px",
color: theme.palette.grey2.main,
}}
>
Изображение
</Typography>
</Box>
<UploadImageModal
open={openImageModal}
onClose={() => setOpenImageModal(false)}
imgHC={(fileList) => {
if (fileList?.length) {
const clonContent = listQuestions[totalIndex].content;
clonContent.picture = URL.createObjectURL(fileList[0]);
updateQuestionsList(totalIndex, { content: clonContent });
}
}}
/>
2023-04-15 09:10:59 +00:00
<Typography> или</Typography>
2023-09-05 13:54:41 +00:00
<Box
onClick={() => setOpenVideoModal(true)}
2023-04-15 09:10:59 +00:00
sx={{
2023-09-05 13:54:41 +00:00
cursor: "pointer",
display: "flex",
alignItems: "center",
gap: "10px",
2023-04-15 09:10:59 +00:00
}}
>
2023-09-05 13:54:41 +00:00
<AddVideofile />
<Typography
sx={{
fontWeight: 400,
fontSize: "16px",
lineHeight: "18.96px",
color: theme.palette.grey2.main,
}}
>
Видео
</Typography>
</Box>
<UploadVideoModal
open={openVideoModal}
onClose={() => setOpenVideoModal(false)}
video={listQuestions[totalIndex].content.video}
onUpload={(url) => {
const clonContent = listQuestions[totalIndex].content;
clonContent.video = url;
updateQuestionsList(totalIndex, { content: clonContent });
}}
/>
2023-04-15 09:10:59 +00:00
</Box>
</Box>
2023-08-24 11:09:47 +00:00
<ButtonsOptions
switchState={switchState}
SSHC={SSHC}
totalIndex={totalIndex}
/>
<SwitchPageOptions switchState={switchState} totalIndex={totalIndex} />
2023-04-15 09:10:59 +00:00
</>
);
}