import { type } from "arktype"; import { Split } from "lucide-react"; import Button from "~/components/button"; import Chip from "~/components/chip"; import Dialog, { DialogPanel } from "~/components/dialog"; import Input from "~/components/input"; import Switch from "~/components/switch"; import Text from "~/components/text"; import Title from "~/components/title"; import Tooltip from "~/components/tooltip"; import { useForm } from "~/hooks/use-form"; import cn from "~/utils/cn"; const nsSchema = type({ ns: "string.ip", split_name: "string > 0", }); interface Props { nameservers: Record; } export default function AddNameserver({ nameservers }: Props) { const form = useForm({ schema: nsSchema, defaultValues: { split_name: "global" }, validate: (values) => { const ns = values.ns as string; const domain = values.split_name as string; if (!ns) return undefined; const isSplit = domain !== "global"; const isDuplicate = isSplit ? nameservers[domain]?.includes(ns) : Object.values(nameservers).some((nsList) => nsList.includes(ns)); if (isDuplicate) { return { ns: "This nameserver already exists." }; } return undefined; }, }); const split = (form.values.split_name as string) !== "global"; return ( Add nameserver
Restrict to domain } text="Split DNS" />
This nameserver will only be used for some domains.
{ form.setValue("split_name", checked ? "" : "global"); }} />
{split ? ( <> Domain Only single-label or fully-qualified queries matching this suffix should use the nameserver. ) : ( )}
); }