import { Box, Typography, ButtonBase, useTheme, IconButton, } from "@mui/material"; import { useQuizViewStore, updateAnswer } from "@root/quizView/store"; import { UPLOAD_FILE_TYPES_MAP } from "../tools/File"; import UploadIcon from "@icons/UploadIcon"; import CloseBold from "@icons/CloseBold"; import type { ChangeEvent } from "react"; import type { QuizQuestionFile } from "../../../model/questionTypes/file"; import type { DragEvent } from "react"; import type { UploadFileType } from "@model/questionTypes/file"; import { enqueueSnackbar } from "notistack"; import { sendFile } from "@api/quizRelase"; import { useQuestionsStore } from "@root/quizData/store" type FileProps = { currentQuestion: QuizQuestionFile; }; export const UPLOAD_FILE_DESCRIPTIONS_MAP: Record< UploadFileType, { title: string; description: string } > = { all: { title: "Добавить файл", description: "Принимает любые файлы" }, picture: { title: "Добавить изображение", description: "Принимает изображения", }, video: { title: "Добавить видео", description: "Принимает .mp4 и .mov формат — максимум 100мб", }, audio: { title: "Добавить аудиофайл", description: "Принимает аудиофайлы" }, document: { title: "Добавить документ", description: "Принимает документы" }, } as const; export const File = ({ currentQuestion }: FileProps) => { const { settings } = useQuestionsStore() const { answers } = useQuizViewStore(); const answer = answers.find( ({ questionId }) => questionId === currentQuestion.id )?.answer as string; const theme = useTheme(); const uploadFile = async ({ target }: ChangeEvent) => { const file = target.files?.[0]; if (file) { try { await sendFile({ questionId: currentQuestion.id, body: { file: `${file.name}|${URL.createObjectURL(file)}`, name: file.name }, //@ts-ignore qid: settings.qid }) updateAnswer( currentQuestion.id, `${file.name}|${URL.createObjectURL(file)}` ); } catch (e) { enqueueSnackbar("ответ не был засчитан") } } }; return ( {currentQuestion.title} {answer?.split("|")[0] && ( Вы загрузили: {answer?.split("|")[0]} { updateAnswer(currentQuestion.id, ""); }} > )} {!answer?.split("|")[0] && ( ) => event.preventDefault() } sx={{ width: "100%", height: "120px", display: "flex", gap: "50px", justifyContent: "flex-start", alignItems: "center", padding: "33px 44px 33px 55px", backgroundColor: theme.palette.background.default, border: `1px solid ${theme.palette.grey2.main}`, borderRadius: "8px", }} > { UPLOAD_FILE_DESCRIPTIONS_MAP[currentQuestion.content.type] .title } { UPLOAD_FILE_DESCRIPTIONS_MAP[currentQuestion.content.type] .description } )} {answer && currentQuestion.content.type === "picture" && ( )} {answer && currentQuestion.content.type === "video" && ( ); };