frontPanel/src/pages/Questions/helpQuestions.tsx

114 lines
3.1 KiB
TypeScript
Raw Normal View History

2023-09-05 13:54:41 +00:00
import { Box, ButtonBase, Typography } from "@mui/material";
2023-11-27 23:07:24 +00:00
import { updateQuestion } from "@root/questions/actions";
import CustomTextField from "@ui_kit/CustomTextField";
2023-11-15 18:38:02 +00:00
import SelectableButton from "@ui_kit/SelectableButton";
import UploadBox from "@ui_kit/UploadBox";
import { memo, useState } from "react";
import UploadIcon from "../../assets/icons/UploadIcon";
2023-09-05 13:54:41 +00:00
import { UploadVideoModal } from "./UploadVideoModal";
2023-08-15 11:00:45 +00:00
type BackgroundType = "text" | "video";
2023-08-24 11:09:47 +00:00
type HelpQuestionsProps = {
questionId: string;
hintVideo: string;
hintText: string;
2023-08-24 11:09:47 +00:00
};
const HelpQuestions = memo<HelpQuestionsProps>(function ({
questionId,
hintVideo,
hintText,
}) {
2023-12-31 02:53:25 +00:00
const [open, setOpen] = useState(false);
const [backgroundType, setBackgroundType] = useState<BackgroundType>("text");
2023-08-15 11:00:45 +00:00
const updateQuestionHint = (value: string) => {
updateQuestion(questionId, (question) => {
2023-12-31 02:53:25 +00:00
question.content.hint.text = value;
});
};
2023-12-31 02:53:25 +00:00
return (
<Box
sx={{
padding: "20px",
display: "flex",
flexDirection: "column",
gap: "20px",
}}
>
<Typography sx={{ fontWeight: "500" }}>Подсказка консультанта</Typography>
<Box
sx={{
display: "flex",
gap: "10px",
}}
>
<SelectableButton
isSelected={backgroundType === "text"}
onClick={() => setBackgroundType("text")}
sx={{ maxWidth: "130px" }}
>
Текст
</SelectableButton>
<SelectableButton
isSelected={backgroundType === "video"}
onClick={() => setBackgroundType("video")}
sx={{ maxWidth: "130px" }}
2023-08-15 09:51:18 +00:00
>
2023-12-31 02:53:25 +00:00
Видео
</SelectableButton>
</Box>
{backgroundType === "text" ? (
<>
<CustomTextField
placeholder={"Текст консультанта"}
value={hintText}
2023-12-31 02:53:25 +00:00
onChange={({ target }) => updateQuestionHint(target.value || " ")}
2024-02-16 23:41:38 +00:00
maxLength={100}
2023-12-31 02:53:25 +00:00
/>
</>
) : (
<Box>
<Typography sx={{ paddingBottom: "15px", fontWeight: "500" }}>
Загрузите видео
</Typography>
<ButtonBase
onClick={() => setOpen(true)}
sx={{ justifyContent: "flex-start" }}
>
{hintVideo ? (
<video src={hintVideo} width="400" controls />
) : (
2023-12-31 02:53:25 +00:00
<>
<UploadBox
icon={<UploadIcon />}
sx={{
height: "48px",
width: "48px",
}}
/>
</>
)}
2023-12-31 02:53:25 +00:00
</ButtonBase>
<UploadVideoModal
open={open}
onClose={() => setOpen(false)}
video={hintVideo}
2023-12-31 02:53:25 +00:00
onUpload={(url) =>
updateQuestion(questionId, (question) => {
2023-12-31 02:53:25 +00:00
question.content.hint.video = url;
})
}
/>
</Box>
2023-12-31 02:53:25 +00:00
)}
</Box>
);
});
HelpQuestions.displayName = "HelpQuestions";
export default HelpQuestions;