@gusto/embedded-react-sdk 0.44.0 → 0.44.2
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 +21 -0
- package/dist/components/Base/useBaseSubmit.js +6 -6
- package/dist/components/Base/useBaseSubmit.js.map +1 -1
- package/dist/components/Company/AssignSignatory/AssignSignatorySelection.js +1 -1
- package/dist/components/Company/AssignSignatory/CreateSignatory/Actions.js +1 -1
- package/dist/components/Company/AssignSignatory/CreateSignatory/useCreateSignatory.js +1 -1
- package/dist/components/Company/AssignSignatory/InviteSignatory/Actions.js +1 -1
- package/dist/components/Company/AssignSignatory/InviteSignatory/useInviteSignatory.js +1 -1
- package/dist/components/Company/AssignSignatory/TitleSelect.js +1 -1
- package/dist/components/Company/AssignSignatory/useAssignSignatory.js +1 -1
- package/dist/components/Company/BankAccount/BankAccountForm/Actions.js +1 -1
- package/dist/components/Company/BankAccount/BankAccountForm/context.js +1 -1
- package/dist/components/Company/BankAccount/BankAccountList/Actions.js +1 -1
- package/dist/components/Company/BankAccount/BankAccountVerify/Actions.js +1 -1
- package/dist/components/Company/DocumentSigner/DocumentList/Actions.js +1 -1
- package/dist/components/Company/DocumentSigner/DocumentList/DocumentList.js +9 -9
- package/dist/components/Company/DocumentSigner/DocumentList/DocumentList.js.map +1 -1
- package/dist/components/Company/DocumentSigner/DocumentList/useDocumentList.js +1 -1
- package/dist/components/Company/FederalTaxes/Actions.js +1 -1
- package/dist/components/Company/FederalTaxes/useFederalTaxes.js +1 -1
- package/dist/components/Company/Industry/Actions.js +1 -1
- package/dist/components/Company/Industry/Context.js +1 -1
- package/dist/components/Company/Industry/Edit.js +1 -1
- package/dist/components/Company/Locations/LocationForm/Actions.js +1 -1
- package/dist/components/Company/Locations/LocationForm/useLocationForm.js +1 -1
- package/dist/components/Company/Locations/LocationsList/Actions.js +1 -1
- package/dist/components/Company/Locations/LocationsList/List.js +1 -1
- package/dist/components/Company/Locations/LocationsList/useLocationsList.js +1 -1
- package/dist/components/Company/OnboardingOverview/context.js +1 -1
- package/dist/components/Company/PaySchedule/PaySchedule.d.ts +2 -2
- package/dist/components/Company/PaySchedule/PaySchedule.js +6 -6
- package/dist/components/Company/PaySchedule/PaySchedule.js.map +1 -1
- package/dist/components/Company/PaySchedule/PayScheduleList.js +8 -8
- package/dist/components/Company/PaySchedule/PayScheduleList.js.map +1 -1
- package/dist/components/Company/PaySchedule/shared/usePayScheduleForm/usePayScheduleForm.d.ts +3 -3
- package/dist/components/Company/PaySchedule/shared/usePayScheduleForm/usePayScheduleForm.js +12 -12
- package/dist/components/Company/PaySchedule/shared/usePayScheduleForm/usePayScheduleForm.js.map +1 -1
- package/dist/components/Company/StateTaxes/StateTaxesForm/Actions.js +1 -1
- package/dist/components/Company/StateTaxes/StateTaxesForm/context.js +1 -1
- package/dist/components/Company/StateTaxes/StateTaxesList/Actions.js +1 -1
- package/dist/components/Company/StateTaxes/StateTaxesList/context.js +1 -1
- package/dist/components/Contractor/Address/Address.js +16 -16
- package/dist/components/Contractor/Address/Address.js.map +1 -1
- package/dist/components/Contractor/Address/Form.js +4 -4
- package/dist/components/Contractor/Address/useAddress.js +1 -1
- package/dist/components/Contractor/PaymentMethod/PaymentMethod.js +8 -8
- package/dist/components/Contractor/PaymentMethod/PaymentMethod.js.map +1 -1
- package/dist/components/Contractor/PaymentMethod/PaymentTypeForm.js +1 -1
- package/dist/components/Contractor/Payments/PaymentsList/PaymentsList.js +5 -5
- package/dist/components/Contractor/Payments/PaymentsList/PaymentsList.js.map +1 -1
- package/dist/components/Contractor/Profile/useContractorProfile.js +1 -1
- package/dist/components/Contractor/Submit/Submit.js +22 -20
- package/dist/components/Contractor/Submit/Submit.js.map +1 -1
- package/dist/components/Employee/Dashboard/hooks/useEmployeeCompensation.d.ts +1 -1
- package/dist/components/Employee/Dashboard/hooks/useEmployeeCompensation.js +6 -6
- package/dist/components/Employee/Dashboard/hooks/useEmployeeCompensation.js.map +1 -1
- package/dist/components/Employee/Dashboard/hooks/useEmployeeForms.js +3 -3
- package/dist/components/Employee/Dashboard/hooks/useEmployeeForms.js.map +1 -1
- package/dist/components/Employee/Deductions/Deductions.js +7 -7
- package/dist/components/Employee/Deductions/Deductions.js.map +1 -1
- package/dist/components/Employee/Deductions/DeductionsForm/ChildSupportForm.js +24 -24
- package/dist/components/Employee/Deductions/DeductionsForm/ChildSupportForm.js.map +1 -1
- package/dist/components/Employee/Deductions/DeductionsForm/CustomDeductionForm.js +13 -9
- package/dist/components/Employee/Deductions/DeductionsForm/CustomDeductionForm.js.map +1 -1
- package/dist/components/Employee/Deductions/DeductionsForm/DeductionsForm.js +2 -2
- package/dist/components/Employee/Deductions/DeductionsForm/DeductionsForm.js.map +1 -1
- package/dist/components/Employee/Deductions/DeductionsForm/GarnishmentForm.d.ts +1 -2
- package/dist/components/Employee/Deductions/DeductionsForm/GarnishmentForm.js +17 -17
- package/dist/components/Employee/Deductions/DeductionsForm/GarnishmentForm.js.map +1 -1
- package/dist/components/Employee/Deductions/DeductionsList/DeductionsList.js +30 -30
- package/dist/components/Employee/Deductions/DeductionsList/DeductionsList.js.map +1 -1
- package/dist/components/Employee/DocumentSigner/DocumentList/Actions.js +1 -1
- package/dist/components/Employee/DocumentSigner/DocumentList/DocumentList.js +8 -8
- package/dist/components/Employee/DocumentSigner/DocumentList/DocumentList.js.map +1 -1
- package/dist/components/Employee/DocumentSigner/DocumentList/useDocumentList.js +1 -1
- package/dist/components/Employee/DocumentSigner/DocumentSigner.js +1 -1
- package/dist/components/Employee/DocumentSigner/DocumentSigner.js.map +1 -1
- package/dist/components/Employee/DocumentSigner/EmploymentEligibility/EmploymentEligibilityPresentation.js +12 -12
- package/dist/components/Employee/DocumentSigner/EmploymentEligibility/EmploymentEligibilityPresentation.js.map +1 -1
- package/dist/components/Employee/DocumentSigner/EmploymentEligibility/EmploymentEligibilitySchema.js +1 -1
- package/dist/components/Employee/DocumentSigner/EmploymentEligibility/EmploymentEligibilitySchema.js.map +1 -1
- package/dist/components/Employee/FederalTaxes/management/FederalTaxes.js +1 -1
- package/dist/components/Employee/FederalTaxes/onboarding/FederalTaxes.js +1 -1
- package/dist/components/Employee/PaymentMethod/Actions.js +1 -1
- package/dist/components/Employee/PaymentMethod/BankAccountEdit.js +1 -1
- package/dist/components/Employee/PaymentMethod/BankAccountsList.js +1 -1
- package/dist/components/Employee/PaymentMethod/PaymentMethod.js +14 -14
- package/dist/components/Employee/PaymentMethod/PaymentMethod.js.map +1 -1
- package/dist/components/Employee/PaymentMethod/PaymentTypeForm.js +1 -1
- package/dist/components/Employee/PaymentMethod/Split.js +1 -1
- package/dist/components/Employee/PaymentMethod/usePaymentMethod.js +1 -1
- package/dist/components/Employee/Profile/management/Profile.js +1 -1
- package/dist/components/Employee/Profile/onboarding/AdminProfile.js +1 -1
- package/dist/components/Employee/Profile/onboarding/EmployeeProfile.js +1 -1
- package/dist/components/Employee/StateTaxes/management/StateTaxes.js +1 -1
- package/dist/components/Employee/StateTaxes/onboarding/StateTaxes.js +1 -1
- package/dist/components/Employee/StateTaxes/shared/EmployeeStateTaxesView.js +19 -17
- package/dist/components/Employee/StateTaxes/shared/EmployeeStateTaxesView.js.map +1 -1
- package/dist/components/Employee/StateTaxes/shared/EmployeeStateTaxesView.module.scss.js +8 -0
- package/dist/components/Employee/StateTaxes/shared/EmployeeStateTaxesView.module.scss.js.map +1 -0
- package/dist/components/Employee/Taxes/Actions.js +1 -1
- package/dist/components/Employee/Taxes/FederalForm.js +1 -1
- package/dist/components/Employee/Taxes/useTaxes.js +1 -1
- package/dist/components/Employee/Terminations/TerminateEmployee/TerminateEmployee.js +11 -11
- package/dist/components/Employee/Terminations/TerminateEmployee/TerminateEmployee.js.map +1 -1
- package/dist/components/Employee/Terminations/TerminationSummary/TerminationSummary.js +3 -3
- package/dist/components/Employee/Terminations/TerminationSummary/TerminationSummary.js.map +1 -1
- package/dist/components/InformationRequests/InformationRequestForm/InformationRequestForm.js +40 -45
- package/dist/components/InformationRequests/InformationRequestForm/InformationRequestForm.js.map +1 -1
- package/dist/components/InformationRequests/InformationRequestList/InformationRequestList.js +1 -1
- package/dist/components/InformationRequests/InformationRequestList/InformationRequestList.js.map +1 -1
- package/dist/components/Payroll/ConfirmWireDetails/ConfirmWireDetailsForm/ConfirmWireDetailsForm.js +17 -17
- package/dist/components/Payroll/ConfirmWireDetails/ConfirmWireDetailsForm/ConfirmWireDetailsForm.js.map +1 -1
- package/dist/components/Payroll/Dismissal/DismissalPayPeriodSelection/DismissalPayPeriodSelection.js +7 -7
- package/dist/components/Payroll/Dismissal/DismissalPayPeriodSelection/DismissalPayPeriodSelection.js.map +1 -1
- package/dist/components/Payroll/GrossUpModal/GrossUpModal.js +1 -1
- package/dist/components/Payroll/OffCyclePayPeriodDateForm/OffCyclePayPeriodDateFormPresentation.js +1 -1
- package/dist/components/Payroll/OffCycleReasonSelection/OffCycleReasonSelectionPresentation.js +1 -1
- package/dist/components/Payroll/OffCycleTaxWithholdingModal/OffCycleTaxWithholdingModal.js +1 -1
- package/dist/components/Payroll/PayrollBlocker/components/PayrollBlockerList.js +10 -10
- package/dist/components/Payroll/PayrollBlocker/components/PayrollBlockerList.js.map +1 -1
- package/dist/components/Payroll/PayrollBlocker/payrollHelpers.d.ts +2 -2
- package/dist/components/Payroll/PayrollBlocker/payrollHelpers.js +21 -25
- package/dist/components/Payroll/PayrollBlocker/payrollHelpers.js.map +1 -1
- package/dist/components/Payroll/PayrollConfiguration/PayrollConfigurationPresentation.d.ts +1 -1
- package/dist/components/Payroll/PayrollConfiguration/PayrollConfigurationPresentation.js.map +1 -1
- package/dist/components/Payroll/PayrollConfiguration/usePayrollConfigurationData.d.ts +2 -2
- package/dist/components/Payroll/PayrollConfiguration/usePayrollConfigurationData.js +1 -1
- package/dist/components/Payroll/PayrollConfiguration/usePayrollConfigurationData.js.map +1 -1
- package/dist/components/Payroll/PayrollEditEmployee/PayrollEditEmployee.js +4 -4
- package/dist/components/Payroll/PayrollEditEmployee/PayrollEditEmployee.js.map +1 -1
- package/dist/components/Payroll/PayrollEditEmployee/PayrollEditEmployeePresentation.d.ts +1 -1
- package/dist/components/Payroll/PayrollEditEmployee/PayrollEditEmployeePresentation.js.map +1 -1
- package/dist/components/Payroll/PayrollList/PayrollList.js +4 -4
- package/dist/components/Payroll/PayrollList/PayrollList.js.map +1 -1
- package/dist/components/Payroll/PayrollList/PayrollListPresentation.d.ts +2 -2
- package/dist/components/Payroll/PayrollList/PayrollListPresentation.js.map +1 -1
- package/dist/components/Payroll/RecoveryCases/RecoveryCasesList/RecoveryCasesList.js +5 -5
- package/dist/components/Payroll/RecoveryCases/RecoveryCasesList/RecoveryCasesList.js.map +1 -1
- package/dist/components/Payroll/RecoveryCases/RecoveryCasesResubmit/RecoveryCasesResubmit.js +1 -1
- package/dist/components/Payroll/RecoveryCases/RecoveryCasesResubmit/RecoveryCasesResubmit.js.map +1 -1
- package/dist/components/Payroll/TransitionCreation/TransitionCreation.js +7 -7
- package/dist/components/Payroll/TransitionCreation/TransitionCreation.js.map +1 -1
- package/dist/components/Payroll/TransitionPayrollAlert/TransitionPayrollAlert.d.ts +1 -1
- package/dist/components/Payroll/TransitionPayrollAlert/TransitionPayrollAlert.js +70 -53
- package/dist/components/Payroll/TransitionPayrollAlert/TransitionPayrollAlert.js.map +1 -1
- package/dist/components/Payroll/TransitionPayrollAlert/TransitionPayrollAlertPresentation.d.ts +1 -1
- package/dist/components/Payroll/TransitionPayrollAlert/TransitionPayrollAlertPresentation.js.map +1 -1
- package/dist/components/Payroll/helpers.d.ts +1 -1
- package/dist/components/Payroll/helpers.js.map +1 -1
- package/dist/components/Payroll/usePreparedPayrollData.d.ts +2 -2
- package/dist/components/Payroll/usePreparedPayrollData.js +10 -10
- package/dist/components/Payroll/usePreparedPayrollData.js.map +1 -1
- package/dist/components/TimeOff/HolidayPolicyDetail/HolidayPolicyDetailPresentation.js +1 -1
- package/dist/components/TimeOff/TimeOffManagement/SelectEmployees/SelectEmployeesTimeOff.js +41 -41
- package/dist/components/TimeOff/TimeOffManagement/SelectEmployees/SelectEmployeesTimeOff.js.map +1 -1
- package/dist/components/TimeOff/shared/EmployeeTable/EmployeeTable.js +1 -1
- package/dist/components/TimeOff/shared/PolicyDetailLayout/PolicyDetailLayout.js +1 -1
- package/dist/contexts/GustoProvider/GustoProviderCustomUIAdapter.js +1 -1
- package/dist/helpers/dateFormatting.js +52 -56
- package/dist/helpers/dateFormatting.js.map +1 -1
- package/dist/partner-hook-utils/form/fields/CheckboxHookField.js +1 -1
- package/dist/partner-hook-utils/form/fields/NumberInputHookField.js +1 -1
- package/dist/partner-hook-utils/form/fields/RadioGroupHookField.js +1 -1
- package/dist/partner-hook-utils/form/fields/SelectHookField.js +1 -1
- package/dist/partner-hook-utils/form/fields/SwitchHookField.js +1 -1
- package/dist/partner-hook-utils/form/fields/TextInputHookField.js +1 -1
- package/dist/style.css +1 -1
- package/dist/test-utils/assertions.d.ts +4 -0
- package/package.json +13 -10
package/dist/components/Company/PaySchedule/shared/usePayScheduleForm/usePayScheduleForm.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { UseFormProps } from 'react-hook-form';
|
|
2
|
-
import {
|
|
2
|
+
import { PayScheduleShow } from '@gusto/embedded-api/models/components/payscheduleshow';
|
|
3
3
|
import { PaySchedulePreviewPayPeriod } from '@gusto/embedded-api/models/components/payschedulepreviewpayperiod';
|
|
4
4
|
import { PayScheduleOptionalFieldsToRequire, PayScheduleFormData } from './payScheduleSchema';
|
|
5
5
|
import { CustomNameField, FrequencyField, CustomTwicePerMonthField, AnchorPayDateField, AnchorEndOfPayPeriodField, Day1Field, Day2Field } from './fields';
|
|
@@ -24,7 +24,7 @@ export interface PayScheduleFields {
|
|
|
24
24
|
}
|
|
25
25
|
export interface UsePayScheduleFormReady extends BaseFormHookReady<FieldsMetadata, PayScheduleFormData, PayScheduleFields> {
|
|
26
26
|
data: {
|
|
27
|
-
paySchedule:
|
|
27
|
+
paySchedule: PayScheduleShow | null;
|
|
28
28
|
payPeriodPreview: PaySchedulePreviewPayPeriod[] | null;
|
|
29
29
|
payPreviewLoading: boolean;
|
|
30
30
|
paymentSpeedDays: number | null;
|
|
@@ -34,7 +34,7 @@ export interface UsePayScheduleFormReady extends BaseFormHookReady<FieldsMetadat
|
|
|
34
34
|
mode: 'create' | 'update';
|
|
35
35
|
};
|
|
36
36
|
actions: {
|
|
37
|
-
onSubmit: () => Promise<HookSubmitResult<
|
|
37
|
+
onSubmit: () => Promise<HookSubmitResult<PayScheduleShow> | undefined>;
|
|
38
38
|
};
|
|
39
39
|
}
|
|
40
40
|
export declare function usePayScheduleForm({ companyId, payScheduleId, optionalFieldsToRequire, defaultValues: partnerDefaults, validationMode, shouldFocusError, }: UsePayScheduleFormProps): HookLoadingResult | UsePayScheduleFormReady;
|
|
@@ -9,8 +9,8 @@ import { usePaymentConfigsGet as ue } from "@gusto/embedded-api/react-query/paym
|
|
|
9
9
|
import { RFCDate as d } from "@gusto/embedded-api/types/rfcdate";
|
|
10
10
|
import { createPayScheduleSchema as me } from "./payScheduleSchema.js";
|
|
11
11
|
import { Day2Field as ye, Day1Field as he, AnchorEndOfPayPeriodField as Pe, AnchorPayDateField as le, CustomTwicePerMonthField as fe, FrequencyField as we, CustomNameField as pe } from "./fields.js";
|
|
12
|
-
import { useDeriveFieldsMetadata as
|
|
13
|
-
import { useHookFormInternals as
|
|
12
|
+
import { useDeriveFieldsMetadata as Se } from "../../../../../partner-hook-utils/form/useDeriveFieldsMetadata.js";
|
|
13
|
+
import { useHookFormInternals as Ee } from "../../../../../partner-hook-utils/form/useHookFormInternals.js";
|
|
14
14
|
import { createGetFormSubmissionValues as ve } from "../../../../../partner-hook-utils/form/getFormSubmissionValues.js";
|
|
15
15
|
import { withOptions as q } from "../../../../../partner-hook-utils/form/withOptions.js";
|
|
16
16
|
import { composeErrorHandler as De } from "../../../../../partner-hook-utils/composeErrorHandler.js";
|
|
@@ -43,10 +43,10 @@ function Ke({
|
|
|
43
43
|
const h = ce(
|
|
44
44
|
{ companyId: e, payScheduleId: s ?? "" },
|
|
45
45
|
{ enabled: !!s }
|
|
46
|
-
), m = ue({ companyUuid: e }), o = h.data?.
|
|
46
|
+
), m = ue({ companyUuid: e }), o = h.data?.payScheduleShow ?? null, k = m.data?.paymentConfigs?.paymentSpeed, V = Te(k), P = !o, p = P ? "create" : "update", [S, _] = te(
|
|
47
47
|
() => me({ mode: p, optionalFieldsToRequire: u }),
|
|
48
48
|
[p, u]
|
|
49
|
-
),
|
|
49
|
+
), E = {
|
|
50
50
|
customName: o?.customName ?? n?.customName ?? "",
|
|
51
51
|
frequency: o?.frequency ?? n?.frequency ?? "Every week",
|
|
52
52
|
customTwicePerMonth: ge(
|
|
@@ -59,11 +59,11 @@ function Ke({
|
|
|
59
59
|
day1: o?.day1 ?? n?.day1 ?? NaN,
|
|
60
60
|
day2: o?.day2 ?? n?.day2 ?? NaN
|
|
61
61
|
}, t = ne({
|
|
62
|
-
resolver: re(
|
|
62
|
+
resolver: re(S),
|
|
63
63
|
mode: R,
|
|
64
64
|
shouldFocusError: L,
|
|
65
|
-
defaultValues:
|
|
66
|
-
values:
|
|
65
|
+
defaultValues: E,
|
|
66
|
+
values: E,
|
|
67
67
|
resetOptions: { keepDirtyValues: !0 }
|
|
68
68
|
}), r = i({ control: t.control, name: "frequency" }), y = i({
|
|
69
69
|
control: t.control,
|
|
@@ -91,7 +91,7 @@ function Ke({
|
|
|
91
91
|
baseSubmitHandler: Y,
|
|
92
92
|
error: x,
|
|
93
93
|
setError: z
|
|
94
|
-
} = Me("PayScheduleForm"), N = De(s ? [h, m] : [m], { submitError: x, setSubmitError: z }), j = r === "Twice per month", J = r === "Monthly" || r === "Twice per month" && y === "custom", K = r === "Twice per month" && y === "custom", c =
|
|
94
|
+
} = Me("PayScheduleForm"), N = De(s ? [h, m] : [m], { submitError: x, setSubmitError: z }), j = r === "Twice per month", J = r === "Monthly" || r === "Twice per month" && y === "custom", K = r === "Twice per month" && y === "custom", c = Se(_, t.control), X = {
|
|
95
95
|
customName: c.customName,
|
|
96
96
|
frequency: q(
|
|
97
97
|
c.frequency,
|
|
@@ -126,7 +126,7 @@ function Ke({
|
|
|
126
126
|
day2: a.day2 || void 0
|
|
127
127
|
}
|
|
128
128
|
}
|
|
129
|
-
})).
|
|
129
|
+
})).payScheduleShow } : w = { mode: "update", data: (await T.mutateAsync({
|
|
130
130
|
request: {
|
|
131
131
|
payScheduleId: o.uuid,
|
|
132
132
|
companyId: e,
|
|
@@ -140,7 +140,7 @@ function Ke({
|
|
|
140
140
|
version: o.version
|
|
141
141
|
}
|
|
142
142
|
}
|
|
143
|
-
})).
|
|
143
|
+
})).payScheduleShow };
|
|
144
144
|
}), O();
|
|
145
145
|
},
|
|
146
146
|
() => {
|
|
@@ -148,7 +148,7 @@ function Ke({
|
|
|
148
148
|
}
|
|
149
149
|
)();
|
|
150
150
|
}), w;
|
|
151
|
-
}, $ =
|
|
151
|
+
}, $ = Ee(t);
|
|
152
152
|
return m.isLoading || (s ? h.isLoading : !1) ? { isLoading: !0, errorHandling: N } : {
|
|
153
153
|
isLoading: !1,
|
|
154
154
|
data: {
|
|
@@ -175,7 +175,7 @@ function Ke({
|
|
|
175
175
|
},
|
|
176
176
|
fieldsMetadata: X,
|
|
177
177
|
hookFormInternals: $,
|
|
178
|
-
getFormSubmissionValues: ve(t,
|
|
178
|
+
getFormSubmissionValues: ve(t, S)
|
|
179
179
|
}
|
|
180
180
|
};
|
|
181
181
|
}
|
package/dist/components/Company/PaySchedule/shared/usePayScheduleForm/usePayScheduleForm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePayScheduleForm.js","sources":["../../../../../../src/components/Company/PaySchedule/shared/usePayScheduleForm/usePayScheduleForm.tsx"],"sourcesContent":["import { useEffect, 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 { PaySchedule } from '@gusto/embedded-api/models/components/payschedule'\nimport type { PaySchedulePreviewPayPeriod } from '@gusto/embedded-api/models/components/payschedulepreviewpayperiod'\nimport { usePaySchedulesGet } from '@gusto/embedded-api/react-query/paySchedulesGet'\nimport { usePaySchedulesGetPreview } from '@gusto/embedded-api/react-query/paySchedulesGetPreview'\nimport { usePaySchedulesCreateMutation } from '@gusto/embedded-api/react-query/paySchedulesCreate'\nimport { usePaySchedulesUpdateMutation } from '@gusto/embedded-api/react-query/paySchedulesUpdate'\nimport { usePaymentConfigsGet } from '@gusto/embedded-api/react-query/paymentConfigsGet'\nimport { RFCDate } from '@gusto/embedded-api/types/rfcdate'\nimport {\n createPayScheduleSchema,\n type PayScheduleOptionalFieldsToRequire,\n type PayScheduleFormData,\n type PayScheduleFormOutputs,\n type PayScheduleFrequency,\n} from './payScheduleSchema'\nimport {\n CustomNameField,\n FrequencyField,\n CustomTwicePerMonthField,\n AnchorPayDateField,\n AnchorEndOfPayPeriodField,\n Day1Field,\n Day2Field,\n} 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 { parsePaymentSpeedDays } from '@/hooks/useCompanyPaymentSpeed'\nimport { formatDateToStringDate } from '@/helpers/dateFormatting'\n\nexport type { PayScheduleOptionalFieldsToRequire } from './payScheduleSchema'\n\nexport interface UsePayScheduleFormProps {\n companyId: string\n payScheduleId?: string\n optionalFieldsToRequire?: PayScheduleOptionalFieldsToRequire\n defaultValues?: Partial<PayScheduleFormData>\n validationMode?: UseFormProps['mode']\n shouldFocusError?: boolean\n}\n\nexport interface PayScheduleFields {\n CustomName: typeof CustomNameField\n Frequency: typeof FrequencyField\n CustomTwicePerMonth: typeof CustomTwicePerMonthField | undefined\n AnchorPayDate: typeof AnchorPayDateField\n AnchorEndOfPayPeriod: typeof AnchorEndOfPayPeriodField\n Day1: typeof Day1Field | undefined\n Day2: typeof Day2Field | undefined\n}\n\nexport interface UsePayScheduleFormReady extends BaseFormHookReady<\n FieldsMetadata,\n PayScheduleFormData,\n PayScheduleFields\n> {\n data: {\n paySchedule: PaySchedule | null\n payPeriodPreview: PaySchedulePreviewPayPeriod[] | null\n payPreviewLoading: boolean\n paymentSpeedDays: number | null\n }\n status: { isPending: boolean; mode: 'create' | 'update' }\n actions: {\n onSubmit: () => Promise<HookSubmitResult<PaySchedule> | undefined>\n }\n}\n\nconst FREQUENCY_OPTIONS: Array<{ value: PayScheduleFrequency; label: string }> = [\n { value: 'Every week', label: 'Every week' },\n { value: 'Every other week', label: 'Every other week' },\n { value: 'Twice per month', label: 'Twice per month' },\n { value: 'Monthly', label: 'Monthly' },\n]\n\nconst FREQUENCY_ENTRIES: PayScheduleFrequency[] = FREQUENCY_OPTIONS.map(o => o.value)\n\nconst TWICE_PER_MONTH_OPTIONS = [\n { value: '1st15th', label: '15th and Last day of the month' },\n { value: 'custom', label: 'Custom' },\n]\n\nconst TWICE_PER_MONTH_ENTRIES = TWICE_PER_MONTH_OPTIONS.map(o => o.value)\n\nfunction formatWatchedDate(value: unknown): string {\n if (value instanceof Date) return formatDateToStringDate(value) || ''\n if (typeof value === 'string' && value) return value\n return ''\n}\n\nfunction deriveCustomTwicePerMonth(\n frequency: string | undefined,\n day1: number | undefined,\n day2: number | undefined,\n): string {\n if (frequency !== 'Twice per month') return ''\n if (day1 === 15 && day2 === 31) return '1st15th'\n return 'custom'\n}\n\nexport function usePayScheduleForm({\n companyId,\n payScheduleId,\n optionalFieldsToRequire,\n defaultValues: partnerDefaults,\n validationMode = 'onSubmit',\n shouldFocusError = true,\n}: UsePayScheduleFormProps): HookLoadingResult | UsePayScheduleFormReady {\n const payScheduleQuery = usePaySchedulesGet(\n { companyId, payScheduleId: payScheduleId ?? '' },\n { enabled: !!payScheduleId },\n )\n\n const paymentConfigsQuery = usePaymentConfigsGet({ companyUuid: companyId })\n\n const currentPaySchedule = payScheduleQuery.data?.paySchedule ?? null\n const paymentSpeed = paymentConfigsQuery.data?.paymentConfigs?.paymentSpeed\n const paymentSpeedDays = parsePaymentSpeedDays(paymentSpeed)\n\n const isCreateMode = !currentPaySchedule\n const mode = isCreateMode ? 'create' : 'update'\n\n const [schema, metadataConfig] = useMemo(\n () => createPayScheduleSchema({ mode, optionalFieldsToRequire }),\n [mode, optionalFieldsToRequire],\n )\n\n const resolvedDefaults: PayScheduleFormData = {\n customName: currentPaySchedule?.customName ?? partnerDefaults?.customName ?? '',\n frequency: (currentPaySchedule?.frequency ??\n partnerDefaults?.frequency ??\n 'Every week') as PayScheduleFrequency,\n customTwicePerMonth: deriveCustomTwicePerMonth(\n currentPaySchedule?.frequency ?? partnerDefaults?.frequency,\n currentPaySchedule?.day1 ?? partnerDefaults?.day1 ?? undefined,\n currentPaySchedule?.day2 ?? partnerDefaults?.day2 ?? undefined,\n ),\n anchorPayDate:\n currentPaySchedule?.anchorPayDate?.toString() ?? partnerDefaults?.anchorPayDate ?? null,\n anchorEndOfPayPeriod:\n currentPaySchedule?.anchorEndOfPayPeriod?.toString() ??\n partnerDefaults?.anchorEndOfPayPeriod ??\n null,\n day1: currentPaySchedule?.day1 ?? partnerDefaults?.day1 ?? NaN,\n day2: currentPaySchedule?.day2 ?? partnerDefaults?.day2 ?? NaN,\n }\n\n const formMethods = useForm<PayScheduleFormData, unknown, PayScheduleFormOutputs>({\n resolver: zodResolver(schema),\n mode: validationMode,\n shouldFocusError,\n defaultValues: resolvedDefaults,\n values: resolvedDefaults,\n resetOptions: { keepDirtyValues: true },\n })\n\n const watchedFrequency = useWatch({ control: formMethods.control, name: 'frequency' })\n const watchedCustomTwicePerMonth = useWatch({\n control: formMethods.control,\n name: 'customTwicePerMonth',\n })\n const watchedAnchorPayDate = useWatch({ control: formMethods.control, name: 'anchorPayDate' })\n const watchedAnchorEndOfPayPeriod = useWatch({\n control: formMethods.control,\n name: 'anchorEndOfPayPeriod',\n })\n const watchedDay1 = useWatch({ control: formMethods.control, name: 'day1' })\n const watchedDay2 = useWatch({ control: formMethods.control, name: 'day2' })\n\n useEffect(() => {\n if (watchedFrequency === 'Twice per month' && watchedCustomTwicePerMonth === '1st15th') {\n formMethods.setValue('day1', 15)\n formMethods.setValue('day2', 31)\n }\n }, [watchedFrequency, watchedCustomTwicePerMonth, formMethods.setValue])\n\n const formattedAnchorPayDate = formatWatchedDate(watchedAnchorPayDate)\n const formattedAnchorEndOfPayPeriod = formatWatchedDate(watchedAnchorEndOfPayPeriod)\n\n const previewEnabled = Boolean(formattedAnchorPayDate && formattedAnchorEndOfPayPeriod)\n\n const previewQuery = usePaySchedulesGetPreview(\n {\n companyId,\n frequency: watchedFrequency,\n ...(formattedAnchorPayDate && { anchorPayDate: new RFCDate(formattedAnchorPayDate) }),\n ...(formattedAnchorEndOfPayPeriod && {\n anchorEndOfPayPeriod: new RFCDate(formattedAnchorEndOfPayPeriod),\n }),\n day1: watchedDay1 || undefined,\n day2: watchedDay2 || undefined,\n } as Parameters<typeof usePaySchedulesGetPreview>[0],\n { enabled: previewEnabled },\n )\n\n const payPeriodPreview: PaySchedulePreviewPayPeriod[] | undefined =\n previewQuery.data?.paySchedulePreview?.payPeriods\n const payPreviewLoading = previewQuery.isLoading && previewEnabled\n\n const createPayScheduleMutation = usePaySchedulesCreateMutation()\n const updatePayScheduleMutation = usePaySchedulesUpdateMutation()\n\n const isPending = createPayScheduleMutation.isPending || updatePayScheduleMutation.isPending\n\n const {\n baseSubmitHandler,\n error: submitError,\n setError: setSubmitError,\n } = useBaseSubmit('PayScheduleForm')\n\n const queries = payScheduleId ? [payScheduleQuery, paymentConfigsQuery] : [paymentConfigsQuery]\n const errorHandling = composeErrorHandler(queries, { submitError, setSubmitError })\n\n const showCustomTwicePerMonth = watchedFrequency === 'Twice per month'\n const showDay1 =\n watchedFrequency === 'Monthly' ||\n (watchedFrequency === 'Twice per month' && watchedCustomTwicePerMonth === 'custom')\n const showDay2 = watchedFrequency === 'Twice per month' && watchedCustomTwicePerMonth === 'custom'\n\n const baseMetadata = useDeriveFieldsMetadata(metadataConfig, formMethods.control)\n const fieldsMetadata = {\n customName: baseMetadata.customName,\n frequency: withOptions<PayScheduleFrequency>(\n baseMetadata.frequency,\n FREQUENCY_OPTIONS,\n FREQUENCY_ENTRIES,\n ),\n customTwicePerMonth: withOptions<string>(\n baseMetadata.customTwicePerMonth,\n TWICE_PER_MONTH_OPTIONS,\n TWICE_PER_MONTH_ENTRIES,\n ),\n anchorPayDate: baseMetadata.anchorPayDate,\n anchorEndOfPayPeriod: baseMetadata.anchorEndOfPayPeriod,\n day1: baseMetadata.day1,\n day2: baseMetadata.day2,\n }\n\n const onSubmit = async (): Promise<HookSubmitResult<PaySchedule> | undefined> => {\n let submitResult: HookSubmitResult<PaySchedule> | undefined\n\n await new Promise<void>(resolve => {\n void formMethods.handleSubmit(\n async (data: PayScheduleFormOutputs) => {\n await baseSubmitHandler(data, async payload => {\n const anchorPayDate = payload.anchorPayDate ?? ''\n const anchorEndOfPayPeriod = payload.anchorEndOfPayPeriod ?? ''\n\n if (isCreateMode) {\n const result = await createPayScheduleMutation.mutateAsync({\n request: {\n companyId,\n payScheduleCreateRequest: {\n frequency: payload.frequency,\n anchorPayDate: new RFCDate(anchorPayDate),\n anchorEndOfPayPeriod: new RFCDate(anchorEndOfPayPeriod),\n customName: payload.customName,\n day1: payload.day1 || undefined,\n day2: payload.day2 || undefined,\n },\n },\n })\n\n submitResult = { mode: 'create', data: result.paySchedule! }\n } else {\n const result = await updatePayScheduleMutation.mutateAsync({\n request: {\n payScheduleId: currentPaySchedule.uuid,\n companyId,\n payScheduleUpdateRequest: {\n frequency: payload.frequency,\n anchorPayDate: new RFCDate(anchorPayDate),\n anchorEndOfPayPeriod: new RFCDate(anchorEndOfPayPeriod),\n customName: payload.customName,\n day1: payload.day1 || undefined,\n day2: payload.day2 || undefined,\n version: currentPaySchedule.version!,\n },\n },\n })\n\n submitResult = { mode: 'update', data: result.paySchedule! }\n }\n })\n resolve()\n },\n () => {\n resolve()\n },\n )()\n })\n\n return submitResult\n }\n\n const hookFormInternals = useHookFormInternals(formMethods)\n\n const isDataLoading =\n paymentConfigsQuery.isLoading || (payScheduleId ? payScheduleQuery.isLoading : false)\n\n if (isDataLoading) {\n return { isLoading: true as const, errorHandling }\n }\n\n return {\n isLoading: false as const,\n data: {\n paySchedule: currentPaySchedule,\n payPeriodPreview: payPeriodPreview ?? null,\n payPreviewLoading,\n paymentSpeedDays,\n },\n status: {\n isPending,\n mode: isCreateMode ? ('create' as const) : ('update' as const),\n },\n actions: { onSubmit },\n errorHandling,\n form: {\n Fields: {\n CustomName: CustomNameField,\n Frequency: FrequencyField,\n CustomTwicePerMonth: showCustomTwicePerMonth ? CustomTwicePerMonthField : undefined,\n AnchorPayDate: AnchorPayDateField,\n AnchorEndOfPayPeriod: AnchorEndOfPayPeriodField,\n Day1: showDay1 ? Day1Field : undefined,\n Day2: showDay2 ? Day2Field : undefined,\n },\n fieldsMetadata,\n hookFormInternals,\n getFormSubmissionValues: createGetFormSubmissionValues(formMethods, schema),\n },\n }\n}\n\nexport type UsePayScheduleFormResult = HookLoadingResult | UsePayScheduleFormReady\nexport type PayScheduleFieldsMetadata = UsePayScheduleFormReady['form']['fieldsMetadata']\nexport type PayScheduleFormFields = UsePayScheduleFormReady['form']['Fields']\n"],"names":["FREQUENCY_OPTIONS","FREQUENCY_ENTRIES","o","TWICE_PER_MONTH_OPTIONS","TWICE_PER_MONTH_ENTRIES","formatWatchedDate","value","formatDateToStringDate","deriveCustomTwicePerMonth","frequency","day1","day2","usePayScheduleForm","companyId","payScheduleId","optionalFieldsToRequire","partnerDefaults","validationMode","shouldFocusError","payScheduleQuery","usePaySchedulesGet","paymentConfigsQuery","usePaymentConfigsGet","currentPaySchedule","paymentSpeed","paymentSpeedDays","parsePaymentSpeedDays","isCreateMode","mode","schema","metadataConfig","useMemo","createPayScheduleSchema","resolvedDefaults","formMethods","useForm","zodResolver","watchedFrequency","useWatch","watchedCustomTwicePerMonth","watchedAnchorPayDate","watchedAnchorEndOfPayPeriod","watchedDay1","watchedDay2","useEffect","formattedAnchorPayDate","formattedAnchorEndOfPayPeriod","previewEnabled","previewQuery","usePaySchedulesGetPreview","RFCDate","payPeriodPreview","payPreviewLoading","createPayScheduleMutation","usePaySchedulesCreateMutation","updatePayScheduleMutation","usePaySchedulesUpdateMutation","isPending","baseSubmitHandler","submitError","setSubmitError","useBaseSubmit","errorHandling","composeErrorHandler","showCustomTwicePerMonth","showDay1","showDay2","baseMetadata","useDeriveFieldsMetadata","fieldsMetadata","withOptions","onSubmit","submitResult","resolve","data","payload","anchorPayDate","anchorEndOfPayPeriod","hookFormInternals","useHookFormInternals","CustomNameField","FrequencyField","CustomTwicePerMonthField","AnchorPayDateField","AnchorEndOfPayPeriodField","Day1Field","Day2Field","createGetFormSubmissionValues"],"mappings":";;;;;;;;;;;;;;;;;;;AAiFA,MAAMA,IAA2E;AAAA,EAC/E,EAAE,OAAO,cAAc,OAAO,aAAA;AAAA,EAC9B,EAAE,OAAO,oBAAoB,OAAO,mBAAA;AAAA,EACpC,EAAE,OAAO,mBAAmB,OAAO,kBAAA;AAAA,EACnC,EAAE,OAAO,WAAW,OAAO,UAAA;AAC7B,GAEMC,KAA4CD,EAAkB,IAAI,CAAAE,MAAKA,EAAE,KAAK,GAE9EC,IAA0B;AAAA,EAC9B,EAAE,OAAO,WAAW,OAAO,iCAAA;AAAA,EAC3B,EAAE,OAAO,UAAU,OAAO,SAAA;AAC5B,GAEMC,KAA0BD,EAAwB,IAAI,CAAAD,MAAKA,EAAE,KAAK;A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A,MACN,WAAAgC;AAAA,MACA,MAAM9B,IAAgB,WAAsB;AAAA,IAAA;AAAA,IAE9C,SAAS,EAAE,UAAA4C,EAAA;AAAA,IACX,eAAAT;AAAA,IACA,MAAM;AAAA,MACJ,QAAQ;AAAA,QACN,YAAYkB;AAAA,QACZ,WAAWC;AAAA,QACX,qBAAqBjB,IAA0BkB,KAA2B;AAAA,QAC1E,eAAeC;AAAA,QACf,sBAAsBC;AAAA,QACtB,MAAMnB,IAAWoB,KAAY;AAAA,QAC7B,MAAMnB,IAAWoB,KAAY;AAAA,MAAA;AAAA,MAE/B,gBAAAjB;AAAA,MACA,mBAAAS;AAAA,MACA,yBAAyBS,GAA8BrD,GAAaL,CAAM;AAAA,IAAA;AAAA,EAC5E;AAEJ;"}
|
|
1
|
+
{"version":3,"file":"usePayScheduleForm.js","sources":["../../../../../../src/components/Company/PaySchedule/shared/usePayScheduleForm/usePayScheduleForm.tsx"],"sourcesContent":["import { useEffect, 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 { PayScheduleShow } from '@gusto/embedded-api/models/components/payscheduleshow'\nimport type { PaySchedulePreviewPayPeriod } from '@gusto/embedded-api/models/components/payschedulepreviewpayperiod'\nimport { usePaySchedulesGet } from '@gusto/embedded-api/react-query/paySchedulesGet'\nimport { usePaySchedulesGetPreview } from '@gusto/embedded-api/react-query/paySchedulesGetPreview'\nimport { usePaySchedulesCreateMutation } from '@gusto/embedded-api/react-query/paySchedulesCreate'\nimport { usePaySchedulesUpdateMutation } from '@gusto/embedded-api/react-query/paySchedulesUpdate'\nimport { usePaymentConfigsGet } from '@gusto/embedded-api/react-query/paymentConfigsGet'\nimport { RFCDate } from '@gusto/embedded-api/types/rfcdate'\nimport {\n createPayScheduleSchema,\n type PayScheduleOptionalFieldsToRequire,\n type PayScheduleFormData,\n type PayScheduleFormOutputs,\n type PayScheduleFrequency,\n} from './payScheduleSchema'\nimport {\n CustomNameField,\n FrequencyField,\n CustomTwicePerMonthField,\n AnchorPayDateField,\n AnchorEndOfPayPeriodField,\n Day1Field,\n Day2Field,\n} 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 { parsePaymentSpeedDays } from '@/hooks/useCompanyPaymentSpeed'\nimport { formatDateToStringDate } from '@/helpers/dateFormatting'\n\nexport type { PayScheduleOptionalFieldsToRequire } from './payScheduleSchema'\n\nexport interface UsePayScheduleFormProps {\n companyId: string\n payScheduleId?: string\n optionalFieldsToRequire?: PayScheduleOptionalFieldsToRequire\n defaultValues?: Partial<PayScheduleFormData>\n validationMode?: UseFormProps['mode']\n shouldFocusError?: boolean\n}\n\nexport interface PayScheduleFields {\n CustomName: typeof CustomNameField\n Frequency: typeof FrequencyField\n CustomTwicePerMonth: typeof CustomTwicePerMonthField | undefined\n AnchorPayDate: typeof AnchorPayDateField\n AnchorEndOfPayPeriod: typeof AnchorEndOfPayPeriodField\n Day1: typeof Day1Field | undefined\n Day2: typeof Day2Field | undefined\n}\n\nexport interface UsePayScheduleFormReady extends BaseFormHookReady<\n FieldsMetadata,\n PayScheduleFormData,\n PayScheduleFields\n> {\n data: {\n paySchedule: PayScheduleShow | null\n payPeriodPreview: PaySchedulePreviewPayPeriod[] | null\n payPreviewLoading: boolean\n paymentSpeedDays: number | null\n }\n status: { isPending: boolean; mode: 'create' | 'update' }\n actions: {\n onSubmit: () => Promise<HookSubmitResult<PayScheduleShow> | undefined>\n }\n}\n\nconst FREQUENCY_OPTIONS: Array<{ value: PayScheduleFrequency; label: string }> = [\n { value: 'Every week', label: 'Every week' },\n { value: 'Every other week', label: 'Every other week' },\n { value: 'Twice per month', label: 'Twice per month' },\n { value: 'Monthly', label: 'Monthly' },\n]\n\nconst FREQUENCY_ENTRIES: PayScheduleFrequency[] = FREQUENCY_OPTIONS.map(o => o.value)\n\nconst TWICE_PER_MONTH_OPTIONS = [\n { value: '1st15th', label: '15th and Last day of the month' },\n { value: 'custom', label: 'Custom' },\n]\n\nconst TWICE_PER_MONTH_ENTRIES = TWICE_PER_MONTH_OPTIONS.map(o => o.value)\n\nfunction formatWatchedDate(value: unknown): string {\n if (value instanceof Date) return formatDateToStringDate(value) || ''\n if (typeof value === 'string' && value) return value\n return ''\n}\n\nfunction deriveCustomTwicePerMonth(\n frequency: string | undefined,\n day1: number | undefined,\n day2: number | undefined,\n): string {\n if (frequency !== 'Twice per month') return ''\n if (day1 === 15 && day2 === 31) return '1st15th'\n return 'custom'\n}\n\nexport function usePayScheduleForm({\n companyId,\n payScheduleId,\n optionalFieldsToRequire,\n defaultValues: partnerDefaults,\n validationMode = 'onSubmit',\n shouldFocusError = true,\n}: UsePayScheduleFormProps): HookLoadingResult | UsePayScheduleFormReady {\n const payScheduleQuery = usePaySchedulesGet(\n { companyId, payScheduleId: payScheduleId ?? '' },\n { enabled: !!payScheduleId },\n )\n\n const paymentConfigsQuery = usePaymentConfigsGet({ companyUuid: companyId })\n\n const currentPaySchedule = payScheduleQuery.data?.payScheduleShow ?? null\n const paymentSpeed = paymentConfigsQuery.data?.paymentConfigs?.paymentSpeed\n const paymentSpeedDays = parsePaymentSpeedDays(paymentSpeed)\n\n const isCreateMode = !currentPaySchedule\n const mode = isCreateMode ? 'create' : 'update'\n\n const [schema, metadataConfig] = useMemo(\n () => createPayScheduleSchema({ mode, optionalFieldsToRequire }),\n [mode, optionalFieldsToRequire],\n )\n\n const resolvedDefaults: PayScheduleFormData = {\n customName: currentPaySchedule?.customName ?? partnerDefaults?.customName ?? '',\n frequency: (currentPaySchedule?.frequency ??\n partnerDefaults?.frequency ??\n 'Every week') as PayScheduleFrequency,\n customTwicePerMonth: deriveCustomTwicePerMonth(\n currentPaySchedule?.frequency ?? partnerDefaults?.frequency,\n currentPaySchedule?.day1 ?? partnerDefaults?.day1 ?? undefined,\n currentPaySchedule?.day2 ?? partnerDefaults?.day2 ?? undefined,\n ),\n anchorPayDate:\n currentPaySchedule?.anchorPayDate?.toString() ?? partnerDefaults?.anchorPayDate ?? null,\n anchorEndOfPayPeriod:\n currentPaySchedule?.anchorEndOfPayPeriod?.toString() ??\n partnerDefaults?.anchorEndOfPayPeriod ??\n null,\n day1: currentPaySchedule?.day1 ?? partnerDefaults?.day1 ?? NaN,\n day2: currentPaySchedule?.day2 ?? partnerDefaults?.day2 ?? NaN,\n }\n\n const formMethods = useForm<PayScheduleFormData, unknown, PayScheduleFormOutputs>({\n resolver: zodResolver(schema),\n mode: validationMode,\n shouldFocusError,\n defaultValues: resolvedDefaults,\n values: resolvedDefaults,\n resetOptions: { keepDirtyValues: true },\n })\n\n const watchedFrequency = useWatch({ control: formMethods.control, name: 'frequency' })\n const watchedCustomTwicePerMonth = useWatch({\n control: formMethods.control,\n name: 'customTwicePerMonth',\n })\n const watchedAnchorPayDate = useWatch({ control: formMethods.control, name: 'anchorPayDate' })\n const watchedAnchorEndOfPayPeriod = useWatch({\n control: formMethods.control,\n name: 'anchorEndOfPayPeriod',\n })\n const watchedDay1 = useWatch({ control: formMethods.control, name: 'day1' })\n const watchedDay2 = useWatch({ control: formMethods.control, name: 'day2' })\n\n useEffect(() => {\n if (watchedFrequency === 'Twice per month' && watchedCustomTwicePerMonth === '1st15th') {\n formMethods.setValue('day1', 15)\n formMethods.setValue('day2', 31)\n }\n }, [watchedFrequency, watchedCustomTwicePerMonth, formMethods.setValue])\n\n const formattedAnchorPayDate = formatWatchedDate(watchedAnchorPayDate)\n const formattedAnchorEndOfPayPeriod = formatWatchedDate(watchedAnchorEndOfPayPeriod)\n\n const previewEnabled = Boolean(formattedAnchorPayDate && formattedAnchorEndOfPayPeriod)\n\n const previewQuery = usePaySchedulesGetPreview(\n {\n companyId,\n frequency: watchedFrequency,\n ...(formattedAnchorPayDate && { anchorPayDate: new RFCDate(formattedAnchorPayDate) }),\n ...(formattedAnchorEndOfPayPeriod && {\n anchorEndOfPayPeriod: new RFCDate(formattedAnchorEndOfPayPeriod),\n }),\n day1: watchedDay1 || undefined,\n day2: watchedDay2 || undefined,\n } as Parameters<typeof usePaySchedulesGetPreview>[0],\n { enabled: previewEnabled },\n )\n\n const payPeriodPreview: PaySchedulePreviewPayPeriod[] | undefined =\n previewQuery.data?.paySchedulePreview?.payPeriods\n const payPreviewLoading = previewQuery.isLoading && previewEnabled\n\n const createPayScheduleMutation = usePaySchedulesCreateMutation()\n const updatePayScheduleMutation = usePaySchedulesUpdateMutation()\n\n const isPending = createPayScheduleMutation.isPending || updatePayScheduleMutation.isPending\n\n const {\n baseSubmitHandler,\n error: submitError,\n setError: setSubmitError,\n } = useBaseSubmit('PayScheduleForm')\n\n const queries = payScheduleId ? [payScheduleQuery, paymentConfigsQuery] : [paymentConfigsQuery]\n const errorHandling = composeErrorHandler(queries, { submitError, setSubmitError })\n\n const showCustomTwicePerMonth = watchedFrequency === 'Twice per month'\n const showDay1 =\n watchedFrequency === 'Monthly' ||\n (watchedFrequency === 'Twice per month' && watchedCustomTwicePerMonth === 'custom')\n const showDay2 = watchedFrequency === 'Twice per month' && watchedCustomTwicePerMonth === 'custom'\n\n const baseMetadata = useDeriveFieldsMetadata(metadataConfig, formMethods.control)\n const fieldsMetadata = {\n customName: baseMetadata.customName,\n frequency: withOptions<PayScheduleFrequency>(\n baseMetadata.frequency,\n FREQUENCY_OPTIONS,\n FREQUENCY_ENTRIES,\n ),\n customTwicePerMonth: withOptions<string>(\n baseMetadata.customTwicePerMonth,\n TWICE_PER_MONTH_OPTIONS,\n TWICE_PER_MONTH_ENTRIES,\n ),\n anchorPayDate: baseMetadata.anchorPayDate,\n anchorEndOfPayPeriod: baseMetadata.anchorEndOfPayPeriod,\n day1: baseMetadata.day1,\n day2: baseMetadata.day2,\n }\n\n const onSubmit = async (): Promise<HookSubmitResult<PayScheduleShow> | undefined> => {\n let submitResult: HookSubmitResult<PayScheduleShow> | undefined\n\n await new Promise<void>(resolve => {\n void formMethods.handleSubmit(\n async (data: PayScheduleFormOutputs) => {\n await baseSubmitHandler(data, async payload => {\n const anchorPayDate = payload.anchorPayDate ?? ''\n const anchorEndOfPayPeriod = payload.anchorEndOfPayPeriod ?? ''\n\n if (isCreateMode) {\n const result = await createPayScheduleMutation.mutateAsync({\n request: {\n companyId,\n payScheduleCreateRequest: {\n frequency: payload.frequency,\n anchorPayDate: new RFCDate(anchorPayDate),\n anchorEndOfPayPeriod: new RFCDate(anchorEndOfPayPeriod),\n customName: payload.customName,\n day1: payload.day1 || undefined,\n day2: payload.day2 || undefined,\n },\n },\n })\n\n submitResult = { mode: 'create', data: result.payScheduleShow! }\n } else {\n const result = await updatePayScheduleMutation.mutateAsync({\n request: {\n payScheduleId: currentPaySchedule.uuid,\n companyId,\n payScheduleUpdateRequest: {\n frequency: payload.frequency,\n anchorPayDate: new RFCDate(anchorPayDate),\n anchorEndOfPayPeriod: new RFCDate(anchorEndOfPayPeriod),\n customName: payload.customName,\n day1: payload.day1 || undefined,\n day2: payload.day2 || undefined,\n version: currentPaySchedule.version!,\n },\n },\n })\n\n submitResult = { mode: 'update', data: result.payScheduleShow! }\n }\n })\n resolve()\n },\n () => {\n resolve()\n },\n )()\n })\n\n return submitResult\n }\n\n const hookFormInternals = useHookFormInternals(formMethods)\n\n const isDataLoading =\n paymentConfigsQuery.isLoading || (payScheduleId ? payScheduleQuery.isLoading : false)\n\n if (isDataLoading) {\n return { isLoading: true as const, errorHandling }\n }\n\n return {\n isLoading: false as const,\n data: {\n paySchedule: currentPaySchedule,\n payPeriodPreview: payPeriodPreview ?? null,\n payPreviewLoading,\n paymentSpeedDays,\n },\n status: {\n isPending,\n mode: isCreateMode ? ('create' as const) : ('update' as const),\n },\n actions: { onSubmit },\n errorHandling,\n form: {\n Fields: {\n CustomName: CustomNameField,\n Frequency: FrequencyField,\n CustomTwicePerMonth: showCustomTwicePerMonth ? CustomTwicePerMonthField : undefined,\n AnchorPayDate: AnchorPayDateField,\n AnchorEndOfPayPeriod: AnchorEndOfPayPeriodField,\n Day1: showDay1 ? Day1Field : undefined,\n Day2: showDay2 ? Day2Field : undefined,\n },\n fieldsMetadata,\n hookFormInternals,\n getFormSubmissionValues: createGetFormSubmissionValues(formMethods, schema),\n },\n }\n}\n\nexport type UsePayScheduleFormResult = HookLoadingResult | UsePayScheduleFormReady\nexport type PayScheduleFieldsMetadata = UsePayScheduleFormReady['form']['fieldsMetadata']\nexport type PayScheduleFormFields = UsePayScheduleFormReady['form']['Fields']\n"],"names":["FREQUENCY_OPTIONS","FREQUENCY_ENTRIES","o","TWICE_PER_MONTH_OPTIONS","TWICE_PER_MONTH_ENTRIES","formatWatchedDate","value","formatDateToStringDate","deriveCustomTwicePerMonth","frequency","day1","day2","usePayScheduleForm","companyId","payScheduleId","optionalFieldsToRequire","partnerDefaults","validationMode","shouldFocusError","payScheduleQuery","usePaySchedulesGet","paymentConfigsQuery","usePaymentConfigsGet","currentPaySchedule","paymentSpeed","paymentSpeedDays","parsePaymentSpeedDays","isCreateMode","mode","schema","metadataConfig","useMemo","createPayScheduleSchema","resolvedDefaults","formMethods","useForm","zodResolver","watchedFrequency","useWatch","watchedCustomTwicePerMonth","watchedAnchorPayDate","watchedAnchorEndOfPayPeriod","watchedDay1","watchedDay2","useEffect","formattedAnchorPayDate","formattedAnchorEndOfPayPeriod","previewEnabled","previewQuery","usePaySchedulesGetPreview","RFCDate","payPeriodPreview","payPreviewLoading","createPayScheduleMutation","usePaySchedulesCreateMutation","updatePayScheduleMutation","usePaySchedulesUpdateMutation","isPending","baseSubmitHandler","submitError","setSubmitError","useBaseSubmit","errorHandling","composeErrorHandler","showCustomTwicePerMonth","showDay1","showDay2","baseMetadata","useDeriveFieldsMetadata","fieldsMetadata","withOptions","onSubmit","submitResult","resolve","data","payload","anchorPayDate","anchorEndOfPayPeriod","hookFormInternals","useHookFormInternals","CustomNameField","FrequencyField","CustomTwicePerMonthField","AnchorPayDateField","AnchorEndOfPayPeriodField","Day1Field","Day2Field","createGetFormSubmissionValues"],"mappings":";;;;;;;;;;;;;;;;;;;AAiFA,MAAMA,IAA2E;AAAA,EAC/E,EAAE,OAAO,cAAc,OAAO,aAAA;AAAA,EAC9B,EAAE,OAAO,oBAAoB,OAAO,mBAAA;AAAA,EACpC,EAAE,OAAO,mBAAmB,OAAO,kBAAA;AAAA,EACnC,EAAE,OAAO,WAAW,OAAO,UAAA;AAC7B,GAEMC,KAA4CD,EAAkB,IAAI,CAAAE,MAAKA,EAAE,KAAK,GAE9EC,IAA0B;AAAA,EAC9B,EAAE,OAAO,WAAW,OAAO,iCAAA;AAAA,EAC3B,EAAE,OAAO,UAAU,OAAO,SAAA;AAC5B,GAEMC,KAA0BD,EAAwB,IAAI,CAAAD,MAAKA,EAAE,KAAK;AAExE,SAASG,EAAkBC,GAAwB;AACjD,SAAIA,aAAiB,OAAaC,GAAuBD,CAAK,KAAK,KAC/D,OAAOA,KAAU,YAAYA,IAAcA,IACxC;AACT;AAEA,SAASE,GACPC,GACAC,GACAC,GACQ;AACR,SAAIF,MAAc,oBAA0B,KACxCC,MAAS,MAAMC,MAAS,KAAW,YAChC;AACT;AAEO,SAASC,GAAmB;AAAA,EACjC,WAAAC;AAAA,EACA,eAAAC;AAAA,EACA,yBAAAC;AAAA,EACA,eAAeC;AAAA,EACf,gBAAAC,IAAiB;AAAA,EACjB,kBAAAC,IAAmB;AACrB,GAAyE;AACvE,QAAMC,IAAmBC;AAAA,IACvB,EAAE,WAAAP,GAAW,eAAeC,KAAiB,GAAA;AAAA,IAC7C,EAAE,SAAS,CAAC,CAACA,EAAA;AAAA,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|
1
1
|
import { jsxs as i, jsx as n } from "react/jsx-runtime";
|
|
2
2
|
import { useTranslation as a } from "react-i18next";
|
|
3
3
|
import { useStateTaxesForm as s } from "./context.js";
|
|
4
|
-
import "../../../../shared/constants.js";
|
|
5
4
|
import "classnames";
|
|
5
|
+
import "../../../../shared/constants.js";
|
|
6
6
|
import { ActionsLayout as m } from "../../../Common/ActionsLayout/ActionsLayout.js";
|
|
7
7
|
import { useComponentContext as c } from "../../../../contexts/ComponentAdapter/useComponentContext.js";
|
|
8
8
|
function y() {
|
|
@@ -7,7 +7,7 @@ import "../../../Base/useBase.js";
|
|
|
7
7
|
import "@gusto/embedded-api/models/errors/apierror";
|
|
8
8
|
import "@gusto/embedded-api/models/errors/gustoembeddederror";
|
|
9
9
|
import "@gusto/embedded-api/models/errors/sdkvalidationerror";
|
|
10
|
-
import "@gusto/embedded-api/models/errors/
|
|
10
|
+
import "@gusto/embedded-api/models/errors/unprocessableentityerror";
|
|
11
11
|
import "@gusto/embedded-api/models/errors/httpclienterrors";
|
|
12
12
|
import "dompurify";
|
|
13
13
|
import "../../../../contexts/LocaleProvider/useLocale.js";
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { jsx as t } from "react/jsx-runtime";
|
|
2
2
|
import { useTranslation as i } from "react-i18next";
|
|
3
3
|
import { useStateTaxesList as e } from "./context.js";
|
|
4
|
-
import "../../../../shared/constants.js";
|
|
5
4
|
import "classnames";
|
|
5
|
+
import "../../../../shared/constants.js";
|
|
6
6
|
import { ActionsLayout as m } from "../../../Common/ActionsLayout/ActionsLayout.js";
|
|
7
7
|
import { useComponentContext as s } from "../../../../contexts/ComponentAdapter/useComponentContext.js";
|
|
8
8
|
function x() {
|
|
@@ -7,7 +7,7 @@ import "../../../Base/useBase.js";
|
|
|
7
7
|
import "@gusto/embedded-api/models/errors/apierror";
|
|
8
8
|
import "@gusto/embedded-api/models/errors/gustoembeddederror";
|
|
9
9
|
import "@gusto/embedded-api/models/errors/sdkvalidationerror";
|
|
10
|
-
import "@gusto/embedded-api/models/errors/
|
|
10
|
+
import "@gusto/embedded-api/models/errors/unprocessableentityerror";
|
|
11
11
|
import "@gusto/embedded-api/models/errors/httpclienterrors";
|
|
12
12
|
import "dompurify";
|
|
13
13
|
import "../../../../contexts/LocaleProvider/useLocale.js";
|
|
@@ -1,40 +1,40 @@
|
|
|
1
1
|
import { jsx as t, jsxs as F, Fragment as R } from "react/jsx-runtime";
|
|
2
2
|
import { useContractorsGetSuspense as g } from "@gusto/embedded-api/react-query/contractorsGet";
|
|
3
|
-
import { useContractorsGetAddressSuspense as
|
|
4
|
-
import { useContractorsUpdateAddressMutation as
|
|
5
|
-
import { useForm as
|
|
6
|
-
import { zodResolver as
|
|
3
|
+
import { useContractorsGetAddressSuspense as U } from "@gusto/embedded-api/react-query/contractorsGetAddress";
|
|
4
|
+
import { useContractorsUpdateAddressMutation as z } from "@gusto/embedded-api/react-query/contractorsUpdateAddress";
|
|
5
|
+
import { useForm as E, FormProvider as P } from "react-hook-form";
|
|
6
|
+
import { zodResolver as T } from "@hookform/resolvers/zod";
|
|
7
7
|
import { AddressFormSchema as b, AddressProvider as x } from "./useAddress.js";
|
|
8
8
|
import { Head as O } from "./Head.js";
|
|
9
9
|
import { Form as _ } from "./Form.js";
|
|
10
10
|
import { Actions as B } from "./Actions.js";
|
|
11
11
|
import { Form as N } from "../../Common/Form/Form.js";
|
|
12
|
-
import { useComponentDictionary as j, useI18n as
|
|
13
|
-
import { Flex as
|
|
12
|
+
import { useComponentDictionary as j, useI18n as w } from "../../../i18n/I18n.js";
|
|
13
|
+
import { Flex as G } from "../../Common/Flex/Flex.js";
|
|
14
14
|
import "classnames";
|
|
15
15
|
import { contractorEvents as d } from "../../../shared/constants.js";
|
|
16
|
-
import { BaseComponent as
|
|
17
|
-
import { useBase as
|
|
16
|
+
import { BaseComponent as H } from "../../Base/Base.js";
|
|
17
|
+
import { useBase as M } from "../../Base/useBase.js";
|
|
18
18
|
function nt(r) {
|
|
19
|
-
return /* @__PURE__ */ t(
|
|
19
|
+
return /* @__PURE__ */ t(H, { ...r, children: /* @__PURE__ */ t(q, { ...r, children: r.children }) });
|
|
20
20
|
}
|
|
21
|
-
function
|
|
22
|
-
j("Contractor.Address", p),
|
|
23
|
-
const { onEvent: i, baseSubmitHandler: u } =
|
|
21
|
+
function q({ contractorId: r, defaultValues: e, children: n, className: a, dictionary: p }) {
|
|
22
|
+
j("Contractor.Address", p), w("Contractor.Address");
|
|
23
|
+
const { onEvent: i, baseSubmitHandler: u } = M(), { data: c } = g({ contractorUuid: r }), { data: f } = U({ contractorUuid: r }), { mutateAsync: A, isPending: h } = z(), D = c.contractor, C = c.contractor?.type, o = f.contractorAddress, S = {
|
|
24
24
|
street1: o?.street1 || e?.street1 || "",
|
|
25
25
|
street2: o?.street2 || e?.street2 || "",
|
|
26
26
|
city: o?.city || e?.city || "",
|
|
27
27
|
state: o?.state || e?.state || "",
|
|
28
28
|
zip: o?.zip || e?.zip || ""
|
|
29
|
-
}, m =
|
|
30
|
-
resolver:
|
|
29
|
+
}, m = E({
|
|
30
|
+
resolver: T(b),
|
|
31
31
|
defaultValues: S
|
|
32
32
|
}), l = async (v) => {
|
|
33
33
|
await u(v, async (s) => {
|
|
34
34
|
const { contractorAddress: y } = await A({
|
|
35
35
|
request: {
|
|
36
36
|
contractorUuid: r,
|
|
37
|
-
|
|
37
|
+
contractorAddressUpdateBody: {
|
|
38
38
|
version: o?.version,
|
|
39
39
|
street1: s.street1,
|
|
40
40
|
street2: s.street2,
|
|
@@ -56,7 +56,7 @@ function M({ contractorId: r, defaultValues: e, children: n, className: a, dicti
|
|
|
56
56
|
address: o,
|
|
57
57
|
isPending: h
|
|
58
58
|
},
|
|
59
|
-
children: /* @__PURE__ */ t(
|
|
59
|
+
children: /* @__PURE__ */ t(P, { ...m, children: /* @__PURE__ */ t(N, { onSubmit: m.handleSubmit(l), children: /* @__PURE__ */ t(G, { flexDirection: "column", gap: 32, alignItems: "stretch", children: n || /* @__PURE__ */ F(R, { children: [
|
|
60
60
|
/* @__PURE__ */ t(O, {}),
|
|
61
61
|
/* @__PURE__ */ t(_, {}),
|
|
62
62
|
/* @__PURE__ */ t(B, {})
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Address.js","sources":["../../../../src/components/Contractor/Address/Address.tsx"],"sourcesContent":["import type { ReactNode } from 'react'\nimport { useContractorsGetSuspense } from '@gusto/embedded-api/react-query/contractorsGet'\nimport { useContractorsGetAddressSuspense } from '@gusto/embedded-api/react-query/contractorsGetAddress'\nimport { useContractorsUpdateAddressMutation } from '@gusto/embedded-api/react-query/contractorsUpdateAddress'\nimport { FormProvider, useForm } from 'react-hook-form'\nimport { zodResolver } from '@hookform/resolvers/zod'\nimport { AddressFormSchema, AddressProvider } from './useAddress'\nimport { Head } from './Head'\nimport { Form } from './Form'\nimport { Actions } from './Actions'\nimport type { AddressDefaultValues, AddressFormValues } from './useAddress'\nimport { Form as HtmlForm } from '@/components/Common/Form/Form'\nimport { useI18n, useComponentDictionary } from '@/i18n'\nimport { Flex } from '@/components/Common'\nimport type { BaseComponentInterface } from '@/components/Base/Base'\nimport { BaseComponent } from '@/components/Base/Base'\nimport { useBase } from '@/components/Base/useBase'\nimport { contractorEvents } from '@/shared/constants'\n\nexport interface AddressProps extends BaseComponentInterface<'Contractor.Address'> {\n contractorId: string\n defaultValues?: AddressDefaultValues\n children?: ReactNode\n className?: string\n}\n\nexport function Address(props: AddressProps) {\n return (\n <BaseComponent {...props}>\n <Root {...props}>{props.children}</Root>\n </BaseComponent>\n )\n}\n\nfunction Root({ contractorId, defaultValues, children, className, dictionary }: AddressProps) {\n useComponentDictionary('Contractor.Address', dictionary)\n useI18n('Contractor.Address')\n\n const { onEvent, baseSubmitHandler } = useBase()\n\n const { data: contractorData } = useContractorsGetSuspense({ contractorUuid: contractorId })\n const { data: addressData } = useContractorsGetAddressSuspense({ contractorUuid: contractorId })\n\n const { mutateAsync: updateAddress, isPending: isUpdatingAddressPending } =\n useContractorsUpdateAddressMutation()\n\n const contractor = contractorData.contractor\n const contractorType = contractorData.contractor?.type\n const address = addressData.contractorAddress\n\n const formDefaultValues = {\n street1: address?.street1 || defaultValues?.street1 || '',\n street2: address?.street2 || defaultValues?.street2 || '',\n city: address?.city || defaultValues?.city || '',\n state: address?.state || defaultValues?.state || '',\n zip: address?.zip || defaultValues?.zip || '',\n }\n\n const formMethods = useForm<AddressFormValues>({\n resolver: zodResolver(AddressFormSchema),\n defaultValues: formDefaultValues,\n })\n\n const onSubmit = async (data: AddressFormValues) => {\n await baseSubmitHandler(data, async payload => {\n const { contractorAddress } = await updateAddress({\n request: {\n contractorUuid: contractorId,\n
|
|
1
|
+
{"version":3,"file":"Address.js","sources":["../../../../src/components/Contractor/Address/Address.tsx"],"sourcesContent":["import type { ReactNode } from 'react'\nimport { useContractorsGetSuspense } from '@gusto/embedded-api/react-query/contractorsGet'\nimport { useContractorsGetAddressSuspense } from '@gusto/embedded-api/react-query/contractorsGetAddress'\nimport { useContractorsUpdateAddressMutation } from '@gusto/embedded-api/react-query/contractorsUpdateAddress'\nimport { FormProvider, useForm } from 'react-hook-form'\nimport { zodResolver } from '@hookform/resolvers/zod'\nimport { AddressFormSchema, AddressProvider } from './useAddress'\nimport { Head } from './Head'\nimport { Form } from './Form'\nimport { Actions } from './Actions'\nimport type { AddressDefaultValues, AddressFormValues } from './useAddress'\nimport { Form as HtmlForm } from '@/components/Common/Form/Form'\nimport { useI18n, useComponentDictionary } from '@/i18n'\nimport { Flex } from '@/components/Common'\nimport type { BaseComponentInterface } from '@/components/Base/Base'\nimport { BaseComponent } from '@/components/Base/Base'\nimport { useBase } from '@/components/Base/useBase'\nimport { contractorEvents } from '@/shared/constants'\n\nexport interface AddressProps extends BaseComponentInterface<'Contractor.Address'> {\n contractorId: string\n defaultValues?: AddressDefaultValues\n children?: ReactNode\n className?: string\n}\n\nexport function Address(props: AddressProps) {\n return (\n <BaseComponent {...props}>\n <Root {...props}>{props.children}</Root>\n </BaseComponent>\n )\n}\n\nfunction Root({ contractorId, defaultValues, children, className, dictionary }: AddressProps) {\n useComponentDictionary('Contractor.Address', dictionary)\n useI18n('Contractor.Address')\n\n const { onEvent, baseSubmitHandler } = useBase()\n\n const { data: contractorData } = useContractorsGetSuspense({ contractorUuid: contractorId })\n const { data: addressData } = useContractorsGetAddressSuspense({ contractorUuid: contractorId })\n\n const { mutateAsync: updateAddress, isPending: isUpdatingAddressPending } =\n useContractorsUpdateAddressMutation()\n\n const contractor = contractorData.contractor\n const contractorType = contractorData.contractor?.type\n const address = addressData.contractorAddress\n\n const formDefaultValues = {\n street1: address?.street1 || defaultValues?.street1 || '',\n street2: address?.street2 || defaultValues?.street2 || '',\n city: address?.city || defaultValues?.city || '',\n state: address?.state || defaultValues?.state || '',\n zip: address?.zip || defaultValues?.zip || '',\n }\n\n const formMethods = useForm<AddressFormValues>({\n resolver: zodResolver(AddressFormSchema),\n defaultValues: formDefaultValues,\n })\n\n const onSubmit = async (data: AddressFormValues) => {\n await baseSubmitHandler(data, async payload => {\n const { contractorAddress } = await updateAddress({\n request: {\n contractorUuid: contractorId,\n contractorAddressUpdateBody: {\n version: address?.version as string,\n street1: payload.street1,\n street2: payload.street2,\n city: payload.city,\n state: payload.state,\n zip: payload.zip,\n },\n },\n })\n\n onEvent(contractorEvents.CONTRACTOR_ADDRESS_UPDATED, contractorAddress)\n onEvent(contractorEvents.CONTRACTOR_ADDRESS_DONE)\n })\n }\n\n return (\n <section className={className}>\n <AddressProvider\n value={{\n contractor,\n contractorType,\n address,\n isPending: isUpdatingAddressPending,\n }}\n >\n <FormProvider {...formMethods}>\n <HtmlForm onSubmit={formMethods.handleSubmit(onSubmit)}>\n <Flex flexDirection=\"column\" gap={32} alignItems=\"stretch\">\n {children ? (\n children\n ) : (\n <>\n <Head />\n <Form />\n <Actions />\n </>\n )}\n </Flex>\n </HtmlForm>\n </FormProvider>\n </AddressProvider>\n </section>\n )\n}\n\nexport default Address\n"],"names":["Address","props","jsx","BaseComponent","Root","contractorId","defaultValues","children","className","dictionary","useComponentDictionary","useI18n","onEvent","baseSubmitHandler","useBase","contractorData","useContractorsGetSuspense","addressData","useContractorsGetAddressSuspense","updateAddress","isUpdatingAddressPending","useContractorsUpdateAddressMutation","contractor","contractorType","address","formDefaultValues","formMethods","useForm","zodResolver","AddressFormSchema","onSubmit","data","payload","contractorAddress","contractorEvents","AddressProvider","FormProvider","HtmlForm","Flex","jsxs","Fragment","Head","Form","Actions"],"mappings":";;;;;;;;;;;;;;;;;AA0BO,SAASA,GAAQC,GAAqB;AAC3C,SACE,gBAAAC,EAACC,GAAA,EAAe,GAAGF,GACjB,UAAA,gBAAAC,EAACE,KAAM,GAAGH,GAAQ,UAAAA,EAAM,SAAA,CAAS,EAAA,CACnC;AAEJ;AAEA,SAASG,EAAK,EAAE,cAAAC,GAAc,eAAAC,GAAe,UAAAC,GAAU,WAAAC,GAAW,YAAAC,KAA4B;AAC5F,EAAAC,EAAuB,sBAAsBD,CAAU,GACvDE,EAAQ,oBAAoB;AAE5B,QAAM,EAAE,SAAAC,GAAS,mBAAAC,EAAA,IAAsBC,EAAA,GAEjC,EAAE,MAAMC,EAAA,IAAmBC,EAA0B,EAAE,gBAAgBX,GAAc,GACrF,EAAE,MAAMY,EAAA,IAAgBC,EAAiC,EAAE,gBAAgBb,GAAc,GAEzF,EAAE,aAAac,GAAe,WAAWC,EAAA,IAC7CC,EAAA,GAEIC,IAAaP,EAAe,YAC5BQ,IAAiBR,EAAe,YAAY,MAC5CS,IAAUP,EAAY,mBAEtBQ,IAAoB;AAAA,IACxB,SAASD,GAAS,WAAWlB,GAAe,WAAW;AAAA,IACvD,SAASkB,GAAS,WAAWlB,GAAe,WAAW;AAAA,IACvD,MAAMkB,GAAS,QAAQlB,GAAe,QAAQ;AAAA,IAC9C,OAAOkB,GAAS,SAASlB,GAAe,SAAS;AAAA,IACjD,KAAKkB,GAAS,OAAOlB,GAAe,OAAO;AAAA,EAAA,GAGvCoB,IAAc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";
|
|
2
2
|
import { useTranslation as i } from "react-i18next";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { Grid as o } from "../../Common/Grid/Grid.js";
|
|
4
|
+
import { STATES_ABBR as l } from "../../../shared/constants.js";
|
|
5
5
|
import { TextInputField as t } from "../../Common/Fields/TextInputField/TextInputField.js";
|
|
6
6
|
import { SelectField as m } from "../../Common/Fields/SelectField/SelectField.js";
|
|
7
7
|
function g() {
|
|
8
8
|
const { t: e } = i("Contractor.Address");
|
|
9
|
-
return /* @__PURE__ */ s(
|
|
9
|
+
return /* @__PURE__ */ s(o, { gridTemplateColumns: { base: "1fr", small: ["1fr", "1fr"] }, gap: 20, children: [
|
|
10
10
|
/* @__PURE__ */ r(
|
|
11
11
|
t,
|
|
12
12
|
{
|
|
@@ -30,7 +30,7 @@ function g() {
|
|
|
30
30
|
m,
|
|
31
31
|
{
|
|
32
32
|
name: "state",
|
|
33
|
-
options:
|
|
33
|
+
options: l.map((a) => ({
|
|
34
34
|
label: e(`statesHash.${a}`, { ns: "common", defaultValue: a }),
|
|
35
35
|
value: a
|
|
36
36
|
})),
|
|
@@ -8,7 +8,7 @@ import "../../Base/useBase.js";
|
|
|
8
8
|
import "@gusto/embedded-api/models/errors/apierror";
|
|
9
9
|
import "@gusto/embedded-api/models/errors/gustoembeddederror";
|
|
10
10
|
import "@gusto/embedded-api/models/errors/sdkvalidationerror";
|
|
11
|
-
import "@gusto/embedded-api/models/errors/
|
|
11
|
+
import "@gusto/embedded-api/models/errors/unprocessableentityerror";
|
|
12
12
|
import "@gusto/embedded-api/models/errors/httpclienterrors";
|
|
13
13
|
import "dompurify";
|
|
14
14
|
import "../../../contexts/LocaleProvider/useLocale.js";
|
|
@@ -42,13 +42,13 @@ function yt({ contractorId: o, className: P, dictionary: C }) {
|
|
|
42
42
|
ot("Contractor.PaymentMethod", C), nt("Contractor.PaymentMethod");
|
|
43
43
|
const { t: u } = j("Contractor.PaymentMethod"), { onEvent: a, baseSubmitHandler: b } = ct(), d = at(), A = $(), N = I(), [T, p] = W(!1), g = Y({
|
|
44
44
|
contractorUuid: o
|
|
45
|
-
}),
|
|
45
|
+
}), k = z(N, {
|
|
46
46
|
contractorUuid: o
|
|
47
47
|
}), i = g.data.contractorPaymentMethod, {
|
|
48
|
-
data: { contractorBankAccountList:
|
|
48
|
+
data: { contractorBankAccountList: D }
|
|
49
49
|
} = L({
|
|
50
50
|
contractorUuid: o
|
|
51
|
-
}), t =
|
|
51
|
+
}), t = D?.[0] || void 0, { mutateAsync: E, isPending: R } = Z(), { mutateAsync: B, isPending: v } = K(), O = J(
|
|
52
52
|
() => ({
|
|
53
53
|
type: i.type || m.check,
|
|
54
54
|
name: t?.name || "",
|
|
@@ -69,10 +69,10 @@ function yt({ contractorId: o, className: P, dictionary: C }) {
|
|
|
69
69
|
r.setError("accountNumber", { type: "validate" });
|
|
70
70
|
return;
|
|
71
71
|
}
|
|
72
|
-
const w = await
|
|
72
|
+
const w = await B({
|
|
73
73
|
request: {
|
|
74
74
|
contractorUuid: o,
|
|
75
|
-
|
|
75
|
+
contractorBankAccountCreateRequestBody: {
|
|
76
76
|
name: h,
|
|
77
77
|
routingNumber: l,
|
|
78
78
|
accountNumber: f,
|
|
@@ -81,10 +81,10 @@ function yt({ contractorId: o, className: P, dictionary: C }) {
|
|
|
81
81
|
}
|
|
82
82
|
});
|
|
83
83
|
a(s.CONTRACTOR_BANK_ACCOUNT_CREATED, w), p(!0);
|
|
84
|
-
const q = (await A.fetchQuery(
|
|
84
|
+
const q = (await A.fetchQuery(k)).contractorPaymentMethod;
|
|
85
85
|
p(!1), y = q.version;
|
|
86
86
|
}
|
|
87
|
-
const F = await
|
|
87
|
+
const F = await E({
|
|
88
88
|
request: {
|
|
89
89
|
contractorUuid: o,
|
|
90
90
|
requestBody: {
|
|
@@ -105,7 +105,7 @@ function yt({ contractorId: o, className: P, dictionary: C }) {
|
|
|
105
105
|
{
|
|
106
106
|
type: "submit",
|
|
107
107
|
variant: "primary",
|
|
108
|
-
isDisabled: R ||
|
|
108
|
+
isDisabled: R || v || T,
|
|
109
109
|
children: u("continueCta")
|
|
110
110
|
}
|
|
111
111
|
) })
|
|
@@ -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/react-query/contractorPaymentMethodGet'\nimport { useContractorPaymentMethodGetBankAccountsSuspense } from '@gusto/embedded-api/react-query/contractorPaymentMethodGetBankAccounts'\nimport { useContractorPaymentMethodsCreateBankAccountMutation } from '@gusto/embedded-api/react-query/contractorPaymentMethodsCreateBankAccount'\nimport { useMemo, useState } from 'react'\nimport z from 'zod'\nimport { zodResolver } from '@hookform/resolvers/zod'\nimport { useContractorPaymentMethodUpdateMutation } from '@gusto/embedded-api/react-query/contractorPaymentMethodUpdate'\nimport { useQueryClient } from '@tanstack/react-query'\nimport { buildContractorPaymentMethodGetQuery } from '@gusto/embedded-api/react-query/contractorPaymentMethodGet'\nimport { useGustoEmbeddedContext } from '@gusto/embedded-api/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\nexport type PaymentMethodSchemaInputs = z.input<typeof PaymentMethodSchema>\nexport type PaymentMethodSchemaOutputs = z.output<typeof PaymentMethodSchema>\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 requestBody: {\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,IACf,eAAeD,EAAE,IAAA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AAA,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 type { SubmitHandler } from 'react-hook-form'\nimport { FormProvider, useForm, useWatch } from 'react-hook-form'\nimport { useContractorPaymentMethodGetSuspense } from '@gusto/embedded-api/react-query/contractorPaymentMethodGet'\nimport { useContractorPaymentMethodGetBankAccountsSuspense } from '@gusto/embedded-api/react-query/contractorPaymentMethodGetBankAccounts'\nimport { useContractorPaymentMethodsCreateBankAccountMutation } from '@gusto/embedded-api/react-query/contractorPaymentMethodsCreateBankAccount'\nimport { useMemo, useState } from 'react'\nimport z from 'zod'\nimport { zodResolver } from '@hookform/resolvers/zod'\nimport { useContractorPaymentMethodUpdateMutation } from '@gusto/embedded-api/react-query/contractorPaymentMethodUpdate'\nimport { useQueryClient } from '@tanstack/react-query'\nimport { buildContractorPaymentMethodGetQuery } from '@gusto/embedded-api/react-query/contractorPaymentMethodGet'\nimport { useGustoEmbeddedContext } from '@gusto/embedded-api/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\nexport type PaymentMethodSchemaInputs = z.input<typeof PaymentMethodSchema>\nexport type PaymentMethodSchemaOutputs = z.output<typeof PaymentMethodSchema>\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,IACf,eAAeD,EAAE,IAAA;AAAA;AAAA,IACjB,aAAaA,EAAE,KAAK,CAAC,YAAY,SAAS,CAAC;AAAA,EAAA,CAC5C;AAAA,EACDA,EAAE,OAAO;AAAA,IACP,MAAMA,EAAE,QAAQ,OAAO;AAAA,EAAA,CACxB;AACH,CAAC;AAKM,SAASE,GAAcC,GAA2B;AACvD,SACE,gBAAAC,EAACC,IAAA,EAAe,GAAGF,GACjB,UAAA,gBAAAC,EAACE,MAAM,GAAGH,GAAQ,UAAAA,EAAM,SAAA,CAAS,EAAA,CACnC;AAEJ;AAEA,SAASG,GAAK,EAAE,cAAAC,GAAc,WAAAC,GAAW,YAAAC,KAAkC;AACzE,EAAAC,GAAuB,4BAA4BD,CAAU,GAC7DE,GAAQ,0BAA0B;AAClC,QAAM,EAAE,GAAAC,EAAA,I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E,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,8 +1,8 @@
|
|
|
1
1
|
import { jsx as i } from "react/jsx-runtime";
|
|
2
2
|
import { useTranslation as r } from "react-i18next";
|
|
3
3
|
import { z as t } from "zod";
|
|
4
|
-
import { PAYMENT_METHODS as o } from "../../../shared/constants.js";
|
|
5
4
|
import "classnames";
|
|
5
|
+
import { PAYMENT_METHODS as o } from "../../../shared/constants.js";
|
|
6
6
|
import { RadioGroupField as p } from "../../Common/Fields/RadioGroupField/RadioGroupField.js";
|
|
7
7
|
t.object({
|
|
8
8
|
type: t.enum(["Check", "Direct Deposit"])
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as p } from "react/jsx-runtime";
|
|
2
2
|
import { useState as b, useMemo as i, useCallback as k } from "react";
|
|
3
|
-
import { useContractorPaymentGroupsGetListSuspense as
|
|
4
|
-
import { useInformationRequestsGetInformationRequestsSuspense as
|
|
3
|
+
import { useContractorPaymentGroupsGetListSuspense as B } from "@gusto/embedded-api/react-query/contractorPaymentGroupsGetList";
|
|
4
|
+
import { useInformationRequestsGetInformationRequestsSuspense as L } from "@gusto/embedded-api/react-query/informationRequestsGetInformationRequests";
|
|
5
5
|
import { InformationRequestStatus as g } from "@gusto/embedded-api/models/components/informationrequest";
|
|
6
6
|
import { PaymentsListPresentation as E } from "./PaymentsListPresentation.js";
|
|
7
7
|
import { useComponentDictionary as G } from "../../../../i18n/I18n.js";
|
|
@@ -20,15 +20,15 @@ const W = (t = 3) => {
|
|
|
20
20
|
};
|
|
21
21
|
}, Y = ({ companyId: t, dictionary: o, onEvent: e, alerts: f }) => {
|
|
22
22
|
G("Contractor.Payments.PaymentsList", o);
|
|
23
|
-
const [a, h] = b(3), { currentPage: C, itemsPerPage: D, getPaginationProps: T } = U(), { startDate: y, endDate: O } = i(() => W(a), [a]), { data: R } =
|
|
23
|
+
const [a, h] = b(3), { currentPage: C, itemsPerPage: D, getPaginationProps: T } = U(), { startDate: y, endDate: O } = i(() => W(a), [a]), { data: R } = B({
|
|
24
24
|
companyId: t,
|
|
25
25
|
startDate: y,
|
|
26
26
|
endDate: O,
|
|
27
27
|
page: C,
|
|
28
28
|
per: D
|
|
29
|
-
}), c = R.contractorPaymentGroupWithBlockers || [], A = T(R.httpMeta.response.headers), { data: M } =
|
|
29
|
+
}), c = R.contractorPaymentGroupWithBlockers || [], A = T(R.httpMeta.response.headers), { data: M } = L({
|
|
30
30
|
companyUuid: t
|
|
31
|
-
}), m = M.
|
|
31
|
+
}), m = M.informationRequests ?? [], w = i(() => c.some((n) => (n.creditBlockers || []).some((r) => {
|
|
32
32
|
if (r.status !== "unresolved") return !1;
|
|
33
33
|
const s = r.unblockOptions?.find(
|
|
34
34
|
(I) => I.unblockType === "submit_wire"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PaymentsList.js","sources":["../../../../../src/components/Contractor/Payments/PaymentsList/PaymentsList.tsx"],"sourcesContent":["import { useState, useMemo, useCallback } from 'react'\nimport { useContractorPaymentGroupsGetListSuspense } from '@gusto/embedded-api/react-query/contractorPaymentGroupsGetList'\nimport { useInformationRequestsGetInformationRequestsSuspense } from '@gusto/embedded-api/react-query/informationRequestsGetInformationRequests'\nimport { InformationRequestStatus } from '@gusto/embedded-api/models/components/informationrequest'\nimport type { InternalAlert } from '../types'\nimport { PaymentsListPresentation } from './PaymentsListPresentation'\nimport { useComponentDictionary } from '@/i18n'\nimport { BaseComponent, type BaseComponentInterface } from '@/components/Base'\nimport { componentEvents } from '@/shared/constants'\nimport { usePagination } from '@/hooks/usePagination/usePagination'\n\ninterface PaymentsListProps extends BaseComponentInterface<'Contractor.Payments.PaymentsList'> {\n companyId: string\n alerts?: InternalAlert[]\n}\n\nexport function PaymentsList(props: PaymentsListProps) {\n return (\n <BaseComponent {...props}>\n <Root {...props}>{props.children}</Root>\n </BaseComponent>\n )\n}\n\nconst calculateDateRange = (months: number = 3) => {\n const endDate = new Date()\n const startDate = new Date()\n\n startDate.setMonth(startDate.getMonth() - months)\n //Max range allowed by the API is 12 months\n endDate.setMonth(endDate.getMonth() + (12 - months))\n\n return {\n startDate: startDate.toISOString().split('T')[0] || '',\n endDate: endDate.toISOString().split('T')[0] || '',\n }\n}\n\nexport const Root = ({ companyId, dictionary, onEvent, alerts }: PaymentsListProps) => {\n useComponentDictionary('Contractor.Payments.PaymentsList', dictionary)\n\n const [numberOfMonths, setNumberOfMonths] = useState(3)\n const { currentPage, itemsPerPage, getPaginationProps } = usePagination()\n\n const { startDate, endDate } = useMemo(() => calculateDateRange(numberOfMonths), [numberOfMonths])\n\n const { data } = useContractorPaymentGroupsGetListSuspense({\n companyId,\n startDate,\n endDate,\n page: currentPage,\n per: itemsPerPage,\n })\n const contractorPayments = data.contractorPaymentGroupWithBlockers || []\n const paginationProps = getPaginationProps(data.httpMeta.response.headers)\n\n const { data: informationRequestsData } = useInformationRequestsGetInformationRequestsSuspense({\n companyUuid: companyId,\n })\n const informationRequests = informationRequestsData.
|
|
1
|
+
{"version":3,"file":"PaymentsList.js","sources":["../../../../../src/components/Contractor/Payments/PaymentsList/PaymentsList.tsx"],"sourcesContent":["import { useState, useMemo, useCallback } from 'react'\nimport { useContractorPaymentGroupsGetListSuspense } from '@gusto/embedded-api/react-query/contractorPaymentGroupsGetList'\nimport { useInformationRequestsGetInformationRequestsSuspense } from '@gusto/embedded-api/react-query/informationRequestsGetInformationRequests'\nimport { InformationRequestStatus } from '@gusto/embedded-api/models/components/informationrequest'\nimport type { InternalAlert } from '../types'\nimport { PaymentsListPresentation } from './PaymentsListPresentation'\nimport { useComponentDictionary } from '@/i18n'\nimport { BaseComponent, type BaseComponentInterface } from '@/components/Base'\nimport { componentEvents } from '@/shared/constants'\nimport { usePagination } from '@/hooks/usePagination/usePagination'\n\ninterface PaymentsListProps extends BaseComponentInterface<'Contractor.Payments.PaymentsList'> {\n companyId: string\n alerts?: InternalAlert[]\n}\n\nexport function PaymentsList(props: PaymentsListProps) {\n return (\n <BaseComponent {...props}>\n <Root {...props}>{props.children}</Root>\n </BaseComponent>\n )\n}\n\nconst calculateDateRange = (months: number = 3) => {\n const endDate = new Date()\n const startDate = new Date()\n\n startDate.setMonth(startDate.getMonth() - months)\n //Max range allowed by the API is 12 months\n endDate.setMonth(endDate.getMonth() + (12 - months))\n\n return {\n startDate: startDate.toISOString().split('T')[0] || '',\n endDate: endDate.toISOString().split('T')[0] || '',\n }\n}\n\nexport const Root = ({ companyId, dictionary, onEvent, alerts }: PaymentsListProps) => {\n useComponentDictionary('Contractor.Payments.PaymentsList', dictionary)\n\n const [numberOfMonths, setNumberOfMonths] = useState(3)\n const { currentPage, itemsPerPage, getPaginationProps } = usePagination()\n\n const { startDate, endDate } = useMemo(() => calculateDateRange(numberOfMonths), [numberOfMonths])\n\n const { data } = useContractorPaymentGroupsGetListSuspense({\n companyId,\n startDate,\n endDate,\n page: currentPage,\n per: itemsPerPage,\n })\n const contractorPayments = data.contractorPaymentGroupWithBlockers || []\n const paginationProps = getPaginationProps(data.httpMeta.response.headers)\n\n const { data: informationRequestsData } = useInformationRequestsGetInformationRequestsSuspense({\n companyUuid: companyId,\n })\n const informationRequests = informationRequestsData.informationRequests ?? []\n\n const hasUnresolvedWireInRequests = useMemo(() => {\n return contractorPayments.some(payment => {\n const creditBlockers = payment.creditBlockers || []\n return creditBlockers.some(blocker => {\n if (blocker.status !== 'unresolved') return false\n const wireOption = blocker.unblockOptions?.find(\n option => option.unblockType === 'submit_wire',\n )\n return wireOption && 'metadata' in wireOption && wireOption.metadata.wireInRequestUuid\n })\n })\n }, [contractorPayments])\n\n const handleRespondToRfi = useCallback(() => {\n onEvent(componentEvents.CONTRACTOR_PAYMENT_RFI_RESPOND)\n }, [onEvent])\n\n const rfiAlerts = useMemo(() => {\n const rfiAlertsArray: InternalAlert[] = []\n\n const hasPendingResponseRfis = informationRequests.some(\n request => request.status === InformationRequestStatus.PendingResponse,\n )\n const hasPendingReviewRfis = informationRequests.some(\n request => request.status === InformationRequestStatus.PendingReview,\n )\n\n if (hasPendingResponseRfis) {\n rfiAlertsArray.push({\n type: 'error',\n title: 'rfiPendingResponseTitle',\n content: 'rfiPendingResponseDescription',\n onAction: handleRespondToRfi,\n actionLabel: 'rfiRespondCta',\n })\n } else if (hasPendingReviewRfis) {\n rfiAlertsArray.push({\n type: 'info',\n title: 'rfiPendingReviewTitle',\n content: 'rfiPendingReviewDescription',\n })\n }\n\n return rfiAlertsArray\n }, [informationRequests, handleRespondToRfi])\n\n const onCreatePayment = () => {\n onEvent(componentEvents.CONTRACTOR_PAYMENT_CREATE)\n }\n\n const handleDateRangeChange = (numberOfMonths: number) => {\n setNumberOfMonths(numberOfMonths)\n }\n\n const onViewPayment = (paymentId: string) => {\n onEvent(componentEvents.CONTRACTOR_PAYMENT_VIEW, { paymentId })\n }\n\n const allAlerts = useMemo(() => {\n return [...rfiAlerts, ...(alerts || [])]\n }, [rfiAlerts, alerts])\n\n return (\n <PaymentsListPresentation\n contractorPayments={contractorPayments}\n numberOfMonths={numberOfMonths}\n onCreatePayment={onCreatePayment}\n onDateRangeChange={handleDateRangeChange}\n onViewPayment={onViewPayment}\n alerts={allAlerts}\n companyId={companyId}\n hasUnresolvedWireInRequests={hasUnresolvedWireInRequests}\n onEvent={onEvent}\n paginationProps={paginationProps}\n />\n )\n}\n"],"names":["PaymentsList","props","jsx","BaseComponent","Root","calculateDateRange","months","endDate","startDate","companyId","dictionary","onEvent","alerts","useComponentDictionary","numberOfMonths","setNumberOfMonths","useState","currentPage","itemsPerPage","getPaginationProps","usePagination","useMemo","data","useContractorPaymentGroupsGetListSuspense","contractorPayments","paginationProps","informationRequestsData","useInformationRequestsGetInformationRequestsSuspense","informationRequests","hasUnresolvedWireInRequests","payment","blocker","wireOption","option","handleRespondToRfi","useCallback","componentEvents","rfiAlerts","rfiAlertsArray","hasPendingResponseRfis","request","InformationRequestStatus","hasPendingReviewRfis","onCreatePayment","handleDateRangeChange","onViewPayment","paymentId","allAlerts","PaymentsListPresentation"],"mappings":";;;;;;;;;;;AAgBO,SAASA,EAAaC,GAA0B;AACrD,SACE,gBAAAC,EAACC,GAAA,EAAe,GAAGF,GACjB,UAAA,gBAAAC,EAACE,KAAM,GAAGH,GAAQ,UAAAA,EAAM,SAAA,CAAS,EAAA,CACnC;AAEJ;AAEA,MAAMI,IAAqB,CAACC,IAAiB,MAAM;AACjD,QAAMC,wBAAc,KAAA,GACdC,wBAAgB,KAAA;AAEtB,SAAAA,EAAU,SAASA,EAAU,SAAA,IAAaF,CAAM,GAEhDC,EAAQ,SAASA,EAAQ,SAAA,KAAc,KAAKD,EAAO,GAE5C;AAAA,IACL,WAAWE,EAAU,YAAA,EAAc,MAAM,GAAG,EAAE,CAAC,KAAK;AAAA,IACpD,SAASD,EAAQ,YAAA,EAAc,MAAM,GAAG,EAAE,CAAC,KAAK;AAAA,EAAA;AAEpD,GAEaH,IAAO,CAAC,EAAE,WAAAK,GAAW,YAAAC,GAAY,SAAAC,GAAS,QAAAC,QAAgC;AACrF,EAAAC,EAAuB,oCAAoCH,CAAU;AAErE,QAAM,CAACI,GAAgBC,CAAiB,IAAIC,EAAS,CAAC,GAChD,EAAE,aAAAC,GAAa,cAAAC,GAAc,oBAAAC,EAAA,IAAuBC,EAAA,GAEpD,EAAE,WAAAZ,GAAW,SAAAD,EAAA,IAAYc,EAAQ,MAAMhB,EAAmBS,CAAc,GAAG,CAACA,CAAc,CAAC,GAE3F,EAAE,MAAAQ,EAAA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