/** * External dependencies */ import { __ } from '@wordpress/i18n'; import { SelectControl, TextControl } from '@wordpress/components'; /** * Internal dependencies */ import type { PickupLocation } from '../types'; import { countryStateOptions, states } from '../utils'; const Form = ( { formRef, values, setValues, }: { formRef: React.RefObject< HTMLFormElement >; values: PickupLocation; setValues: React.Dispatch< React.SetStateAction< PickupLocation > >; } ) => { const { country: selectedCountry, state: selectedState } = values.address; const setLocationField = ( field: keyof PickupLocation ) => ( newValue: string | boolean ) => { setValues( ( prevValue: PickupLocation ) => ( { ...prevValue, [ field ]: newValue, } ) ); }; const setLocationAddressField = ( field: keyof PickupLocation[ 'address' ] ) => ( newValue: string | boolean ) => { setValues( ( prevValue ) => ( { ...prevValue, address: { ...prevValue.address, [ field ]: newValue, }, } ) ); }; const countryHasStates = states[ selectedCountry ] && Object.keys( states[ selectedCountry ] ).length > 0; return (
); }; export default Form;