import { type } from "arktype"; import Button from "~/components/button"; import Code from "~/components/code"; import Dialog, { DialogPanel } from "~/components/dialog"; import Input from "~/components/input"; import Select from "~/components/select"; import Text from "~/components/text"; import Title from "~/components/title"; import { useForm } from "~/hooks/use-form"; const recordSchema = type({ record_type: "'A' | 'AAAA'", record_name: "string > 0", record_value: "string > 0", }); interface Props { records: { name: string; type: "A" | "AAAA" | string; value: string }[]; } export default function AddRecord({ records }: Props) { const form = useForm({ schema: recordSchema, defaultValues: { record_type: "A" }, validate: (values) => { const name = values.record_name as string; const ip = values.record_value as string; if (name.length === 0 || ip.length === 0) return undefined; const lookup = records.find((r) => r.name === name); if (lookup?.value === ip) { return { record_name: "This record already exists.", record_value: "This record already exists.", }; } return undefined; }, }); const name = form.values.record_name as string; const ip = form.values.record_value as string; const recordType = form.values.record_type as string; const isDuplicate = !!form.errors.record_name?.includes("already exists") && !!form.errors.record_value?.includes("already exists"); return ( form.reset()}> Add DNS record Enter the domain and IP address for the new DNS record.
{isDuplicate ? (

A record with the domain name {name} and IP address {ip}{" "} already exists.

) : undefined}
); }