import { useMemo, useState } from 'react'; import Code from '~/components/Code'; import Dialog from '~/components/Dialog'; import Input from '~/components/Input'; import Select from '~/components/Select'; interface Props { records: { name: string; type: 'A' | 'AAAA' | string; value: string }[]; } export default function AddRecord({ records }: Props) { 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 ( Add DNS record 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}
); }