Skip to main content

useContractorDetailsForm

useContractorDetailsForm(input: UseContractorDetailsFormProps): HookLoadingResult | UseContractorDetailsFormReady

Headless hook for creating or updating a contractor's profile details — individual vs. business type, wage type, names, SSN/EIN, work state, and the self-onboarding preference.

Remarks

Returns a discriminated union: a loading variant while the contractor fetch resolves, and a ready variant exposing the form's data, pending status, submit action, error handling, and bound Fields. Field visibility is driven by the current type and wageType (self-onboarding only toggles the Email field); fields that do not apply are undefined on form.Fields. SSN/EIN are exposed by contractor type regardless of self-onboarding — each consumer decides whether to render them. Self-onboarding is only toggleable when the contractor's onboarding status allows it.

Example

Example
import {
useContractorDetailsForm,
SDKFormProvider,
type UseContractorDetailsFormReady,
} from '@gusto/embedded-react-sdk'

function ContractorDetailsPage({
companyId,
contractorId,
}: {
companyId: string
contractorId: string
}) {
const contractorDetails = useContractorDetailsForm({ companyId, contractorId })

if (contractorDetails.isLoading) return <div>Loading...</div>

return <ContractorDetailsReady contractorDetails={contractorDetails} />
}

function ContractorDetailsReady({
contractorDetails,
}: {
contractorDetails: UseContractorDetailsFormReady
}) {
const { Fields } = contractorDetails.form

return (
<SDKFormProvider formHookResult={contractorDetails}>
<form onSubmit={e => { e.preventDefault(); void contractorDetails.actions.onSubmit() }}>
<Fields.Type label="Contractor type" />
<Fields.WageType label="Wage type" />
{Fields.FirstName && <Fields.FirstName label="First name" />}
{Fields.LastName && <Fields.LastName label="Last name" />}
{Fields.BusinessName && <Fields.BusinessName label="Business name" />}
<Fields.StartDate label="Start date" />
<button type="submit" disabled={contractorDetails.status.isPending}>Save</button>
</form>
</SDKFormProvider>
)
}

Props

UseContractorDetailsFormProps

Options for useContractorDetailsForm.

Remarks

Discriminated by mode: in create mode supply companyId and omit contractorId; in update mode supply contractorId (and optionally companyId).

Shared options — apply to every variant.

PropertyTypeDescription
defaultValues?Partial<ContractorDetailsFormData>Initial values applied before any contractor data loads.
optionalFieldsToRequire?ContractorDetailsOptionalFieldsToRequireFields that are optional by default but should be promoted to required for this form instance.
shouldFocusError?booleanWhether react-hook-form should focus the first error on validation failure. Defaults to true.
validationMode?UseFormProps["mode"]When validation runs. Forwarded to react-hook-form's mode. Defaults to 'onSubmit'.
withSelfOnboardingField?booleanWhether to expose the self-onboarding toggle as form.Fields.SelfOnboarding. Defaults to true.

Supply the fields for exactly one of the following variants:

Variant 1

PropertyType
companyIdstring
contractorId?never

Variant 2

PropertyType
contractorIdstring
companyId?string

Returns

HookLoadingResult | UseContractorDetailsFormReady

A HookLoadingResult while loading, or a UseContractorDetailsFormReady once ready.

UseContractorDetailsFormResult

UseContractorDetailsFormResult = HookLoadingResult | UseContractorDetailsFormReady

Return type of useContractorDetailsForm.


UseContractorDetailsFormReady

The ready-state result returned by useContractorDetailsForm once data has loaded.

PropertyTypeDescription
actionsobjectSubmit and related actions.
actions.onSubmit(options?: ContractorDetailsSubmitOptions) => Promise<HookSubmitResult<Contractor> | undefined>Validates the form and submits the changes. Returns the created or updated contractor, or undefined when validation fails.
dataobjectThe loaded contractor data, or null in create mode.
data.contractorContractor | nullThe contractor being edited, or null in create mode.
errorHandlingHookErrorHandlingError state and recovery actions.
formobjectForm bindings: pre-bound field components, per-field metadata, submission values, and react-hook-form internals.
form.FieldsContractorDetailsFormFields-
form.fieldsMetadataContractorDetailsFieldsMetadata-
form.getFormSubmissionValues() => ContractorDetailsFormData | undefined-
form.hookFormInternalsHookFormInternals<ContractorDetailsFormData>-
isLoadingfalseAlways false in this branch; discriminates from HookLoadingResult.
statusobjectSubmit status and form mode.
status.isPendingbooleantrue while the create or update mutation is in flight.
status.mode"create" | "update"'create' when no contractorId was supplied, 'update' otherwise.

