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";
|
2023-03-15 22:56:53 +00:00
|
|
|
|
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";
|
2024-02-29 11:23:52 +00:00
|
|
|
|
import { memo, useState } from "react";
|
2023-05-03 19:21:00 +00:00
|
|
|
|
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
|
|
|
|
|
2023-03-15 22:56:53 +00:00
|
|
|
|
type BackgroundType = "text" | "video";
|
|
|
|
|
|
2023-08-24 11:09:47 +00:00
|
|
|
|
type HelpQuestionsProps = {
|
2024-02-29 11:23:52 +00:00
|
|
|
|
questionId: string;
|
|
|
|
|
hintVideo: string;
|
|
|
|
|
hintText: string;
|
2023-08-24 11:09:47 +00:00
|
|
|
|
};
|
|
|
|
|
|
2024-02-29 11:23:52 +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
|
|
|
|
|
2024-02-26 15:56:07 +00:00
|
|
|
|
const updateQuestionHint = (value: string) => {
|
2024-02-29 11:23:52 +00:00
|
|
|
|
updateQuestion(questionId, (question) => {
|
2023-12-31 02:53:25 +00:00
|
|
|
|
question.content.hint.text = value;
|
|
|
|
|
});
|
2024-02-26 15:56:07 +00:00
|
|
|
|
};
|
2023-07-30 21:25:47 +00:00
|
|
|
|
|
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={"Текст консультанта"}
|
2024-02-29 11:23:52 +00:00
|
|
|
|
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" }}
|
|
|
|
|
>
|
2024-02-29 11:23:52 +00:00
|
|
|
|
{hintVideo ? (
|
|
|
|
|
<video src={hintVideo} width="400" controls />
|
2023-07-30 21:25:47 +00:00
|
|
|
|
) : (
|
2023-12-31 02:53:25 +00:00
|
|
|
|
<>
|
|
|
|
|
<UploadBox
|
|
|
|
|
icon={<UploadIcon />}
|
|
|
|
|
sx={{
|
|
|
|
|
height: "48px",
|
|
|
|
|
width: "48px",
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
</>
|
2023-07-30 21:25:47 +00:00
|
|
|
|
)}
|
2023-12-31 02:53:25 +00:00
|
|
|
|
</ButtonBase>
|
|
|
|
|
<UploadVideoModal
|
|
|
|
|
open={open}
|
|
|
|
|
onClose={() => setOpen(false)}
|
2024-02-29 11:23:52 +00:00
|
|
|
|
video={hintVideo}
|
2023-12-31 02:53:25 +00:00
|
|
|
|
onUpload={(url) =>
|
2024-02-29 11:23:52 +00:00
|
|
|
|
updateQuestion(questionId, (question) => {
|
2023-12-31 02:53:25 +00:00
|
|
|
|
question.content.hint.video = url;
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
/>
|
2023-03-15 22:56:53 +00:00
|
|
|
|
</Box>
|
2023-12-31 02:53:25 +00:00
|
|
|
|
)}
|
|
|
|
|
</Box>
|
|
|
|
|
);
|
2024-02-29 11:23:52 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
HelpQuestions.displayName = "HelpQuestions";
|
|
|
|
|
|
|
|
|
|
export default HelpQuestions;
|