import { useState } from 'react'; import Code from '~/components/Code'; import Dialog from '~/components/Dialog'; import Input from '~/components/Input'; import type { Machine } from '~/types'; interface RenameProps { machine: Machine; isOpen: boolean; magic?: string; setIsOpen: (isOpen: boolean) => void; } export default function Rename({ machine, magic, isOpen, setIsOpen, }: RenameProps) { const [name, setName] = useState(machine.givenName); return ( Edit machine name for {machine.givenName} This name is shown in the admin panel, in Tailscale clients, and used when generating MagicDNS names. { if (value.length === 0) { return 'Cannot be empty'; } // DNS hostname validation if (value.toLowerCase() !== value) { return 'Cannot contain uppercase letters'; } if (value.length > 63) { return 'DNS hostnames cannot be 64+ characters'; } // Test for invalid characters if (!/^[a-z0-9-]+$/.test(value)) { return 'Cannot contain special characters'; } // Test for leading/trailing hyphens if (value.startsWith('-') || value.endsWith('-')) { return 'Cannot start or end with a hyphen'; } // Test for consecutive hyphens if (value.includes('--')) { return 'Cannot contain consecutive hyphens'; } }} /> {magic ? ( name.length > 0 && name !== machine.givenName ? (

This machine will be accessible by the hostname{' '} {name.toLowerCase().replaceAll(/\s+/g, '-')} {'. '} The hostname {machine.givenName}{' '} will no longer point to this machine.

) : (

This machine is accessible by the hostname{' '} {machine.givenName}.

) ) : undefined}
); }