import { useMutation } from "@tanstack/react-query"; import { HardDrive, Plus } from "lucide-react"; import { useId } from "react"; import { useNavigate } from "react-router"; import { toast } from "sonner"; import { createVolumeMutation } from "~/client/api-client/@tanstack/react-query.gen"; import { CreateVolumeForm, type FormValues } from "~/client/components/create-volume-form"; import { Button } from "~/client/components/ui/button"; import { Card, CardContent, CardHeader, CardTitle } from "~/client/components/ui/card"; import { parseError } from "~/client/lib/errors"; import type { Route } from "./+types/create-volume"; import { Alert, AlertDescription } from "~/client/components/ui/alert"; export const handle = { breadcrumb: () => [{ label: "Volumes", href: "/volumes" }, { label: "Create" }], }; export function meta(_: Route.MetaArgs) { return [ { title: "Zerobyte - Create Volume" }, { name: "description", content: "Create a new storage volume with automatic mounting and health checks.", }, ]; } export default function CreateVolume() { const navigate = useNavigate(); const formId = useId(); const createVolume = useMutation({ ...createVolumeMutation(), onSuccess: (data) => { toast.success("Volume created successfully"); navigate(`/volumes/${data.name}`); }, }); const handleSubmit = (values: FormValues) => { createVolume.mutate({ body: { config: values, name: values.name, }, }); }; return (
Create Volume
{createVolume.isError && ( Failed to create volume:
{parseError(createVolume.error)?.message}
)}
); }