Skip to main content

useContractorPayForm

useContractorPayForm(props: UseContractorPayFormProps): HookLoadingResult | UseContractorPayFormReady

Headless React Hook Form hook for editing a contractor's compensation.

Remarks​

Owns wageType (Fixed or Hourly) and, when Hourly, hourlyRate. Always operates in update mode — a contractor's wage type is set at creation. Every submit echoes the contractor's current type back to the API alongside the changed fields: the update endpoint's wire schema defaults an omitted type to "Individual", so a narrower payload would silently misrepresent a Business contractor.

Example​

Example
import { useContractorPayForm, SDKFormProvider } from '@gusto/embedded-react-sdk'

function PayScreen({ contractorId }: { contractorId: string }) {
const pay = useContractorPayForm({ contractorId })

if (pay.isLoading) return null
const { Fields } = pay.form

return (
<SDKFormProvider formHookResult={pay}>
<form
onSubmit={e => {
e.preventDefault()
void pay.actions.onSubmit()
}}
>
<Fields.WageType label="Compensation type" />
<Fields.HourlyRate label="Hourly rate" />
<button type="submit" disabled={pay.status.isPending}>Save</button>
</form>
</SDKFormProvider>
)
}

Props​

UseContractorPayFormProps​

Props for useContractorPayForm.

PropertyTypeDescription
contractorIdstringContractor whose compensation is being edited.
shouldFocusError?booleanAuto-focus the first invalid field on submit. Set to false when using composeSubmitHandler. Defaults to true.
validationMode?"all" | "onChange" | "onBlur" | "onSubmit" | "onTouched"When validation runs. Passed through to react-hook-form. Defaults to 'onSubmit'.

Returns​

HookLoadingResult | UseContractorPayFormReady

A loading-state result while data loads, or a UseContractorPayFormReady once ready.

UseContractorPayFormResult​

UseContractorPayFormResult = HookLoadingResult | UseContractorPayFormReady

Return type of useContractorPayForm — a discriminated union on isLoading.


UseContractorPayFormReady​

Ready-state return value of useContractorPayForm.

PropertyTypeDescription
actionsobjectSubmit the form. Returns the updated contractor on success or undefined on validation/mutation failure.
actions.onSubmit() => Promise<HookSubmitResult<Contractor> | undefined>-
dataobjectThe full contractor entity, loaded from the API.
data.contractorContractor-
errorHandlingHookErrorHandlingError state and recovery actions.
formobjectForm bindings: pre-bound field components, per-field metadata, submission values, and react-hook-form internals.
form.FieldsContractorPayFormFields-
form.fieldsMetadataContractorPayFieldsMetadata-
form.getFormSubmissionValues() => ContractorPayFormData | undefined-
form.hookFormInternalsHookFormInternals<ContractorPayFormData>-
isLoadingfalseAlways false in this branch; discriminates from HookLoadingResult.
statusobjectisPending reflects the in-flight update mutation; mode is always 'update'. isHourly reflects the currently selected wage type so a composing component can decide whether to render the hourly-rate field.
status.isHourlyboolean-
status.isPendingboolean-
status.mode"update"-

Fields​

ContractorPayFormFields​

Field components exposed by useContractorPayForm on form.Fields.

PropertyTypeDescription
HourlyRateComponentType<HourlyRateFieldProps>Bound to hourlyRate. Required and rendered only when wageType is Hourly.
WageTypeComponentType<WageTypeFieldProps>Bound to wageType. Selects whether the contractor is paid Fixed or Hourly.

HourlyRate​

Bound to hourlyRate. Required and rendered only when wageType is Hourly.

<form.Fields.HourlyRate
label="Hourly rate"
validationMessages={{ REQUIRED: '…', MAX_HOURLY_RATE: '…' }}
/>

ContractorPayHourlyRateFieldProps​

HookFieldProps<NumberInputHookFieldProps<ContractorPayRequiredValidation | ContractorPayMaxHourlyRateValidation>>

Props accepted by useContractorPayForm'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<ContractorPayRequiredValidation | ContractorPayMaxHourlyRateValidation>Custom error text keyed by validation error code.

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


WageType​

Bound to wageType. Selects whether the contractor is paid Fixed or Hourly.

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

ContractorPayWageTypeFieldProps​

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

Props accepted by useContractorPayForm'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: ContractorPayFormData["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.

Utility types​

ContractorPayErrorCode​

ContractorPayErrorCode = "REQUIRED" | "MAX_HOURLY_RATE"

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


ContractorPayErrorCodes​

const ContractorPayErrorCodes: object

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

Type Declaration​

NameType
MAX_HOURLY_RATE"MAX_HOURLY_RATE"
REQUIRED"REQUIRED"

ContractorPayFieldsMetadata​

FieldType
hourlyRateFieldMetadata
wageTypeFieldMetadataWithOptions<"Fixed" | "Hourly">

Per-field metadata exposed on form.fieldsMetadata for useContractorPayForm.


ContractorPayFormData​

Shape of the values managed by the contractor pay form.

Properties​

PropertyType
hourlyRatenumber
wageType"Fixed" | "Hourly"

ContractorPayFormField​

ContractorPayFormField = "hourlyRate" | "wageType"

Field names accepted by the contractor pay form.


ContractorPayMaxHourlyRateValidation​

ContractorPayMaxHourlyRateValidation = "MAX_HOURLY_RATE"

Validation code for an hourly rate above the server's maximum cap.


ContractorPayRequiredValidation​

ContractorPayRequiredValidation = "REQUIRED"

Validation code for a required contractor pay field.


ContractorPayWageType​

const ContractorPayWageType: object = ApiWageType

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

Type Declaration​

NameType
Fixed"Fixed"
Hourly"Hourly"

Endpoints​