import { Button, Divider, Dropdown, IconButton, List, ListItem, Menu, MenuButton, MenuItem, Radio, RadioGroup } from "@mui/joy"; import { useEffect, useState } from "react"; import { toast } from "react-hot-toast"; import { Link } from "react-router-dom"; import * as api from "@/helpers/api"; import { useGlobalStore } from "@/store/module"; import { useTranslate } from "@/utils/i18n"; import showCreateStorageServiceDialog from "../CreateStorageServiceDialog"; import { showCommonDialog } from "../Dialog/CommonDialog"; import Icon from "../Icon"; import LearnMore from "../LearnMore"; import showUpdateLocalStorageDialog from "../UpdateLocalStorageDialog"; const StorageSection = () => { const t = useTranslate(); const globalStore = useGlobalStore(); const systemStatus = globalStore.state.systemStatus; const [storageServiceId, setStorageServiceId] = useState(systemStatus.storageServiceId); const [storageList, setStorageList] = useState([]); useEffect(() => { fetchStorageList(); }, []); const fetchStorageList = async () => { const { data: storageList } = await api.getStorageList(); setStorageList(storageList); }; const handleActiveStorageServiceChanged = async (storageId: StorageId) => { await api.upsertSystemSetting({ name: "storage-service-id", value: JSON.stringify(storageId), }); try { await globalStore.fetchSystemStatus(); } catch (error: any) { console.error(error); } setStorageServiceId(storageId); }; const handleDeleteStorage = (storage: ObjectStorage) => { showCommonDialog({ title: t("setting.storage-section.delete-storage"), content: t("setting.storage-section.warning-text", { name: storage.name }), style: "danger", dialogName: "delete-storage-dialog", onConfirm: async () => { try { await api.deleteStorage(storage.id); } catch (error: any) { console.error(error); toast.error(error.response.data.message); } await fetchStorageList(); }, }); }; return (
{t("setting.storage-section.current-storage")}
{ handleActiveStorageServiceChanged(Number(event.target.value)); }} >
showUpdateLocalStorageDialog(systemStatus.localStoragePath)}>
{storageList.map((storage) => ( ))}
{t("setting.storage-section.storage-services")}
{storageList.map((storage) => (

{storage.name}

showCreateStorageServiceDialog(storage, fetchStorageList)}>{t("common.edit")} handleDeleteStorage(storage)}>{t("common.delete")}
))} {storageList.length === 0 && (

No storage service found.

)}

{t("common.learn-more")}:

Docs - Local storage Choosing a Storage for Your Resource: Database, S3 or Local Storage?
); }; export default StorageSection;