import { useQuery } from "@tanstack/react-query"; import { getStorages } from "../utils/api/storages"; import { Sheet, Table, Button, CircularProgress, Typography, Alert, } from "@mui/joy"; import { useTranslation } from "react-i18next"; import type { Storage } from "../misc/interfaces"; import type { AlertInterface } from "../misc/interfaces"; import type { ApiError } from "../utils/api/apiError"; import { StorageRow } from "../components/StorageRow"; import { useEffect, useState } from "react"; import { AddStorageModal } from "../components/modals/AddStorageModal"; import AddIcon from "@mui/icons-material/Add"; export const Storages = () => { const { t } = useTranslation(); const [modal, setModal] = useState(false); const [alert, setAlert] = useState({ isAlert: false, type: "neutral", header: "", text: "", }); const showError = (error: unknown) => { const errorCode = (error as { code?: string })?.code; setAlert({ isAlert: true, type: "danger", header: t("error"), text: errorCode ? t(errorCode) : t("unknown-error"), }); }; const { data: storages, isLoading, isError: storagesError, error: storagesErrorObj, } = useQuery({ queryKey: ["storages"], queryFn: () => getStorages(), }); useEffect(() => { if (storagesError && storagesErrorObj) { showError(storagesErrorObj); } }, [storagesError, storagesErrorObj]); return ( <>
{t("storages")} {t("storage-delete-info")}
{alert.isAlert && ( {alert.header}
{alert.text}
)}
{isLoading ? (
) : ( <>
{t("storages")}
*:nth-child(n+4)": { textAlign: "left" }, }} > {storages?.map((storage: Storage) => ( ))}
{t("storage-name")} {t("description")} {t("created-at")} {t("updated-at")}
)}
); };