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
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.
| Property | Type | Description |
|---|---|---|
defaultValues? | Partial<ContractorDetailsFormData> | Initial values applied before any contractor data loads. |
optionalFieldsToRequire? | ContractorDetailsOptionalFieldsToRequire | Fields that are optional by default but should be promoted to required for this form instance. |
shouldFocusError? | boolean | Whether 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? | boolean | Whether 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
| Property | Type |
|---|---|
companyId | string |
contractorId? | never |
Variant 2
| Property | Type |
|---|---|
contractorId | string |
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.
| Property | Type | Description |
|---|---|---|
actions | object | Submit 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. |
data | object | The loaded contractor data, or null in create mode. |
data.contractor | Contractor | null | The contractor being edited, or null in create mode. |
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 | ContractorDetailsFormFields | - |
form.fieldsMetadata | ContractorDetailsFieldsMetadata | - |
form.getFormSubmissionValues | () => ContractorDetailsFormData | undefined | - |
form.hookFormInternals | HookFormInternals<ContractorDetailsFormData> | - |
isLoading | false | Always false in this branch; discriminates from HookLoadingResult. |
status | object | Submit status and form mode. |
status.isPending | boolean | true 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.
| Property | Type | Description |
|---|---|---|
StartDate | ComponentType<StartDateFieldProps> | Date picker bound to startDate. Always available. |
Type | ComponentType<TypeFieldProps> | Radio group bound to type. Always available. |
WageType | ComponentType<WageTypeFieldProps> | Radio group bound to wageType. Always available. |
BusinessName | ComponentType<BusinessNameFieldProps> | undefined | Text input bound to businessName; available only for business contractors. |
Ein | ComponentType<EinFieldProps> | undefined | 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. |
Email | ComponentType<EmailFieldProps> | undefined | Text input bound to email; available only when self-onboarding is enabled. |
FileNewHireReport | ComponentType<FileNewHireReportFieldProps> | undefined | Switch bound to fileNewHireReport; available only for individual contractors. |
FirstName | ComponentType<FirstNameFieldProps> | undefined | Text input bound to firstName; available only for individual contractors. |
HourlyRate | ComponentType<HourlyRateFieldProps> | undefined | Number input bound to hourlyRate; available only when wageType is Hourly. |
LastName | ComponentType<LastNameFieldProps> | undefined | Text input bound to lastName; available only for individual contractors. |
MiddleInitial | ComponentType<MiddleInitialFieldProps> | undefined | Text input bound to middleInitial; available only for individual contractors. |
SelfOnboarding | ComponentType<SelfOnboardingFieldProps> | undefined | Switch bound to selfOnboarding; available only when toggleable. |
Ssn | ComponentType<SsnFieldProps> | undefined | 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. |
WorkState | ComponentType<WorkStateFieldProps> | undefined | Select 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.
| 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<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.
| 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<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.
| 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<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
Props accepted by useContractorDetailsForm's Fields.FileNewHireReport component.
| Property | Type | Description |
|---|---|---|
label | string | Visible 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.
| 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<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.
| Property | Type | Description |
|---|---|---|
label | string | Visible 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.
| 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<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.
| 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<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
Props accepted by useContractorDetailsForm's Fields.SelfOnboarding component.
| Property | Type | Description |
|---|---|---|
label | string | Visible 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.
| 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<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.
| Property | Type | Description |
|---|---|---|
label | string | Visible 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.
| Property | Type | Description |
|---|---|---|
label | string | Visible 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"]) => string | Maps 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.
| Property | Type | Description |
|---|---|---|
label | string | Visible 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"]) => string | Maps 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.
| 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<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
constContractorDetailsErrorCodes: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
| Name | Type |
|---|---|
INVALID_EIN | "INVALID_EIN" |
INVALID_EMAIL | "INVALID_EMAIL" |
INVALID_NAME | "INVALID_NAME" |
INVALID_SSN | "INVALID_SSN" |
REQUIRED | "REQUIRED" |
ContractorDetailsFieldsMetadata
| Field | Type |
|---|---|
businessName | FieldMetadata |
ein | FieldMetadata |
email | FieldMetadata |
fileNewHireReport | FieldMetadata |
firstName | FieldMetadata |
hourlyRate | FieldMetadata |
lastName | FieldMetadata |
middleInitial | FieldMetadata |
selfOnboarding | FieldMetadata |
ssn | FieldMetadata |
startDate | FieldMetadata |
type | FieldMetadataWithOptions<"Business" | "Individual"> |
wageType | FieldMetadataWithOptions<"Fixed" | "Hourly"> |
workState | 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"> |
Shape of form.fieldsMetadata returned by useContractorDetailsForm.
ContractorDetailsFormData
Shape of the values managed by the contractor details form.
Properties
| Property | Type |
|---|---|
businessName | string |
ein | string |
email | string |
fileNewHireReport | boolean |
firstName | string |
hourlyRate | number |
lastName | string |
middleInitial | string |
selfOnboarding | boolean |
ssn | string |
startDate | string |
type | "Business" | "Individual" |
wageType | "Fixed" | "Hourly" |
workState | string |
ContractorDetailsOptionalFieldsToRequire
ContractorDetailsOptionalFieldsToRequire =
OptionalFieldsToRequire<typeofrequiredFieldsConfig>
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
| Property | Type | Description |
|---|---|---|
companyId? | string | Override the company identifier supplied to the hook (e.g. after creating the company in the same flow). Only used in create mode. |
ContractorType
constContractorType:object=ApiContractorType
Contractor type enum (Individual / Business) re-exported from the API model.
Type Declaration
| Name | Type |
|---|---|
Business | "Business" |
Individual | "Individual" |
WageType
constWageType:object=ApiWageType
Contractor wage type enum (Fixed / Hourly) re-exported from the API model.
Type Declaration
| Name | Type |
|---|---|
Fixed | "Fixed" |
Hourly | "Hourly" |