@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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PaymentMethod.js","sources":["../../../../src/components/Contractor/PaymentMethod/PaymentMethod.tsx"],"sourcesContent":["import { useTranslation } from 'react-i18next'\nimport type { SubmitHandler } from 'react-hook-form'\nimport { FormProvider, useForm, useWatch } from 'react-hook-form'\nimport { useContractorPaymentMethodGetSuspense } from '@gusto/embedded-api-v-2025-11-15/react-query/contractorPaymentMethodGet'\nimport { useContractorPaymentMethodGetBankAccountsSuspense } from '@gusto/embedded-api-v-2025-11-15/react-query/contractorPaymentMethodGetBankAccounts'\nimport { useContractorPaymentMethodsCreateBankAccountMutation } from '@gusto/embedded-api-v-2025-11-15/react-query/contractorPaymentMethodsCreateBankAccount'\nimport { useMemo, useState } from 'react'\nimport z from 'zod'\nimport { zodResolver } from '@hookform/resolvers/zod'\nimport { useContractorPaymentMethodUpdateMutation } from '@gusto/embedded-api-v-2025-11-15/react-query/contractorPaymentMethodUpdate'\nimport { useQueryClient } from '@tanstack/react-query'\nimport { buildContractorPaymentMethodGetQuery } from '@gusto/embedded-api-v-2025-11-15/react-query/contractorPaymentMethodGet'\nimport { useGustoEmbeddedContext } from '@gusto/embedded-api-v-2025-11-15/react-query/_context'\nimport type { PaymentMethodProps } from './types'\nimport { BankAccountForm } from './BankAccountForm'\nimport { PaymentTypeForm } from './PaymentTypeForm'\nimport { useI18n } from '@/i18n'\nimport { BaseComponent, useBase } from '@/components/Base'\nimport { useComponentContext } from '@/contexts/ComponentAdapter/useComponentContext'\nimport { Form } from '@/components/Common/Form'\nimport { useComponentDictionary } from '@/i18n/I18n'\nimport { componentEvents, PAYMENT_METHODS } from '@/shared/constants'\nimport { ActionsLayout } from '@/components/Common/ActionsLayout'\nimport { Flex } from '@/components/Common'\nimport { accountNumberValidation, routingNumberValidation } from '@/helpers/validations'\n\nconst PaymentMethodSchema = z.discriminatedUnion('type', [\n z.object({\n type: z.literal('Direct Deposit'),\n name: z.string().min(1),\n routingNumber: routingNumberValidation,\n accountNumber: z.any(), //Explicitely setting account number as most permissive\n accountType: z.enum(['Checking', 'Savings']),\n }),\n z.object({\n type: z.literal('Check'),\n }),\n])\n\ntype PaymentMethodSchemaInputs = z.input<typeof PaymentMethodSchema>\n\n/**\n * Manages a contractor's payment method, capturing a bank account for direct deposit or recording check as the payment method.\n *\n * Displays the current payment type, lets the user switch between direct deposit and check, and\n * collects bank account details (account holder name, routing number, account number, and account\n * type) when direct deposit is selected. Submitting creates the bank account if needed and then\n * updates the contractor's payment method.\n *\n * @events\n * | Event | Description | Data |\n * | ----- | ----------- | ---- |\n * | `contractor/bankAccount/created` | Fired after a bank account is created for the contractor | The API response object; access the created bank account at `.contractorBankAccount` |\n * | `contractor/paymentMethod/updated` | Fired after the payment method is updated | The API response object; access the updated payment method at `.contractorPaymentMethod` |\n * | `contractor/paymentMethod/done` | Fired when the payment method step completes | — |\n *\n * @param props - Component configuration; see {@link PaymentMethodProps}.\n * @returns The rendered payment method form.\n * @public\n *\n * @example\n * ```tsx\n * import { ContractorOnboarding } from '@gusto/embedded-react-sdk'\n *\n * function PaymentMethodStep() {\n * return (\n * <ContractorOnboarding.PaymentMethod\n * contractorId=\"contractor-uuid\"\n * onEvent={() => {}}\n * />\n * )\n * }\n * ```\n */\nexport function PaymentMethod(props: PaymentMethodProps) {\n return (\n <BaseComponent {...props}>\n <Root {...props}>{props.children}</Root>\n </BaseComponent>\n )\n}\n\nfunction Root({ contractorId, className, dictionary }: PaymentMethodProps) {\n useComponentDictionary('Contractor.PaymentMethod', dictionary)\n useI18n('Contractor.PaymentMethod')\n const { t } = useTranslation('Contractor.PaymentMethod')\n const { onEvent, baseSubmitHandler } = useBase()\n const Components = useComponentContext()\n const queryClient = useQueryClient()\n const gustoClient = useGustoEmbeddedContext()\n const [isPaymentMethodPending, setIsPaymentMethodPending] = useState(false)\n\n const contractorPaymentMethod = useContractorPaymentMethodGetSuspense({\n contractorUuid: contractorId,\n })\n\n const getPaymentMethodQuery = buildContractorPaymentMethodGetQuery(gustoClient, {\n contractorUuid: contractorId,\n })\n\n const paymentMethod = contractorPaymentMethod.data.contractorPaymentMethod!\n\n const {\n data: { contractorBankAccountList },\n } = useContractorPaymentMethodGetBankAccountsSuspense({\n contractorUuid: contractorId,\n })\n const bankAccount = contractorBankAccountList?.[0] || undefined\n\n const { mutateAsync: updatePaymentMethod, isPending: paymentMethodPending } =\n useContractorPaymentMethodUpdateMutation()\n const { mutateAsync: createBankAccount, isPending: bankAccountPending } =\n useContractorPaymentMethodsCreateBankAccountMutation()\n\n const defaultValues = useMemo(\n () => ({\n type: paymentMethod.type || PAYMENT_METHODS.check,\n name: bankAccount?.name || '',\n routingNumber: bankAccount?.routingNumber || '',\n accountNumber: bankAccount?.hiddenAccountNumber || '',\n accountType: bankAccount?.accountType || 'Checking',\n }),\n [paymentMethod, bankAccount],\n )\n\n const formMethods = useForm({\n resolver: zodResolver(PaymentMethodSchema),\n defaultValues: defaultValues,\n })\n\n const watchedType = useWatch({ control: formMethods.control, name: 'type' })\n const onSubmit: SubmitHandler<PaymentMethodSchemaInputs> = async data => {\n await baseSubmitHandler(data, async payload => {\n let updatedPaymentMethodVersion: string | undefined\n if (payload.type === PAYMENT_METHODS.directDeposit) {\n /** Custom validation logic for accountNumber - because masked account value is used as default value, it is only validated when any of the bank-related fields are modified*/\n const { name, accountNumber, routingNumber, accountType } = payload\n if (\n name !== bankAccount?.name ||\n routingNumber !== bankAccount.routingNumber ||\n accountType !== bankAccount.accountType ||\n accountNumber !== bankAccount.hiddenAccountNumber\n ) {\n const res = accountNumberValidation.safeParse(payload.accountNumber)\n if (!res.success) {\n formMethods.setError('accountNumber', { type: 'validate' })\n return\n }\n }\n\n const bankAccountResponse = await createBankAccount({\n request: {\n contractorUuid: contractorId,\n contractorBankAccountCreateRequestBody: {\n name,\n routingNumber,\n accountNumber,\n accountType,\n },\n },\n })\n\n onEvent(componentEvents.CONTRACTOR_BANK_ACCOUNT_CREATED, bankAccountResponse)\n\n // We have to fetch the updated payment method imperatively here because updating the bank\n // account will cause the payment method version to update. This ensures we have the latest version.\n setIsPaymentMethodPending(true)\n const updatedPaymentMethodResponse = await queryClient.fetchQuery(getPaymentMethodQuery)\n const updatedPaymentMethod = updatedPaymentMethodResponse.contractorPaymentMethod!\n setIsPaymentMethodPending(false)\n\n updatedPaymentMethodVersion = updatedPaymentMethod.version as string\n }\n // For check payment method, no bank account creation needed\n const paymentMethodResponse = await updatePaymentMethod({\n request: {\n contractorUuid: contractorId,\n requestBody: {\n type: payload.type,\n version: updatedPaymentMethodVersion || (paymentMethod.version as string),\n },\n },\n })\n onEvent(componentEvents.CONTRACTOR_PAYMENT_METHOD_UPDATED, paymentMethodResponse)\n onEvent(componentEvents.CONTRACTOR_PAYMENT_METHOD_DONE)\n })\n }\n\n const showBankAccountForm = watchedType === PAYMENT_METHODS.directDeposit\n\n return (\n <section className={className}>\n <FormProvider {...formMethods}>\n <Form onSubmit={formMethods.handleSubmit(onSubmit)}>\n <Flex gap={32} flexDirection={'column'}>\n <Components.Heading as=\"h2\">{t('title')}</Components.Heading>\n <PaymentTypeForm />\n {showBankAccountForm && <BankAccountForm bankAccount={bankAccount} />}\n <ActionsLayout>\n <Components.Button\n type=\"submit\"\n variant=\"primary\"\n isDisabled={paymentMethodPending || bankAccountPending || isPaymentMethodPending}\n >\n {t('continueCta')}\n </Components.Button>\n </ActionsLayout>\n </Flex>\n </Form>\n </FormProvider>\n </section>\n )\n}\n"],"names":["PaymentMethodSchema","z","routingNumberValidation","PaymentMethod","props","jsx","BaseComponent","Root","contractorId","className","dictionary","useComponentDictionary","useI18n","t","useTranslation","onEvent","baseSubmitHandler","useBase","Components","useComponentContext","queryClient","useQueryClient","gustoClient","useGustoEmbeddedContext","isPaymentMethodPending","setIsPaymentMethodPending","useState","contractorPaymentMethod","useContractorPaymentMethodGetSuspense","getPaymentMethodQuery","buildContractorPaymentMethodGetQuery","paymentMethod","contractorBankAccountList","useContractorPaymentMethodGetBankAccountsSuspense","bankAccount","updatePaymentMethod","paymentMethodPending","useContractorPaymentMethodUpdateMutation","createBankAccount","bankAccountPending","useContractorPaymentMethodsCreateBankAccountMutation","defaultValues","useMemo","PAYMENT_METHODS","formMethods","useForm","zodResolver","watchedType","useWatch","onSubmit","data","payload","updatedPaymentMethodVersion","name","accountNumber","routingNumber","accountType","accountNumberValidation","bankAccountResponse","componentEvents","updatedPaymentMethod","paymentMethodResponse","showBankAccountForm","FormProvider","Form","jsxs","Flex","PaymentTypeForm","BankAccountForm","ActionsLayout"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AA0BA,MAAMA,KAAsBC,EAAE,mBAAmB,QAAQ;AAAA,EACvDA,EAAE,OAAO;AAAA,IACP,MAAMA,EAAE,QAAQ,gBAAgB;AAAA,IAChC,MAAMA,EAAE,SAAS,IAAI,CAAC;AAAA,IACtB,eAAeC;AAAA,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AAAA,YACX,MAAM2C,EAAQ;AAAA,YACd,SAASC,KAAgCrB,EAAc;AAAA,UAAA;AAAA,QACzD;AAAA,MACF,CACD;AACD,MAAAhB,EAAQ4C,EAAgB,mCAAmCE,CAAqB,GAChF9C,EAAQ4C,EAAgB,8BAA8B;AAAA,IACxD,CAAC;AAAA,EACH,GAEMG,IAAsBf,MAAgBJ,EAAgB;AAE5D,2BACG,WAAA,EAAQ,WAAAlC,GACP,4BAACsD,GAAA,EAAc,GAAGnB,GAChB,UAAA,gBAAAvC,EAAC2D,IAAA,EAAK,UAAUpB,EAAY,aAAaK,CAAQ,GAC/C,UAAA,gBAAAgB,EAACC,MAAK,KAAK,IAAI,eAAe,UAC5B,UAAA;AAAA,IAAA,gBAAA7D,EAACa,EAAW,SAAX,EAAmB,IAAG,MAAM,UAAAL,EAAE,OAAO,GAAE;AAAA,sBACvCsD,IAAA,EAAgB;AAAA,IAChBL,KAAuB,gBAAAzD,EAAC+D,IAAA,EAAgB,aAAAlC,EAAA,CAA0B;AAAA,sBAClEmC,IAAA,EACC,UAAA,gBAAAhE;AAAA,MAACa,EAAW;AAAA,MAAX;AAAA,QACC,MAAK;AAAA,QACL,SAAQ;AAAA,QACR,YAAYkB,KAAwBG,KAAsBf;AAAA,QAEzD,YAAE,aAAa;AAAA,MAAA;AAAA,IAAA,EAClB,CACF;AAAA,EAAA,GACF,EAAA,CACF,GACF,GACF;AAEJ;"}
|
|
1
|
+
{"version":3,"file":"PaymentMethod.js","sources":["../../../../src/components/Contractor/PaymentMethod/PaymentMethod.tsx"],"sourcesContent":["import { useTranslation } from 'react-i18next'\nimport classNames from 'classnames'\nimport type { PaymentMethodProps } from './types'\nimport {\n useContractorPaymentMethodForm,\n type ContractorPaymentMethodFormType,\n} from './shared/useContractorPaymentMethodForm'\nimport { useContractorBankAccountForm } from './shared/useContractorBankAccountForm'\nimport styles from './PaymentMethod.module.scss'\nimport { useI18n } from '@/i18n'\nimport { BaseBoundaries, BaseLayout } from '@/components/Base'\nimport { useComponentContext } from '@/contexts/ComponentAdapter/useComponentContext'\nimport { Form } from '@/components/Common/Form'\nimport { useComponentDictionary } from '@/i18n/I18n'\nimport { componentEvents, PAYMENT_METHODS } from '@/shared/constants'\nimport { composeErrorHandler } from '@/partner-hook-utils/composeErrorHandler'\nimport { composeSubmitHandler } from '@/partner-hook-utils/form/composeSubmitHandler'\nimport { ActionsLayout } from '@/components/Common/ActionsLayout'\nimport { Flex } from '@/components/Common'\nimport type { RadioGroupProps } from '@/components/Common/UI/RadioGroup/RadioGroupTypes'\n\n/**\n * Manages a contractor's payment method, capturing a bank account for direct deposit or recording check as the payment method.\n *\n * Displays the current payment type, lets the user switch between direct deposit and check, and\n * collects bank account details (account holder name, routing number, account number, and account\n * type) when direct deposit is selected. Direct deposit creates the bank account (which updates the\n * payment method server-side); check updates the contractor's payment method type directly.\n *\n * @events\n * | Event | Description | Data |\n * | ----- | ----------- | ---- |\n * | `contractor/bankAccount/created` | Fired on the direct deposit path after the bank account is created | The created bank account at `.contractorBankAccount` |\n * | `contractor/paymentMethod/updated` | Fired on the check path after the payment method type is updated | The updated payment method at `.contractorPaymentMethod` |\n * | `contractor/paymentMethod/done` | Fired when the payment method step completes | — |\n *\n * @param props - Component configuration; see {@link PaymentMethodProps}.\n * @returns The rendered payment method form.\n * @public\n *\n * @example\n * ```tsx\n * import { ContractorOnboarding } from '@gusto/embedded-react-sdk'\n *\n * function PaymentMethodStep() {\n * return (\n * <ContractorOnboarding.PaymentMethod\n * contractorId=\"contractor-uuid\"\n * onEvent={() => {}}\n * />\n * )\n * }\n * ```\n */\nexport function PaymentMethod({ dictionary, ...props }: PaymentMethodProps) {\n useComponentDictionary('Contractor.PaymentMethod', dictionary)\n return (\n <BaseBoundaries componentName=\"Contractor.PaymentMethod\">\n <Root {...props} />\n </BaseBoundaries>\n )\n}\n\nfunction Root({ contractorId, className, onEvent }: Omit<PaymentMethodProps, 'dictionary'>) {\n useI18n('Contractor.PaymentMethod')\n const { t } = useTranslation('Contractor.PaymentMethod')\n const Components = useComponentContext()\n\n const paymentMethodForm = useContractorPaymentMethodForm({\n contractorId,\n shouldFocusError: false,\n })\n const bankAccountForm = useContractorBankAccountForm({\n contractorId,\n shouldFocusError: false,\n })\n\n if (paymentMethodForm.isLoading || bankAccountForm.isLoading) {\n const loadingErrorHandling = composeErrorHandler([paymentMethodForm, bankAccountForm])\n return <BaseLayout isLoading error={loadingErrorHandling.errors} />\n }\n\n const isDirectDeposit = paymentMethodForm.status.isDirectDeposit\n const { Type } = paymentMethodForm.form.Fields\n const { Name, RoutingNumber, AccountNumber, AccountType } = bankAccountForm.form.Fields\n\n // Direct Deposit always submits the bank account (which sets the payment\n // method server-side); Check updates the payment method type directly. The\n // account number is pre-filled with the masked token, which the API treats as\n // \"keep the existing account,\" so an unchanged submit preserves it while a\n // newly typed number replaces it.\n const submitDirectDeposit = async () => {\n const result = await bankAccountForm.actions.onSubmit()\n if (!result) return\n onEvent(componentEvents.CONTRACTOR_BANK_ACCOUNT_CREATED, {\n contractorBankAccount: result.data,\n })\n onEvent(componentEvents.CONTRACTOR_PAYMENT_METHOD_DONE)\n }\n\n const submitCheck = async () => {\n const result = await paymentMethodForm.actions.onSubmit()\n if (!result) return\n onEvent(componentEvents.CONTRACTOR_PAYMENT_METHOD_UPDATED, {\n contractorPaymentMethod: result.data,\n })\n onEvent(componentEvents.CONTRACTOR_PAYMENT_METHOD_DONE)\n }\n\n const { handleSubmit, errorHandling } = isDirectDeposit\n ? composeSubmitHandler([paymentMethodForm, bankAccountForm], submitDirectDeposit)\n : composeSubmitHandler([paymentMethodForm], submitCheck)\n\n const isPending = paymentMethodForm.status.isPending || bankAccountForm.status.isPending\n\n const TypeFieldComponent = (radioProps: RadioGroupProps) => (\n <Components.RadioGroup\n {...radioProps}\n shouldVisuallyHideLabel\n options={radioProps.options.map(option => ({\n ...option,\n description:\n option.value === PAYMENT_METHODS.directDeposit\n ? t('directDepositDescription')\n : t('checkDescription'),\n }))}\n />\n )\n\n return (\n <section className={classNames(styles.root, className)}>\n <BaseLayout error={errorHandling.errors}>\n <Form onSubmit={handleSubmit}>\n <Flex gap={32} flexDirection=\"column\">\n <Components.Heading as=\"h2\">{t('title')}</Components.Heading>\n <Type\n label={t('paymentFieldsetLegend')}\n getOptionLabel={(value: ContractorPaymentMethodFormType) =>\n value === PAYMENT_METHODS.directDeposit ? t('directDepositLabel') : t('checkLabel')\n }\n FieldComponent={TypeFieldComponent}\n formHookResult={paymentMethodForm}\n />\n {isDirectDeposit && (\n <>\n <Name\n label={t('bankAccountForm.nameLabel')}\n validationMessages={{ REQUIRED: t('bankAccountForm.validations.accountName') }}\n formHookResult={bankAccountForm}\n />\n <RoutingNumber\n label={t('bankAccountForm.routingNumberLabel')}\n description={t('bankAccountForm.routingNumberDescription')}\n validationMessages={{\n REQUIRED: t('bankAccountForm.validations.routingNumber'),\n INVALID_ROUTING_NUMBER: t('bankAccountForm.validations.routingNumber'),\n }}\n formHookResult={bankAccountForm}\n />\n <AccountNumber\n label={t('bankAccountForm.accountNumberLabel')}\n validationMessages={{\n REQUIRED: t('bankAccountForm.validations.accountNumber'),\n INVALID_ACCOUNT_NUMBER: t('bankAccountForm.validations.accountNumber'),\n }}\n formHookResult={bankAccountForm}\n />\n <AccountType\n label={t('bankAccountForm.accountTypeLabel')}\n getOptionLabel={(value: string) =>\n value === 'Checking'\n ? t('bankAccountForm.accountTypeChecking')\n : t('bankAccountForm.accountTypeSavings')\n }\n formHookResult={bankAccountForm}\n />\n </>\n )}\n <ActionsLayout>\n <Components.Button type=\"submit\" variant=\"primary\" isDisabled={isPending}>\n {t('continueCta')}\n </Components.Button>\n </ActionsLayout>\n </Flex>\n </Form>\n </BaseLayout>\n </section>\n )\n}\n"],"names":["PaymentMethod","dictionary","props","useComponentDictionary","jsx","BaseBoundaries","Root","contractorId","className","onEvent","useI18n","t","useTranslation","Components","useComponentContext","paymentMethodForm","useContractorPaymentMethodForm","bankAccountForm","useContractorBankAccountForm","loadingErrorHandling","composeErrorHandler","BaseLayout","isDirectDeposit","Type","Name","RoutingNumber","AccountNumber","AccountType","submitDirectDeposit","result","componentEvents","submitCheck","handleSubmit","errorHandling","composeSubmitHandler","isPending","TypeFieldComponent","radioProps","option","PAYMENT_METHODS","classNames","styles","Form","Flex","value","jsxs","Fragment","ActionsLayout"],"mappings":";;;;;;;;;;;;;;;;;AAsDO,SAASA,GAAc,EAAE,YAAAC,GAAY,GAAGC,KAA6B;AAC1E,SAAAC,EAAuB,4BAA4BF,CAAU,GAE3D,gBAAAG,EAACC,KAAe,eAAc,4BAC5B,4BAACC,GAAA,EAAM,GAAGJ,GAAO,EAAA,CACnB;AAEJ;AAEA,SAASI,EAAK,EAAE,cAAAC,GAAc,WAAAC,GAAW,SAAAC,KAAmD;AAC1F,EAAAC,EAAQ,0BAA0B;AAClC,QAAM,EAAE,GAAAC,EAAA,IAAMC,EAAe,0BAA0B,GACjDC,IAAaC,EAAA,GAEbC,IAAoBC,EAA+B;AAAA,IACvD,cAAAT;AAAA,IACA,kBAAkB;AAAA,EAAA,CACnB,GACKU,IAAkBC,EAA6B;AAAA,IACnD,cAAAX;AAAA,IACA,kBAAkB;AAAA,EAAA,CACnB;AAED,MAAIQ,EAAkB,aAAaE,EAAgB,WAAW;AAC5D,UAAME,IAAuBC,EAAoB,CAACL,GAAmBE,CAAe,CAAC;AACrF,6BAAQI,GAAA,EAAW,WAAS,IAAC,OAAOF,EAAqB,QAAQ;AAAA,EACnE;AAEA,QAAMG,IAAkBP,EAAkB,OAAO,iBAC3C,EAAE,MAAAQ,EAAA,IAASR,EAAkB,KAAK,QAClC,EAAE,MAAAS,GAAM,eAAAC,GAAe,eAAAC,GAAe,aAAAC,MAAgBV,EAAgB,KAAK,QAO3EW,IAAsB,YAAY;AACtC,UAAMC,IAAS,MAAMZ,EAAgB,QAAQ,SAAA;AAC7C,IAAKY,MACLpB,EAAQqB,EAAgB,iCAAiC;AAAA,MACvD,uBAAuBD,EAAO;AAAA,IAAA,CA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
|
|
|
1
|
+
{"version":3,"file":"PaymentMethod.module.scss.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;"}
|
package/dist/components/Contractor/PaymentMethod/shared/useContractorBankAccountForm/fields.d.ts
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { ContractorAccountType, ContractorBankAccountErrorCodes } from './useContractorBankAccountFormSchema';
|
|
2
|
+
import { TextInputHookFieldProps } from '../../../../../partner-hook-utils/form/fields/TextInputHookField';
|
|
3
|
+
import { RadioGroupHookFieldProps } from '../../../../../partner-hook-utils/form/fields/RadioGroupHookField';
|
|
4
|
+
import { HookFieldProps } from '../../../../../partner-hook-utils/types';
|
|
5
|
+
/**
|
|
6
|
+
* Validation error code emitted by {@link useContractorBankAccountForm} fields
|
|
7
|
+
* that only emit `REQUIRED`.
|
|
8
|
+
*
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
export type RequiredValidation = typeof ContractorBankAccountErrorCodes.REQUIRED;
|
|
12
|
+
/**
|
|
13
|
+
* Validation error codes emitted by the `routingNumber` field of
|
|
14
|
+
* {@link useContractorBankAccountForm}.
|
|
15
|
+
*
|
|
16
|
+
* @public
|
|
17
|
+
*/
|
|
18
|
+
export type RoutingNumberValidation = (typeof ContractorBankAccountErrorCodes)[keyof Pick<typeof ContractorBankAccountErrorCodes, 'REQUIRED' | 'INVALID_ROUTING_NUMBER'>];
|
|
19
|
+
/**
|
|
20
|
+
* Validation error codes emitted by the `accountNumber` field of
|
|
21
|
+
* {@link useContractorBankAccountForm}.
|
|
22
|
+
*
|
|
23
|
+
* @public
|
|
24
|
+
*/
|
|
25
|
+
export type AccountNumberValidation = (typeof ContractorBankAccountErrorCodes)[keyof Pick<typeof ContractorBankAccountErrorCodes, 'REQUIRED' | 'INVALID_ACCOUNT_NUMBER'>];
|
|
26
|
+
/**
|
|
27
|
+
* Props accepted by {@link useContractorBankAccountForm}'s `Fields.Name` component.
|
|
28
|
+
*
|
|
29
|
+
* @public
|
|
30
|
+
*/
|
|
31
|
+
export type NameFieldProps = HookFieldProps<TextInputHookFieldProps<RequiredValidation>>;
|
|
32
|
+
/**
|
|
33
|
+
* Text input bound to the `name` field of {@link useContractorBankAccountForm}.
|
|
34
|
+
*
|
|
35
|
+
* @remarks
|
|
36
|
+
* Surfaced to partners as `form.Fields.Name`; see {@link ContractorBankAccountFormFields}.
|
|
37
|
+
*
|
|
38
|
+
* @param props - See {@link NameFieldProps}.
|
|
39
|
+
* @returns The rendered text input bound to `name`.
|
|
40
|
+
* @internal
|
|
41
|
+
*/
|
|
42
|
+
export declare function NameField(props: NameFieldProps): import("react").JSX.Element;
|
|
43
|
+
/**
|
|
44
|
+
* Props accepted by {@link useContractorBankAccountForm}'s `Fields.RoutingNumber` component.
|
|
45
|
+
*
|
|
46
|
+
* @public
|
|
47
|
+
*/
|
|
48
|
+
export type RoutingNumberFieldProps = HookFieldProps<TextInputHookFieldProps<RoutingNumberValidation>>;
|
|
49
|
+
/**
|
|
50
|
+
* Text input bound to the `routingNumber` field of {@link useContractorBankAccountForm}.
|
|
51
|
+
*
|
|
52
|
+
* @remarks
|
|
53
|
+
* Surfaced to partners as `form.Fields.RoutingNumber`; see {@link ContractorBankAccountFormFields}.
|
|
54
|
+
*
|
|
55
|
+
* @param props - See {@link RoutingNumberFieldProps}.
|
|
56
|
+
* @returns The rendered text input bound to `routingNumber`.
|
|
57
|
+
* @internal
|
|
58
|
+
*/
|
|
59
|
+
export declare function RoutingNumberField(props: RoutingNumberFieldProps): import("react").JSX.Element;
|
|
60
|
+
/**
|
|
61
|
+
* Props accepted by {@link useContractorBankAccountForm}'s `Fields.AccountNumber` component.
|
|
62
|
+
*
|
|
63
|
+
* @public
|
|
64
|
+
*/
|
|
65
|
+
export type AccountNumberFieldProps = HookFieldProps<TextInputHookFieldProps<AccountNumberValidation>>;
|
|
66
|
+
/**
|
|
67
|
+
* Text input bound to the `accountNumber` field of {@link useContractorBankAccountForm}.
|
|
68
|
+
*
|
|
69
|
+
* @remarks
|
|
70
|
+
* Surfaced to partners as `form.Fields.AccountNumber`; see {@link ContractorBankAccountFormFields}.
|
|
71
|
+
*
|
|
72
|
+
* @param props - See {@link AccountNumberFieldProps}.
|
|
73
|
+
* @returns The rendered text input bound to `accountNumber`.
|
|
74
|
+
* @internal
|
|
75
|
+
*/
|
|
76
|
+
export declare function AccountNumberField(props: AccountNumberFieldProps): import("react").JSX.Element;
|
|
77
|
+
/**
|
|
78
|
+
* Props accepted by {@link useContractorBankAccountForm}'s `Fields.AccountType` component.
|
|
79
|
+
*
|
|
80
|
+
* @public
|
|
81
|
+
*/
|
|
82
|
+
export type AccountTypeFieldProps = HookFieldProps<RadioGroupHookFieldProps<RequiredValidation, ContractorAccountType>>;
|
|
83
|
+
/**
|
|
84
|
+
* Radio group bound to the `accountType` field of {@link useContractorBankAccountForm}.
|
|
85
|
+
*
|
|
86
|
+
* @remarks
|
|
87
|
+
* Surfaced to partners as `form.Fields.AccountType`; see {@link ContractorBankAccountFormFields}.
|
|
88
|
+
*
|
|
89
|
+
* @param props - See {@link AccountTypeFieldProps}.
|
|
90
|
+
* @returns The rendered radio group bound to `accountType`.
|
|
91
|
+
* @internal
|
|
92
|
+
*/
|
|
93
|
+
export declare function AccountTypeField(props: AccountTypeFieldProps): import("react").JSX.Element;
|
package/dist/components/Contractor/PaymentMethod/shared/useContractorBankAccountForm/fields.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { jsx as n } from "react/jsx-runtime";
|
|
2
|
+
import { TextInputHookField as o } from "../../../../../partner-hook-utils/form/fields/TextInputHookField.js";
|
|
3
|
+
import { RadioGroupHookField as r } from "../../../../../partner-hook-utils/form/fields/RadioGroupHookField.js";
|
|
4
|
+
function m(e) {
|
|
5
|
+
return /* @__PURE__ */ n(o, { ...e, name: "name" });
|
|
6
|
+
}
|
|
7
|
+
function c(e) {
|
|
8
|
+
return /* @__PURE__ */ n(o, { ...e, name: "routingNumber" });
|
|
9
|
+
}
|
|
10
|
+
function a(e) {
|
|
11
|
+
return /* @__PURE__ */ n(o, { ...e, name: "accountNumber" });
|
|
12
|
+
}
|
|
13
|
+
function p(e) {
|
|
14
|
+
return /* @__PURE__ */ n(r, { ...e, name: "accountType" });
|
|
15
|
+
}
|
|
16
|
+
export {
|
|
17
|
+
a as AccountNumberField,
|
|
18
|
+
p as AccountTypeField,
|
|
19
|
+
m as NameField,
|
|
20
|
+
c as RoutingNumberField
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=fields.js.map
|
package/dist/components/Contractor/PaymentMethod/shared/useContractorBankAccountForm/fields.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fields.js","sources":["../../../../../../src/components/Contractor/PaymentMethod/shared/useContractorBankAccountForm/fields.tsx"],"sourcesContent":["import type {\n ContractorAccountType,\n ContractorBankAccountErrorCodes,\n} from './useContractorBankAccountFormSchema'\nimport type { TextInputHookFieldProps } from '@/partner-hook-utils/form/fields/TextInputHookField'\nimport type { RadioGroupHookFieldProps } from '@/partner-hook-utils/form/fields/RadioGroupHookField'\nimport { TextInputHookField, RadioGroupHookField } from '@/partner-hook-utils/form/fields'\nimport type { HookFieldProps } from '@/partner-hook-utils/types'\n\n/**\n * Validation error code emitted by {@link useContractorBankAccountForm} fields\n * that only emit `REQUIRED`.\n *\n * @public\n */\nexport type RequiredValidation = typeof ContractorBankAccountErrorCodes.REQUIRED\n\n/**\n * Validation error codes emitted by the `routingNumber` field of\n * {@link useContractorBankAccountForm}.\n *\n * @public\n */\nexport type RoutingNumberValidation = (typeof ContractorBankAccountErrorCodes)[keyof Pick<\n typeof ContractorBankAccountErrorCodes,\n 'REQUIRED' | 'INVALID_ROUTING_NUMBER'\n>]\n\n/**\n * Validation error codes emitted by the `accountNumber` field of\n * {@link useContractorBankAccountForm}.\n *\n * @public\n */\nexport type AccountNumberValidation = (typeof ContractorBankAccountErrorCodes)[keyof Pick<\n typeof ContractorBankAccountErrorCodes,\n 'REQUIRED' | 'INVALID_ACCOUNT_NUMBER'\n>]\n\n/**\n * Props accepted by {@link useContractorBankAccountForm}'s `Fields.Name` component.\n *\n * @public\n */\nexport type NameFieldProps = HookFieldProps<TextInputHookFieldProps<RequiredValidation>>\n\n/**\n * Text input bound to the `name` field of {@link useContractorBankAccountForm}.\n *\n * @remarks\n * Surfaced to partners as `form.Fields.Name`; see {@link ContractorBankAccountFormFields}.\n *\n * @param props - See {@link NameFieldProps}.\n * @returns The rendered text input bound to `name`.\n * @internal\n */\nexport function NameField(props: NameFieldProps) {\n return <TextInputHookField {...props} name=\"name\" />\n}\n\n/**\n * Props accepted by {@link useContractorBankAccountForm}'s `Fields.RoutingNumber` component.\n *\n * @public\n */\nexport type RoutingNumberFieldProps = HookFieldProps<\n TextInputHookFieldProps<RoutingNumberValidation>\n>\n\n/**\n * Text input bound to the `routingNumber` field of {@link useContractorBankAccountForm}.\n *\n * @remarks\n * Surfaced to partners as `form.Fields.RoutingNumber`; see {@link ContractorBankAccountFormFields}.\n *\n * @param props - See {@link RoutingNumberFieldProps}.\n * @returns The rendered text input bound to `routingNumber`.\n * @internal\n */\nexport function RoutingNumberField(props: RoutingNumberFieldProps) {\n return <TextInputHookField {...props} name=\"routingNumber\" />\n}\n\n/**\n * Props accepted by {@link useContractorBankAccountForm}'s `Fields.AccountNumber` component.\n *\n * @public\n */\nexport type AccountNumberFieldProps = HookFieldProps<\n TextInputHookFieldProps<AccountNumberValidation>\n>\n\n/**\n * Text input bound to the `accountNumber` field of {@link useContractorBankAccountForm}.\n *\n * @remarks\n * Surfaced to partners as `form.Fields.AccountNumber`; see {@link ContractorBankAccountFormFields}.\n *\n * @param props - See {@link AccountNumberFieldProps}.\n * @returns The rendered text input bound to `accountNumber`.\n * @internal\n */\nexport function AccountNumberField(props: AccountNumberFieldProps) {\n return <TextInputHookField {...props} name=\"accountNumber\" />\n}\n\n/**\n * Props accepted by {@link useContractorBankAccountForm}'s `Fields.AccountType` component.\n *\n * @public\n */\nexport type AccountTypeFieldProps = HookFieldProps<\n RadioGroupHookFieldProps<RequiredValidation, ContractorAccountType>\n>\n\n/**\n * Radio group bound to the `accountType` field of {@link useContractorBankAccountForm}.\n *\n * @remarks\n * Surfaced to partners as `form.Fields.AccountType`; see {@link ContractorBankAccountFormFields}.\n *\n * @param props - See {@link AccountTypeFieldProps}.\n * @returns The rendered radio group bound to `accountType`.\n * @internal\n */\nexport function AccountTypeField(props: AccountTypeFieldProps) {\n return <RadioGroupHookField {...props} name=\"accountType\" />\n}\n"],"names":["NameField","props","jsx","TextInputHookField","RoutingNumberField","AccountNumberField","AccountTypeField","RadioGroupHookField"],"mappings":";;;AAwDO,SAASA,EAAUC,GAAuB;AAC/C,SAAO,gBAAAC,EAACC,GAAA,EAAoB,GAAGF,GAAO,MAAK,QAAO;AACpD;AAqBO,SAASG,EAAmBH,GAAgC;AACjE,SAAO,gBAAAC,EAACC,GAAA,EAAoB,GAAGF,GAAO,MAAK,iBAAgB;AAC7D;AAqBO,SAASI,EAAmBJ,GAAgC;AACjE,SAAO,gBAAAC,EAACC,GAAA,EAAoB,GAAGF,GAAO,MAAK,iBAAgB;AAC7D;AAqBO,SAASK,EAAiBL,GAA8B;AAC7D,SAAO,gBAAAC,EAACK,GAAA,EAAqB,GAAGN,GAAO,MAAK,eAAc;AAC5D;"}
|
package/dist/components/Contractor/PaymentMethod/shared/useContractorBankAccountForm/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import "./types/i18next.d.ts"
|
|
2
|
+
export { useContractorBankAccountForm } from './useContractorBankAccountForm';
|
|
3
|
+
export type { UseContractorBankAccountFormProps, UseContractorBankAccountFormResult, UseContractorBankAccountFormReady, ContractorBankAccountFormFields, ContractorBankAccountFieldsMetadata, } from './useContractorBankAccountForm';
|
|
4
|
+
export { ContractorBankAccountErrorCodes, ACCOUNT_TYPES, createContractorBankAccountSchema, type ContractorBankAccountErrorCode, type ContractorAccountType, type ContractorBankAccountFormData, type ContractorBankAccountFormOutputs, type ContractorBankAccountFormField, type ContractorBankAccountOptionalFieldsToRequire, } from './useContractorBankAccountFormSchema';
|
|
5
|
+
export { type RequiredValidation as ContractorBankAccountRequiredValidation, type RoutingNumberValidation as ContractorBankAccountRoutingNumberValidation, type AccountNumberValidation as ContractorBankAccountAccountNumberValidation, type NameFieldProps, type RoutingNumberFieldProps, type AccountNumberFieldProps, type AccountTypeFieldProps, } from './fields';
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { ComponentType } from 'react';
|
|
2
|
+
import { UseFormProps } from 'react-hook-form';
|
|
3
|
+
import { ContractorBankAccount } from '@gusto/embedded-api-v-2025-11-15/models/components/contractorbankaccount';
|
|
4
|
+
import { ContractorBankAccountFormData, ContractorBankAccountOptionalFieldsToRequire } from './useContractorBankAccountFormSchema';
|
|
5
|
+
import { AccountNumberFieldProps, AccountTypeFieldProps, NameFieldProps, RoutingNumberFieldProps } from './fields';
|
|
6
|
+
import { BaseFormHookReady, FieldsMetadata, HookLoadingResult, HookSubmitResult } from '../../../../../partner-hook-utils/types';
|
|
7
|
+
/**
|
|
8
|
+
* Props for {@link useContractorBankAccountForm}.
|
|
9
|
+
*
|
|
10
|
+
* @public
|
|
11
|
+
*/
|
|
12
|
+
export interface UseContractorBankAccountFormProps {
|
|
13
|
+
/** Contractor for whom to create the bank account. */
|
|
14
|
+
contractorId: string;
|
|
15
|
+
/** Override optional fields to be required. */
|
|
16
|
+
optionalFieldsToRequire?: ContractorBankAccountOptionalFieldsToRequire;
|
|
17
|
+
/** Pre-fill form values. The contractor's existing bank account is used when no override is supplied. */
|
|
18
|
+
defaultValues?: Partial<ContractorBankAccountFormData>;
|
|
19
|
+
/** When validation runs. Passed through to react-hook-form. Defaults to `'onSubmit'`. */
|
|
20
|
+
validationMode?: UseFormProps['mode'];
|
|
21
|
+
/** Auto-focus the first invalid field on submit. Set to `false` when using `composeSubmitHandler`. Defaults to `true`. */
|
|
22
|
+
shouldFocusError?: boolean;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Field components exposed by {@link useContractorBankAccountForm} on `form.Fields`.
|
|
26
|
+
*
|
|
27
|
+
* @public
|
|
28
|
+
*/
|
|
29
|
+
export interface ContractorBankAccountFormFields {
|
|
30
|
+
/** Bound to `name`. Captures the bank account nickname. */
|
|
31
|
+
Name: ComponentType<NameFieldProps>;
|
|
32
|
+
/** Bound to `routingNumber`. Validated against a 9-digit numeric pattern. */
|
|
33
|
+
RoutingNumber: ComponentType<RoutingNumberFieldProps>;
|
|
34
|
+
/**
|
|
35
|
+
* Bound to `accountNumber`. Pre-filled with the masked account number (e.g.
|
|
36
|
+
* "XXXX1207"), which is accepted unchanged to keep the existing account; a
|
|
37
|
+
* newly entered value is validated against the 1–17 digit numeric pattern.
|
|
38
|
+
*/
|
|
39
|
+
AccountNumber: ComponentType<AccountNumberFieldProps>;
|
|
40
|
+
/**
|
|
41
|
+
* Bound to `accountType`. Options are `Checking` and `Savings`; defaults to
|
|
42
|
+
* `Checking`. Supply `getOptionLabel` to translate the option labels.
|
|
43
|
+
*/
|
|
44
|
+
AccountType: ComponentType<AccountTypeFieldProps>;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Ready-state return value of {@link useContractorBankAccountForm}.
|
|
48
|
+
*
|
|
49
|
+
* @public
|
|
50
|
+
*/
|
|
51
|
+
export interface UseContractorBankAccountFormReady extends BaseFormHookReady<FieldsMetadata, ContractorBankAccountFormData, ContractorBankAccountFormFields> {
|
|
52
|
+
/** The contractor's current bank account, loaded from the API, if any. */
|
|
53
|
+
data: {
|
|
54
|
+
bankAccount: ContractorBankAccount | undefined;
|
|
55
|
+
};
|
|
56
|
+
/** `isPending` reflects the in-flight create mutation; `mode` is always `'create'`. */
|
|
57
|
+
status: {
|
|
58
|
+
isPending: boolean;
|
|
59
|
+
mode: 'create';
|
|
60
|
+
};
|
|
61
|
+
/** Submit the form. Returns the created bank account on success or `undefined` on validation/mutation failure. */
|
|
62
|
+
actions: {
|
|
63
|
+
onSubmit: () => Promise<HookSubmitResult<ContractorBankAccount> | undefined>;
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Headless React Hook Form hook for creating a contractor's bank account.
|
|
68
|
+
*
|
|
69
|
+
* @remarks
|
|
70
|
+
* Captures the account nickname, routing number, account number, and account
|
|
71
|
+
* type. Creating a bank account also updates the contractor's payment method to
|
|
72
|
+
* Direct Deposit on the Gusto API as a side-effect, so the Direct Deposit path
|
|
73
|
+
* needs only this submit — no separate payment method update.
|
|
74
|
+
*
|
|
75
|
+
* When the contractor already has a bank account on file, the account number
|
|
76
|
+
* field is pre-filled with the masked token the API returns (e.g. "XXXX1207").
|
|
77
|
+
* The API requires `account_number` on every write and treats that exact masked
|
|
78
|
+
* value as "keep the existing account," so submitting it unchanged preserves the
|
|
79
|
+
* account while still applying any name/routing/type edits; typing a real number
|
|
80
|
+
* replaces it.
|
|
81
|
+
*
|
|
82
|
+
* @param props - See {@link UseContractorBankAccountFormProps}.
|
|
83
|
+
* @returns A loading-state result while data loads, or a {@link UseContractorBankAccountFormReady} once ready.
|
|
84
|
+
* @public
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```tsx
|
|
88
|
+
* import { useContractorBankAccountForm, SDKFormProvider } from '@gusto/embedded-react-sdk'
|
|
89
|
+
*
|
|
90
|
+
* function AddBankAccount({ contractorId }: { contractorId: string }) {
|
|
91
|
+
* const bankForm = useContractorBankAccountForm({ contractorId })
|
|
92
|
+
*
|
|
93
|
+
* if (bankForm.isLoading) return null
|
|
94
|
+
* const { Fields } = bankForm.form
|
|
95
|
+
*
|
|
96
|
+
* return (
|
|
97
|
+
* <SDKFormProvider formHookResult={bankForm}>
|
|
98
|
+
* <form
|
|
99
|
+
* onSubmit={e => {
|
|
100
|
+
* e.preventDefault()
|
|
101
|
+
* void bankForm.actions.onSubmit()
|
|
102
|
+
* }}
|
|
103
|
+
* >
|
|
104
|
+
* <Fields.Name label="Account nickname" />
|
|
105
|
+
* <Fields.RoutingNumber label="Routing number" />
|
|
106
|
+
* <Fields.AccountNumber label="Account number" />
|
|
107
|
+
* <Fields.AccountType label="Account type" />
|
|
108
|
+
* <button type="submit" disabled={bankForm.status.isPending}>Save</button>
|
|
109
|
+
* </form>
|
|
110
|
+
* </SDKFormProvider>
|
|
111
|
+
* )
|
|
112
|
+
* }
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
export declare function useContractorBankAccountForm({ contractorId, optionalFieldsToRequire, defaultValues: partnerDefaults, validationMode, shouldFocusError, }: UseContractorBankAccountFormProps): HookLoadingResult | UseContractorBankAccountFormReady;
|
|
116
|
+
/**
|
|
117
|
+
* Return type of {@link useContractorBankAccountForm} — a discriminated union on `isLoading`.
|
|
118
|
+
*
|
|
119
|
+
* @public
|
|
120
|
+
*/
|
|
121
|
+
export type UseContractorBankAccountFormResult = HookLoadingResult | UseContractorBankAccountFormReady;
|
|
122
|
+
/**
|
|
123
|
+
* Per-field metadata exposed on `form.fieldsMetadata` for {@link useContractorBankAccountForm}.
|
|
124
|
+
*
|
|
125
|
+
* @public
|
|
126
|
+
*/
|
|
127
|
+
export type ContractorBankAccountFieldsMetadata = UseContractorBankAccountFormReady['form']['fieldsMetadata'];
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { useMemo as N } from "react";
|
|
2
|
+
import { useForm as E } from "react-hook-form";
|
|
3
|
+
import { zodResolver as P } from "@hookform/resolvers/zod";
|
|
4
|
+
import { useContractorPaymentMethodGetBankAccounts as V } from "@gusto/embedded-api-v-2025-11-15/react-query/contractorPaymentMethodGetBankAccounts";
|
|
5
|
+
import { useContractorPaymentMethodsCreateBankAccountMutation as H } from "@gusto/embedded-api-v-2025-11-15/react-query/contractorPaymentMethodsCreateBankAccount";
|
|
6
|
+
import { createContractorBankAccountSchema as L, ACCOUNT_TYPES as g } from "./useContractorBankAccountFormSchema.js";
|
|
7
|
+
import { AccountTypeField as O, AccountNumberField as R, RoutingNumberField as U, NameField as x } from "./fields.js";
|
|
8
|
+
import { useDeriveFieldsMetadata as G } from "../../../../../partner-hook-utils/form/useDeriveFieldsMetadata.js";
|
|
9
|
+
import { useHookFormInternals as I } from "../../../../../partner-hook-utils/form/useHookFormInternals.js";
|
|
10
|
+
import { createGetFormSubmissionValues as q } from "../../../../../partner-hook-utils/form/getFormSubmissionValues.js";
|
|
11
|
+
import { withOptions as z } from "../../../../../partner-hook-utils/form/withOptions.js";
|
|
12
|
+
import { composeErrorHandler as K } from "../../../../../partner-hook-utils/composeErrorHandler.js";
|
|
13
|
+
import { useBaseSubmit as Q } from "../../../../Base/useBaseSubmit.js";
|
|
14
|
+
import { SDKInternalError as Y } from "../../../../../types/sdkError.js";
|
|
15
|
+
function at({
|
|
16
|
+
contractorId: m,
|
|
17
|
+
optionalFieldsToRequire: i,
|
|
18
|
+
defaultValues: o,
|
|
19
|
+
validationMode: A = "onSubmit",
|
|
20
|
+
shouldFocusError: k = !0
|
|
21
|
+
}) {
|
|
22
|
+
const u = V({
|
|
23
|
+
contractorUuid: m
|
|
24
|
+
}), t = u.data?.contractorBankAccountList?.[0] ?? void 0, r = t?.hiddenAccountNumber ?? void 0, [s, y] = N(
|
|
25
|
+
() => L({
|
|
26
|
+
optionalFieldsToRequire: i,
|
|
27
|
+
existingAccountNumberMask: r
|
|
28
|
+
}),
|
|
29
|
+
[i, r]
|
|
30
|
+
), d = N(
|
|
31
|
+
() => ({
|
|
32
|
+
name: o?.name ?? t?.name ?? "",
|
|
33
|
+
routingNumber: o?.routingNumber ?? t?.routingNumber ?? "",
|
|
34
|
+
accountNumber: o?.accountNumber ?? r ?? "",
|
|
35
|
+
accountType: o?.accountType ?? t?.accountType ?? "Checking"
|
|
36
|
+
}),
|
|
37
|
+
[o, t, r]
|
|
38
|
+
), n = E({
|
|
39
|
+
resolver: P(s),
|
|
40
|
+
mode: A,
|
|
41
|
+
shouldFocusError: k,
|
|
42
|
+
defaultValues: d,
|
|
43
|
+
values: d,
|
|
44
|
+
resetOptions: { keepDirtyValues: !0 }
|
|
45
|
+
}), b = H(), B = b.isPending, {
|
|
46
|
+
baseSubmitHandler: F,
|
|
47
|
+
error: h,
|
|
48
|
+
setError: C
|
|
49
|
+
} = Q("ContractorBankAccountForm"), p = K([u], {
|
|
50
|
+
submitError: h,
|
|
51
|
+
setSubmitError: C
|
|
52
|
+
}), S = g.map((e) => ({ value: e, label: e })), c = G(y, n.control), T = {
|
|
53
|
+
name: c.name,
|
|
54
|
+
routingNumber: c.routingNumber,
|
|
55
|
+
accountNumber: c.accountNumber,
|
|
56
|
+
accountType: z(c.accountType, S, [
|
|
57
|
+
...g
|
|
58
|
+
])
|
|
59
|
+
}, M = async () => {
|
|
60
|
+
let e;
|
|
61
|
+
return await new Promise((f) => {
|
|
62
|
+
n.handleSubmit(
|
|
63
|
+
async (v) => {
|
|
64
|
+
await F(v, async (a) => {
|
|
65
|
+
const l = await b.mutateAsync({
|
|
66
|
+
request: {
|
|
67
|
+
contractorUuid: m,
|
|
68
|
+
contractorBankAccountCreateRequestBody: {
|
|
69
|
+
name: a.name,
|
|
70
|
+
routingNumber: a.routingNumber,
|
|
71
|
+
accountNumber: a.accountNumber,
|
|
72
|
+
accountType: a.accountType
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
if (!l.contractorBankAccount)
|
|
77
|
+
throw new Y("Bank account creation failed");
|
|
78
|
+
e = { mode: "create", data: l.contractorBankAccount };
|
|
79
|
+
}), f();
|
|
80
|
+
},
|
|
81
|
+
() => {
|
|
82
|
+
f();
|
|
83
|
+
}
|
|
84
|
+
)();
|
|
85
|
+
}), e;
|
|
86
|
+
}, w = I(n);
|
|
87
|
+
return u.isLoading ? { isLoading: !0, errorHandling: p } : {
|
|
88
|
+
isLoading: !1,
|
|
89
|
+
data: { bankAccount: t },
|
|
90
|
+
status: { isPending: B, mode: "create" },
|
|
91
|
+
actions: { onSubmit: M },
|
|
92
|
+
errorHandling: p,
|
|
93
|
+
form: {
|
|
94
|
+
Fields: {
|
|
95
|
+
Name: x,
|
|
96
|
+
RoutingNumber: U,
|
|
97
|
+
AccountNumber: R,
|
|
98
|
+
AccountType: O
|
|
99
|
+
},
|
|
100
|
+
fieldsMetadata: T,
|
|
101
|
+
hookFormInternals: w,
|
|
102
|
+
getFormSubmissionValues: q(n, s)
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
export {
|
|
107
|
+
at as useContractorBankAccountForm
|
|
108
|
+
};
|
|
109
|
+
//# sourceMappingURL=useContractorBankAccountForm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useContractorBankAccountForm.js","sources":["../../../../../../src/components/Contractor/PaymentMethod/shared/useContractorBankAccountForm/useContractorBankAccountForm.tsx"],"sourcesContent":["import type { ComponentType } from 'react'\nimport { useMemo } from 'react'\nimport { useForm } from 'react-hook-form'\nimport type { UseFormProps } from 'react-hook-form'\nimport { zodResolver } from '@hookform/resolvers/zod'\nimport type { ContractorBankAccount } from '@gusto/embedded-api-v-2025-11-15/models/components/contractorbankaccount'\nimport { useContractorPaymentMethodGetBankAccounts } from '@gusto/embedded-api-v-2025-11-15/react-query/contractorPaymentMethodGetBankAccounts'\nimport { useContractorPaymentMethodsCreateBankAccountMutation } from '@gusto/embedded-api-v-2025-11-15/react-query/contractorPaymentMethodsCreateBankAccount'\nimport {\n ACCOUNT_TYPES,\n createContractorBankAccountSchema,\n type ContractorAccountType,\n type ContractorBankAccountFormData,\n type ContractorBankAccountFormOutputs,\n type ContractorBankAccountOptionalFieldsToRequire,\n} from './useContractorBankAccountFormSchema'\nimport type {\n AccountNumberFieldProps,\n AccountTypeFieldProps,\n NameFieldProps,\n RoutingNumberFieldProps,\n} from './fields'\nimport { AccountNumberField, AccountTypeField, NameField, RoutingNumberField } 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'\n\n/**\n * Props for {@link useContractorBankAccountForm}.\n *\n * @public\n */\nexport interface UseContractorBankAccountFormProps {\n /** Contractor for whom to create the bank account. */\n contractorId: string\n /** Override optional fields to be required. */\n optionalFieldsToRequire?: ContractorBankAccountOptionalFieldsToRequire\n /** Pre-fill form values. The contractor's existing bank account is used when no override is supplied. */\n defaultValues?: Partial<ContractorBankAccountFormData>\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 useContractorBankAccountForm} on `form.Fields`.\n *\n * @public\n */\nexport interface ContractorBankAccountFormFields {\n /** Bound to `name`. Captures the bank account nickname. */\n Name: ComponentType<NameFieldProps>\n /** Bound to `routingNumber`. Validated against a 9-digit numeric pattern. */\n RoutingNumber: ComponentType<RoutingNumberFieldProps>\n /**\n * Bound to `accountNumber`. Pre-filled with the masked account number (e.g.\n * \"XXXX1207\"), which is accepted unchanged to keep the existing account; a\n * newly entered value is validated against the 1–17 digit numeric pattern.\n */\n AccountNumber: ComponentType<AccountNumberFieldProps>\n /**\n * Bound to `accountType`. Options are `Checking` and `Savings`; defaults to\n * `Checking`. Supply `getOptionLabel` to translate the option labels.\n */\n AccountType: ComponentType<AccountTypeFieldProps>\n}\n\n/**\n * Ready-state return value of {@link useContractorBankAccountForm}.\n *\n * @public\n */\nexport interface UseContractorBankAccountFormReady extends BaseFormHookReady<\n FieldsMetadata,\n ContractorBankAccountFormData,\n ContractorBankAccountFormFields\n> {\n /** The contractor's current bank account, loaded from the API, if any. */\n data: {\n bankAccount: ContractorBankAccount | undefined\n }\n /** `isPending` reflects the in-flight create mutation; `mode` is always `'create'`. */\n status: { isPending: boolean; mode: 'create' }\n /** Submit the form. Returns the created bank account on success or `undefined` on validation/mutation failure. */\n actions: {\n onSubmit: () => Promise<HookSubmitResult<ContractorBankAccount> | undefined>\n }\n}\n\n/**\n * Headless React Hook Form hook for creating a contractor's bank account.\n *\n * @remarks\n * Captures the account nickname, routing number, account number, and account\n * type. Creating a bank account also updates the contractor's payment method to\n * Direct Deposit on the Gusto API as a side-effect, so the Direct Deposit path\n * needs only this submit — no separate payment method update.\n *\n * When the contractor already has a bank account on file, the account number\n * field is pre-filled with the masked token the API returns (e.g. \"XXXX1207\").\n * The API requires `account_number` on every write and treats that exact masked\n * value as \"keep the existing account,\" so submitting it unchanged preserves the\n * account while still applying any name/routing/type edits; typing a real number\n * replaces it.\n *\n * @param props - See {@link UseContractorBankAccountFormProps}.\n * @returns A loading-state result while data loads, or a {@link UseContractorBankAccountFormReady} once ready.\n * @public\n *\n * @example\n * ```tsx\n * import { useContractorBankAccountForm, SDKFormProvider } from '@gusto/embedded-react-sdk'\n *\n * function AddBankAccount({ contractorId }: { contractorId: string }) {\n * const bankForm = useContractorBankAccountForm({ contractorId })\n *\n * if (bankForm.isLoading) return null\n * const { Fields } = bankForm.form\n *\n * return (\n * <SDKFormProvider formHookResult={bankForm}>\n * <form\n * onSubmit={e => {\n * e.preventDefault()\n * void bankForm.actions.onSubmit()\n * }}\n * >\n * <Fields.Name label=\"Account nickname\" />\n * <Fields.RoutingNumber label=\"Routing number\" />\n * <Fields.AccountNumber label=\"Account number\" />\n * <Fields.AccountType label=\"Account type\" />\n * <button type=\"submit\" disabled={bankForm.status.isPending}>Save</button>\n * </form>\n * </SDKFormProvider>\n * )\n * }\n * ```\n */\nexport function useContractorBankAccountForm({\n contractorId,\n optionalFieldsToRequire,\n defaultValues: partnerDefaults,\n validationMode = 'onSubmit',\n shouldFocusError = true,\n}: UseContractorBankAccountFormProps): HookLoadingResult | UseContractorBankAccountFormReady {\n const bankAccountsQuery = useContractorPaymentMethodGetBankAccounts({\n contractorUuid: contractorId,\n })\n const bankAccount = bankAccountsQuery.data?.contractorBankAccountList?.[0] ?? undefined\n\n const existingAccountNumberMask = bankAccount?.hiddenAccountNumber ?? undefined\n\n const [schema, metadataConfig] = useMemo(\n () =>\n createContractorBankAccountSchema({\n optionalFieldsToRequire,\n existingAccountNumberMask,\n }),\n [optionalFieldsToRequire, existingAccountNumberMask],\n )\n\n // The account number is seeded with the masked token the API returns (e.g.\n // \"XXXX1207\"). The bank account API requires account_number on every write\n // and treats that exact masked value as \"keep the existing account,\" so\n // submitting it unchanged preserves the account; typing a new number replaces it.\n const resolvedDefaults: ContractorBankAccountFormData = useMemo(\n () => ({\n name: partnerDefaults?.name ?? bankAccount?.name ?? '',\n routingNumber: partnerDefaults?.routingNumber ?? bankAccount?.routingNumber ?? '',\n accountNumber: partnerDefaults?.accountNumber ?? existingAccountNumberMask ?? '',\n accountType: (partnerDefaults?.accountType ??\n bankAccount?.accountType ??\n 'Checking') as ContractorAccountType,\n }),\n [partnerDefaults, bankAccount, existingAccountNumberMask],\n )\n\n const formMethods = useForm<\n ContractorBankAccountFormData,\n unknown,\n ContractorBankAccountFormOutputs\n >({\n resolver: zodResolver(schema),\n mode: validationMode,\n shouldFocusError,\n defaultValues: resolvedDefaults,\n values: resolvedDefaults,\n resetOptions: { keepDirtyValues: true },\n })\n\n const createMutation = useContractorPaymentMethodsCreateBankAccountMutation()\n const isPending = createMutation.isPending\n\n const {\n baseSubmitHandler,\n error: submitError,\n setError: setSubmitError,\n } = useBaseSubmit('ContractorBankAccountForm')\n\n const errorHandling = composeErrorHandler([bankAccountsQuery], {\n submitError,\n setSubmitError,\n })\n\n const accountTypeOptions = ACCOUNT_TYPES.map(value => ({ value, label: value }))\n\n const baseMetadata = useDeriveFieldsMetadata(metadataConfig, formMethods.control)\n const fieldsMetadata = {\n name: baseMetadata.name,\n routingNumber: baseMetadata.routingNumber,\n accountNumber: baseMetadata.accountNumber,\n accountType: withOptions<ContractorAccountType>(baseMetadata.accountType, accountTypeOptions, [\n ...ACCOUNT_TYPES,\n ]),\n }\n\n const onSubmit = async (): Promise<HookSubmitResult<ContractorBankAccount> | undefined> => {\n let submitResult: HookSubmitResult<ContractorBankAccount> | undefined\n\n await new Promise<void>(resolve => {\n void formMethods.handleSubmit(\n async (data: ContractorBankAccountFormOutputs) => {\n await baseSubmitHandler(data, async payload => {\n const response = await createMutation.mutateAsync({\n request: {\n contractorUuid: contractorId,\n contractorBankAccountCreateRequestBody: {\n name: payload.name,\n routingNumber: payload.routingNumber,\n accountNumber: payload.accountNumber,\n accountType: payload.accountType,\n },\n },\n })\n\n if (!response.contractorBankAccount) {\n throw new SDKInternalError('Bank account creation failed')\n }\n\n submitResult = { mode: 'create' as const, data: response.contractorBankAccount }\n })\n resolve()\n },\n () => {\n resolve()\n },\n )()\n })\n\n return submitResult\n }\n\n const hookFormInternals = useHookFormInternals(formMethods)\n\n if (bankAccountsQuery.isLoading) {\n return { isLoading: true as const, errorHandling }\n }\n\n return {\n isLoading: false as const,\n data: { bankAccount },\n status: { isPending, mode: 'create' as const },\n actions: { onSubmit },\n errorHandling,\n form: {\n Fields: {\n Name: NameField,\n RoutingNumber: RoutingNumberField,\n AccountNumber: AccountNumberField,\n AccountType: AccountTypeField,\n },\n fieldsMetadata,\n hookFormInternals,\n getFormSubmissionValues: createGetFormSubmissionValues(formMethods, schema),\n },\n }\n}\n\n/**\n * Return type of {@link useContractorBankAccountForm} — a discriminated union on `isLoading`.\n *\n * @public\n */\nexport type UseContractorBankAccountFormResult =\n HookLoadingResult | UseContractorBankAccountFormReady\n\n/**\n * Per-field metadata exposed on `form.fieldsMetadata` for {@link useContractorBankAccountForm}.\n *\n * @public\n */\nexport type ContractorBankAccountFieldsMetadata =\n UseContractorBankAccountFormReady['form']['fieldsMetadata']\n"],"names":["useContractorBankAccountForm","contractorId","optionalFieldsToRequire","partnerDefaults","validationMode","shouldFocusError","bankAccountsQuery","useContractorPaymentMethodGetBankAccounts","bankAccount","existingAccountNumberMask","schema","metadataConfig","useMemo","createContractorBankAccountSchema","resolvedDefaults","formMethods","useForm","zodResolver","createMutation","useContractorPaymentMethodsCreateBankAccountMutation","isPending","baseSubmitHandler","submitError","setSubmitError","useBaseSubmit","errorHandling","composeErrorHandler","accountTypeOptions","ACCOUNT_TYPES","value","baseMetadata","useDeriveFieldsMetadata","fieldsMetadata","withOptions","onSubmit","submitResult","resolve","data","payload","response","SDKInternalError","hookFormInternals","useHookFormInternals","NameField","RoutingNumberField","AccountNumberField","AccountTypeField","createGetFormSubmissionValues"],"mappings":";;;;;;;;;;;;;;AAqJO,SAASA,GAA6B;AAAA,EAC3C,cAAAC;AAAA,EACA,yBAAAC;AAAA,EACA,eAAeC;AAAA,EACf,gBAAAC,IAAiB;AAAA,EACjB,kBAAAC,IAAmB;AACrB,GAA6F;AAC3F,QAAMC,IAAoBC,EAA0C;AAAA,IAClE,gBAAgBN;AAAA,EAAA,CACjB,GACKO,IAAcF,EAAkB,MAAM,4BAA4B,CAAC,KAAK,QAExEG,IAA4BD,GAAa,uBAAuB,QAEhE,CAACE,GAAQC,CAAc,IAAIC;AAAA,IAC/B,MACEC,EAAkC;AAAA,MAChC,yBAAAX;AAAA,MACA,2BAAAO;AAAA,IAAA,CACD;AAAA,IACH,CAACP,GAAyBO,CAAyB;AAAA,EAAA,GAO/CK,IAAkDF;AAAA,IACtD,OAAO;AAAA,MACL,MAAMT,GAAiB,QAAQK,GAAa,QAAQ;AAAA,MACpD,eAAeL,GAAiB,iBAAiBK,GAAa,iBAAiB;AAAA,MAC/E,eAAeL,GAAiB,iBAAiBM,KAA6B;AAAA,MAC9E,aAAcN,GAAiB,eAC7BK,GAAa,eACb;AAAA,IAAA;A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EAAS;AACZ,oBAAM,IAAIC,EAAiB,8BAA8B;AAG3D,YAAAL,IAAe,EAAE,MAAM,UAAmB,MAAMI,EAAS,sBAAA;AAAA,UAC3D,CAAC,GACDH,EAAA;AAAA,QACF;AAAA,QACA,MAAM;AACJ,UAAAA,EAAA;AAAA,QACF;AAAA,MAAA,EACF;AAAA,IACF,CAAC,GAEMD;AAAA,EACT,GAEMM,IAAoBC,EAAqB3B,CAAW;AAE1D,SAAIT,EAAkB,YACb,EAAE,WAAW,IAAe,eAAAmB,EAAA,IAG9B;AAAA,IACL,WAAW;AAAA,IACX,MAAM,EAAE,aAAAjB,EAAA;AAAA,IACR,QAAQ,EAAE,WAAAY,GAAW,MAAM,SAAA;AAAA,IAC3B,SAAS,EAAE,UAAAc,EAAA;AAAA,IACX,eAAAT;AAAA,IACA,MAAM;AAAA,MACJ,QAAQ;AAAA,QACN,MAAMkB;AAAA,QACN,eAAeC;AAAA,QACf,eAAeC;AAAA,QACf,aAAaC;AAAA,MAAA;AAAA,MAEf,gBAAAd;AAAA,MACA,mBAAAS;AAAA,MACA,yBAAyBM,EAA8BhC,GAAaL,CAAM;AAAA,IAAA;AAAA,EAC5E;AAEJ;"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { OptionalFieldsToRequire } from '../../../../../partner-hook-utils/form/buildFormSchema';
|
|
3
|
+
/**
|
|
4
|
+
* Validation error codes emitted by the contractor bank account form schema.
|
|
5
|
+
* Map these codes to localized copy in `validationMessages` when composing the
|
|
6
|
+
* hook.
|
|
7
|
+
*
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
export declare const ContractorBankAccountErrorCodes: {
|
|
11
|
+
readonly REQUIRED: "REQUIRED";
|
|
12
|
+
readonly INVALID_ROUTING_NUMBER: "INVALID_ROUTING_NUMBER";
|
|
13
|
+
readonly INVALID_ACCOUNT_NUMBER: "INVALID_ACCOUNT_NUMBER";
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Union of validation error code strings emitted by the contractor bank account
|
|
17
|
+
* form schema.
|
|
18
|
+
*
|
|
19
|
+
* @public
|
|
20
|
+
*/
|
|
21
|
+
export type ContractorBankAccountErrorCode = (typeof ContractorBankAccountErrorCodes)[keyof typeof ContractorBankAccountErrorCodes];
|
|
22
|
+
/**
|
|
23
|
+
* Supported bank account type values: checking and savings.
|
|
24
|
+
*
|
|
25
|
+
* @public
|
|
26
|
+
*/
|
|
27
|
+
export declare const ACCOUNT_TYPES: readonly ["Checking", "Savings"];
|
|
28
|
+
/**
|
|
29
|
+
* Union of bank account type values that the form accepts.
|
|
30
|
+
*
|
|
31
|
+
* @public
|
|
32
|
+
*/
|
|
33
|
+
export type ContractorAccountType = (typeof ACCOUNT_TYPES)[number];
|
|
34
|
+
/**
|
|
35
|
+
* Field names accepted by the contractor bank account form.
|
|
36
|
+
*
|
|
37
|
+
* @public
|
|
38
|
+
*/
|
|
39
|
+
export type ContractorBankAccountFormField = "name" | "routingNumber" | "accountNumber" | "accountType";
|
|
40
|
+
/**
|
|
41
|
+
* Shape of the values managed by the contractor bank account form.
|
|
42
|
+
*
|
|
43
|
+
* @public
|
|
44
|
+
* @interface
|
|
45
|
+
*/
|
|
46
|
+
export type ContractorBankAccountFormData = { name: string; routingNumber: string; accountNumber: string; accountType: "Checking" | "Savings"; };
|
|
47
|
+
/**
|
|
48
|
+
* Shape of the validated values produced by the contractor bank account form on
|
|
49
|
+
* submit.
|
|
50
|
+
*
|
|
51
|
+
* @public
|
|
52
|
+
*/
|
|
53
|
+
export type ContractorBankAccountFormOutputs = ContractorBankAccountFormData;
|
|
54
|
+
/**
|
|
55
|
+
* Keys of optional contractor bank account fields that can be promoted to
|
|
56
|
+
* required via the hook's `optionalFieldsToRequire` option.
|
|
57
|
+
*
|
|
58
|
+
* @public
|
|
59
|
+
*/
|
|
60
|
+
export type ContractorBankAccountOptionalFieldsToRequire = { create?: never[] | undefined; update?: never[] | undefined; };
|
|
61
|
+
/** @internal */
|
|
62
|
+
interface ContractorBankAccountSchemaOptions {
|
|
63
|
+
optionalFieldsToRequire?: ContractorBankAccountOptionalFieldsToRequire;
|
|
64
|
+
/**
|
|
65
|
+
* The contractor's current masked account number (e.g. `"XXXX1207"`), if one
|
|
66
|
+
* is on file. The bank account API requires `account_number` on every write
|
|
67
|
+
* and treats this exact masked token as "keep the existing account number,"
|
|
68
|
+
* so the field is pre-filled with it and validation accepts it unchanged. Any
|
|
69
|
+
* other value must be a real 1–17 digit account number.
|
|
70
|
+
*/
|
|
71
|
+
existingAccountNumberMask?: string;
|
|
72
|
+
}
|
|
73
|
+
/** @internal */
|
|
74
|
+
export declare function createContractorBankAccountSchema(options?: ContractorBankAccountSchemaOptions): import('../../../../../partner-hook-utils/form/buildFormSchema').BuildFormSchemaResult<{
|
|
75
|
+
accountNumber: z.ZodString;
|
|
76
|
+
name: z.ZodString;
|
|
77
|
+
routingNumber: z.ZodString;
|
|
78
|
+
accountType: z.ZodEnum<{
|
|
79
|
+
Checking: "Checking";
|
|
80
|
+
Savings: "Savings";
|
|
81
|
+
}>;
|
|
82
|
+
}>;
|
|
83
|
+
export {};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { z as e } from "zod";
|
|
2
|
+
import { buildFormSchema as i } from "../../../../../partner-hook-utils/form/buildFormSchema.js";
|
|
3
|
+
import { ACCOUNT_NUMBER_REGEX as N, ROUTING_NUMBER_REGEX as u } from "../../../../../helpers/validations.js";
|
|
4
|
+
const r = {
|
|
5
|
+
REQUIRED: "REQUIRED",
|
|
6
|
+
INVALID_ROUTING_NUMBER: "INVALID_ROUTING_NUMBER",
|
|
7
|
+
INVALID_ACCOUNT_NUMBER: "INVALID_ACCOUNT_NUMBER"
|
|
8
|
+
}, m = ["Checking", "Savings"], n = {
|
|
9
|
+
name: e.string(),
|
|
10
|
+
routingNumber: e.string().regex(u, {
|
|
11
|
+
message: r.INVALID_ROUTING_NUMBER
|
|
12
|
+
}),
|
|
13
|
+
accountNumber: e.string().regex(N, {
|
|
14
|
+
message: r.INVALID_ACCOUNT_NUMBER
|
|
15
|
+
}),
|
|
16
|
+
accountType: e.enum(m)
|
|
17
|
+
}, E = {
|
|
18
|
+
name: "always",
|
|
19
|
+
routingNumber: "always",
|
|
20
|
+
accountNumber: "always",
|
|
21
|
+
accountType: "always"
|
|
22
|
+
};
|
|
23
|
+
function _(c = {}) {
|
|
24
|
+
const { optionalFieldsToRequire: a, existingAccountNumberMask: o } = c, s = o ? e.string().refine((t) => t === o || N.test(t), {
|
|
25
|
+
message: r.INVALID_ACCOUNT_NUMBER
|
|
26
|
+
}) : n.accountNumber;
|
|
27
|
+
return i(
|
|
28
|
+
{ ...n, accountNumber: s },
|
|
29
|
+
{
|
|
30
|
+
requiredFieldsConfig: E,
|
|
31
|
+
requiredErrorCode: r.REQUIRED,
|
|
32
|
+
mode: "create",
|
|
33
|
+
optionalFieldsToRequire: a
|
|
34
|
+
}
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
export {
|
|
38
|
+
m as ACCOUNT_TYPES,
|
|
39
|
+
r as ContractorBankAccountErrorCodes,
|
|
40
|
+
_ as createContractorBankAccountSchema
|
|
41
|
+
};
|
|
42
|
+
//# sourceMappingURL=useContractorBankAccountFormSchema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useContractorBankAccountFormSchema.js","sources":["../../../../../../src/components/Contractor/PaymentMethod/shared/useContractorBankAccountForm/useContractorBankAccountFormSchema.ts"],"sourcesContent":["import { z } from 'zod'\nimport {\n buildFormSchema,\n type OptionalFieldsToRequire,\n type RequiredFieldConfig,\n} from '@/partner-hook-utils/form/buildFormSchema'\nimport { ACCOUNT_NUMBER_REGEX, ROUTING_NUMBER_REGEX } from '@/helpers/validations'\n\n/**\n * Validation error codes emitted by the contractor bank account form schema.\n * Map these codes to localized copy in `validationMessages` when composing the\n * hook.\n *\n * @public\n */\nexport const ContractorBankAccountErrorCodes = {\n REQUIRED: 'REQUIRED',\n INVALID_ROUTING_NUMBER: 'INVALID_ROUTING_NUMBER',\n INVALID_ACCOUNT_NUMBER: 'INVALID_ACCOUNT_NUMBER',\n} as const\n\n/**\n * Union of validation error code strings emitted by the contractor bank account\n * form schema.\n *\n * @public\n */\nexport type ContractorBankAccountErrorCode =\n (typeof ContractorBankAccountErrorCodes)[keyof typeof ContractorBankAccountErrorCodes]\n\n/**\n * Supported bank account type values: checking and savings.\n *\n * @public\n */\nexport const ACCOUNT_TYPES = ['Checking', 'Savings'] as const\n\n/**\n * Union of bank account type values that the form accepts.\n *\n * @public\n */\nexport type ContractorAccountType = (typeof ACCOUNT_TYPES)[number]\n\nconst fieldValidators = {\n name: z.string(),\n routingNumber: z.string().regex(ROUTING_NUMBER_REGEX, {\n message: ContractorBankAccountErrorCodes.INVALID_ROUTING_NUMBER,\n }),\n accountNumber: z.string().regex(ACCOUNT_NUMBER_REGEX, {\n message: ContractorBankAccountErrorCodes.INVALID_ACCOUNT_NUMBER,\n }),\n accountType: z.enum(ACCOUNT_TYPES),\n}\n\n/**\n * Field names accepted by the contractor bank account form.\n *\n * @public\n */\nexport type ContractorBankAccountFormField = keyof typeof fieldValidators\n\n/**\n * Shape of the values managed by the contractor bank account form.\n *\n * @public\n * @interface\n */\nexport type ContractorBankAccountFormData = {\n [K in keyof typeof fieldValidators]: z.infer<(typeof fieldValidators)[K]>\n}\n\n/**\n * Shape of the validated values produced by the contractor bank account form on\n * submit.\n *\n * @public\n */\nexport type ContractorBankAccountFormOutputs = ContractorBankAccountFormData\n\nconst requiredFieldsConfig = {\n name: 'always',\n routingNumber: 'always',\n accountNumber: 'always',\n accountType: 'always',\n} satisfies RequiredFieldConfig<typeof fieldValidators>\n\n/**\n * Keys of optional contractor bank account fields that can be promoted to\n * required via the hook's `optionalFieldsToRequire` option.\n *\n * @public\n */\nexport type ContractorBankAccountOptionalFieldsToRequire = OptionalFieldsToRequire<\n typeof requiredFieldsConfig\n>\n\n/** @internal */\ninterface ContractorBankAccountSchemaOptions {\n optionalFieldsToRequire?: ContractorBankAccountOptionalFieldsToRequire\n /**\n * The contractor's current masked account number (e.g. `\"XXXX1207\"`), if one\n * is on file. The bank account API requires `account_number` on every write\n * and treats this exact masked token as \"keep the existing account number,\"\n * so the field is pre-filled with it and validation accepts it unchanged. Any\n * other value must be a real 1–17 digit account number.\n */\n existingAccountNumberMask?: string\n}\n\n/** @internal */\nexport function createContractorBankAccountSchema(\n options: ContractorBankAccountSchemaOptions = {},\n) {\n const { optionalFieldsToRequire, existingAccountNumberMask } = options\n\n const accountNumber = existingAccountNumberMask\n ? z\n .string()\n .refine(value => value === existingAccountNumberMask || ACCOUNT_NUMBER_REGEX.test(value), {\n message: ContractorBankAccountErrorCodes.INVALID_ACCOUNT_NUMBER,\n })\n : fieldValidators.accountNumber\n\n return buildFormSchema(\n { ...fieldValidators, accountNumber },\n {\n requiredFieldsConfig,\n requiredErrorCode: ContractorBankAccountErrorCodes.REQUIRED,\n mode: 'create',\n optionalFieldsToRequire,\n },\n )\n}\n"],"names":["ContractorBankAccountErrorCodes","ACCOUNT_TYPES","fieldValidators","z","ROUTING_NUMBER_REGEX","ACCOUNT_NUMBER_REGEX","requiredFieldsConfig","createContractorBankAccountSchema","options","optionalFieldsToRequire","existingAccountNumberMask","accountNumber","value","buildFormSchema"],"mappings":";;;AAeO,MAAMA,IAAkC;AAAA,EAC7C,UAAU;AAAA,EACV,wBAAwB;AAAA,EACxB,wBAAwB;AAC1B,GAgBaC,IAAgB,CAAC,YAAY,SAAS,GAS7CC,IAAkB;AAAA,EACtB,MAAMC,EAAE,OAAA;AAAA,EACR,eAAeA,EAAE,SAAS,MAAMC,GAAsB;AAAA,IACpD,SAASJ,EAAgC;AAAA,EAAA,CAC1C;AAAA,EACD,eAAeG,EAAE,SAAS,MAAME,GAAsB;AAAA,IACpD,SAASL,EAAgC;AAAA,EAAA,CAC1C;AAAA,EACD,aAAaG,EAAE,KAAKF,CAAa;AACnC,GA2BMK,IAAuB;AAAA,EAC3B,MAAM;AAAA,EACN,eAAe;AAAA,EACf,eAAe;AAAA,EACf,aAAa;AACf;AA0BO,SAASC,EACdC,IAA8C,IAC9C;AACA,QAAM,EAAE,yBAAAC,GAAyB,2BAAAC,EAAA,IAA8BF,GAEzDG,IAAgBD,IAClBP,EACG,OAAA,EACA,OAAO,CAAAS,MAASA,MAAUF,KAA6BL,EAAqB,KAAKO,CAAK,GAAG;AAAA,IACxF,SAASZ,EAAgC;AAAA,EAAA,CAC1C,IACHE,EAAgB;AAEpB,SAAOW;AAAA,IACL,EAAE,GAAGX,GAAiB,eAAAS,EAAA;AAAA,IACtB;AAAA,MACE,sBAAAL;AAAA,MACA,mBAAmBN,EAAgC;AAAA,MACnD,MAAM;AAAA,MACN,yBAAAS;AAAA,IAAA;AAAA,EACF;AAEJ;"}
|