frontPanel/src/pages/Questions/UploadVideoModal.tsx

130 lines
4.3 KiB
TypeScript
Raw Normal View History

2024-06-17 14:28:24 +00:00
import { Box, Button, ButtonBase, Dialog, Typography, useTheme } from "@mui/material";
2023-09-05 13:54:41 +00:00
import CustomTextField from "@ui_kit/CustomTextField";
2024-06-17 14:28:24 +00:00
import SelectableButton from "@ui_kit/SelectableButton";
2023-09-05 13:54:41 +00:00
import { useState } from "react";
import UploadIcon from "../../assets/icons/UploadIcon";
import type { DragEvent } from "react";
type BackgroundTypeModal = "linkVideo" | "ownVideo";
type HelpQuestionsProps = {
open: boolean;
onClose: () => void;
2024-06-17 14:28:24 +00:00
video: string | null;
2023-09-05 13:54:41 +00:00
onUpload: (number: string) => void;
};
2024-06-17 14:28:24 +00:00
export default function UploadVideoModal({ open, onClose, video, onUpload }: HelpQuestionsProps) {
const [backgroundTypeModal, setBackgroundTypeModal] = useState<BackgroundTypeModal>("linkVideo");
2023-09-05 13:54:41 +00:00
const theme = useTheme();
const handleDrop = (event: DragEvent<HTMLDivElement>) => {
event.preventDefault();
event.stopPropagation();
if (event.dataTransfer.files.length) {
onUpload(URL.createObjectURL(event.dataTransfer.files[0]));
}
};
return (
2024-06-17 14:28:24 +00:00
<Dialog
2023-12-31 02:53:25 +00:00
open={open}
onClose={onClose}
2024-06-17 14:28:24 +00:00
PaperProps={{
sx: {
maxWidth: "640px",
2023-09-05 13:54:41 +00:00
borderRadius: "12px",
boxShadow: 24,
p: 0,
overflow: "hidden",
2024-06-17 14:28:24 +00:00
},
}}
>
<Box
sx={{
display: "flex",
padding: "20px",
background: theme.palette.background.default,
2023-09-05 13:54:41 +00:00
}}
>
2024-06-17 14:28:24 +00:00
<Typography sx={{ color: "#9A9AAF" }}>
Видео можно вставить с любого хостинга: YouTube, Vimeo или загрузить собственное
</Typography>
<Button
onClick={onClose}
variant="contained"
>
Готово
</Button>
</Box>
<Box sx={{ padding: "20px", gap: "10px", display: "flex" }}>
<SelectableButton
isSelected={backgroundTypeModal === "linkVideo"}
onClick={() => setBackgroundTypeModal("linkVideo")}
sx={{ maxWidth: "170px", padding: "10px" }}
>
Ссылка на видео
</SelectableButton>
<SelectableButton
isSelected={backgroundTypeModal === "ownVideo"}
onClick={() => setBackgroundTypeModal("ownVideo")}
sx={{ maxWidth: "170px", padding: "10px" }}
2023-09-05 13:54:41 +00:00
>
2024-06-17 14:28:24 +00:00
Загрузить свое
</SelectableButton>
</Box>
{backgroundTypeModal === "linkVideo" ? (
<Box sx={{ padding: "20px" }}>
<Typography sx={{ paddingBottom: "15px", fontWeight: "500" }}>Ссылка на видео</Typography>
<CustomTextField
placeholder={"http://example.com"}
value={video || ""}
onChange={({ target }) => onUpload(target.value || " ")}
/>
2023-09-05 13:54:41 +00:00
</Box>
2024-06-17 14:28:24 +00:00
) : (
<Box sx={{ padding: "20px" }}>
<Typography sx={{ paddingBottom: "15px", fontWeight: "500" }}>Загрузите видео</Typography>
<ButtonBase
component="label"
sx={{ justifyContent: "flex-start", width: "100%" }}
2023-09-05 13:54:41 +00:00
>
2024-06-17 14:28:24 +00:00
<input
onChange={({ target }) => {
if (target.files?.length) {
onUpload(URL.createObjectURL(target.files[0] || " "));
}
}}
hidden
accept="video/*"
multiple
type="file"
2023-09-05 13:54:41 +00:00
/>
2024-06-17 14:28:24 +00:00
<Box
onDragOver={(event: DragEvent<HTMLDivElement>) => event.preventDefault()}
onDrop={handleDrop}
sx={{
width: "580px",
padding: "33px 33px 33px 50px",
display: "flex",
alignItems: "center",
backgroundColor: theme.palette.background.default,
border: `1px solid ${theme.palette.grey2.main}`,
borderRadius: "8px",
gap: "50px",
}}
2023-12-31 02:53:25 +00:00
>
2024-06-17 14:28:24 +00:00
<UploadIcon />
<Box sx={{ color: "#9A9AAF" }}>
<Typography sx={{ fontWeight: "500" }}>Добавить видео</Typography>
<Typography sx={{ fontSize: "16px" }}>Принимает .mp4 и .mov формат максимум 100мб</Typography>
2023-09-05 13:54:41 +00:00
</Box>
2024-06-17 14:28:24 +00:00
</Box>
</ButtonBase>
</Box>
)}
</Dialog>
2023-09-05 13:54:41 +00:00
);
2024-06-17 14:28:24 +00:00
}