import { useMemo, useState } from "react"; 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"; interface Props { records: { name: string; type: "A" | "AAAA" | string; value: string }[]; } export default function AddRecord({ records }: Props) { const [type, setType] = useState<"A" | "AAAA" | string>("A"); const [name, setName] = useState(""); const [ip, setIp] = useState(""); const isDuplicate = useMemo(() => { if (name.length === 0 || ip.length === 0) return false; const lookup = records.find((record) => record.name === name); if (!lookup) return false; return lookup.value === ip; }, [records, name, ip]); return ( { setName(""); setIp(""); }} > 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}
); }