Fields

ContractorDetailsFormFields

The Field components exposed by useContractorDetailsForm as form.Fields.

Remarks

Conditionally-visible fields are undefined when they do not apply to the current type, wageType, or self-onboarding selection. Always null-check before rendering.

PropertyTypeDescription
StartDateComponentType<StartDateFieldProps>Date picker bound to startDate. Always available.
TypeComponentType<TypeFieldProps>Radio group bound to type. Always available.
WageTypeComponentType<WageTypeFieldProps>Radio group bound to wageType. Always available.
BusinessNameComponentType<BusinessNameFieldProps> | undefinedText input bound to businessName; available only for business contractors.
EinComponentType<EinFieldProps> | undefinedText input bound to ein; available only for business contractors. Auto-formats as XX-XXXXXXX. When an EIN is already on file the field shows a masked placeholder and the required rule is waived.
EmailComponentType<EmailFieldProps> | undefinedText input bound to email; available only when self-onboarding is enabled.
FileNewHireReportComponentType<FileNewHireReportFieldProps> | undefinedSwitch bound to fileNewHireReport; available only for individual contractors.
FirstNameComponentType<FirstNameFieldProps> | undefinedText input bound to firstName; available only for individual contractors.
HourlyRateComponentType<HourlyRateFieldProps> | undefinedNumber input bound to hourlyRate; available only when wageType is Hourly.
LastNameComponentType<LastNameFieldProps> | undefinedText input bound to lastName; available only for individual contractors.
MiddleInitialComponentType<MiddleInitialFieldProps> | undefinedText input bound to middleInitial; available only for individual contractors.
SelfOnboardingComponentType<SelfOnboardingFieldProps> | undefinedSwitch bound to selfOnboarding; available only when toggleable.
SsnComponentType<SsnFieldProps> | undefinedText input bound to ssn; available only for individual contractors. Auto-formats as XXX-XX-XXXX. When an SSN is already on file the field shows a masked placeholder and the required rule is waived.
WorkStateComponentType<WorkStateFieldProps> | undefinedSelect bound to workState; available only for individual contractors filing a new-hire report.

BusinessName

Text input bound to businessName; available only for business contractors.

{form.Fields.BusinessName && (
<form.Fields.BusinessName
label="Business name"
validationMessages={{ REQUIRED: '…' }}
/>
)}

ContractorBusinessNameFieldProps

HookFieldProps<TextInputHookFieldProps<ContractorDetailsRequiredValidation>>

Props accepted by useContractorDetailsForm's Fields.BusinessName component.

PropertyTypeDescription
labelstringVisible label rendered above the field.
FieldComponent?ComponentType<TextInputProps>Replaces the default text input UI component; must accept the same props as TextInputProps.
validationMessages?ValidationMessages<ContractorDetailsRequiredValidation>Custom error text keyed by validation error code.

Also accepts description, formHookResult, placeholder, transform from TextInputHookFieldProps.


Ein

Text input bound to ein; available only for business contractors. Auto-formats as XX-XXXXXXX. When an EIN is already on file the field shows a masked placeholder and the required rule is waived.

{form.Fields.Ein && (
<form.Fields.Ein
label="Ein"
validationMessages={{ INVALID_EIN: '…', REQUIRED: '…' }}
/>
)}

ContractorEinFieldProps

HookFieldProps<TextInputHookFieldProps<ContractorDetailsEinValidation, ContractorDetailsEinRequiredValidation>>

Props accepted by useContractorDetailsForm's Fields.Ein component.

PropertyTypeDescription
labelstringVisible label rendered above the field.
FieldComponent?ComponentType<TextInputProps>Replaces the default text input UI component; must accept the same props as TextInputProps.
validationMessages?ValidationMessages<ContractorDetailsEinValidation, ContractorDetailsEinRequiredValidation>Custom error text keyed by validation error code.

Also accepts description, formHookResult, placeholder, transform from TextInputHookFieldProps.


Email

Text input bound to email; available only when self-onboarding is enabled.

{form.Fields.Email && (
<form.Fields.Email
label="Email"
validationMessages={{ REQUIRED: '…', INVALID_EMAIL: '…' }}
/>
)}

ContractorEmailFieldProps

