2023-11-29 13:49:52 +00:00
|
|
|
|
import { AnyTypedQuizQuestion } from "@model/questionTypes/shared";
|
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";
|
|
|
|
|
import { useState } from "react";
|
2023-09-20 09:07:33 +00:00
|
|
|
|
import { useDebouncedCallback } from "use-debounce";
|
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 = {
|
2023-12-31 02:53:25 +00:00
|
|
|
|
question: AnyTypedQuizQuestion;
|
2023-08-24 11:09:47 +00:00
|
|
|
|
};
|
|
|
|
|
|
2023-11-15 18:38:02 +00:00
|
|
|
|
export default function HelpQuestions({ question }: HelpQuestionsProps) {
|
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
|
|
|
|
|
2023-12-31 02:53:25 +00:00
|
|
|
|
const updateQuestionHint = useDebouncedCallback((value) => {
|
|
|
|
|
updateQuestion(question.id, (question) => {
|
|
|
|
|
question.content.hint.text = value;
|
|
|
|
|
});
|
|
|
|
|
}, 200);
|
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={"Текст консультанта"}
|
|
|
|
|
text={question.content.hint.text}
|
|
|
|
|
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" }}
|
|
|
|
|
>
|
|
|
|
|
{question.content.hint.video ? (
|
|
|
|
|
<video src={question.content.hint.video} 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)}
|
|
|
|
|
video={question.content.hint.video}
|
|
|
|
|
onUpload={(url) =>
|
|
|
|
|
updateQuestion(question.id, (question) => {
|
|
|
|
|
question.content.hint.video = url;
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
/>
|
2023-03-15 22:56:53 +00:00
|
|
|
|
</Box>
|
2023-12-31 02:53:25 +00:00
|
|
|
|
)}
|
|
|
|
|
</Box>
|
|
|
|
|
);
|
2023-07-30 21:25:47 +00:00
|
|
|
|
}
|