import Icons from "@/components/ui/icons"; import Modal from "@/components/ui/modal"; import { SelectField } from "@/components/ui/select"; import { useZForm, UseZFormReturn } from "@/hooks/useZForm"; import api from "@/lib/api"; import { createDisclosure } from "@/lib/utils"; import { useQuery } from "@tanstack/react-query"; import React from "react"; import { Button, Label, ScrollView, XStack } from "tamagui"; import { FormSchema, formSchema, incusTypes, pveTypes, typeOptions, } from "../schema/form"; import { InputField } from "@/components/ui/input"; import FormField from "@/components/ui/form"; import { useKeychains, useSaveHost } from "../hooks/query"; export const hostFormModal = createDisclosure(); const HostForm = () => { const { data } = hostFormModal.use(); const form = useZForm(formSchema, data); const isEditing = data?.id != null; const type = form.watch("type"); const keys = useKeychains(); const saveMutation = useSaveHost(); const onSubmit = form.handleSubmit((values) => { saveMutation.mutate(values, { onSuccess: () => { hostFormModal.onClose(); form.reset(); }, }); }); return ( {type === "pve" && } {type === "incus" && } ({ label: key.label, value: key.id, }))} /> {type === "ssh" && ( ({ label: key.label, value: key.id, }))} /> )} ); }; type MiscFormFieldProps = { form: UseZFormReturn; }; const PVEFormFields = ({ form }: MiscFormFieldProps) => { return ( <> ); }; const IncusFormFields = ({ form }: MiscFormFieldProps) => { const type = form.watch("metadata.type"); return ( <> {type === "lxc" && ( )} ); }; export default HostForm;