HookFieldProps<TextInputHookFieldProps<ContractorDetailsEmailValidation>>

Props accepted by useContractorDetailsForm's Fields.Email component.

PropertyTypeDescription
labelstringVisible label rendered above the field.
FieldComponent?ComponentType<TextInputProps>Replaces the default text input UI component; must accept the same props as TextInputProps.
validationMessages?ValidationMessages<ContractorDetailsEmailValidation>Custom error text keyed by validation error code.

Also accepts description, formHookResult, placeholder, transform from TextInputHookFieldProps.


FileNewHireReport

Switch bound to fileNewHireReport; available only for individual contractors.

{form.Fields.FileNewHireReport && (
<form.Fields.FileNewHireReport label="File new hire report" />
)}

ContractorFileNewHireReportFieldProps

HookFieldProps<SwitchHookFieldProps>

Props accepted by useContractorDetailsForm's Fields.FileNewHireReport component.

PropertyTypeDescription
labelstringVisible label rendered above the field.
FieldComponent?ComponentType<SwitchProps>Replaces the default toggle switch UI component; must accept the same props as SwitchProps.

Also accepts description, formHookResult from SwitchHookFieldProps.


FirstName

Text input bound to firstName; available only for individual contractors.

{form.Fields.FirstName && (
<form.Fields.FirstName
label="First name"
validationMessages={{ REQUIRED: '…', INVALID_NAME: '…' }}
/>
)}

ContractorFirstNameFieldProps

HookFieldProps<TextInputHookFieldProps<ContractorDetailsNameValidation>>

Props accepted by useContractorDetailsForm's Fields.FirstName component.

PropertyTypeDescription
labelstringVisible label rendered above the field.
FieldComponent?ComponentType<TextInputProps>Replaces the default text input UI component; must accept the same props as TextInputProps.
validationMessages?ValidationMessages<ContractorDetailsNameValidation>Custom error text keyed by validation error code.

Also accepts description, formHookResult, placeholder, transform from TextInputHookFieldProps.


HourlyRate

Number input bound to hourlyRate; available only when wageType is Hourly.

{form.Fields.HourlyRate && (
<form.Fields.HourlyRate
label="Hourly rate"
validationMessages={{ REQUIRED: '…' }}
/>
)}

ContractorHourlyRateFieldProps

HookFieldProps<NumberInputHookFieldProps<ContractorDetailsRequiredValidation>>

Props accepted by useContractorDetailsForm's Fields.HourlyRate component.

PropertyTypeDescription
labelstringVisible label rendered above the field.
FieldComponent?ComponentType<NumberInputProps>Replaces the default number input UI component; must accept the same props as NumberInputProps.
validationMessages?ValidationMessages<ContractorDetailsRequiredValidation>Custom error text keyed by validation error code.

Also accepts description, format, formHookResult, max, min, placeholder from NumberInputHookFieldProps.


LastName

Text input bound to lastName; available only for individual contractors.

{form.Fields.LastName && (
<form.Fields.LastName
label="Last name"
validationMessages={{ REQUIRED: '…', INVALID_NAME: '…' }}
/>
)}

ContractorLastNameFieldProps

HookFieldProps<TextInputHookFieldProps<ContractorDetailsNameValidation>>

Props accepted by useContractorDetailsForm's Fields.LastName component.

PropertyTypeDescription
labelstringVisible label rendered above the field.
FieldComponent?ComponentType<TextInputProps>Replaces the default text input UI component; must accept the same props as TextInputProps.
validationMessages?ValidationMessages<ContractorDetailsNameValidation>Custom error text keyed by validation error code.

Also accepts description, formHookResult, placeholder, transform from TextInputHookFieldProps.


MiddleInitial

Text input bound to middleInitial; available only for individual contractors.

{form.Fields.MiddleInitial && (
<form.Fields.MiddleInitial
label="Middle initial"
validationMessages={{ REQUIRED: '…' }}
/>
)}

ContractorMiddleInitialFieldProps

HookFieldProps<TextInputHookFieldProps<ContractorDetailsRequiredValidation>>

Props accepted by useContractorDetailsForm's Fields.MiddleInitial component.

PropertyTypeDescription
labelstringVisible label rendered above the field.
FieldComponent?ComponentType<TextInputProps>Replaces the default text input UI component; must accept the same props as TextInputProps.
validationMessages?ValidationMessages<ContractorDetailsRequiredValidation>Custom error text keyed by validation error code.

