useContractorAddressForm
useContractorAddressForm(
props:UseContractorAddressFormProps):HookLoadingResult|UseContractorAddressFormReady
Form hook for editing a contractor's address.
Remarks
A contractor always has exactly one address (created with the contractor),
so this hook operates only in update mode and issues a PUT on submit. The
same address is labelled a "home" address for Individual contractors and a
"business" address for Business contractors; the hook exposes contractorType
so the consuming component can choose the appropriate copy.
Example
import {
useContractorAddressForm,
SDKFormProvider,
type UseContractorAddressFormReady,
} from '@gusto/embedded-react-sdk'
function ContractorAddressPage({ contractorId }: { contractorId: string }) {
const contractorAddress = useContractorAddressForm({ contractorId })
if (contractorAddress.isLoading) return <div>Loading...</div>
return <ContractorAddressReady contractorAddress={contractorAddress} />
}
function ContractorAddressReady({
contractorAddress,
}: {
contractorAddress: UseContractorAddressFormReady
}) {
const { Fields } = contractorAddress.form
return (
<SDKFormProvider formHookResult={contractorAddress}>
<form onSubmit={e => { e.preventDefault(); void contractorAddress.actions.onSubmit() }}>
<Fields.Street1 label="Street address" />
<Fields.Street2 label="Apt, suite, etc. (optional)" />
<Fields.City label="City" />
<Fields.State label="State" />
<Fields.Zip label="ZIP code" />
<button type="submit" disabled={contractorAddress.status.isPending}>Save</button>
</form>
</SDKFormProvider>
)
}
Props
UseContractorAddressFormProps
Configuration options for useContractorAddressForm.
| Property | Type | Description |
|---|---|---|
contractorId | string | UUID of the contractor whose address is being edited. |
defaultValues? | Partial<ContractorAddressFormData> | Pre-fill form values. Server data takes precedence. |
optionalFieldsToRequire? | ContractorAddressOptionalFieldsToRequire | Override fields that are optional by default to be required. See ContractorAddressOptionalFieldsToRequire. |
shouldFocusError? | boolean | Auto-focus the first invalid field on submit. Set to false when using composeSubmitHandler so submit-time focus is coordinated across multiple forms. Defaults to true. |
validationMode? | "onChange" | "onBlur" | "onSubmit" | "onTouched" | "all" | Passed through to react-hook-form. Defaults to 'onSubmit'. |
Returns
HookLoadingResult | UseContractorAddressFormReady
A HookLoadingResult while loading, or a UseContractorAddressFormReady once ready.
UseContractorAddressFormResult
UseContractorAddressFormResult =
HookLoadingResult|UseContractorAddressFormReady
Discriminated union returned by useContractorAddressForm.
UseContractorAddressFormReady
Ready-state shape returned by useContractorAddressForm once data has loaded.
Remarks
Discriminated by isLoading: false. Extends BaseFormHookReady with
the contractor-address-specific data, status, actions, and form.Fields shape.
| Property | Type | Description |
|---|---|---|
actions | object | Available actions. |
actions.onSubmit | (options?: ContractorAddressSubmitOptions) => Promise<HookSubmitResult<ContractorAddress> | undefined> | - |
data | object | Static entity data resolved from the API. |
data.contractor | Contractor | The full contractor entity loaded alongside the address. |
data.contractorAddress | ContractorAddress | The contractor address row loaded for update. |
data.contractorType | ContractorType | undefined | The contractor's type — drives whether the address is labelled "home" (Individual) or "business" (Business). |
errorHandling | HookErrorHandling | Error state and recovery actions. |
form | object | Form bindings: pre-bound field components, per-field metadata, submission values, and react-hook-form internals. |
form.Fields | ContractorAddressFormFields | - |
form.fieldsMetadata | ContractorAddressFieldsMetadata | - |
form.getFormSubmissionValues | () => ContractorAddressFormData | undefined | - |
form.hookFormInternals | HookFormInternals<ContractorAddressFormData> | - |
isLoading | false | Always false in this branch; discriminates from HookLoadingResult. |
status | object | Reactive status flags. |
status.isPending | boolean | - |
status.mode | "update" | - |
Fields
ContractorAddressFormFields
Field components exposed by useContractorAddressForm on form.Fields.
| Property | Type | Description |
|---|---|---|
City | ComponentType<CityFieldProps> | Bound to city. Text input for the city. Required. |
State | ComponentType<StateFieldProps> | Bound to state. Select whose options are the standard two-letter US state abbreviations. Supply getOptionLabel to localize the option labels. Required. |
Street1 | ComponentType<Street1FieldProps> | Bound to street1. Text input for the first street address line. Required. |
Street2 | ComponentType<Street2FieldProps> | Bound to street2. Text input for the second street address line. Optional. |
Zip | ComponentType<ZipFieldProps> | Bound to zip. Text input for the ZIP code. Required; also validates ZIP format and emits INVALID_ZIP when the value does not match. |
City
Bound to city. Text input for the city. Required.
<form.Fields.City
label="City"
validationMessages={{ REQUIRED: '…' }}
/>
ContractorAddressCityFieldProps
HookFieldProps<TextInputHookFieldProps<ContractorAddressRequiredValidation>>
Props accepted by useContractorAddressForm's Fields.City component.
| Property | Type | Description |
|---|---|---|
label | string | Visible label rendered above the field. |
FieldComponent? | ComponentType<TextInputProps> | Replaces the default text input UI component; must accept the same props as TextInputProps. |
validationMessages? | ValidationMessages<ContractorAddressRequiredValidation> | Custom error text keyed by validation error code. |
Also accepts description, formHookResult, placeholder, transform from TextInputHookFieldProps.
State
Bound to state. Select whose options are the standard two-letter US state
abbreviations. Supply getOptionLabel to localize the option labels. Required.
<form.Fields.State
label="State"
validationMessages={{ REQUIRED: '…' }}
/>
ContractorAddressStateFieldProps
HookFieldProps<SelectHookFieldProps<ContractorAddressRequiredValidation,string>>
Props accepted by useContractorAddressForm's Fields.State component.
| Property | Type | Description |
|---|---|---|
label | string | Visible label rendered above the field. |
placeholder | string | Placeholder text displayed when no option is selected. Required so empty dropdowns always communicate the action — pass an empty string only when a default value is guaranteed. |
FieldComponent? | ComponentType<SelectProps> | Replaces the default select UI component; must accept the same props as SelectProps. |
getOptionLabel? | (entry: string) => string | Maps a raw option entry to its display label; when omitted, options use the labels provided by the hook. |
validationMessages? | ValidationMessages<ContractorAddressRequiredValidation> | Custom error text keyed by validation error code. |
Also accepts description, formHookResult, portalContainer from SelectHookFieldProps.
Street1
Bound to street1. Text input for the first street address line. Required.
<form.Fields.Street1
label="Street1"
validationMessages={{ REQUIRED: '…' }}
/>
ContractorAddressStreet1FieldProps
HookFieldProps<TextInputHookFieldProps<ContractorAddressRequiredValidation>>
Props accepted by useContractorAddressForm's Fields.Street1 component.
| Property | Type | Description |
|---|---|---|
label | string | Visible label rendered above the field. |
FieldComponent? | ComponentType<TextInputProps> | Replaces the default text input UI component; must accept the same props as TextInputProps. |
validationMessages? | ValidationMessages<ContractorAddressRequiredValidation> | Custom error text keyed by validation error code. |
Also accepts description, formHookResult, placeholder, transform from TextInputHookFieldProps.
Street2
Bound to street2. Text input for the second street address line. Optional.
<form.Fields.Street2
label="Street2"
validationMessages={{ REQUIRED: '…' }}
/>
ContractorAddressStreet2FieldProps
HookFieldProps<TextInputHookFieldProps<ContractorAddressRequiredValidation>>
Props accepted by useContractorAddressForm's Fields.Street2 component.
| Property | Type | Description |
|---|---|---|
label | string | Visible label rendered above the field. |
FieldComponent? | ComponentType<TextInputProps> | Replaces the default text input UI component; must accept the same props as TextInputProps. |
validationMessages? | ValidationMessages<ContractorAddressRequiredValidation> | Custom error text keyed by validation error code. |
Also accepts description, formHookResult, placeholder, transform from TextInputHookFieldProps.
Zip
Bound to zip. Text input for the ZIP code. Required; also validates ZIP
format and emits INVALID_ZIP when the value does not match.
<form.Fields.Zip
label="Zip"
validationMessages={{ REQUIRED: '…', INVALID_ZIP: '…' }}
/>
ContractorAddressZipFieldProps
HookFieldProps<TextInputHookFieldProps<ContractorAddressZipValidation>>
Props accepted by useContractorAddressForm's Fields.Zip component.
| Property | Type | Description |
|---|---|---|
label | string | Visible label rendered above the field. |
FieldComponent? | ComponentType<TextInputProps> | Replaces the default text input UI component; must accept the same props as TextInputProps. |
validationMessages? | ValidationMessages<ContractorAddressZipValidation> | Custom error text keyed by validation error code. |
Also accepts description, formHookResult, placeholder, transform from TextInputHookFieldProps.
Validations
ContractorAddressRequiredValidation
ContractorAddressRequiredValidation =
"REQUIRED"
The required-field error code produced by useContractorAddressForm fields that only emit REQUIRED.
Remarks
Used as the validationMessages key for the street, city, and state fields.
See ContractorAddressErrorCodes.
ContractorAddressZipValidation
ContractorAddressZipValidation =
"REQUIRED"|"INVALID_ZIP"
Validation error codes emitted by the zip field of useContractorAddressForm.
Remarks
Use these as keys in validationMessages on Fields.Zip. See
ContractorAddressErrorCodes.
Utility types
ContractorAddressErrorCode
ContractorAddressErrorCode =
"REQUIRED"|"INVALID_ZIP"
Union of validation error code strings emitted by the contractor address form schema.
ContractorAddressErrorCodes
constContractorAddressErrorCodes:object
Validation error codes emitted by the contractor address form schema. Map
these codes to localized copy in validationMessages when composing the
hook.
Type Declaration
| Name | Type |
|---|---|
INVALID_ZIP | "INVALID_ZIP" |
REQUIRED | "REQUIRED" |
ContractorAddressField
ContractorAddressField =
"street1"|"city"|"state"|"zip"|"street2"
Field names accepted by the contractor address form.
ContractorAddressFieldsMetadata
| Field | Type |
|---|---|
city | FieldMetadata |
state | FieldMetadataWithOptions<"AL" | "AK" | "AZ" | "AR" | "CA" | "CO" | "CT" | "DE" | "DC" | "FL" | "GA" | "HI" | "ID" | "IL" | "IN" | "IA" | "KS" | "KY" | "LA" | "ME" | "MD" | "MA" | "MI" | "MN" | "MS" | "MO" | "MT" | "NE" | "NV" | "NH" | "NJ" | "NM" | "NY" | "NC" | "ND" | "OH" | "OK" | "OR" | "PA" | "RI" | "SC" | "SD" | "TN" | "TX" | "UT" | "VT" | "VA" | "WA" | "WV" | "WI" | "WY"> |
street1 | FieldMetadata |
street2 | FieldMetadata |
zip | FieldMetadata |
Type of form.fieldsMetadata returned by useContractorAddressForm.
ContractorAddressFormData
Shape of the values managed by the contractor address form.
Properties
| Property | Type |
|---|---|
city | string |
state | string |
street1 | string |
street2 | string |
zip | string |
ContractorAddressOptionalFieldsToRequire
ContractorAddressOptionalFieldsToRequire =
OptionalFieldsToRequire<typeofrequiredFieldsConfig>
Keys of optional contractor address fields that can be promoted to required
via the hook's optionalFieldsToRequire option.
ContractorAddressSubmitOptions
Optional overrides passed to onSubmit.
Properties
| Property | Type | Description |
|---|---|---|
contractorId? | string | Override the contractor identifier supplied to the hook. |