import { Alert, AlertTitle, Checkbox, DialogContent, Stack, Typography } from "@mui/material"; import { useSnackbar } from "notistack"; import { useEffect, useRef, useState } from "react"; import { useTranslation } from "react-i18next"; import { sendImport } from "../../../api/api"; import { User } from "../../../api/user"; import { useAppDispatch } from "../../../redux/hooks"; import { DefaultCloseAction } from "../../Common/Snackbar/snackbar"; import { DenseFilledTextField, SmallFormControlLabel } from "../../Common/StyledComponents"; import DraggableDialog from "../../Dialogs/DraggableDialog"; import SettingForm from "../../Pages/Setting/SettingForm"; import SinglePolicySelectionInput from "../Common/SinglePolicySelectionInput"; import { NoMarginHelperText } from "../Settings/Settings"; import UserSearchInput from "./UserSearchInput"; // TODO: Add API call for creating import task export interface ImportFileDialogProps { open: boolean; onClose: () => void; } interface ImportTaskForm { storagePolicyId: number | undefined; externalPath: string; recursive: boolean; targetUser: User | null; targetPath: string; extractMediaMeta: boolean | undefined; } const defaultForm: ImportTaskForm = { storagePolicyId: undefined, externalPath: "", recursive: true, targetUser: null, targetPath: "/", extractMediaMeta: false, }; export const ImportFileDialog = ({ open, onClose }: ImportFileDialogProps) => { const { t } = useTranslation("dashboard"); const dispatch = useAppDispatch(); const { enqueueSnackbar } = useSnackbar(); const [loading, setLoading] = useState(false); const [formState, setFormState] = useState({ ...defaultForm }); const formRef = useRef(null); useEffect(() => { if (open) { setFormState({ ...defaultForm }); } }, [open]); const handleSubmit = () => { if (!formRef.current?.checkValidity()) { formRef.current?.reportValidity(); return; } if (!formState.targetUser) { enqueueSnackbar(t("file.pleaseSelectUser"), { variant: "error", action: DefaultCloseAction }); return; } setLoading(true); dispatch( sendImport({ src: formState.externalPath, dst: formState.targetPath, extract_media_meta: false, user_id: formState.targetUser.id, recursive: formState.recursive, policy_id: formState.storagePolicyId ?? 0, }), ) .then(() => { enqueueSnackbar(t("file.importTaskCreated"), { variant: "success", action: DefaultCloseAction }); onClose(); }) .finally(() => { setLoading(false); }); }; const handlePolicyChange = (value: number) => { setFormState({ ...formState, storagePolicyId: value }); }; const handleUserSelected = (user: User) => { setFormState({ ...formState, targetUser: user }); }; return (
{ e.preventDefault(); handleSubmit(); }} > theme.typography.body2.fontSize }}> {t("file.importExternalFolderDes")} theme.typography.body2.fontSize }}> {t("file.importWarning")}
    {t("file.importWarnings", { returnObjects: true }).map((warning, index) => (
  • {warning.toString()}
  • ))}
{t("file.storagePolicyDes")} setFormState({ ...formState, externalPath: e.target.value })} /> {t("file.selectSrcDes")} {t("file.targetUserDes")} setFormState({ ...formState, targetPath: e.target.value })} placeholder={"/"} /> {t("file.dstFolderPathDes")} setFormState({ ...formState, recursive: e.target.checked })} /> } labelPlacement="end" label={{t("file.recursivelyImport")}} /> {t("file.recursivelyImportDes")} setFormState({ ...formState, extractMediaMeta: e.target.checked })} /> } labelPlacement="end" label={{t("file.extractMediaMeta")}} /> {t("file.extractMediaMetaDes")}
); }; export default ImportFileDialog;