import { useMemo, useState } from 'react'; import Dialog from '~/components/Dialog'; import Input from '~/components/Input'; interface AddDomainProps { domains: string[]; isDisabled?: boolean; } export default function AddDomain({ domains, isDisabled }: AddDomainProps) { const [domain, setDomain] = useState(''); const isInvalid = useMemo(() => { if (!domain || domain.trim().length === 0) { // Empty domain is invalid, but no error shown return false; } if (domains.includes(domain.trim())) { return true; } try { // Check if domain is a valid FQDN const url = new URL(`http://${domain.trim()}`); return url.hostname !== domain.trim(); } catch (e) { // If URL constructor fails, it's not a valid domain return true; } }, [domain, domains]); return ( Add domain Add domain Add this domain to a list of allowed email domains that can authenticate with Headscale via OIDC. 0 ? `Matches users with @${domain.trim()}` : 'Enter a domain to match users with their email addresses.' } placeholder="example.com" name="domain" onChange={setDomain} isInvalid={domain.trim().length === 0 || isInvalid} /> {isInvalid && (

The domain you entered is invalid or already exists in the list.

)}
); }