import { arktypeResolver } from "@hookform/resolvers/arktype"; import { volumeConfigSchema } from "@ironmount/schemas"; import { type } from "arktype"; import { Plus } from "lucide-react"; import { useForm } from "react-hook-form"; import { slugify } from "~/lib/utils"; import { Button } from "./ui/button"; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger, } from "./ui/dialog"; import { Form, FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage } from "./ui/form"; import { Input } from "./ui/input"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "./ui/select"; export const formSchema = type({ name: "2<=string<=32", }).and(volumeConfigSchema); type FormValues = typeof formSchema.infer; type Props = { open: boolean; setOpen: (open: boolean) => void; onSubmit: (values: FormValues) => void; }; export const CreateVolumeDialog = ({ open, setOpen, onSubmit }: Props) => { const form = useForm({ resolver: arktypeResolver(formSchema), defaultValues: { name: "", backend: "directory", }, }); const watchedBackend = form.watch("backend"); return ( Create volume Enter a name for the new volume.
( Name field.onChange(slugify(e.target.value))} max={32} min={1} /> Unique identifier for the volume. )} /> ( Backend Choose the storage backend for this volume. )} /> {watchedBackend === "nfs" && ( <> ( Server NFS server IP address or hostname. )} /> ( Export Path Path to the NFS export on the server. )} /> ( Port field.onChange(parseInt(e.target.value, 10) || undefined)} /> NFS server port (default: 2049). )} /> ( Version NFS protocol version to use. )} /> )} {/* {createVolume.error && ( */} {/*
*/} {/* {createVolume.error.message} */} {/*
*/} {/* )} */}
); };