useContractorPaymentMethodForm
useContractorPaymentMethodForm(
props:UseContractorPaymentMethodFormProps):HookLoadingResult|UseContractorPaymentMethodFormReady
Headless React Hook Form hook for managing a contractor's payment method type.
Remarks
Owns only the payment method type selection (Direct Deposit or Check) and,
on submit, updates the contractor's payment method via PUT. Always operates
in update mode — every contractor has a payment method, defaulting to Check.
The bank account itself is managed by the separate useContractorBankAccountForm
hook. On the Direct Deposit path the bank-account POST updates the payment
method as a server side-effect, so a composing component submits the bank form
instead of this hook; this hook's onSubmit is used for the Check path.
status.isDirectDeposit lets the component drive that branching.
Example
import { useContractorPaymentMethodForm, SDKFormProvider } from '@gusto/embedded-react-sdk'
function PaymentTypeScreen({ contractorId }: { contractorId: string }) {
const paymentMethod = useContractorPaymentMethodForm({ contractorId })
if (paymentMethod.isLoading) return null
const { Fields } = paymentMethod.form
return (
<SDKFormProvider formHookResult={paymentMethod}>
<form
onSubmit={e => {
e.preventDefault()
void paymentMethod.actions.onSubmit()
}}
>
<Fields.Type label="Select payment method" />
<button type="submit" disabled={paymentMethod.status.isPending}>Save</button>
</form>
</SDKFormProvider>
)
}
Props
UseContractorPaymentMethodFormProps
Props for useContractorPaymentMethodForm.
| Property | Type | Description |
|---|---|---|
contractorId | string | Contractor whose payment method is being edited. |
defaultValues? | Partial<ContractorPaymentMethodFormData> | Pre-fill form values. Server data (the current payment method) is used when no override is supplied. |
shouldFocusError? | boolean | Auto-focus the first invalid field on submit. Set to false when using composeSubmitHandler. Defaults to true. |
validationMode? | "onChange" | "onBlur" | "onSubmit" | "onTouched" | "all" | When validation runs. Passed through to react-hook-form. Defaults to 'onSubmit'. |
Returns
HookLoadingResult | UseContractorPaymentMethodFormReady
A loading-state result while data loads, or a UseContractorPaymentMethodFormReady once ready.
UseContractorPaymentMethodFormResult
UseContractorPaymentMethodFormResult =
HookLoadingResult|UseContractorPaymentMethodFormReady
Return type of useContractorPaymentMethodForm — a discriminated union on isLoading.
UseContractorPaymentMethodFormReady
Ready-state return value of useContractorPaymentMethodForm.
| Property | Type | Description |
|---|---|---|
actions | object | Submit the form. Returns the updated payment method on success or undefined on validation/mutation failure. |
actions.onSubmit | () => Promise<HookSubmitResult<ContractorPaymentMethod> | undefined> | - |
data | object | The contractor's current payment method, loaded from the API. |
data.paymentMethod | ContractorPaymentMethod | - |
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 | ContractorPaymentMethodFormFields | - |
form.fieldsMetadata | ContractorPaymentMethodFieldsMetadata | - |
form.getFormSubmissionValues | () => ContractorPaymentMethodFormData | undefined | - |
form.hookFormInternals | HookFormInternals<ContractorPaymentMethodFormData> | - |
isLoading | false | Always false in this branch; discriminates from HookLoadingResult. |
status | object | isPending reflects the in-flight update mutation; mode is always 'update'. isDirectDeposit reflects the currently selected type so a composing component can render bank fields and decide whether to submit the bank-account form. |
status.isDirectDeposit | boolean | - |
status.isPending | boolean | - |
status.mode | "update" | - |
Fields
ContractorPaymentMethodFormFields
Field components exposed by useContractorPaymentMethodForm on form.Fields.
| Property | Type | Description |
|---|---|---|
Type | ComponentType<TypeFieldProps> | Radio group bound to type. Selects whether the contractor is paid by Direct Deposit or Check. Supply getOptionLabel to translate the option labels. |
Type
Radio group bound to type. Selects whether the contractor is paid by
Direct Deposit or Check. Supply getOptionLabel to translate the option
labels.
<form.Fields.Type label="Type" />
ContractorPaymentMethodTypeFieldProps
HookFieldProps<RadioGroupHookFieldProps<never,ContractorPaymentMethodFormType>>
Props accepted by useContractorPaymentMethodForm'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: ContractorPaymentMethodFormType) => 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.
Utility types
ContractorPaymentMethodErrorCode
ContractorPaymentMethodErrorCode =
"REQUIRED"
Union of validation error code strings emitted by the contractor payment method form schema.
ContractorPaymentMethodErrorCodes
constContractorPaymentMethodErrorCodes:object
Validation error codes emitted by the contractor payment method form schema.
Map these codes to localized copy in validationMessages when composing the
hook.
Type Declaration
| Name | Type |
|---|---|
REQUIRED | "REQUIRED" |
ContractorPaymentMethodFieldsMetadata
| Field | Type |
|---|---|
type | FieldMetadataWithOptions<ContractorPaymentMethodFormType> |
Per-field metadata exposed on form.fieldsMetadata for useContractorPaymentMethodForm.
ContractorPaymentMethodFormData
Shape of the values managed by the contractor payment method form.
Properties
| Property | Type |
|---|---|
type | "Check" | "Direct Deposit" |
ContractorPaymentMethodFormField
ContractorPaymentMethodFormField =
"type"
Field names accepted by the contractor payment method form.
ContractorPaymentMethodFormType
ContractorPaymentMethodFormType =
"Check"|"Direct Deposit"
Union of payment method type values that the form accepts.