import { useMutation, useSuspenseQuery } from "@tanstack/react-query"; import { HardDrive, Check, Save } from "lucide-react"; import { useId, useState } from "react"; import { toast } from "sonner"; import { getVolumeOptions, updateVolumeMutation } from "~/client/api-client/@tanstack/react-query.gen"; import { type UpdateVolumeResponse } from "~/client/api-client/types.gen"; import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, } from "~/client/components/ui/alert-dialog"; import { Alert, AlertDescription } from "~/client/components/ui/alert"; import { Button } from "~/client/components/ui/button"; import { Card, CardContent, CardHeader, CardTitle } from "~/client/components/ui/card"; import { parseError } from "~/client/lib/errors"; import { useNavigate } from "@tanstack/react-router"; import { ManagedBadge } from "~/client/components/managed-badge"; import { CreateVolumeForm, formSchema, type FormValues } from "../components/create-volume-form"; export function EditVolumePage({ volumeId }: { volumeId: string }) { const navigate = useNavigate(); const formId = useId(); const [open, setOpen] = useState(false); const [pendingValues, setPendingValues] = useState(null); const { data } = useSuspenseQuery({ ...getVolumeOptions({ path: { shortId: volumeId } }), }); const { volume } = data; const updateVolume = useMutation({ ...updateVolumeMutation(), onSuccess: (updatedVolume: UpdateVolumeResponse) => { toast.success("Volume updated successfully"); setOpen(false); setPendingValues(null); void navigate({ to: `/volumes/${updatedVolume.shortId}` }); }, onError: (error) => { toast.error("Failed to update volume", { description: parseError(error)?.message, }); setOpen(false); setPendingValues(null); }, }); const handleSubmit = (values: FormValues) => { setPendingValues(values); setOpen(true); }; const confirmUpdate = () => { if (!pendingValues) { return; } const { name, ...config } = formSchema.parse(pendingValues); updateVolume.mutate({ path: { shortId: volume.shortId }, body: { name, config }, }); }; return ( <>
Edit Volume {volume.provisioningId && }
{updateVolume.isError && ( Failed to update volume:
{parseError(updateVolume.error)?.message}
)}
Update Volume Configuration Editing the volume will remount it with the new config immediately. This may temporarily disrupt access to the volume. Continue? Cancel Update ); }