@gusto/embedded-react-sdk 0.49.0 → 0.50.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +26 -0
- package/dist/components/Base/createCompoundContext.d.ts +1 -1
- package/dist/components/Base/createCompoundContext.js.map +1 -1
- package/dist/components/Common/UI/Breadcrumbs/Breadcrumbs.js +1 -1
- package/dist/components/Common/UI/CalendarPreview/CalendarLegend.d.ts +1 -1
- package/dist/components/Common/UI/CalendarPreview/CalendarLegend.js.map +1 -1
- package/dist/components/Common/UI/FileInput/FileInput.js +1 -1
- package/dist/components/Common/UI/ProgressBar/ProgressBar.js +4 -4
- package/dist/components/Company/AssignSignatory/CreateSignatory/useCreateSignatory.js +5 -3
- package/dist/components/Company/AssignSignatory/CreateSignatory/useCreateSignatory.js.map +1 -1
- package/dist/components/Company/AssignSignatory/InviteSignatory/useInviteSignatory.js +5 -3
- package/dist/components/Company/AssignSignatory/InviteSignatory/useInviteSignatory.js.map +1 -1
- package/dist/components/Company/AssignSignatory/useAssignSignatory.js +7 -5
- package/dist/components/Company/AssignSignatory/useAssignSignatory.js.map +1 -1
- package/dist/components/Company/BankAccount/BankAccountForm/context.js +5 -3
- package/dist/components/Company/BankAccount/BankAccountForm/context.js.map +1 -1
- package/dist/components/Company/DocumentSigner/DocumentList/useDocumentList.js +5 -3
- package/dist/components/Company/DocumentSigner/DocumentList/useDocumentList.js.map +1 -1
- package/dist/components/Company/DocumentSigner/shared/useSignCompanyForm/signCompanyFormSchema.d.ts +1 -0
- package/dist/components/Company/DocumentSigner/shared/useSignCompanyForm/signCompanyFormSchema.js.map +1 -1
- package/dist/components/Company/FederalTaxes/useFederalTaxes.js +10 -8
- package/dist/components/Company/FederalTaxes/useFederalTaxes.js.map +1 -1
- package/dist/components/Company/Industry/Context.js +8 -6
- package/dist/components/Company/Industry/Context.js.map +1 -1
- package/dist/components/Company/Locations/LocationForm/useLocationForm.js +5 -3
- package/dist/components/Company/Locations/LocationForm/useLocationForm.js.map +1 -1
- package/dist/components/Company/Locations/LocationsList/useLocationsList.js +5 -3
- package/dist/components/Company/Locations/LocationsList/useLocationsList.js.map +1 -1
- package/dist/components/Company/OnboardingFlow/OnboardingFlow.d.ts +1 -1
- package/dist/components/Company/OnboardingFlow/OnboardingFlow.js.map +1 -1
- package/dist/components/Company/OnboardingOverview/context.js +5 -3
- package/dist/components/Company/OnboardingOverview/context.js.map +1 -1
- package/dist/components/Company/PaySchedule/shared/usePayScheduleForm/payScheduleSchema.d.ts +1 -0
- package/dist/components/Company/PaySchedule/shared/usePayScheduleForm/payScheduleSchema.js.map +1 -1
- package/dist/components/Company/StateTaxes/StateTaxesForm/context.js +5 -3
- package/dist/components/Company/StateTaxes/StateTaxesForm/context.js.map +1 -1
- package/dist/components/Company/StateTaxes/StateTaxesList/context.js +5 -3
- package/dist/components/Company/StateTaxes/StateTaxesList/context.js.map +1 -1
- package/dist/components/Contractor/Address/shared/useContractorAddressForm/contractorAddressSchema.d.ts +1 -0
- package/dist/components/Contractor/Address/shared/useContractorAddressForm/contractorAddressSchema.js.map +1 -1
- package/dist/components/Contractor/Address/shared/useContractorAddressForm/useContractorAddressForm.d.ts +38 -0
- package/dist/components/Contractor/Address/shared/useContractorAddressForm/useContractorAddressForm.js.map +1 -1
- package/dist/components/Contractor/Documents/DocumentsList/useContractorDocumentsList/useContractorDocumentsList.d.ts +1 -0
- package/dist/components/Contractor/Documents/DocumentsList/useContractorDocumentsList/useContractorDocumentsList.js.map +1 -1
- package/dist/components/Contractor/OnboardingFlow/OnboardingFlow.d.ts +3 -3
- package/dist/components/Contractor/OnboardingFlow/OnboardingFlow.js.map +1 -1
- package/dist/components/Contractor/PaymentMethod/PaymentMethod.d.ts +5 -5
- package/dist/components/Contractor/PaymentMethod/PaymentMethod.js +105 -108
- package/dist/components/Contractor/PaymentMethod/PaymentMethod.js.map +1 -1
- package/dist/components/Contractor/PaymentMethod/PaymentMethod.module.scss.js +8 -0
- package/dist/components/Contractor/PaymentMethod/PaymentMethod.module.scss.js.map +1 -0
- package/dist/components/Contractor/PaymentMethod/shared/index.d.ts +2 -0
- package/dist/components/Contractor/PaymentMethod/shared/useContractorBankAccountForm/fields.d.ts +93 -0
- package/dist/components/Contractor/PaymentMethod/shared/useContractorBankAccountForm/fields.js +22 -0
- package/dist/components/Contractor/PaymentMethod/shared/useContractorBankAccountForm/fields.js.map +1 -0
- package/dist/components/Contractor/PaymentMethod/shared/useContractorBankAccountForm/index.d.ts +5 -0
- package/dist/components/Contractor/PaymentMethod/shared/useContractorBankAccountForm/useContractorBankAccountForm.d.ts +127 -0
- package/dist/components/Contractor/PaymentMethod/shared/useContractorBankAccountForm/useContractorBankAccountForm.js +109 -0
- package/dist/components/Contractor/PaymentMethod/shared/useContractorBankAccountForm/useContractorBankAccountForm.js.map +1 -0
- package/dist/components/Contractor/PaymentMethod/shared/useContractorBankAccountForm/useContractorBankAccountFormSchema.d.ts +83 -0
- package/dist/components/Contractor/PaymentMethod/shared/useContractorBankAccountForm/useContractorBankAccountFormSchema.js +42 -0
- package/dist/components/Contractor/PaymentMethod/shared/useContractorBankAccountForm/useContractorBankAccountFormSchema.js.map +1 -0
- package/dist/components/Contractor/PaymentMethod/shared/useContractorPaymentMethodForm/contractorPaymentMethodSchema.d.ts +58 -0
- package/dist/components/Contractor/PaymentMethod/shared/useContractorPaymentMethodForm/contractorPaymentMethodSchema.js +21 -0
- package/dist/components/Contractor/PaymentMethod/shared/useContractorPaymentMethodForm/contractorPaymentMethodSchema.js.map +1 -0
- package/dist/components/Contractor/PaymentMethod/shared/useContractorPaymentMethodForm/fields.d.ts +20 -0
- package/dist/components/Contractor/PaymentMethod/shared/useContractorPaymentMethodForm/fields.js +9 -0
- package/dist/components/Contractor/PaymentMethod/shared/useContractorPaymentMethodForm/fields.js.map +1 -0
- package/dist/components/Contractor/PaymentMethod/shared/useContractorPaymentMethodForm/index.d.ts +5 -0
- package/dist/components/Contractor/PaymentMethod/shared/useContractorPaymentMethodForm/useContractorPaymentMethodForm.d.ts +117 -0
- package/dist/components/Contractor/PaymentMethod/shared/useContractorPaymentMethodForm/useContractorPaymentMethodForm.js +91 -0
- package/dist/components/Contractor/PaymentMethod/shared/useContractorPaymentMethodForm/useContractorPaymentMethodForm.js.map +1 -0
- package/dist/components/Contractor/PaymentMethod/types.d.ts +0 -5
- package/dist/components/Contractor/Payments/PaymentFlow/PaymentFlow.d.ts +2 -2
- package/dist/components/Contractor/Payments/PaymentFlow/PaymentFlow.js.map +1 -1
- package/dist/components/Contractor/Profile/shared/useContractorDetailsForm/contractorDetailsSchema.d.ts +1 -0
- package/dist/components/Contractor/Profile/shared/useContractorDetailsForm/contractorDetailsSchema.js.map +1 -1
- package/dist/components/Contractor/Profile/shared/useContractorDetailsForm/useContractorDetailsForm.d.ts +45 -0
- package/dist/components/Contractor/Profile/shared/useContractorDetailsForm/useContractorDetailsForm.js.map +1 -1
- package/dist/components/Employee/Compensation/shared/useCompensationForm/compensationSchema.d.ts +1 -0
- package/dist/components/Employee/Compensation/shared/useCompensationForm/compensationSchema.js.map +1 -1
- package/dist/components/Employee/Dashboard/DashboardFlow.d.ts +1 -1
- package/dist/components/Employee/Dashboard/DashboardFlow.js.map +1 -1
- package/dist/components/Employee/Deductions/shared/useChildSupportGarnishmentForm/childSupportGarnishmentFormSchema.d.ts +1 -0
- package/dist/components/Employee/Deductions/shared/useChildSupportGarnishmentForm/childSupportGarnishmentFormSchema.js.map +1 -1
- package/dist/components/Employee/Deductions/shared/useDeductionForm/deductionFormSchema.d.ts +1 -0
- package/dist/components/Employee/Deductions/shared/useDeductionForm/deductionFormSchema.js.map +1 -1
- package/dist/components/Employee/Documents/onboarding/DocumentSigner/DocumentList/useDocumentList.js +5 -3
- package/dist/components/Employee/Documents/onboarding/DocumentSigner/DocumentList/useDocumentList.js.map +1 -1
- package/dist/components/Employee/Documents/shared/useSignEmployeeForm/signEmployeeFormSchema.d.ts +1 -0
- package/dist/components/Employee/Documents/shared/useSignEmployeeForm/signEmployeeFormSchema.js.map +1 -1
- package/dist/components/Employee/EmployeeListFlow/EmployeeListFlow.d.ts +2 -2
- package/dist/components/Employee/EmployeeListFlow/EmployeeListFlow.js.map +1 -1
- package/dist/components/Employee/FederalTaxes/shared/FederalTaxesView.js +1 -1
- package/dist/components/Employee/FederalTaxes/shared/useFederalTaxesForm/federalTaxesSchema.d.ts +1 -0
- package/dist/components/Employee/FederalTaxes/shared/useFederalTaxesForm/federalTaxesSchema.js.map +1 -1
- package/dist/components/Employee/OnboardingExecutionFlow/OnboardingExecutionFlow.d.ts +2 -2
- package/dist/components/Employee/OnboardingExecutionFlow/OnboardingExecutionFlow.js.map +1 -1
- package/dist/components/Employee/OnboardingFlow/OnboardingFlow.d.ts +3 -3
- package/dist/components/Employee/OnboardingFlow/OnboardingFlow.js.map +1 -1
- package/dist/components/Employee/PaymentMethod/shared/useBankForm/useBankForm.d.ts +4 -4
- package/dist/components/Employee/PaymentMethod/shared/useBankForm/useBankForm.js.map +1 -1
- package/dist/components/Employee/PaymentMethod/shared/useBankForm/useBankFormSchema.d.ts +1 -0
- package/dist/components/Employee/PaymentMethod/shared/useBankForm/useBankFormSchema.js +7 -6
- package/dist/components/Employee/PaymentMethod/shared/useBankForm/useBankFormSchema.js.map +1 -1
- package/dist/components/Employee/PaymentMethod/shared/usePaymentMethodForm/usePaymentMethodForm.d.ts +1 -1
- package/dist/components/Employee/PaymentMethod/shared/usePaymentMethodForm/usePaymentMethodForm.js.map +1 -1
- package/dist/components/Employee/PaymentMethod/shared/usePaymentMethodForm/usePaymentMethodFormSchema.d.ts +1 -0
- package/dist/components/Employee/PaymentMethod/shared/usePaymentMethodForm/usePaymentMethodFormSchema.js.map +1 -1
- package/dist/components/Employee/PaymentMethod/shared/useSplitPaymentsForm/useSplitPaymentsForm.d.ts +2 -2
- package/dist/components/Employee/PaymentMethod/shared/useSplitPaymentsForm/useSplitPaymentsForm.js.map +1 -1
- package/dist/components/Employee/Profile/shared/useEmployeeDetailsForm/employeeDetailsSchema.d.ts +1 -0
- package/dist/components/Employee/Profile/shared/useEmployeeDetailsForm/employeeDetailsSchema.js.map +1 -1
- package/dist/components/Employee/Profile/shared/useEmployeeDetailsForm/useEmployeeDetailsForm.d.ts +11 -12
- package/dist/components/Employee/Profile/shared/useEmployeeDetailsForm/useEmployeeDetailsForm.js.map +1 -1
- package/dist/components/Employee/Profile/shared/useHomeAddressForm/homeAddressSchema.d.ts +1 -0
- package/dist/components/Employee/Profile/shared/useHomeAddressForm/homeAddressSchema.js.map +1 -1
- package/dist/components/Employee/Profile/shared/useHomeAddressForm/useHomeAddressForm.d.ts +36 -0
- package/dist/components/Employee/Profile/shared/useHomeAddressForm/useHomeAddressForm.js.map +1 -1
- package/dist/components/Employee/Profile/shared/useWorkAddressForm/useWorkAddressForm.d.ts +31 -0
- package/dist/components/Employee/Profile/shared/useWorkAddressForm/useWorkAddressForm.js.map +1 -1
- package/dist/components/Employee/Profile/shared/useWorkAddressForm/workAddressSchema.d.ts +1 -0
- package/dist/components/Employee/Profile/shared/useWorkAddressForm/workAddressSchema.js.map +1 -1
- package/dist/components/Employee/SelfOnboardingFlow/SelfOnboardingFlow.d.ts +2 -2
- package/dist/components/Employee/SelfOnboardingFlow/SelfOnboardingFlow.js.map +1 -1
- package/dist/components/Employee/StateTaxes/shared/useEmployeeStateTaxesForm/fieldProps.d.ts +36 -18
- package/dist/components/Employee/StateTaxes/shared/useEmployeeStateTaxesForm/fields.d.ts +113 -13
- package/dist/components/Employee/StateTaxes/shared/useEmployeeStateTaxesForm/fields.js.map +1 -1
- package/dist/components/Employee/StateTaxes/shared/useEmployeeStateTaxesForm/index.d.ts +1 -1
- package/dist/components/Employee/StateTaxes/shared/useEmployeeStateTaxesForm/useEmployeeStateTaxesForm.d.ts +2 -7
- package/dist/components/Employee/StateTaxes/shared/useEmployeeStateTaxesForm/useEmployeeStateTaxesForm.js.map +1 -1
- package/dist/components/Flow/Flow.js +1 -1
- package/dist/components/InformationRequests/InformationRequests.d.ts +3 -3
- package/dist/components/InformationRequests/InformationRequests.js.map +1 -1
- package/dist/components/Payroll/usePreparedPayrollData.js +10 -8
- package/dist/components/Payroll/usePreparedPayrollData.js.map +1 -1
- package/dist/helpers/validations.d.ts +12 -0
- package/dist/helpers/validations.js +6 -4
- package/dist/helpers/validations.js.map +1 -1
- package/dist/index.d.ts +6 -2
- package/dist/index.js +247 -237
- package/dist/index.js.map +1 -1
- package/dist/models/external.d.ts +6 -0
- package/dist/style.css +1 -1
- package/dist/types/sdkError.js +13 -6
- package/dist/types/sdkError.js.map +1 -1
- package/package.json +7 -7
- package/dist/components/Contractor/PaymentMethod/BankAccountForm.d.ts +0 -3
- package/dist/components/Contractor/PaymentMethod/BankAccountForm.js +0 -56
- package/dist/components/Contractor/PaymentMethod/BankAccountForm.js.map +0 -1
- package/dist/components/Contractor/PaymentMethod/PaymentTypeForm.d.ts +0 -2
- package/dist/components/Contractor/PaymentMethod/PaymentTypeForm.js +0 -33
- package/dist/components/Contractor/PaymentMethod/PaymentTypeForm.js.map +0 -1
- /package/docs/{appendix → guides}/endpoint-inventory.json +0 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Validation error codes emitted by the contractor payment method form schema.
|
|
4
|
+
* Map these codes to localized copy in `validationMessages` when composing the
|
|
5
|
+
* hook.
|
|
6
|
+
*
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export declare const ContractorPaymentMethodErrorCodes: {
|
|
10
|
+
readonly REQUIRED: "REQUIRED";
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Union of validation error code strings emitted by the contractor payment
|
|
14
|
+
* method form schema.
|
|
15
|
+
*
|
|
16
|
+
* @public
|
|
17
|
+
*/
|
|
18
|
+
export type ContractorPaymentMethodErrorCode = (typeof ContractorPaymentMethodErrorCodes)[keyof typeof ContractorPaymentMethodErrorCodes];
|
|
19
|
+
/**
|
|
20
|
+
* Supported payment method type values: direct deposit and check.
|
|
21
|
+
*
|
|
22
|
+
* @public
|
|
23
|
+
*/
|
|
24
|
+
export declare const PAYMENT_METHOD_TYPES: readonly ["Direct Deposit", "Check"];
|
|
25
|
+
/**
|
|
26
|
+
* Union of payment method type values that the form accepts.
|
|
27
|
+
*
|
|
28
|
+
* @public
|
|
29
|
+
*/
|
|
30
|
+
export type ContractorPaymentMethodFormType = (typeof PAYMENT_METHOD_TYPES)[number];
|
|
31
|
+
/**
|
|
32
|
+
* Field names accepted by the contractor payment method form.
|
|
33
|
+
*
|
|
34
|
+
* @public
|
|
35
|
+
*/
|
|
36
|
+
export type ContractorPaymentMethodFormField = "type";
|
|
37
|
+
/**
|
|
38
|
+
* Shape of the values managed by the contractor payment method form.
|
|
39
|
+
*
|
|
40
|
+
* @public
|
|
41
|
+
* @interface
|
|
42
|
+
*/
|
|
43
|
+
export type ContractorPaymentMethodFormData = { type: "Check" | "Direct Deposit"; };
|
|
44
|
+
/**
|
|
45
|
+
* Shape of the validated values produced by the contractor payment method form
|
|
46
|
+
* on submit.
|
|
47
|
+
*
|
|
48
|
+
* @public
|
|
49
|
+
*/
|
|
50
|
+
export type ContractorPaymentMethodFormOutputs = ContractorPaymentMethodFormData;
|
|
51
|
+
/** @internal */
|
|
52
|
+
export declare function createContractorPaymentMethodSchema(): import('../../../../../partner-hook-utils/form/buildFormSchema').BuildFormSchemaResult<{
|
|
53
|
+
type: z.ZodEnum<{
|
|
54
|
+
Check: "Check";
|
|
55
|
+
"Direct Deposit": "Direct Deposit";
|
|
56
|
+
}>;
|
|
57
|
+
}>;
|
|
58
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { z as r } from "zod";
|
|
2
|
+
import { buildFormSchema as e } from "../../../../../partner-hook-utils/form/buildFormSchema.js";
|
|
3
|
+
import { PAYMENT_METHODS as o } from "../../../../../shared/constants.js";
|
|
4
|
+
const t = {
|
|
5
|
+
REQUIRED: "REQUIRED"
|
|
6
|
+
}, c = [o.directDeposit, o.check], d = {
|
|
7
|
+
type: r.enum(c)
|
|
8
|
+
}, i = {};
|
|
9
|
+
function a() {
|
|
10
|
+
return e(d, {
|
|
11
|
+
requiredFieldsConfig: i,
|
|
12
|
+
requiredErrorCode: t.REQUIRED,
|
|
13
|
+
mode: "update"
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
export {
|
|
17
|
+
t as ContractorPaymentMethodErrorCodes,
|
|
18
|
+
c as PAYMENT_METHOD_TYPES,
|
|
19
|
+
a as createContractorPaymentMethodSchema
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=contractorPaymentMethodSchema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contractorPaymentMethodSchema.js","sources":["../../../../../../src/components/Contractor/PaymentMethod/shared/useContractorPaymentMethodForm/contractorPaymentMethodSchema.ts"],"sourcesContent":["import { z } from 'zod'\nimport {\n buildFormSchema,\n type RequiredFieldConfig,\n} from '@/partner-hook-utils/form/buildFormSchema'\nimport { PAYMENT_METHODS } from '@/shared/constants'\n\n/**\n * Validation error codes emitted by the contractor payment method form schema.\n * Map these codes to localized copy in `validationMessages` when composing the\n * hook.\n *\n * @public\n */\nexport const ContractorPaymentMethodErrorCodes = {\n REQUIRED: 'REQUIRED',\n} as const\n\n/**\n * Union of validation error code strings emitted by the contractor payment\n * method form schema.\n *\n * @public\n */\nexport type ContractorPaymentMethodErrorCode =\n (typeof ContractorPaymentMethodErrorCodes)[keyof typeof ContractorPaymentMethodErrorCodes]\n\n/**\n * Supported payment method type values: direct deposit and check.\n *\n * @public\n */\nexport const PAYMENT_METHOD_TYPES = [PAYMENT_METHODS.directDeposit, PAYMENT_METHODS.check] as const\n\n/**\n * Union of payment method type values that the form accepts.\n *\n * @public\n */\nexport type ContractorPaymentMethodFormType = (typeof PAYMENT_METHOD_TYPES)[number]\n\nconst fieldValidators = {\n type: z.enum(PAYMENT_METHOD_TYPES),\n}\n\n/**\n * Field names accepted by the contractor payment method form.\n *\n * @public\n */\nexport type ContractorPaymentMethodFormField = keyof typeof fieldValidators\n\n/**\n * Shape of the values managed by the contractor payment method form.\n *\n * @public\n * @interface\n */\nexport type ContractorPaymentMethodFormData = {\n [K in keyof typeof fieldValidators]: z.infer<(typeof fieldValidators)[K]>\n}\n\n/**\n * Shape of the validated values produced by the contractor payment method form\n * on submit.\n *\n * @public\n */\nexport type ContractorPaymentMethodFormOutputs = ContractorPaymentMethodFormData\n\nconst requiredFieldsConfig = {} satisfies RequiredFieldConfig<typeof fieldValidators>\n\n/** @internal */\nexport function createContractorPaymentMethodSchema() {\n return buildFormSchema(fieldValidators, {\n requiredFieldsConfig,\n requiredErrorCode: ContractorPaymentMethodErrorCodes.REQUIRED,\n mode: 'update',\n })\n}\n"],"names":["ContractorPaymentMethodErrorCodes","PAYMENT_METHOD_TYPES","PAYMENT_METHODS","fieldValidators","z","requiredFieldsConfig","createContractorPaymentMethodSchema","buildFormSchema"],"mappings":";;;AAcO,MAAMA,IAAoC;AAAA,EAC/C,UAAU;AACZ,GAgBaC,IAAuB,CAACC,EAAgB,eAAeA,EAAgB,KAAK,GASnFC,IAAkB;AAAA,EACtB,MAAMC,EAAE,KAAKH,CAAoB;AACnC,GA2BMI,IAAuB,CAAA;AAGtB,SAASC,IAAsC;AACpD,SAAOC,EAAgBJ,GAAiB;AAAA,IACtC,sBAAAE;AAAA,IACA,mBAAmBL,EAAkC;AAAA,IACrD,MAAM;AAAA,EAAA,CACP;AACH;"}
|
package/dist/components/Contractor/PaymentMethod/shared/useContractorPaymentMethodForm/fields.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ContractorPaymentMethodFormType } from './contractorPaymentMethodSchema';
|
|
2
|
+
import { RadioGroupHookFieldProps } from '../../../../../partner-hook-utils/form/fields/RadioGroupHookField';
|
|
3
|
+
import { HookFieldProps } from '../../../../../partner-hook-utils/types';
|
|
4
|
+
/**
|
|
5
|
+
* Props accepted by {@link useContractorPaymentMethodForm}'s `Fields.Type` component.
|
|
6
|
+
*
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export type TypeFieldProps = HookFieldProps<RadioGroupHookFieldProps<never, ContractorPaymentMethodFormType>>;
|
|
10
|
+
/**
|
|
11
|
+
* Radio group bound to the `type` field of {@link useContractorPaymentMethodForm}.
|
|
12
|
+
*
|
|
13
|
+
* @remarks
|
|
14
|
+
* Surfaced to partners as `form.Fields.Type`; see {@link ContractorPaymentMethodFormFields}.
|
|
15
|
+
*
|
|
16
|
+
* @param props - See {@link TypeFieldProps}.
|
|
17
|
+
* @returns The rendered radio group bound to `type`.
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
20
|
+
export declare function TypeField(props: TypeFieldProps): import("react").JSX.Element;
|
package/dist/components/Contractor/PaymentMethod/shared/useContractorPaymentMethodForm/fields.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { jsx as r } from "react/jsx-runtime";
|
|
2
|
+
import { RadioGroupHookField as e } from "../../../../../partner-hook-utils/form/fields/RadioGroupHookField.js";
|
|
3
|
+
function t(o) {
|
|
4
|
+
return /* @__PURE__ */ r(e, { ...o, name: "type" });
|
|
5
|
+
}
|
|
6
|
+
export {
|
|
7
|
+
t as TypeField
|
|
8
|
+
};
|
|
9
|
+
//# sourceMappingURL=fields.js.map
|
package/dist/components/Contractor/PaymentMethod/shared/useContractorPaymentMethodForm/fields.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fields.js","sources":["../../../../../../src/components/Contractor/PaymentMethod/shared/useContractorPaymentMethodForm/fields.tsx"],"sourcesContent":["import type { ContractorPaymentMethodFormType } from './contractorPaymentMethodSchema'\nimport type { RadioGroupHookFieldProps } from '@/partner-hook-utils/form/fields/RadioGroupHookField'\nimport { RadioGroupHookField } from '@/partner-hook-utils/form/fields'\nimport type { HookFieldProps } from '@/partner-hook-utils/types'\n\n/**\n * Props accepted by {@link useContractorPaymentMethodForm}'s `Fields.Type` component.\n *\n * @public\n */\nexport type TypeFieldProps = HookFieldProps<\n RadioGroupHookFieldProps<never, ContractorPaymentMethodFormType>\n>\n\n/**\n * Radio group bound to the `type` field of {@link useContractorPaymentMethodForm}.\n *\n * @remarks\n * Surfaced to partners as `form.Fields.Type`; see {@link ContractorPaymentMethodFormFields}.\n *\n * @param props - See {@link TypeFieldProps}.\n * @returns The rendered radio group bound to `type`.\n * @internal\n */\nexport function TypeField(props: TypeFieldProps) {\n return <RadioGroupHookField {...props} name=\"type\" />\n}\n"],"names":["TypeField","props","jsx","RadioGroupHookField"],"mappings":";;AAwBO,SAASA,EAAUC,GAAuB;AAC/C,SAAO,gBAAAC,EAACC,GAAA,EAAqB,GAAGF,GAAO,MAAK,QAAO;AACrD;"}
|
package/dist/components/Contractor/PaymentMethod/shared/useContractorPaymentMethodForm/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import "./types/i18next.d.ts"
|
|
2
|
+
export { useContractorPaymentMethodForm } from './useContractorPaymentMethodForm';
|
|
3
|
+
export type { UseContractorPaymentMethodFormProps, UseContractorPaymentMethodFormResult, UseContractorPaymentMethodFormReady, ContractorPaymentMethodFormFields, ContractorPaymentMethodFieldsMetadata, } from './useContractorPaymentMethodForm';
|
|
4
|
+
export { ContractorPaymentMethodErrorCodes, PAYMENT_METHOD_TYPES, createContractorPaymentMethodSchema, type ContractorPaymentMethodErrorCode, type ContractorPaymentMethodFormType, type ContractorPaymentMethodFormData, type ContractorPaymentMethodFormOutputs, type ContractorPaymentMethodFormField, } from './contractorPaymentMethodSchema';
|
|
5
|
+
export { type TypeFieldProps } from './fields';
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { ComponentType } from 'react';
|
|
2
|
+
import { UseFormProps } from 'react-hook-form';
|
|
3
|
+
import { ContractorPaymentMethod } from '@gusto/embedded-api-v-2025-11-15/models/components/contractorpaymentmethod';
|
|
4
|
+
import { ContractorPaymentMethodFormData } from './contractorPaymentMethodSchema';
|
|
5
|
+
import { TypeFieldProps } from './fields';
|
|
6
|
+
import { BaseFormHookReady, FieldsMetadata, HookLoadingResult, HookSubmitResult } from '../../../../../partner-hook-utils/types';
|
|
7
|
+
/**
|
|
8
|
+
* Props for {@link useContractorPaymentMethodForm}.
|
|
9
|
+
*
|
|
10
|
+
* @public
|
|
11
|
+
*/
|
|
12
|
+
export interface UseContractorPaymentMethodFormProps {
|
|
13
|
+
/** Contractor whose payment method is being edited. */
|
|
14
|
+
contractorId: string;
|
|
15
|
+
/** Pre-fill form values. Server data (the current payment method) is used when no override is supplied. */
|
|
16
|
+
defaultValues?: Partial<ContractorPaymentMethodFormData>;
|
|
17
|
+
/** When validation runs. Passed through to react-hook-form. Defaults to `'onSubmit'`. */
|
|
18
|
+
validationMode?: UseFormProps['mode'];
|
|
19
|
+
/** Auto-focus the first invalid field on submit. Set to `false` when using `composeSubmitHandler`. Defaults to `true`. */
|
|
20
|
+
shouldFocusError?: boolean;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Field components exposed by {@link useContractorPaymentMethodForm} on `form.Fields`.
|
|
24
|
+
*
|
|
25
|
+
* @public
|
|
26
|
+
*/
|
|
27
|
+
export interface ContractorPaymentMethodFormFields {
|
|
28
|
+
/**
|
|
29
|
+
* Radio group bound to `type`. Selects whether the contractor is paid by
|
|
30
|
+
* Direct Deposit or Check. Supply `getOptionLabel` to translate the option
|
|
31
|
+
* labels.
|
|
32
|
+
*/
|
|
33
|
+
Type: ComponentType<TypeFieldProps>;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Ready-state return value of {@link useContractorPaymentMethodForm}.
|
|
37
|
+
*
|
|
38
|
+
* @public
|
|
39
|
+
*/
|
|
40
|
+
export interface UseContractorPaymentMethodFormReady extends BaseFormHookReady<FieldsMetadata, ContractorPaymentMethodFormData, ContractorPaymentMethodFormFields> {
|
|
41
|
+
/** The contractor's current payment method, loaded from the API. */
|
|
42
|
+
data: {
|
|
43
|
+
paymentMethod: ContractorPaymentMethod;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* `isPending` reflects the in-flight update mutation; `mode` is always
|
|
47
|
+
* `'update'`. `isDirectDeposit` reflects the currently selected type so a
|
|
48
|
+
* composing component can render bank fields and decide whether to submit the
|
|
49
|
+
* bank-account form.
|
|
50
|
+
*/
|
|
51
|
+
status: {
|
|
52
|
+
isPending: boolean;
|
|
53
|
+
mode: 'update';
|
|
54
|
+
isDirectDeposit: boolean;
|
|
55
|
+
};
|
|
56
|
+
/** Submit the form. Returns the updated payment method on success or `undefined` on validation/mutation failure. */
|
|
57
|
+
actions: {
|
|
58
|
+
onSubmit: () => Promise<HookSubmitResult<ContractorPaymentMethod> | undefined>;
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Headless React Hook Form hook for managing a contractor's payment method type.
|
|
63
|
+
*
|
|
64
|
+
* @remarks
|
|
65
|
+
* Owns only the payment method `type` selection (Direct Deposit or Check) and,
|
|
66
|
+
* on submit, updates the contractor's payment method via `PUT`. Always operates
|
|
67
|
+
* in update mode — every contractor has a payment method, defaulting to Check.
|
|
68
|
+
*
|
|
69
|
+
* The bank account itself is managed by the separate `useContractorBankAccountForm`
|
|
70
|
+
* hook. On the Direct Deposit path the bank-account `POST` updates the payment
|
|
71
|
+
* method as a server side-effect, so a composing component submits the bank form
|
|
72
|
+
* instead of this hook; this hook's `onSubmit` is used for the Check path.
|
|
73
|
+
* `status.isDirectDeposit` lets the component drive that branching.
|
|
74
|
+
*
|
|
75
|
+
* @param props - See {@link UseContractorPaymentMethodFormProps}.
|
|
76
|
+
* @returns A loading-state result while data loads, or a {@link UseContractorPaymentMethodFormReady} once ready.
|
|
77
|
+
* @public
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```tsx
|
|
81
|
+
* import { useContractorPaymentMethodForm, SDKFormProvider } from '@gusto/embedded-react-sdk'
|
|
82
|
+
*
|
|
83
|
+
* function PaymentTypeScreen({ contractorId }: { contractorId: string }) {
|
|
84
|
+
* const paymentMethod = useContractorPaymentMethodForm({ contractorId })
|
|
85
|
+
*
|
|
86
|
+
* if (paymentMethod.isLoading) return null
|
|
87
|
+
* const { Fields } = paymentMethod.form
|
|
88
|
+
*
|
|
89
|
+
* return (
|
|
90
|
+
* <SDKFormProvider formHookResult={paymentMethod}>
|
|
91
|
+
* <form
|
|
92
|
+
* onSubmit={e => {
|
|
93
|
+
* e.preventDefault()
|
|
94
|
+
* void paymentMethod.actions.onSubmit()
|
|
95
|
+
* }}
|
|
96
|
+
* >
|
|
97
|
+
* <Fields.Type label="Select payment method" />
|
|
98
|
+
* <button type="submit" disabled={paymentMethod.status.isPending}>Save</button>
|
|
99
|
+
* </form>
|
|
100
|
+
* </SDKFormProvider>
|
|
101
|
+
* )
|
|
102
|
+
* }
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
export declare function useContractorPaymentMethodForm({ contractorId, defaultValues: partnerDefaults, validationMode, shouldFocusError, }: UseContractorPaymentMethodFormProps): HookLoadingResult | UseContractorPaymentMethodFormReady;
|
|
106
|
+
/**
|
|
107
|
+
* Return type of {@link useContractorPaymentMethodForm} — a discriminated union on `isLoading`.
|
|
108
|
+
*
|
|
109
|
+
* @public
|
|
110
|
+
*/
|
|
111
|
+
export type UseContractorPaymentMethodFormResult = HookLoadingResult | UseContractorPaymentMethodFormReady;
|
|
112
|
+
/**
|
|
113
|
+
* Per-field metadata exposed on `form.fieldsMetadata` for {@link useContractorPaymentMethodForm}.
|
|
114
|
+
*
|
|
115
|
+
* @public
|
|
116
|
+
*/
|
|
117
|
+
export type ContractorPaymentMethodFieldsMetadata = UseContractorPaymentMethodFormReady['form']['fieldsMetadata'];
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { useMemo as l } from "react";
|
|
2
|
+
import { useForm as k, useWatch as A } from "react-hook-form";
|
|
3
|
+
import { zodResolver as L } from "@hookform/resolvers/zod";
|
|
4
|
+
import { useContractorPaymentMethodGet as R } from "@gusto/embedded-api-v-2025-11-15/react-query/contractorPaymentMethodGet";
|
|
5
|
+
import { useContractorPaymentMethodUpdateMutation as U } from "@gusto/embedded-api-v-2025-11-15/react-query/contractorPaymentMethodUpdate";
|
|
6
|
+
import { createContractorPaymentMethodSchema as Y, PAYMENT_METHOD_TYPES as f } from "./contractorPaymentMethodSchema.js";
|
|
7
|
+
import { TypeField as _ } from "./fields.js";
|
|
8
|
+
import { useDeriveFieldsMetadata as q } from "../../../../../partner-hook-utils/form/useDeriveFieldsMetadata.js";
|
|
9
|
+
import { useHookFormInternals as B } from "../../../../../partner-hook-utils/form/useHookFormInternals.js";
|
|
10
|
+
import { createGetFormSubmissionValues as G } from "../../../../../partner-hook-utils/form/getFormSubmissionValues.js";
|
|
11
|
+
import { withOptions as I } from "../../../../../partner-hook-utils/form/withOptions.js";
|
|
12
|
+
import { composeErrorHandler as N } from "../../../../../partner-hook-utils/composeErrorHandler.js";
|
|
13
|
+
import { useBaseSubmit as x } from "../../../../Base/useBaseSubmit.js";
|
|
14
|
+
import { SDKInternalError as h } from "../../../../../types/sdkError.js";
|
|
15
|
+
import { PAYMENT_METHODS as M } from "../../../../../shared/constants.js";
|
|
16
|
+
function mt({
|
|
17
|
+
contractorId: a,
|
|
18
|
+
defaultValues: n,
|
|
19
|
+
validationMode: P = "onSubmit",
|
|
20
|
+
shouldFocusError: b = !0
|
|
21
|
+
}) {
|
|
22
|
+
const r = R({ contractorUuid: a }), t = r.data?.contractorPaymentMethod, [s, S] = l(() => Y(), []), m = l(
|
|
23
|
+
() => ({
|
|
24
|
+
type: n?.type ?? t?.type ?? M.check
|
|
25
|
+
}),
|
|
26
|
+
[n, t]
|
|
27
|
+
), e = k({
|
|
28
|
+
resolver: L(s),
|
|
29
|
+
mode: P,
|
|
30
|
+
shouldFocusError: b,
|
|
31
|
+
defaultValues: m,
|
|
32
|
+
values: m,
|
|
33
|
+
resetOptions: { keepDirtyValues: !0 }
|
|
34
|
+
}), w = A({ control: e.control, name: "type" }) === M.directDeposit, i = U(), E = i.isPending, {
|
|
35
|
+
baseSubmitHandler: F,
|
|
36
|
+
error: T,
|
|
37
|
+
setError: g
|
|
38
|
+
} = x("ContractorPaymentMethodForm"), d = N([r], {
|
|
39
|
+
submitError: T,
|
|
40
|
+
setSubmitError: g
|
|
41
|
+
}), D = f.map((o) => ({ value: o, label: o })), c = q(S, e.control), C = {
|
|
42
|
+
...c,
|
|
43
|
+
type: I(c.type, D, [
|
|
44
|
+
...f
|
|
45
|
+
])
|
|
46
|
+
}, v = async () => {
|
|
47
|
+
if (!t)
|
|
48
|
+
throw new h("Cannot submit payment method form before data is loaded");
|
|
49
|
+
const o = t.version;
|
|
50
|
+
let u;
|
|
51
|
+
return await new Promise((p) => {
|
|
52
|
+
e.handleSubmit(
|
|
53
|
+
async (O) => {
|
|
54
|
+
await F(O, async (V) => {
|
|
55
|
+
const y = await i.mutateAsync({
|
|
56
|
+
request: {
|
|
57
|
+
contractorUuid: a,
|
|
58
|
+
requestBody: { type: V.type, version: o }
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
if (!y.contractorPaymentMethod)
|
|
62
|
+
throw new h("Payment method update failed");
|
|
63
|
+
u = { mode: "update", data: y.contractorPaymentMethod };
|
|
64
|
+
}), p();
|
|
65
|
+
},
|
|
66
|
+
() => {
|
|
67
|
+
p();
|
|
68
|
+
}
|
|
69
|
+
)();
|
|
70
|
+
}), u;
|
|
71
|
+
}, H = B(e);
|
|
72
|
+
return r.isLoading || !t ? { isLoading: !0, errorHandling: d } : {
|
|
73
|
+
isLoading: !1,
|
|
74
|
+
data: { paymentMethod: t },
|
|
75
|
+
status: { isPending: E, mode: "update", isDirectDeposit: w },
|
|
76
|
+
actions: { onSubmit: v },
|
|
77
|
+
errorHandling: d,
|
|
78
|
+
form: {
|
|
79
|
+
Fields: {
|
|
80
|
+
Type: _
|
|
81
|
+
},
|
|
82
|
+
fieldsMetadata: C,
|
|
83
|
+
hookFormInternals: H,
|
|
84
|
+
getFormSubmissionValues: G(e, s)
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
export {
|
|
89
|
+
mt as useContractorPaymentMethodForm
|
|
90
|
+
};
|
|
91
|
+
//# sourceMappingURL=useContractorPaymentMethodForm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useContractorPaymentMethodForm.js","sources":["../../../../../../src/components/Contractor/PaymentMethod/shared/useContractorPaymentMethodForm/useContractorPaymentMethodForm.tsx"],"sourcesContent":["import type { ComponentType } from 'react'\nimport { useMemo } from 'react'\nimport { useForm, useWatch } from 'react-hook-form'\nimport type { UseFormProps } from 'react-hook-form'\nimport { zodResolver } from '@hookform/resolvers/zod'\nimport type { ContractorPaymentMethod } from '@gusto/embedded-api-v-2025-11-15/models/components/contractorpaymentmethod'\nimport { useContractorPaymentMethodGet } from '@gusto/embedded-api-v-2025-11-15/react-query/contractorPaymentMethodGet'\nimport { useContractorPaymentMethodUpdateMutation } from '@gusto/embedded-api-v-2025-11-15/react-query/contractorPaymentMethodUpdate'\nimport {\n createContractorPaymentMethodSchema,\n type ContractorPaymentMethodFormData,\n type ContractorPaymentMethodFormOutputs,\n type ContractorPaymentMethodFormType,\n PAYMENT_METHOD_TYPES,\n} from './contractorPaymentMethodSchema'\nimport type { TypeFieldProps } from './fields'\nimport { TypeField } from './fields'\nimport { useDeriveFieldsMetadata } from '@/partner-hook-utils/form/useDeriveFieldsMetadata'\nimport { useHookFormInternals } from '@/partner-hook-utils/form/useHookFormInternals'\nimport { createGetFormSubmissionValues } from '@/partner-hook-utils/form/getFormSubmissionValues'\nimport { withOptions } from '@/partner-hook-utils/form/withOptions'\nimport { composeErrorHandler } from '@/partner-hook-utils/composeErrorHandler'\nimport type {\n BaseFormHookReady,\n FieldsMetadata,\n HookLoadingResult,\n HookSubmitResult,\n} from '@/partner-hook-utils/types'\nimport { useBaseSubmit } from '@/components/Base/useBaseSubmit'\nimport { SDKInternalError } from '@/types/sdkError'\nimport { PAYMENT_METHODS } from '@/shared/constants'\n\n/**\n * Props for {@link useContractorPaymentMethodForm}.\n *\n * @public\n */\nexport interface UseContractorPaymentMethodFormProps {\n /** Contractor whose payment method is being edited. */\n contractorId: string\n /** Pre-fill form values. Server data (the current payment method) is used when no override is supplied. */\n defaultValues?: Partial<ContractorPaymentMethodFormData>\n /** When validation runs. Passed through to react-hook-form. Defaults to `'onSubmit'`. */\n validationMode?: UseFormProps['mode']\n /** Auto-focus the first invalid field on submit. Set to `false` when using `composeSubmitHandler`. Defaults to `true`. */\n shouldFocusError?: boolean\n}\n\n/**\n * Field components exposed by {@link useContractorPaymentMethodForm} on `form.Fields`.\n *\n * @public\n */\nexport interface ContractorPaymentMethodFormFields {\n /**\n * Radio group bound to `type`. Selects whether the contractor is paid by\n * Direct Deposit or Check. Supply `getOptionLabel` to translate the option\n * labels.\n */\n Type: ComponentType<TypeFieldProps>\n}\n\n/**\n * Ready-state return value of {@link useContractorPaymentMethodForm}.\n *\n * @public\n */\nexport interface UseContractorPaymentMethodFormReady extends BaseFormHookReady<\n FieldsMetadata,\n ContractorPaymentMethodFormData,\n ContractorPaymentMethodFormFields\n> {\n /** The contractor's current payment method, loaded from the API. */\n data: {\n paymentMethod: ContractorPaymentMethod\n }\n /**\n * `isPending` reflects the in-flight update mutation; `mode` is always\n * `'update'`. `isDirectDeposit` reflects the currently selected type so a\n * composing component can render bank fields and decide whether to submit the\n * bank-account form.\n */\n status: { isPending: boolean; mode: 'update'; isDirectDeposit: boolean }\n /** Submit the form. Returns the updated payment method on success or `undefined` on validation/mutation failure. */\n actions: {\n onSubmit: () => Promise<HookSubmitResult<ContractorPaymentMethod> | undefined>\n }\n}\n\n/**\n * Headless React Hook Form hook for managing a contractor's payment method type.\n *\n * @remarks\n * Owns only the payment method `type` selection (Direct Deposit or Check) and,\n * on submit, updates the contractor's payment method via `PUT`. Always operates\n * in update mode — every contractor has a payment method, defaulting to Check.\n *\n * The bank account itself is managed by the separate `useContractorBankAccountForm`\n * hook. On the Direct Deposit path the bank-account `POST` updates the payment\n * method as a server side-effect, so a composing component submits the bank form\n * instead of this hook; this hook's `onSubmit` is used for the Check path.\n * `status.isDirectDeposit` lets the component drive that branching.\n *\n * @param props - See {@link UseContractorPaymentMethodFormProps}.\n * @returns A loading-state result while data loads, or a {@link UseContractorPaymentMethodFormReady} once ready.\n * @public\n *\n * @example\n * ```tsx\n * import { useContractorPaymentMethodForm, SDKFormProvider } from '@gusto/embedded-react-sdk'\n *\n * function PaymentTypeScreen({ contractorId }: { contractorId: string }) {\n * const paymentMethod = useContractorPaymentMethodForm({ contractorId })\n *\n * if (paymentMethod.isLoading) return null\n * const { Fields } = paymentMethod.form\n *\n * return (\n * <SDKFormProvider formHookResult={paymentMethod}>\n * <form\n * onSubmit={e => {\n * e.preventDefault()\n * void paymentMethod.actions.onSubmit()\n * }}\n * >\n * <Fields.Type label=\"Select payment method\" />\n * <button type=\"submit\" disabled={paymentMethod.status.isPending}>Save</button>\n * </form>\n * </SDKFormProvider>\n * )\n * }\n * ```\n */\nexport function useContractorPaymentMethodForm({\n contractorId,\n defaultValues: partnerDefaults,\n validationMode = 'onSubmit',\n shouldFocusError = true,\n}: UseContractorPaymentMethodFormProps): HookLoadingResult | UseContractorPaymentMethodFormReady {\n const paymentMethodQuery = useContractorPaymentMethodGet({ contractorUuid: contractorId })\n const paymentMethod = paymentMethodQuery.data?.contractorPaymentMethod\n\n const [schema, metadataConfig] = useMemo(() => createContractorPaymentMethodSchema(), [])\n\n const resolvedDefaults: ContractorPaymentMethodFormData = useMemo(\n () => ({\n type: (partnerDefaults?.type ??\n paymentMethod?.type ??\n PAYMENT_METHODS.check) as ContractorPaymentMethodFormType,\n }),\n [partnerDefaults, paymentMethod],\n )\n\n const formMethods = useForm<\n ContractorPaymentMethodFormData,\n unknown,\n ContractorPaymentMethodFormOutputs\n >({\n resolver: zodResolver(schema),\n mode: validationMode,\n shouldFocusError,\n defaultValues: resolvedDefaults,\n values: resolvedDefaults,\n resetOptions: { keepDirtyValues: true },\n })\n\n const watchedType = useWatch({ control: formMethods.control, name: 'type' })\n const isDirectDeposit = watchedType === PAYMENT_METHODS.directDeposit\n\n const updatePaymentMethodMutation = useContractorPaymentMethodUpdateMutation()\n const isPending = updatePaymentMethodMutation.isPending\n\n const {\n baseSubmitHandler,\n error: submitError,\n setError: setSubmitError,\n } = useBaseSubmit('ContractorPaymentMethodForm')\n\n const errorHandling = composeErrorHandler([paymentMethodQuery], {\n submitError,\n setSubmitError,\n })\n\n const typeOptions = PAYMENT_METHOD_TYPES.map(value => ({ value, label: value }))\n\n const baseMetadata = useDeriveFieldsMetadata(metadataConfig, formMethods.control)\n const fieldsMetadata = {\n ...baseMetadata,\n type: withOptions<ContractorPaymentMethodFormType>(baseMetadata.type, typeOptions, [\n ...PAYMENT_METHOD_TYPES,\n ]),\n }\n\n const onSubmit = async (): Promise<HookSubmitResult<ContractorPaymentMethod> | undefined> => {\n if (!paymentMethod) {\n throw new SDKInternalError('Cannot submit payment method form before data is loaded')\n }\n const version = paymentMethod.version as string\n let submitResult: HookSubmitResult<ContractorPaymentMethod> | undefined\n\n await new Promise<void>(resolve => {\n void formMethods.handleSubmit(\n async (data: ContractorPaymentMethodFormOutputs) => {\n await baseSubmitHandler(data, async payload => {\n const updateResponse = await updatePaymentMethodMutation.mutateAsync({\n request: {\n contractorUuid: contractorId,\n requestBody: { type: payload.type, version },\n },\n })\n\n if (!updateResponse.contractorPaymentMethod) {\n throw new SDKInternalError('Payment method update failed')\n }\n\n submitResult = { mode: 'update' as const, data: updateResponse.contractorPaymentMethod }\n })\n resolve()\n },\n () => {\n resolve()\n },\n )()\n })\n\n return submitResult\n }\n\n const hookFormInternals = useHookFormInternals(formMethods)\n\n if (paymentMethodQuery.isLoading || !paymentMethod) {\n return { isLoading: true as const, errorHandling }\n }\n\n return {\n isLoading: false as const,\n data: { paymentMethod },\n status: { isPending, mode: 'update' as const, isDirectDeposit },\n actions: { onSubmit },\n errorHandling,\n form: {\n Fields: {\n Type: TypeField,\n },\n fieldsMetadata,\n hookFormInternals,\n getFormSubmissionValues: createGetFormSubmissionValues(formMethods, schema),\n },\n }\n}\n\n/**\n * Return type of {@link useContractorPaymentMethodForm} — a discriminated union on `isLoading`.\n *\n * @public\n */\nexport type UseContractorPaymentMethodFormResult =\n HookLoadingResult | UseContractorPaymentMethodFormReady\n\n/**\n * Per-field metadata exposed on `form.fieldsMetadata` for {@link useContractorPaymentMethodForm}.\n *\n * @public\n */\nexport type ContractorPaymentMethodFieldsMetadata =\n UseContractorPaymentMethodFormReady['form']['fieldsMetadata']\n"],"names":["useContractorPaymentMethodForm","contractorId","partnerDefaults","validationMode","shouldFocusError","paymentMethodQuery","useContractorPaymentMethodGet","paymentMethod","schema","metadataConfig","useMemo","createContractorPaymentMethodSchema","resolvedDefaults","PAYMENT_METHODS","formMethods","useForm","zodResolver","isDirectDeposit","useWatch","updatePaymentMethodMutation","useContractorPaymentMethodUpdateMutation","isPending","baseSubmitHandler","submitError","setSubmitError","useBaseSubmit","errorHandling","composeErrorHandler","typeOptions","PAYMENT_METHOD_TYPES","value","baseMetadata","useDeriveFieldsMetadata","fieldsMetadata","withOptions","onSubmit","SDKInternalError","version","submitResult","resolve","data","payload","updateResponse","hookFormInternals","useHookFormInternals","TypeField","createGetFormSubmissionValues"],"mappings":";;;;;;;;;;;;;;;AAqIO,SAASA,GAA+B;AAAA,EAC7C,cAAAC;AAAA,EACA,eAAeC;AAAA,EACf,gBAAAC,IAAiB;AAAA,EACjB,kBAAAC,IAAmB;AACrB,GAAiG;AAC/F,QAAMC,IAAqBC,EAA8B,EAAE,gBAAgBL,GAAc,GACnFM,IAAgBF,EAAmB,MAAM,yBAEzC,CAACG,GAAQC,CAAc,IAAIC,EAAQ,MAAMC,EAAA,GAAuC,EAAE,GAElFC,IAAoDF;AAAA,IACxD,OAAO;AAAA,MACL,MAAOR,GAAiB,QACtBK,GAAe,QACfM,EAAgB;AAAA,IAAA;AAAA,IAEpB,CAACX,GAAiBK,CAAa;AAAA,EAAA,GAG3BO,IAAcC,EAIlB;AAAA,IACA,UAAUC,EAAYR,CAAM;AAAA,IAC5B,MAAML;AAAA,IACN,kBAAAC;AAAA,IACA,eAAeQ;AAAA,IACf,QAAQA;AAAA,IACR,cAAc,EAAE,iBAAiB,GAAA;AAAA,EAAK,CACvC,GAGKK,IADcC,EAAS,EAAE,SAASJ,EAAY,SAAS,MAAM,QAAQ,MACnCD,EAAgB,eAElDM,IAA8BC,EAAA,GAC9BC,IAAYF,EAA4B,WAExC;AAAA,IACJ,mBAAAG;AAAA,IACA,OAAOC;AAAA,IACP,UAAUC;AAAA,EAAA,IACRC,EAAc,6BAA6B,GAEzCC,IAAgBC,EAAoB,CAACtB,CAAkB,GAAG;AAAA,IAC9D,aAAAkB;AAAA,IACA,gBAAAC;AAAA,EAAA,CACD,GAEKI,IAAcC,EAAqB,IAAI,CAAAC,OAAU,EAAE,OAAAA,GAAO,OAAOA,IAAQ,GAEzEC,IAAeC,EAAwBvB,GAAgBK,EAAY,OAAO,GAC1EmB,IAAiB;AAAA,IACrB,GAAGF;AAAA,IACH,MAAMG,EAA6CH,EAAa,MAAMH,GAAa;AAAA,MACjF,GAAGC;AAAA,IAAA,CACJ;AAAA,EAAA,GAGGM,IAAW,YAA4E;AAC3F,QAAI,CAAC5B;AACH,YAAM,IAAI6B,EAAiB,yDAAyD;AAEtF,UAAMC,IAAU9B,EAAc;AAC9B,QAAI+B;AAEJ,iBAAM,IAAI,QAAc,CAAAC,MAAW;AACjC,MAAKzB,EAAY;AAAA,QACf,OAAO0B,MAA6C;AAClD,gBAAMlB,EAAkBkB,GAAM,OAAMC,MAAW;AAC7C,kBAAMC,IAAiB,MAAMvB,EAA4B,YAAY;AAAA,cACnE,SAAS;AAAA,gBACP,gBAAgBlB;AAAA,gBAChB,aAAa,EAAE,MAAMwC,EAAQ,MAAM,SAAAJ,EAAA;AAAA,cAAQ;AAAA,YAC7C,CACD;AAED,gBAAI,CAACK,EAAe;AAClB,oBAAM,IAAIN,EAAiB,8BAA8B;AAG3D,YAAAE,IAAe,EAAE,MAAM,UAAmB,MAAMI,EAAe,wBAAA;AAAA,UACjE,CAAC,GACDH,EAAA;AAAA,QACF;AAAA,QACA,MAAM;AACJ,UAAAA,EAAA;AAAA,QACF;AAAA,MAAA,EACF;AAAA,IACF,CAAC,GAEMD;AAAA,EACT,GAEMK,IAAoBC,EAAqB9B,CAAW;AAE1D,SAAIT,EAAmB,aAAa,CAACE,IAC5B,EAAE,WAAW,IAAe,eAAAmB,EAAA,IAG9B;AAAA,IACL,WAAW;AAAA,IACX,MAAM,EAAE,eAAAnB,EAAA;AAAA,IACR,QAAQ,EAAE,WAAAc,GAAW,MAAM,UAAmB,iBAAAJ,EAAA;AAAA,IAC9C,SAAS,EAAE,UAAAkB,EAAA;AAAA,IACX,eAAAT;AAAA,IACA,MAAM;AAAA,MACJ,QAAQ;AAAA,QACN,MAAMmB;AAAA,MAAA;AAAA,MAER,gBAAAZ;AAAA,MACA,mBAAAU;AAAA,MACA,yBAAyBG,EAA8BhC,GAAaN,CAAM;AAAA,IAAA;AAAA,EAC5E;AAEJ;"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { ContractorBankAccount } from '@gusto/embedded-api-v-2025-11-15/models/components/contractorbankaccount';
|
|
2
1
|
import { BaseComponentInterface } from '../../Base';
|
|
3
2
|
/**
|
|
4
3
|
* Props for the {@link PaymentMethod} component.
|
|
@@ -9,7 +8,3 @@ export interface PaymentMethodProps extends BaseComponentInterface<'Contractor.P
|
|
|
9
8
|
/** Identifier of the contractor whose payment method is being managed. */
|
|
10
9
|
contractorId: string;
|
|
11
10
|
}
|
|
12
|
-
/** @internal */
|
|
13
|
-
export interface BankAccountFormProps {
|
|
14
|
-
bankAccount?: ContractorBankAccount;
|
|
15
|
-
}
|
|
@@ -3,9 +3,9 @@ import { PaymentFlowProps } from './PaymentFlowComponents';
|
|
|
3
3
|
* Hub for creating and managing contractor payments for a company.
|
|
4
4
|
*
|
|
5
5
|
* @remarks
|
|
6
|
-
* Composes the contractor payment
|
|
6
|
+
* Composes the contractor payment blocks into a complete experience with breadcrumb navigation between the payments list, the create-payment form, the post-creation summary, the payment-history detail view, and individual contractor payment statements. Also routes into the information-requests flow when a payment-related request needs a response, and surfaces wire-transfer confirmation alerts after a wire details submission.
|
|
7
7
|
*
|
|
8
|
-
* Events emitted by the
|
|
8
|
+
* Events emitted by the blocks bubble up through the single `onEvent` handler.
|
|
9
9
|
*
|
|
10
10
|
* @events
|
|
11
11
|
* | Event | Description | Data |
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PaymentFlow.js","sources":["../../../../../src/components/Contractor/Payments/PaymentFlow/PaymentFlow.tsx"],"sourcesContent":["import { createMachine } from 'robot3'\nimport { useMemo } from 'react'\nimport { paymentFlowBreadcrumbsNodes, paymentMachine } from './paymentStateMachine'\nimport {\n PaymentListContextual,\n type PaymentFlowContextInterface,\n type PaymentFlowProps,\n} from './PaymentFlowComponents'\nimport { Flow } from '@/components/Flow/Flow'\nimport { buildBreadcrumbs } from '@/helpers/breadcrumbHelpers'\n\n/**\n * Hub for creating and managing contractor payments for a company.\n *\n * @remarks\n * Composes the contractor payment
|
|
1
|
+
{"version":3,"file":"PaymentFlow.js","sources":["../../../../../src/components/Contractor/Payments/PaymentFlow/PaymentFlow.tsx"],"sourcesContent":["import { createMachine } from 'robot3'\nimport { useMemo } from 'react'\nimport { paymentFlowBreadcrumbsNodes, paymentMachine } from './paymentStateMachine'\nimport {\n PaymentListContextual,\n type PaymentFlowContextInterface,\n type PaymentFlowProps,\n} from './PaymentFlowComponents'\nimport { Flow } from '@/components/Flow/Flow'\nimport { buildBreadcrumbs } from '@/helpers/breadcrumbHelpers'\n\n/**\n * Hub for creating and managing contractor payments for a company.\n *\n * @remarks\n * Composes the contractor payment blocks into a complete experience with breadcrumb navigation between the payments list, the create-payment form, the post-creation summary, the payment-history detail view, and individual contractor payment statements. Also routes into the information-requests flow when a payment-related request needs a response, and surfaces wire-transfer confirmation alerts after a wire details submission.\n *\n * Events emitted by the blocks bubble up through the single `onEvent` handler.\n *\n * @events\n * | Event | Description | Data |\n * | ----- | ----------- | ---- |\n * | `contractor/payments/create` | Fired when the user chooses to create a new payment | — |\n * | `contractor/payments/created` | Fired when a payment group is successfully created | The created `ContractorPaymentGroup` |\n * | `contractor/payments/view` | Fired when the user selects a payment group to view | `{ paymentId: string }` |\n * | `contractor/payments/view/details` | Fired when the user views a specific contractor payment | `{ contractor: Contractor, paymentGroupId: string }` |\n * | `contractor/payments/cancel` | Fired when a payment is cancelled | `{ paymentId: string }` |\n * | `contractor/payments/exit` | Fired when the user completes the payment flow | `{ uuid?: string | null }` |\n * | `contractor/payments/rfi/respond` | Fired when the user clicks to respond to a pending information request | — |\n * | `payroll/wire/form/done` | Fired when wire transfer details are submitted | `{ wireInRequest: WireInRequest, confirmationAlert: { title: string, content?: string } }` |\n * | `informationRequest/form/done` | Fired when the information-requests flow completes | — |\n * | `informationRequest/form/cancel` | Fired when the information-requests flow is cancelled | — |\n * | `breadcrumb/navigate` | Fired when the user clicks a breadcrumb to navigate back | `{ key: string, onNavigate: (ctx) => ctx }` |\n *\n * @components\n * - {@link PaymentsList}\n * - {@link CreatePayment}\n * - {@link PaymentSummary}\n * - {@link PaymentHistory}\n * - {@link PaymentStatement}\n * - {@link InformationRequests.InformationRequestsFlow | InformationRequestsFlow}\n *\n * @param props - See {@link PaymentFlowProps}.\n * @returns The multi-step contractor payments workflow.\n * @public\n *\n * @example\n * ```tsx title=\"App.tsx\"\n * import { ContractorManagement } from '@gusto/embedded-react-sdk'\n *\n * function MyApp() {\n * return (\n * <ContractorManagement.PaymentFlow\n * companyId=\"a007e1ab-3595-43c2-ab4b-af7a5af2e365\"\n * onEvent={() => {}}\n * />\n * )\n * }\n * ```\n */\nexport const PaymentFlow = ({ companyId, onEvent }: PaymentFlowProps) => {\n const paymentFlow = useMemo(\n () =>\n createMachine('landing', paymentMachine, (initialContext: PaymentFlowContextInterface) => ({\n ...initialContext,\n component: PaymentListContextual,\n companyId,\n header: {\n type: 'breadcrumbs' as const,\n breadcrumbs: buildBreadcrumbs(paymentFlowBreadcrumbsNodes),\n },\n })),\n [companyId],\n )\n return <Flow machine={paymentFlow} onEvent={onEvent} />\n}\n"],"names":["PaymentFlow","companyId","onEvent","paymentFlow","useMemo","createMachine","paymentMachine","initialContext","PaymentListContextual","buildBreadcrumbs","paymentFlowBreadcrumbsNodes","jsx","Flow"],"mappings":";;;;;;;AA4DO,MAAMA,IAAc,CAAC,EAAE,WAAAC,GAAW,SAAAC,QAAgC;AACvE,QAAMC,IAAcC;AAAA,IAClB,MACEC,EAAc,WAAWC,GAAgB,CAACC,OAAiD;AAAA,MACzF,GAAGA;AAAA,MACH,WAAWC;AAAA,MACX,WAAAP;AAAA,MACA,QAAQ;AAAA,QACN,MAAM;AAAA,QACN,aAAaQ,EAAiBC,CAA2B;AAAA,MAAA;AAAA,IAC3D,EACA;AAAA,IACJ,CAACT,CAAS;AAAA,EAAA;AAEZ,SAAO,gBAAAU,EAACC,GAAA,EAAK,SAAST,GAAa,SAAAD,EAAA,CAAkB;AACvD;"}
|
|
@@ -65,6 +65,7 @@ declare const fieldValidators: {
|
|
|
65
65
|
* Shape of the values managed by the contractor details form.
|
|
66
66
|
*
|
|
67
67
|
* @public
|
|
68
|
+
* @interface
|
|
68
69
|
*/
|
|
69
70
|
export type ContractorDetailsFormData = { type: "Business" | "Individual"; wageType: "Fixed" | "Hourly"; startDate: string; hourlyRate: number; selfOnboarding: boolean; fileNewHireReport: boolean; email: string; firstName: string; lastName: string; middleInitial: string; businessName: string; workState: string; ssn: string; ein: string; };
|
|
70
71
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contractorDetailsSchema.js","sources":["../../../../../../src/components/Contractor/Profile/shared/useContractorDetailsForm/contractorDetailsSchema.ts"],"sourcesContent":["import { z } from 'zod'\nimport {\n WageType as ApiWageType,\n ContractorType as ApiContractorType,\n} from '@gusto/embedded-api-v-2025-11-15/models/components/contractor'\nimport {\n buildFormSchema,\n type RequiredFieldConfig,\n type OptionalFieldsToRequire,\n} from '@/partner-hook-utils/form/buildFormSchema'\nimport { coerceNaN, coerceToISODate } from '@/partner-hook-utils/form/preprocessors'\nimport { SSN_REGEX, NAME_REGEX } from '@/helpers/validations'\nimport { normalizeEin } from '@/helpers/federalEin'\n\n/**\n * Contractor type enum (`Individual` / `Business`) re-exported from the API model.\n *\n * @public\n */\nexport const ContractorType = ApiContractorType\n/**\n * Contractor wage type enum (`Fixed` / `Hourly`) re-exported from the API model.\n *\n * @public\n */\nexport const WageType = ApiWageType\n\n// ── Error codes ────────────────────────────────────────────────────────\n\n/**\n * Validation error codes emitted by the contractor details form schema. Map\n * these codes to localized copy in `validationMessages` when composing the\n * hook.\n *\n * @public\n */\nexport const ContractorDetailsErrorCodes = {\n REQUIRED: 'REQUIRED',\n INVALID_NAME: 'INVALID_NAME',\n INVALID_EMAIL: 'INVALID_EMAIL',\n INVALID_SSN: 'INVALID_SSN',\n INVALID_EIN: 'INVALID_EIN',\n} as const\n\n/**\n * Union of validation error code strings emitted by the contractor details\n * form schema.\n *\n * @public\n */\nexport type ContractorDetailsErrorCode =\n (typeof ContractorDetailsErrorCodes)[keyof typeof ContractorDetailsErrorCodes]\n\nconst EIN_FORMAT_REGEX = /^\\d{2}-\\d{7}$/\n\n// ── Field validators ───────────────────────────────────────────────────\n\nconst fieldValidators = {\n type: z.enum([ContractorType.Individual, ContractorType.Business]),\n wageType: z.enum([WageType.Hourly, WageType.Fixed]),\n startDate: z.preprocess(\n coerceToISODate,\n z.iso.date({ error: () => ContractorDetailsErrorCodes.REQUIRED }),\n ),\n hourlyRate: z.preprocess(coerceNaN(0), z.number().min(0)),\n selfOnboarding: z.boolean(),\n fileNewHireReport: z.boolean(),\n email: z.email({ error: () => ContractorDetailsErrorCodes.INVALID_EMAIL }),\n firstName: z\n .string()\n .min(1, { message: ContractorDetailsErrorCodes.REQUIRED })\n .regex(NAME_REGEX, { message: ContractorDetailsErrorCodes.INVALID_NAME }),\n lastName: z\n .string()\n .min(1, { message: ContractorDetailsErrorCodes.REQUIRED })\n .regex(NAME_REGEX, { message: ContractorDetailsErrorCodes.INVALID_NAME }),\n middleInitial: z.string(),\n businessName: z.string(),\n workState: z.string(),\n ssn: z\n .string({ error: () => ContractorDetailsErrorCodes.REQUIRED })\n .refine((v: string) => SSN_REGEX.test(v.replace(/\\D/g, '')), {\n message: ContractorDetailsErrorCodes.INVALID_SSN,\n }),\n ein: z\n .string({ error: () => ContractorDetailsErrorCodes.REQUIRED })\n .refine((v: string) => EIN_FORMAT_REGEX.test(normalizeEin(v)), {\n message: ContractorDetailsErrorCodes.INVALID_EIN,\n }),\n}\n\n/**\n * Shape of the values managed by the contractor details form.\n *\n * @public\n */\nexport type ContractorDetailsFormData = {\n [K in keyof typeof fieldValidators]: z.infer<(typeof fieldValidators)[K]>\n}\n\n/**\n * Shape of the validated values produced by the contractor details form on\n * submit.\n *\n * @public\n */\nexport type ContractorDetailsFormOutputs = ContractorDetailsFormData\n\n// ── Required fields config ─────────────────────────────────────────────\n//\n// Requiredness mirrors the contractor create/update API contract: fields the\n// API requires on create are `'create'` (optional on update), and fields the\n// API treats as optional are `'never'`. Type/wage *applicability* (does a field\n// apply to this contractor at all?) is handled separately by `excludeFields` —\n// see `getExcludedContractorFields` — not by requiredness. SSN/EIN are never\n// gated by `selfOnboarding`: each consumer decides whether to render and require\n// them (admins hide them when inviting; self-onboarding profiles collect them).\n//\n// `email` is the one genuinely value-conditional rule: it always applies but is\n// only required when self-onboarding is on (create and update, matching the\n// API's \"if self_onboarding is true, then email is required\"). A single-operand\n// predicate keeps `buildFormSchema`'s dependency-detecting Proxy accurate.\n\nconst requiredFieldsConfig = {\n startDate: 'create',\n firstName: 'create',\n lastName: 'create',\n businessName: 'create',\n hourlyRate: 'create',\n workState: 'create',\n middleInitial: 'never',\n ssn: 'never',\n ein: 'never',\n email: data => data.selfOnboarding,\n} satisfies RequiredFieldConfig<typeof fieldValidators>\n\n// ── Schema factory ─────────────────────────────────────────────────────\n\n/**\n * Keys of optional contractor details fields that can be promoted to required\n * via the hook's `optionalFieldsToRequire` option.\n *\n * @public\n */\nexport type ContractorDetailsOptionalFieldsToRequire = OptionalFieldsToRequire<\n typeof requiredFieldsConfig\n>\n\n/** @internal */\ninterface ContractorDetailsSchemaOptions {\n mode?: 'create' | 'update'\n optionalFieldsToRequire?: ContractorDetailsOptionalFieldsToRequire\n hasSsn?: boolean\n hasEin?: boolean\n}\n\n/** @internal */\nexport function createContractorDetailsSchema(options: ContractorDetailsSchemaOptions = {}) {\n const { mode = 'create', optionalFieldsToRequire, hasSsn = false, hasEin = false } = options\n\n const fieldsWithRedactedValues: Array<keyof typeof fieldValidators> = []\n if (hasSsn) fieldsWithRedactedValues.push('ssn')\n if (hasEin) fieldsWithRedactedValues.push('ein')\n\n return buildFormSchema(fieldValidators, {\n requiredFieldsConfig,\n requiredErrorCode: ContractorDetailsErrorCodes.REQUIRED,\n mode,\n optionalFieldsToRequire,\n fieldsWithRedactedValues,\n // Applicability gating: evaluated per-validation so a field's required\n // check is skipped while it doesn't apply to the current selection. The\n // field stays in the schema (validated as optional), keeping requiredness\n // static and fully promotable via `optionalFieldsToRequire`.\n excludeFields: getExcludedContractorFields,\n })\n}\n\n/** @internal */\nexport type ContractorDiscriminators = Partial<\n Pick<ContractorDetailsFormData, 'type' | 'wageType' | 'fileNewHireReport'>\n>\n\n/**\n * Fields that don't apply to the given contractor selection. Their required\n * check is skipped at validation time and they're never rendered. `email` is\n * never excluded — it always applies and its requiredness is governed by the\n * `selfOnboarding` predicate.\n *\n * @internal\n */\nexport function getExcludedContractorFields(\n values: ContractorDiscriminators,\n): Array<keyof typeof fieldValidators> {\n const isIndividual = values.type === ContractorType.Individual\n const excluded: Array<keyof typeof fieldValidators> = []\n\n if (values.wageType !== WageType.Hourly) excluded.push('hourlyRate')\n\n if (isIndividual) {\n excluded.push('businessName', 'ein')\n if (!values.fileNewHireReport) excluded.push('workState')\n } else {\n excluded.push('firstName', 'lastName', 'middleInitial', 'fileNewHireReport', 'ssn', 'workState')\n }\n\n return excluded\n}\n"],"names":["ContractorType","ApiContractorType","WageType","ApiWageType","ContractorDetailsErrorCodes","EIN_FORMAT_REGEX","fieldValidators","z","coerceToISODate","coerceNaN","NAME_REGEX","v","SSN_REGEX","normalizeEin","requiredFieldsConfig","data","createContractorDetailsSchema","options","mode","optionalFieldsToRequire","hasSsn","hasEin","fieldsWithRedactedValues","buildFormSchema","getExcludedContractorFields","values","isIndividual","excluded"],"mappings":";;;;;;AAmBO,MAAMA,IAAiBC,GAMjBC,IAAWC,GAWXC,IAA8B;AAAA,EACzC,UAAU;AAAA,EACV,cAAc;AAAA,EACd,eAAe;AAAA,EACf,aAAa;AAAA,EACb,aAAa;AACf,GAWMC,IAAmB,iBAInBC,IAAkB;AAAA,EACtB,MAAMC,EAAE,KAAK,CAACP,EAAe,YAAYA,EAAe,QAAQ,CAAC;AAAA,EACjE,UAAUO,EAAE,KAAK,CAACL,EAAS,QAAQA,EAAS,KAAK,CAAC;AAAA,EAClD,WAAWK,EAAE;AAAA,IACXC;AAAA,IACAD,EAAE,IAAI,KAAK,EAAE,OAAO,MAAMH,EAA4B,UAAU;AAAA,EAAA;AAAA,EAElE,YAAYG,EAAE,WAAWE,EAAU,CAAC,GAAGF,EAAE,OAAA,EAAS,IAAI,CAAC,CAAC;AAAA,EACxD,gBAAgBA,EAAE,QAAA;AAAA,EAClB,mBAAmBA,EAAE,QAAA;AAAA,EACrB,OAAOA,EAAE,MAAM,EAAE,OAAO,MAAMH,EAA4B,eAAe;AAAA,EACzE,WAAWG,EACR,OAAA,EACA,IAAI,GAAG,EAAE,SAASH,EAA4B,SAAA,CAAU,EACxD,MAAMM,GAAY,EAAE,SAASN,EAA4B,cAAc;AAAA,EAC1E,UAAUG,EACP,OAAA,EACA,IAAI,GAAG,EAAE,SAASH,EAA4B,SAAA,CAAU,EACxD,MAAMM,GAAY,EAAE,SAASN,EAA4B,cAAc;AAAA,EAC1E,eAAeG,EAAE,OAAA;AAAA,EACjB,cAAcA,EAAE,OAAA;AAAA,EAChB,WAAWA,EAAE,OAAA;AAAA,EACb,KAAKA,EACF,OAAO,EAAE,OAAO,MAAMH,EAA4B,UAAU,EAC5D,OAAO,CAACO,MAAcC,EAAU,KAAKD,EAAE,QAAQ,OAAO,EAAE,CAAC,GAAG;AAAA,IAC3D,SAASP,EAA4B;AAAA,EAAA,CACtC;AAAA,EACH,KAAKG,EACF,OAAO,EAAE,OAAO,MAAMH,EAA4B,SAAA,CAAU,EAC5D,OAAO,CAACO,MAAcN,EAAiB,KAAKQ,EAAaF,CAAC,CAAC,GAAG;AAAA,IAC7D,SAASP,EAA4B;AAAA,EAAA,CACtC;AACL,
|
|
1
|
+
{"version":3,"file":"contractorDetailsSchema.js","sources":["../../../../../../src/components/Contractor/Profile/shared/useContractorDetailsForm/contractorDetailsSchema.ts"],"sourcesContent":["import { z } from 'zod'\nimport {\n WageType as ApiWageType,\n ContractorType as ApiContractorType,\n} from '@gusto/embedded-api-v-2025-11-15/models/components/contractor'\nimport {\n buildFormSchema,\n type RequiredFieldConfig,\n type OptionalFieldsToRequire,\n} from '@/partner-hook-utils/form/buildFormSchema'\nimport { coerceNaN, coerceToISODate } from '@/partner-hook-utils/form/preprocessors'\nimport { SSN_REGEX, NAME_REGEX } from '@/helpers/validations'\nimport { normalizeEin } from '@/helpers/federalEin'\n\n/**\n * Contractor type enum (`Individual` / `Business`) re-exported from the API model.\n *\n * @public\n */\nexport const ContractorType = ApiContractorType\n/**\n * Contractor wage type enum (`Fixed` / `Hourly`) re-exported from the API model.\n *\n * @public\n */\nexport const WageType = ApiWageType\n\n// ── Error codes ────────────────────────────────────────────────────────\n\n/**\n * Validation error codes emitted by the contractor details form schema. Map\n * these codes to localized copy in `validationMessages` when composing the\n * hook.\n *\n * @public\n */\nexport const ContractorDetailsErrorCodes = {\n REQUIRED: 'REQUIRED',\n INVALID_NAME: 'INVALID_NAME',\n INVALID_EMAIL: 'INVALID_EMAIL',\n INVALID_SSN: 'INVALID_SSN',\n INVALID_EIN: 'INVALID_EIN',\n} as const\n\n/**\n * Union of validation error code strings emitted by the contractor details\n * form schema.\n *\n * @public\n */\nexport type ContractorDetailsErrorCode =\n (typeof ContractorDetailsErrorCodes)[keyof typeof ContractorDetailsErrorCodes]\n\nconst EIN_FORMAT_REGEX = /^\\d{2}-\\d{7}$/\n\n// ── Field validators ───────────────────────────────────────────────────\n\nconst fieldValidators = {\n type: z.enum([ContractorType.Individual, ContractorType.Business]),\n wageType: z.enum([WageType.Hourly, WageType.Fixed]),\n startDate: z.preprocess(\n coerceToISODate,\n z.iso.date({ error: () => ContractorDetailsErrorCodes.REQUIRED }),\n ),\n hourlyRate: z.preprocess(coerceNaN(0), z.number().min(0)),\n selfOnboarding: z.boolean(),\n fileNewHireReport: z.boolean(),\n email: z.email({ error: () => ContractorDetailsErrorCodes.INVALID_EMAIL }),\n firstName: z\n .string()\n .min(1, { message: ContractorDetailsErrorCodes.REQUIRED })\n .regex(NAME_REGEX, { message: ContractorDetailsErrorCodes.INVALID_NAME }),\n lastName: z\n .string()\n .min(1, { message: ContractorDetailsErrorCodes.REQUIRED })\n .regex(NAME_REGEX, { message: ContractorDetailsErrorCodes.INVALID_NAME }),\n middleInitial: z.string(),\n businessName: z.string(),\n workState: z.string(),\n ssn: z\n .string({ error: () => ContractorDetailsErrorCodes.REQUIRED })\n .refine((v: string) => SSN_REGEX.test(v.replace(/\\D/g, '')), {\n message: ContractorDetailsErrorCodes.INVALID_SSN,\n }),\n ein: z\n .string({ error: () => ContractorDetailsErrorCodes.REQUIRED })\n .refine((v: string) => EIN_FORMAT_REGEX.test(normalizeEin(v)), {\n message: ContractorDetailsErrorCodes.INVALID_EIN,\n }),\n}\n\n/**\n * Shape of the values managed by the contractor details form.\n *\n * @public\n * @interface\n */\nexport type ContractorDetailsFormData = {\n [K in keyof typeof fieldValidators]: z.infer<(typeof fieldValidators)[K]>\n}\n\n/**\n * Shape of the validated values produced by the contractor details form on\n * submit.\n *\n * @public\n */\nexport type ContractorDetailsFormOutputs = ContractorDetailsFormData\n\n// ── Required fields config ─────────────────────────────────────────────\n//\n// Requiredness mirrors the contractor create/update API contract: fields the\n// API requires on create are `'create'` (optional on update), and fields the\n// API treats as optional are `'never'`. Type/wage *applicability* (does a field\n// apply to this contractor at all?) is handled separately by `excludeFields` —\n// see `getExcludedContractorFields` — not by requiredness. SSN/EIN are never\n// gated by `selfOnboarding`: each consumer decides whether to render and require\n// them (admins hide them when inviting; self-onboarding profiles collect them).\n//\n// `email` is the one genuinely value-conditional rule: it always applies but is\n// only required when self-onboarding is on (create and update, matching the\n// API's \"if self_onboarding is true, then email is required\"). A single-operand\n// predicate keeps `buildFormSchema`'s dependency-detecting Proxy accurate.\n\nconst requiredFieldsConfig = {\n startDate: 'create',\n firstName: 'create',\n lastName: 'create',\n businessName: 'create',\n hourlyRate: 'create',\n workState: 'create',\n middleInitial: 'never',\n ssn: 'never',\n ein: 'never',\n email: data => data.selfOnboarding,\n} satisfies RequiredFieldConfig<typeof fieldValidators>\n\n// ── Schema factory ─────────────────────────────────────────────────────\n\n/**\n * Keys of optional contractor details fields that can be promoted to required\n * via the hook's `optionalFieldsToRequire` option.\n *\n * @public\n */\nexport type ContractorDetailsOptionalFieldsToRequire = OptionalFieldsToRequire<\n typeof requiredFieldsConfig\n>\n\n/** @internal */\ninterface ContractorDetailsSchemaOptions {\n mode?: 'create' | 'update'\n optionalFieldsToRequire?: ContractorDetailsOptionalFieldsToRequire\n hasSsn?: boolean\n hasEin?: boolean\n}\n\n/** @internal */\nexport function createContractorDetailsSchema(options: ContractorDetailsSchemaOptions = {}) {\n const { mode = 'create', optionalFieldsToRequire, hasSsn = false, hasEin = false } = options\n\n const fieldsWithRedactedValues: Array<keyof typeof fieldValidators> = []\n if (hasSsn) fieldsWithRedactedValues.push('ssn')\n if (hasEin) fieldsWithRedactedValues.push('ein')\n\n return buildFormSchema(fieldValidators, {\n requiredFieldsConfig,\n requiredErrorCode: ContractorDetailsErrorCodes.REQUIRED,\n mode,\n optionalFieldsToRequire,\n fieldsWithRedactedValues,\n // Applicability gating: evaluated per-validation so a field's required\n // check is skipped while it doesn't apply to the current selection. The\n // field stays in the schema (validated as optional), keeping requiredness\n // static and fully promotable via `optionalFieldsToRequire`.\n excludeFields: getExcludedContractorFields,\n })\n}\n\n/** @internal */\nexport type ContractorDiscriminators = Partial<\n Pick<ContractorDetailsFormData, 'type' | 'wageType' | 'fileNewHireReport'>\n>\n\n/**\n * Fields that don't apply to the given contractor selection. Their required\n * check is skipped at validation time and they're never rendered. `email` is\n * never excluded — it always applies and its requiredness is governed by the\n * `selfOnboarding` predicate.\n *\n * @internal\n */\nexport function getExcludedContractorFields(\n values: ContractorDiscriminators,\n): Array<keyof typeof fieldValidators> {\n const isIndividual = values.type === ContractorType.Individual\n const excluded: Array<keyof typeof fieldValidators> = []\n\n if (values.wageType !== WageType.Hourly) excluded.push('hourlyRate')\n\n if (isIndividual) {\n excluded.push('businessName', 'ein')\n if (!values.fileNewHireReport) excluded.push('workState')\n } else {\n excluded.push('firstName', 'lastName', 'middleInitial', 'fileNewHireReport', 'ssn', 'workState')\n }\n\n return excluded\n}\n"],"names":["ContractorType","ApiContractorType","WageType","ApiWageType","ContractorDetailsErrorCodes","EIN_FORMAT_REGEX","fieldValidators","z","coerceToISODate","coerceNaN","NAME_REGEX","v","SSN_REGEX","normalizeEin","requiredFieldsConfig","data","createContractorDetailsSchema","options","mode","optionalFieldsToRequire","hasSsn","hasEin","fieldsWithRedactedValues","buildFormSchema","getExcludedContractorFields","values","isIndividual","excluded"],"mappings":";;;;;;AAmBO,MAAMA,IAAiBC,GAMjBC,IAAWC,GAWXC,IAA8B;AAAA,EACzC,UAAU;AAAA,EACV,cAAc;AAAA,EACd,eAAe;AAAA,EACf,aAAa;AAAA,EACb,aAAa;AACf,GAWMC,IAAmB,iBAInBC,IAAkB;AAAA,EACtB,MAAMC,EAAE,KAAK,CAACP,EAAe,YAAYA,EAAe,QAAQ,CAAC;AAAA,EACjE,UAAUO,EAAE,KAAK,CAACL,EAAS,QAAQA,EAAS,KAAK,CAAC;AAAA,EAClD,WAAWK,EAAE;AAAA,IACXC;AAAA,IACAD,EAAE,IAAI,KAAK,EAAE,OAAO,MAAMH,EAA4B,UAAU;AAAA,EAAA;AAAA,EAElE,YAAYG,EAAE,WAAWE,EAAU,CAAC,GAAGF,EAAE,OAAA,EAAS,IAAI,CAAC,CAAC;AAAA,EACxD,gBAAgBA,EAAE,QAAA;AAAA,EAClB,mBAAmBA,EAAE,QAAA;AAAA,EACrB,OAAOA,EAAE,MAAM,EAAE,OAAO,MAAMH,EAA4B,eAAe;AAAA,EACzE,WAAWG,EACR,OAAA,EACA,IAAI,GAAG,EAAE,SAASH,EAA4B,SAAA,CAAU,EACxD,MAAMM,GAAY,EAAE,SAASN,EAA4B,cAAc;AAAA,EAC1E,UAAUG,EACP,OAAA,EACA,IAAI,GAAG,EAAE,SAASH,EAA4B,SAAA,CAAU,EACxD,MAAMM,GAAY,EAAE,SAASN,EAA4B,cAAc;AAAA,EAC1E,eAAeG,EAAE,OAAA;AAAA,EACjB,cAAcA,EAAE,OAAA;AAAA,EAChB,WAAWA,EAAE,OAAA;AAAA,EACb,KAAKA,EACF,OAAO,EAAE,OAAO,MAAMH,EAA4B,UAAU,EAC5D,OAAO,CAACO,MAAcC,EAAU,KAAKD,EAAE,QAAQ,OAAO,EAAE,CAAC,GAAG;AAAA,IAC3D,SAASP,EAA4B;AAAA,EAAA,CACtC;AAAA,EACH,KAAKG,EACF,OAAO,EAAE,OAAO,MAAMH,EAA4B,SAAA,CAAU,EAC5D,OAAO,CAACO,MAAcN,EAAiB,KAAKQ,EAAaF,CAAC,CAAC,GAAG;AAAA,IAC7D,SAASP,EAA4B;AAAA,EAAA,CACtC;AACL,GAmCMU,IAAuB;AAAA,EAC3B,WAAW;AAAA,EACX,WAAW;AAAA,EACX,UAAU;AAAA,EACV,cAAc;AAAA,EACd,YAAY;AAAA,EACZ,WAAW;AAAA,EACX,eAAe;AAAA,EACf,KAAK;AAAA,EACL,KAAK;AAAA,EACL,OAAO,OAAQC,EAAK;AACtB;AAuBO,SAASC,EAA8BC,IAA0C,IAAI;AAC1F,QAAM,EAAE,MAAAC,IAAO,UAAU,yBAAAC,GAAyB,QAAAC,IAAS,IAAO,QAAAC,IAAS,OAAUJ,GAE/EK,IAAgE,CAAA;AACtE,SAAIF,KAAQE,EAAyB,KAAK,KAAK,GAC3CD,KAAQC,EAAyB,KAAK,KAAK,GAExCC,EAAgBjB,GAAiB;AAAA,IACtC,sBAAAQ;AAAA,IACA,mBAAmBV,EAA4B;AAAA,IAC/C,MAAAc;AAAA,IACA,yBAAAC;AAAA,IACA,0BAAAG;AAAA;AAAA;AAAA;AAAA;AAAA,IAKA,eAAeE;AAAA,EAAA,CAChB;AACH;AAeO,SAASA,EACdC,GACqC;AACrC,QAAMC,IAAeD,EAAO,SAASzB,EAAe,YAC9C2B,IAAgD,CAAA;AAEtD,SAAIF,EAAO,aAAavB,EAAS,UAAQyB,EAAS,KAAK,YAAY,GAE/DD,KACFC,EAAS,KAAK,gBAAgB,KAAK,GAC9BF,EAAO,qBAAmBE,EAAS,KAAK,WAAW,KAExDA,EAAS,KAAK,aAAa,YAAY,iBAAiB,qBAAqB,OAAO,WAAW,GAG1FA;AACT;"}
|
|
@@ -129,6 +129,51 @@ export interface UseContractorDetailsFormReady extends BaseFormHookReady<FieldsM
|
|
|
129
129
|
* @param input - See {@link UseContractorDetailsFormProps}.
|
|
130
130
|
* @returns A {@link HookLoadingResult} while loading, or a {@link UseContractorDetailsFormReady} once ready.
|
|
131
131
|
* @public
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
* ```tsx
|
|
135
|
+
* import {
|
|
136
|
+
* useContractorDetailsForm,
|
|
137
|
+
* SDKFormProvider,
|
|
138
|
+
* type UseContractorDetailsFormReady,
|
|
139
|
+
* } from '@gusto/embedded-react-sdk'
|
|
140
|
+
*
|
|
141
|
+
* function ContractorDetailsPage({
|
|
142
|
+
* companyId,
|
|
143
|
+
* contractorId,
|
|
144
|
+
* }: {
|
|
145
|
+
* companyId: string
|
|
146
|
+
* contractorId: string
|
|
147
|
+
* }) {
|
|
148
|
+
* const contractorDetails = useContractorDetailsForm({ companyId, contractorId })
|
|
149
|
+
*
|
|
150
|
+
* if (contractorDetails.isLoading) return <div>Loading...</div>
|
|
151
|
+
*
|
|
152
|
+
* return <ContractorDetailsReady contractorDetails={contractorDetails} />
|
|
153
|
+
* }
|
|
154
|
+
*
|
|
155
|
+
* function ContractorDetailsReady({
|
|
156
|
+
* contractorDetails,
|
|
157
|
+
* }: {
|
|
158
|
+
* contractorDetails: UseContractorDetailsFormReady
|
|
159
|
+
* }) {
|
|
160
|
+
* const { Fields } = contractorDetails.form
|
|
161
|
+
*
|
|
162
|
+
* return (
|
|
163
|
+
* <SDKFormProvider formHookResult={contractorDetails}>
|
|
164
|
+
* <form onSubmit={e => { e.preventDefault(); void contractorDetails.actions.onSubmit() }}>
|
|
165
|
+
* <Fields.Type label="Contractor type" />
|
|
166
|
+
* <Fields.WageType label="Wage type" />
|
|
167
|
+
* {Fields.FirstName && <Fields.FirstName label="First name" />}
|
|
168
|
+
* {Fields.LastName && <Fields.LastName label="Last name" />}
|
|
169
|
+
* {Fields.BusinessName && <Fields.BusinessName label="Business name" />}
|
|
170
|
+
* <Fields.StartDate label="Start date" />
|
|
171
|
+
* <button type="submit" disabled={contractorDetails.status.isPending}>Save</button>
|
|
172
|
+
* </form>
|
|
173
|
+
* </SDKFormProvider>
|
|
174
|
+
* )
|
|
175
|
+
* }
|
|
176
|
+
* ```
|
|
132
177
|
*/
|
|
133
178
|
export declare function useContractorDetailsForm({ companyId, contractorId, withSelfOnboardingField, optionalFieldsToRequire, defaultValues: partnerDefaults, validationMode, shouldFocusError, }: UseContractorDetailsFormProps): HookLoadingResult | UseContractorDetailsFormReady;
|
|
134
179
|
/**
|