'use client' import { useRef, useState, type ReactNode } from 'react' /** * Three-part address entry (street / postal code / city) with Enter * chaining field to field and submitting from the last one. Skippable: * the address is optional in onboarding, exactly like the wizard. */ interface AddressFieldsProps { placeholders: { street: string; postalCode: string; city: string } enterHint: ReactNode skipLabel: string onSubmit: (v: { addressLine1?: string; postalCode?: string; city?: string }) => void } export default function AddressFields({ placeholders, enterHint, skipLabel, onSubmit }: AddressFieldsProps) { const [street, setStreet] = useState('') const [zip, setZip] = useState('') const [city, setCity] = useState('') const zipRef = useRef(null) const cityRef = useRef(null) function submit() { onSubmit({ addressLine1: street.trim() || undefined, postalCode: zip.trim() || undefined, city: city.trim() || undefined, }) } return (
setStreet(e.target.value)} onKeyDown={(e) => e.key === 'Enter' && zipRef.current?.focus()} />
setZip(e.target.value)} onKeyDown={(e) => e.key === 'Enter' && cityRef.current?.focus()} />
setCity(e.target.value)} onKeyDown={(e) => e.key === 'Enter' && submit()} />

{enterHint}

) }