import { Form, useSubmit } from '@remix-run/react' import { useMemo, useState } from 'react' import Code from '~/components/Code' import Dialog from '~/components/Dialog' import TextField from '~/components/TextField' import { cn } from '~/utils/cn' interface Props { records: { name: string, type: 'A', value: string }[] } export default function AddDNS({ records }: Props) { const submit = useSubmit() 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 {close => ( <> Add DNS record Enter the domain and IP address for the new DNS record.
{ event.preventDefault() if (!name || !ip) return setName('') setIp('') submit({ 'dns.extra_records': [ ...records, { name, type: 'A', value: ip, }, ], }, { method: 'PATCH', encType: 'application/json', }) close() }} > {isDuplicate ? (

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

) : undefined}
Cancel Add
)}
) }