import { Button, IconButton, Input } from "@mui/joy"; import { useState } from "react"; import { toast } from "react-hot-toast"; import * as api from "@/helpers/api"; import { useGlobalStore } from "@/store/module"; import { useTranslate } from "@/utils/i18n"; import { generateDialog } from "./Dialog"; import Icon from "./Icon"; import LearnMore from "./LearnMore"; interface Props extends DialogProps { localStoragePath?: string; confirmCallback?: () => void; } const UpdateLocalStorageDialog: React.FC = (props: Props) => { const t = useTranslate(); const { destroy, localStoragePath, confirmCallback } = props; const globalStore = useGlobalStore(); const [path, setPath] = useState(localStoragePath || ""); const handleCloseBtnClick = () => { destroy(); }; const handleConfirmBtnClick = async () => { try { await api.upsertSystemSetting({ name: "local-storage-path", value: JSON.stringify(path.trim()), }); await globalStore.fetchSystemStatus(); } catch (error: any) { console.error(error); if (error.response.data.error) { const errorText = error.response.data.error as string; const internalIndex = errorText.indexOf("internal="); if (internalIndex !== -1) { const internalError = errorText.substring(internalIndex + 9); toast.error(internalError); } } else { toast.error(error.response.data.message); } } if (confirmCallback) { confirmCallback(); } destroy(); }; return ( <>

{t("setting.storage-section.update-local-path")}

{t("setting.storage-section.update-local-path-description")}

e.g. {"assets/{timestamp}_{filename}"}
setPath(e.target.value)} />
); }; function showUpdateLocalStorageDialog(localStoragePath?: string, confirmCallback?: () => void) { generateDialog( { className: "update-local-storage-dialog", dialogName: "update-local-storage-dialog", }, UpdateLocalStorageDialog, { localStoragePath, confirmCallback }, ); } export default showUpdateLocalStorageDialog;