Also accepts description, formHookResult, placeholder, transform from TextInputHookFieldProps.


SelfOnboarding

Switch bound to selfOnboarding; available only when toggleable.

{form.Fields.SelfOnboarding && (
<form.Fields.SelfOnboarding label="Self onboarding" />
)}

ContractorSelfOnboardingFieldProps

HookFieldProps<SwitchHookFieldProps>

Props accepted by useContractorDetailsForm's Fields.SelfOnboarding component.

PropertyTypeDescription
labelstringVisible label rendered above the field.
FieldComponent?ComponentType<SwitchProps>Replaces the default toggle switch UI component; must accept the same props as SwitchProps.

Also accepts description, formHookResult from SwitchHookFieldProps.


Ssn

Text input bound to ssn; available only for individual contractors. Auto-formats as XXX-XX-XXXX. When an SSN is already on file the field shows a masked placeholder and the required rule is waived.

{form.Fields.Ssn && (
<form.Fields.Ssn
label="Ssn"
validationMessages={{ INVALID_SSN: '…', REQUIRED: '…' }}
/>
)}

ContractorSsnFieldProps

HookFieldProps<TextInputHookFieldProps<ContractorDetailsSsnValidation, ContractorDetailsSsnRequiredValidation>>

Props accepted by useContractorDetailsForm's Fields.Ssn component.

PropertyTypeDescription
labelstringVisible label rendered above the field.
FieldComponent?ComponentType<TextInputProps>Replaces the default text input UI component; must accept the same props as TextInputProps.
validationMessages?ValidationMessages<ContractorDetailsSsnValidation, ContractorDetailsSsnRequiredValidation>Custom error text keyed by validation error code.

Also accepts description, formHookResult, placeholder, transform from TextInputHookFieldProps.


StartDate

Date picker bound to startDate. Always available.

<form.Fields.StartDate
label="Start date"
validationMessages={{ REQUIRED: '…' }}
/>

ContractorStartDateFieldProps

HookFieldProps<DatePickerHookFieldProps<ContractorDetailsRequiredValidation>>

Props accepted by useContractorDetailsForm's Fields.StartDate component.

PropertyTypeDescription
labelstringVisible label rendered above the field.
FieldComponent?ComponentType<DatePickerProps>Replaces the default date picker UI component; must accept the same props as DatePickerProps.
validationMessages?ValidationMessages<ContractorDetailsRequiredValidation>Custom error text keyed by validation error code.

Also accepts description, formHookResult, maxDate, minDate, portalContainer from DatePickerHookFieldProps.


Type

Radio group bound to type. Always available.

<form.Fields.Type label="Type" />

ContractorTypeFieldProps

HookFieldProps<RadioGroupHookFieldProps<never, ContractorDetailsFormData["type"]>>

Props accepted by useContractorDetailsForm's Fields.Type component.

PropertyTypeDescription
labelstringVisible label rendered above the field.
FieldComponent?ComponentType<RadioGroupProps>Replaces the default radio group UI component; must accept the same props as RadioGroupProps.
getOptionLabel?(entry: ContractorDetailsFormData["type"]) => stringMaps a raw option entry to its display label; when omitted, options use the labels provided by the hook.

Also accepts description, formHookResult from RadioGroupHookFieldProps.


WageType

Radio group bound to wageType. Always available.

<form.Fields.WageType label="Wage type" />

ContractorWageTypeFieldProps

HookFieldProps<RadioGroupHookFieldProps<never, ContractorDetailsFormData["wageType"]>>

Props accepted by useContractorDetailsForm's Fields.WageType component.

PropertyTypeDescription
labelstringVisible label rendered above the field.
FieldComponent?ComponentType<RadioGroupProps>Replaces the default radio group UI component; must accept the same props as RadioGroupProps.
getOptionLabel?(entry: ContractorDetailsFormData["wageType"]) => stringMaps a raw option entry to its display label; when omitted, options use the labels provided by the hook.

Also accepts description, formHookResult from RadioGroupHookFieldProps.


WorkState

Select bound to workState; available only for individual contractors filing a new-hire report.

{form.Fields.WorkState && (
<form.Fields.WorkState
label="Work state"
validationMessages={{ REQUIRED: '…' }}
/>
)}

ContractorWorkStateFieldProps

HookFieldProps<SelectHookFieldProps<ContractorDetailsRequiredValidation, string>>

