import { useMutation, useQuery } from "@tanstack/react-query"; import { useNavigate, useParams } from "react-router"; import { toast } from "sonner"; import { getVolume } from "~/api-client"; import { deleteVolumeMutation, getVolumeOptions, mountVolumeMutation, unmountVolumeMutation, } from "~/api-client/@tanstack/react-query.gen"; import { CreateVolumeForm } from "~/components/create-volume-form"; import { Button } from "~/components/ui/button"; import { Card } from "~/components/ui/card"; import { VolumeIcon } from "~/components/volume-icon"; import { parseError } from "~/lib/errors"; import { HealthchecksCard } from "~/modules/details/components/healthchecks-card"; import type { Route } from "./+types/details"; import { cn } from "~/lib/utils"; import { StatusDot } from "~/components/status-dot"; import { VolumeInfoTabContent } from "~/modules/details/tabs/info"; import { Tabs, TabsContent, TabsList, TabsTrigger } from "~/components/ui/tabs"; export const clientLoader = async ({ params }: Route.ClientLoaderArgs) => { const volume = await getVolume({ path: { name: params.name ?? "" } }); if (volume.data) return volume.data; }; export default function DetailsPage({ loaderData }: Route.ComponentProps) { const { name } = useParams<{ name: string }>(); const navigate = useNavigate(); const { data } = useQuery({ ...getVolumeOptions({ path: { name: name ?? "" } }), initialData: loaderData, }); const deleteVol = useMutation({ ...deleteVolumeMutation(), onSuccess: () => { toast.success("Volume deleted successfully"); navigate("/"); }, onError: (error) => { toast.error("Failed to delete volume", { description: parseError(error)?.message, }); }, }); const mountVol = useMutation({ ...mountVolumeMutation(), onSuccess: () => { toast.success("Volume mounted successfully"); }, onError: (error) => { toast.error("Failed to mount volume", { description: parseError(error)?.message, }); }, }); const unmountVol = useMutation({ ...unmountVolumeMutation(), onSuccess: () => { toast.success("Volume unmounted successfully"); }, onError: (error) => { toast.error("Failed to unmount volume", { description: parseError(error)?.message, }); }, }); const handleDeleteConfirm = (name: string) => { if (confirm(`Are you sure you want to delete the volume "${name}"? This action cannot be undone.`)) { deleteVol.mutate({ path: { name } }); } }; if (!name) { return
Volume not found
; } if (!data) { return
Loading...
; } return ( <>
{data.status[0].toUpperCase() + data.status.slice(1)}
Configuration Backups Eplorer Change your password here. ); }