Props accepted by useContractorDetailsForm's Fields.WorkState component.

PropertyTypeDescription
labelstringVisible label rendered above the field.
placeholderstringPlaceholder 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) => stringMaps a raw option entry to its display label; when omitted, options use the labels provided by the hook.
validationMessages?ValidationMessages<ContractorDetailsRequiredValidation>Custom error text keyed by validation error code.

Also accepts description, formHookResult, portalContainer from SelectHookFieldProps.

Validations

ContractorDetailsEinRequiredValidation

ContractorDetailsEinRequiredValidation = "REQUIRED"

Required-field error code emitted by the ein field of useContractorDetailsForm.


ContractorDetailsEinValidation

ContractorDetailsEinValidation = "INVALID_EIN"

Format-validation error code emitted by the ein field of useContractorDetailsForm.


ContractorDetailsEmailValidation

ContractorDetailsEmailValidation = "REQUIRED" | "INVALID_EMAIL"

Validation error codes emitted by the email field of useContractorDetailsForm.


ContractorDetailsNameValidation

ContractorDetailsNameValidation = "REQUIRED" | "INVALID_NAME"

Validation error codes emitted by the name fields of useContractorDetailsForm.


ContractorDetailsRequiredValidation

ContractorDetailsRequiredValidation = "REQUIRED"

Error code emitted by fields of useContractorDetailsForm that only produce REQUIRED.


ContractorDetailsSsnRequiredValidation

ContractorDetailsSsnRequiredValidation = "REQUIRED"

Required-field error code emitted by the ssn field of useContractorDetailsForm.


ContractorDetailsSsnValidation

ContractorDetailsSsnValidation = "INVALID_SSN"

Format-validation error code emitted by the ssn field of useContractorDetailsForm.

Utility types

ContractorDetailsErrorCode

ContractorDetailsErrorCode = "REQUIRED" | "INVALID_NAME" | "INVALID_EMAIL" | "INVALID_SSN" | "INVALID_EIN"

Union of validation error code strings emitted by the contractor details form schema.


ContractorDetailsErrorCodes

const ContractorDetailsErrorCodes: object

Validation error codes emitted by the contractor details form schema. Map these codes to localized copy in validationMessages when composing the hook.

Type Declaration

NameType
INVALID_EIN"INVALID_EIN"
INVALID_EMAIL"INVALID_EMAIL"
INVALID_NAME"INVALID_NAME"
INVALID_SSN"INVALID_SSN"
REQUIRED"REQUIRED"

ContractorDetailsFieldsMetadata

FieldType
businessNameFieldMetadata
einFieldMetadata
emailFieldMetadata
fileNewHireReportFieldMetadata
firstNameFieldMetadata
hourlyRateFieldMetadata
lastNameFieldMetadata
middleInitialFieldMetadata
selfOnboardingFieldMetadata
ssnFieldMetadata
startDateFieldMetadata
typeFieldMetadataWithOptions<"Business" | "Individual">
wageTypeFieldMetadataWithOptions<"Fixed" | "Hourly">
workStateFieldMetadataWithOptions<"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">

Shape of form.fieldsMetadata returned by useContractorDetailsForm.


ContractorDetailsFormData

Shape of the values managed by the contractor details form.

Properties

PropertyType
businessNamestring
einstring
emailstring
fileNewHireReportboolean
firstNamestring
hourlyRatenumber
lastNamestring
middleInitialstring
selfOnboardingboolean
ssnstring
startDatestring
type"Business" | "Individual"
wageType"Fixed" | "Hourly"
workStatestring

ContractorDetailsOptionalFieldsToRequire

ContractorDetailsOptionalFieldsToRequire = OptionalFieldsToRequire<typeof requiredFieldsConfig>

Keys of optional contractor details fields that can be promoted to required via the hook's optionalFieldsToRequire option.


ContractorDetailsSubmitOptions

Optional overrides passed to onSubmit.

Properties

PropertyTypeDescription
companyId?stringOverride the company identifier supplied to the hook (e.g. after creating the company in the same flow). Only used in create mode.

ContractorType

const ContractorType: object = ApiContractorType

Contractor type enum (Individual / Business) re-exported from the API model.

Type Declaration

NameType
Business"Business"
Individual"Individual"

WageType

const WageType: object = ApiWageType

Contractor wage type enum (Fixed / Hourly) re-exported from the API model.

Type Declaration

NameType
Fixed"Fixed"
Hourly"Hourly"

Endpoints