@gusto/embedded-react-sdk 0.55.1 → 0.55.3
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 +36 -0
- package/dist/components/Common/FieldLayout/FieldLayout.js +6 -6
- package/dist/components/Common/Fieldset/Fieldset.js +6 -6
- package/dist/components/Common/HorizontalFieldLayout/HorizontalFieldLayout.js +6 -6
- package/dist/components/Common/UI/Breadcrumbs/Breadcrumbs.js +1 -1
- package/dist/components/Common/UI/FileInput/FileInput.js +1 -1
- package/dist/components/Common/UI/MultiSelectComboBox/MultiSelectComboBox.js +58 -49
- package/dist/components/Common/UI/MultiSelectComboBox/MultiSelectComboBox.js.map +1 -1
- package/dist/components/Common/UI/MultiSelectComboBox/MultiSelectComboBox.module.scss.js +14 -10
- package/dist/components/Common/UI/MultiSelectComboBox/MultiSelectComboBox.module.scss.js.map +1 -1
- package/dist/components/Common/UI/MultiSelectComboBox/MultiSelectComboBoxTypes.d.ts +4 -0
- package/dist/components/Common/UI/ProgressBar/ProgressBar.js +4 -4
- package/dist/components/Company/AssignSignatory/CreateSignatory/useCreateSignatory.js +6 -3
- package/dist/components/Company/AssignSignatory/CreateSignatory/useCreateSignatory.js.map +1 -1
- package/dist/components/Company/AssignSignatory/InviteSignatory/useInviteSignatory.js +6 -3
- package/dist/components/Company/AssignSignatory/InviteSignatory/useInviteSignatory.js.map +1 -1
- package/dist/components/Company/AssignSignatory/useAssignSignatory.js +8 -5
- package/dist/components/Company/AssignSignatory/useAssignSignatory.js.map +1 -1
- package/dist/components/Company/BankAccount/BankAccountForm/context.js +6 -3
- package/dist/components/Company/BankAccount/BankAccountForm/context.js.map +1 -1
- package/dist/components/Company/DocumentSigner/DocumentList/DocumentList.d.ts +4 -0
- package/dist/components/Company/DocumentSigner/DocumentList/DocumentList.js.map +1 -1
- package/dist/components/Company/DocumentSigner/DocumentList/List.js +11 -8
- package/dist/components/Company/DocumentSigner/DocumentList/List.js.map +1 -1
- package/dist/components/Company/DocumentSigner/DocumentList/useDocumentList.js +6 -3
- package/dist/components/Company/DocumentSigner/DocumentList/useDocumentList.js.map +1 -1
- package/dist/components/Company/FederalTaxes/useFederalTaxes.js +11 -8
- package/dist/components/Company/FederalTaxes/useFederalTaxes.js.map +1 -1
- package/dist/components/Company/Industry/Context.js +9 -6
- package/dist/components/Company/Industry/Context.js.map +1 -1
- package/dist/components/Company/Locations/LocationForm/useLocationForm.js +6 -3
- package/dist/components/Company/Locations/LocationForm/useLocationForm.js.map +1 -1
- package/dist/components/Company/Locations/LocationsList/useLocationsList.js +6 -3
- package/dist/components/Company/Locations/LocationsList/useLocationsList.js.map +1 -1
- package/dist/components/Company/OnboardingOverview/context.js +6 -3
- package/dist/components/Company/OnboardingOverview/context.js.map +1 -1
- package/dist/components/Company/StateTaxes/StateTaxesForm/context.js +6 -3
- package/dist/components/Company/StateTaxes/StateTaxesForm/context.js.map +1 -1
- package/dist/components/Company/StateTaxes/StateTaxesList/context.js +6 -3
- package/dist/components/Company/StateTaxes/StateTaxesList/context.js.map +1 -1
- package/dist/components/Company/StateTaxes/TaxRateManagement/context.js +6 -3
- package/dist/components/Company/StateTaxes/TaxRateManagement/context.js.map +1 -1
- package/dist/components/Employee/Compensation/shared/useJobForm/useJobForm.js +116 -116
- package/dist/components/Employee/Compensation/shared/useJobForm/useJobForm.js.map +1 -1
- package/dist/components/Employee/Documents/onboarding/DocumentSigner/DocumentList/DocumentList.d.ts +4 -0
- package/dist/components/Employee/Documents/onboarding/DocumentSigner/DocumentList/DocumentList.js +19 -19
- package/dist/components/Employee/Documents/onboarding/DocumentSigner/DocumentList/DocumentList.js.map +1 -1
- package/dist/components/Employee/Documents/onboarding/DocumentSigner/DocumentList/List.js +16 -13
- package/dist/components/Employee/Documents/onboarding/DocumentSigner/DocumentList/List.js.map +1 -1
- package/dist/components/Employee/Documents/onboarding/DocumentSigner/DocumentList/useDocumentList.js +6 -3
- package/dist/components/Employee/Documents/onboarding/DocumentSigner/DocumentList/useDocumentList.js.map +1 -1
- package/dist/components/Employee/Documents/onboarding/DocumentSigner/DocumentSigner.d.ts +4 -0
- package/dist/components/Employee/Documents/onboarding/DocumentSigner/DocumentSigner.js.map +1 -1
- package/dist/components/Employee/FederalTaxes/shared/FederalTaxesView.js +1 -1
- package/dist/components/Employee/PaymentMethod/management/PaymentMethodBankForm.js +4 -4
- package/dist/components/Employee/PaymentMethod/onboarding/BankForm.js +4 -4
- package/dist/components/Flow/Flow.js +1 -1
- package/dist/components/Payroll/GrossUpModal/GrossUpModal.js +3 -2
- package/dist/components/Payroll/GrossUpModal/GrossUpModal.js.map +1 -1
- package/dist/components/Payroll/OffCycleCreation/OffCycleCreation.js +75 -71
- package/dist/components/Payroll/OffCycleCreation/OffCycleCreation.js.map +1 -1
- package/dist/components/Payroll/PayrollConfiguration/PayrollConfiguration.d.ts +7 -0
- package/dist/components/Payroll/PayrollConfiguration/PayrollConfiguration.js +202 -165
- package/dist/components/Payroll/PayrollConfiguration/PayrollConfiguration.js.map +1 -1
- package/dist/components/Payroll/PayrollConfiguration/usePayrollConfigurationData.d.ts +1 -0
- package/dist/components/Payroll/PayrollConfiguration/usePayrollConfigurationData.js +88 -82
- package/dist/components/Payroll/PayrollConfiguration/usePayrollConfigurationData.js.map +1 -1
- package/dist/components/Payroll/PayrollExecutionFlow/PayrollExecutionFlow.d.ts +1 -0
- package/dist/components/Payroll/PayrollExecutionFlow/PayrollExecutionFlow.js.map +1 -1
- package/dist/components/Payroll/PayrollExecutionFlow/payrollExecutionMachine.js +73 -48
- package/dist/components/Payroll/PayrollExecutionFlow/payrollExecutionMachine.js.map +1 -1
- package/dist/components/Payroll/PayrollFlow/PayrollFlow.d.ts +1 -1
- package/dist/components/Payroll/PayrollFlow/PayrollFlow.js +22 -20
- package/dist/components/Payroll/PayrollFlow/PayrollFlow.js.map +1 -1
- package/dist/components/Payroll/PayrollFlow/PayrollFlowComponents.d.ts +3 -0
- package/dist/components/Payroll/PayrollFlow/PayrollFlowComponents.js +22 -20
- package/dist/components/Payroll/PayrollFlow/PayrollFlowComponents.js.map +1 -1
- package/dist/components/Payroll/PayrollLanding/PayrollLanding.d.ts +2 -0
- package/dist/components/Payroll/PayrollLanding/PayrollLanding.js +34 -26
- package/dist/components/Payroll/PayrollLanding/PayrollLanding.js.map +1 -1
- package/dist/components/Payroll/PayrollLanding/PayrollLandingFlowComponents.d.ts +4 -0
- package/dist/components/Payroll/PayrollLanding/PayrollLandingFlowComponents.js +51 -43
- package/dist/components/Payroll/PayrollLanding/PayrollLandingFlowComponents.js.map +1 -1
- package/dist/components/Payroll/PayrollList/PayrollList.d.ts +2 -0
- package/dist/components/Payroll/PayrollList/PayrollList.js +48 -47
- package/dist/components/Payroll/PayrollList/PayrollList.js.map +1 -1
- package/dist/components/Payroll/PayrollList/PayrollListPresentation.d.ts +2 -1
- package/dist/components/Payroll/PayrollList/PayrollListPresentation.js +44 -43
- package/dist/components/Payroll/PayrollList/PayrollListPresentation.js.map +1 -1
- package/dist/components/Payroll/PayrollOverview/PayrollOverview.d.ts +15 -1
- package/dist/components/Payroll/PayrollOverview/PayrollOverview.js +188 -172
- package/dist/components/Payroll/PayrollOverview/PayrollOverview.js.map +1 -1
- package/dist/components/Payroll/PayrollOverview/PayrollOverviewPresentation.d.ts +3 -1
- package/dist/components/Payroll/PayrollOverview/PayrollOverviewPresentation.js +110 -118
- package/dist/components/Payroll/PayrollOverview/PayrollOverviewPresentation.js.map +1 -1
- package/dist/components/Payroll/PayrollReceipts/PayrollReceipts.js +22 -16
- package/dist/components/Payroll/PayrollReceipts/PayrollReceipts.js.map +1 -1
- package/dist/components/Payroll/PayrollReceipts/PayrollReceiptsPresentation.js +58 -49
- package/dist/components/Payroll/PayrollReceipts/PayrollReceiptsPresentation.js.map +1 -1
- package/dist/components/Payroll/PrintChecks/PrintChecks.d.ts +21 -0
- package/dist/components/Payroll/PrintChecks/PrintChecks.js +68 -0
- package/dist/components/Payroll/PrintChecks/PrintChecks.js.map +1 -0
- package/dist/components/Payroll/PrintChecks/PrintChecksBanner/PrintChecksBanner.d.ts +9 -0
- package/dist/components/Payroll/PrintChecks/PrintChecksBanner/PrintChecksBanner.js +34 -0
- package/dist/components/Payroll/PrintChecks/PrintChecksBanner/PrintChecksBanner.js.map +1 -0
- package/dist/components/Payroll/PrintChecks/PrintChecksBanner/index.d.ts +1 -0
- package/dist/components/Payroll/PrintChecks/PrintChecksComponents.d.ts +48 -0
- package/dist/components/Payroll/PrintChecks/PrintChecksComponents.js +26 -0
- package/dist/components/Payroll/PrintChecks/PrintChecksComponents.js.map +1 -0
- package/dist/components/Payroll/PrintChecks/PrintChecksFailure/PrintChecksFailure.d.ts +14 -0
- package/dist/components/Payroll/PrintChecks/PrintChecksFailure/PrintChecksFailure.js +47 -0
- package/dist/components/Payroll/PrintChecks/PrintChecksFailure/PrintChecksFailure.js.map +1 -0
- package/dist/components/Payroll/PrintChecks/PrintChecksFailure/index.d.ts +1 -0
- package/dist/components/Payroll/PrintChecks/PrintChecksForm/PrintChecksForm.d.ts +16 -0
- package/dist/components/Payroll/PrintChecks/PrintChecksForm/PrintChecksForm.js +144 -0
- package/dist/components/Payroll/PrintChecks/PrintChecksForm/PrintChecksForm.js.map +1 -0
- package/dist/components/Payroll/PrintChecks/PrintChecksForm/index.d.ts +1 -0
- package/dist/components/Payroll/PrintChecks/PrintChecksSummary/PrintChecksSummary.d.ts +14 -0
- package/dist/components/Payroll/PrintChecks/PrintChecksSummary/PrintChecksSummary.js +39 -0
- package/dist/components/Payroll/PrintChecks/PrintChecksSummary/PrintChecksSummary.js.map +1 -0
- package/dist/components/Payroll/PrintChecks/PrintChecksSummary/index.d.ts +1 -0
- package/dist/components/Payroll/PrintChecks/index.d.ts +2 -0
- package/dist/components/Payroll/PrintChecks/printChecksStateMachine.d.ts +33 -0
- package/dist/components/Payroll/PrintChecks/printChecksStateMachine.js +93 -0
- package/dist/components/Payroll/PrintChecks/printChecksStateMachine.js.map +1 -0
- package/dist/components/Payroll/PrintChecks/types.d.ts +14 -0
- package/dist/components/Payroll/helpers.d.ts +0 -15
- package/dist/components/Payroll/helpers.js +13 -18
- package/dist/components/Payroll/helpers.js.map +1 -1
- package/dist/components/Payroll/index.d.ts +2 -0
- package/dist/components/Payroll/index.js +26 -24
- package/dist/components/Payroll/index.js.map +1 -1
- package/dist/components/Payroll/usePreparedPayrollData.js +15 -12
- package/dist/components/Payroll/usePreparedPayrollData.js.map +1 -1
- package/dist/i18n/I18n.js +4 -0
- package/dist/i18n/I18n.js.map +1 -1
- package/dist/i18n/en/Company.DocumentList.json.js +34 -32
- package/dist/i18n/en/Company.DocumentList.json.js.map +1 -1
- package/dist/i18n/en/Employee.DocumentSigner.json.js +24 -22
- package/dist/i18n/en/Employee.DocumentSigner.json.js.map +1 -1
- package/dist/i18n/en/Payroll.PayrollConfiguration.json.js +9 -9
- package/dist/i18n/en/Payroll.PayrollOverview.json.js +36 -36
- package/dist/i18n/en/Payroll.PayrollReceipts.json.js +2 -2
- package/dist/i18n/en/Payroll.PrintChecksBanner.json.js +14 -0
- package/dist/i18n/en/Payroll.PrintChecksBanner.json.js.map +1 -0
- package/dist/i18n/en/Payroll.PrintChecksFailure.json.js +12 -0
- package/dist/i18n/en/Payroll.PrintChecksFailure.json.js.map +1 -0
- package/dist/i18n/en/Payroll.PrintChecksForm.json.js +28 -0
- package/dist/i18n/en/Payroll.PrintChecksForm.json.js.map +1 -0
- package/dist/i18n/en/Payroll.PrintChecksSummary.json.js +14 -0
- package/dist/i18n/en/Payroll.PrintChecksSummary.json.js.map +1 -0
- package/dist/i18n/types.d.ts +376 -8
- package/dist/models/external.d.ts +3 -0
- package/dist/partner-hook-utils/form/buildFormSchema.js +60 -54
- package/dist/partner-hook-utils/form/buildFormSchema.js.map +1 -1
- package/dist/shared/constants.d.ts +28 -0
- package/dist/shared/constants.js +61 -50
- package/dist/shared/constants.js.map +1 -1
- package/dist/style.css +1 -1
- package/docs/guides/endpoint-inventory.json +26 -0
- package/package.json +6 -6
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
import { useMemo as
|
|
2
|
-
import { useForm as
|
|
3
|
-
import { zodResolver as
|
|
4
|
-
import { useJobsAndCompensationsGetJobs as
|
|
5
|
-
import { useJobsAndCompensationsCreateJobMutation as
|
|
6
|
-
import { useJobsAndCompensationsUpdateMutation as
|
|
7
|
-
import { useJobsAndCompensationsUpdateCompensationMutation as
|
|
8
|
-
import { useEmployeeAddressesGetWorkAddresses as
|
|
9
|
-
import { useEmployeesGet as
|
|
10
|
-
import { useFederalTaxDetailsGet as
|
|
11
|
-
import { createJobSchema as
|
|
12
|
-
import { StateWcClassCodeField as
|
|
13
|
-
import { useDeriveFieldsMetadata as
|
|
14
|
-
import { useHookFormInternals as
|
|
15
|
-
import { createGetFormSubmissionValues as
|
|
16
|
-
import { withOptions as
|
|
1
|
+
import { useMemo as P, useState as ce } from "react";
|
|
2
|
+
import { useForm as ue, useWatch as le } from "react-hook-form";
|
|
3
|
+
import { zodResolver as me } from "@hookform/resolvers/zod";
|
|
4
|
+
import { useJobsAndCompensationsGetJobs as fe } from "@gusto/embedded-api/react-query/jobsAndCompensationsGetJobs";
|
|
5
|
+
import { useJobsAndCompensationsCreateJobMutation as he } from "@gusto/embedded-api/react-query/jobsAndCompensationsCreateJob";
|
|
6
|
+
import { useJobsAndCompensationsUpdateMutation as pe } from "@gusto/embedded-api/react-query/jobsAndCompensationsUpdate";
|
|
7
|
+
import { useJobsAndCompensationsUpdateCompensationMutation as be } from "@gusto/embedded-api/react-query/jobsAndCompensationsUpdateCompensation";
|
|
8
|
+
import { useEmployeeAddressesGetWorkAddresses as Ce } from "@gusto/embedded-api/react-query/employeeAddressesGetWorkAddresses";
|
|
9
|
+
import { useEmployeesGet as ve } from "@gusto/embedded-api/react-query/employeesGet";
|
|
10
|
+
import { useFederalTaxDetailsGet as Se } from "@gusto/embedded-api/react-query/federalTaxDetailsGet";
|
|
11
|
+
import { createJobSchema as we } from "./jobSchema.js";
|
|
12
|
+
import { StateWcClassCodeField as We, StateWcCoveredField as De, TwoPercentShareholderField as Je, HireDateField as ge, JobTitleField as Pe } from "./fields.js";
|
|
13
|
+
import { useDeriveFieldsMetadata as Ae } from "../../../../../partner-hook-utils/form/useDeriveFieldsMetadata.js";
|
|
14
|
+
import { useHookFormInternals as ye } from "../../../../../partner-hook-utils/form/useHookFormInternals.js";
|
|
15
|
+
import { createGetFormSubmissionValues as Me } from "../../../../../partner-hook-utils/form/getFormSubmissionValues.js";
|
|
16
|
+
import { withOptions as Q } from "../../../../../partner-hook-utils/form/withOptions.js";
|
|
17
17
|
import { withFlags as A } from "../../../../../partner-hook-utils/form/withFlags.js";
|
|
18
|
-
import { composeErrorHandler as
|
|
19
|
-
import { useBaseSubmit as
|
|
20
|
-
import { SDKInternalError as
|
|
21
|
-
import { WA_RISK_CLASS_CODES as
|
|
22
|
-
function
|
|
18
|
+
import { composeErrorHandler as Fe } from "../../../../../partner-hook-utils/composeErrorHandler.js";
|
|
19
|
+
import { useBaseSubmit as qe } from "../../../../Base/useBaseSubmit.js";
|
|
20
|
+
import { SDKInternalError as d } from "../../../../../types/sdkError.js";
|
|
21
|
+
import { WA_RISK_CLASS_CODES as _ } from "../../../../../models/WA_RISK_CODES.js";
|
|
22
|
+
function Ee(e, a) {
|
|
23
23
|
return !e || !a ? null : e.find((i) => i.uuid === a) ?? null;
|
|
24
24
|
}
|
|
25
|
-
function
|
|
25
|
+
function je(e, {
|
|
26
26
|
showTwoPercentShareholder: a,
|
|
27
27
|
showStateWc: i
|
|
28
28
|
}) {
|
|
@@ -32,7 +32,7 @@ function ke(e, {
|
|
|
32
32
|
twoPercentShareholder: A(e.twoPercentShareholder, {
|
|
33
33
|
isDisabled: !a
|
|
34
34
|
}),
|
|
35
|
-
stateWcCovered:
|
|
35
|
+
stateWcCovered: Q(
|
|
36
36
|
A(e.stateWcCovered, { isDisabled: !i }),
|
|
37
37
|
[
|
|
38
38
|
{ label: "Yes", value: "true" },
|
|
@@ -40,87 +40,89 @@ function ke(e, {
|
|
|
40
40
|
],
|
|
41
41
|
[!0, !1]
|
|
42
42
|
),
|
|
43
|
-
stateWcClassCode:
|
|
43
|
+
stateWcClassCode: Q(
|
|
44
44
|
A(e.stateWcClassCode, { isDisabled: !i }),
|
|
45
|
-
|
|
45
|
+
_.map(({ code: r, description: v }) => ({
|
|
46
46
|
value: r,
|
|
47
47
|
label: `${r}: ${v}`
|
|
48
48
|
})),
|
|
49
|
-
|
|
49
|
+
_
|
|
50
50
|
)
|
|
51
51
|
};
|
|
52
52
|
}
|
|
53
|
-
function
|
|
53
|
+
function st({
|
|
54
54
|
employeeId: e,
|
|
55
55
|
jobId: a,
|
|
56
56
|
optionalFieldsToRequire: i,
|
|
57
57
|
defaultValues: r,
|
|
58
58
|
validationMode: v = "onSubmit",
|
|
59
|
-
shouldFocusError:
|
|
60
|
-
withHireDateField:
|
|
59
|
+
shouldFocusError: K = !0,
|
|
60
|
+
withHireDateField: c = !0,
|
|
61
61
|
withTitleField: h = !0
|
|
62
62
|
}) {
|
|
63
|
-
const
|
|
63
|
+
const p = fe(
|
|
64
64
|
{ employeeId: e ?? "" },
|
|
65
65
|
{ enabled: !!e }
|
|
66
|
-
), S =
|
|
66
|
+
), S = Ce(
|
|
67
67
|
{ employeeId: e ?? "" },
|
|
68
68
|
{ enabled: !!e }
|
|
69
|
-
), w =
|
|
69
|
+
), w = ve({ employeeId: e ?? "" }, { enabled: !!e }), u = p.data?.jobs, y = S.data?.employeeWorkAddressesList?.find((C) => C.active) ?? null, W = w.data?.employee ?? null, M = W?.companyUuid, F = Se(
|
|
70
70
|
{ companyId: M ?? "" },
|
|
71
71
|
{ enabled: !!M }
|
|
72
|
-
),
|
|
73
|
-
() =>
|
|
74
|
-
[
|
|
75
|
-
), j =
|
|
72
|
+
), D = F.data?.federalTaxDetails?.taxableAsScorp === !0, b = y?.state === "WA", o = P(() => Ee(u, a), [u, a]), l = !a, q = l ? "create" : "update", [E, N] = P(
|
|
73
|
+
() => we({ mode: q, optionalFieldsToRequire: i, withHireDateField: c, withTitleField: h }),
|
|
74
|
+
[q, i, c, h]
|
|
75
|
+
), j = P(
|
|
76
76
|
() => ({
|
|
77
|
-
title:
|
|
78
|
-
hireDate:
|
|
79
|
-
twoPercentShareholder:
|
|
80
|
-
stateWcCovered:
|
|
81
|
-
stateWcClassCode:
|
|
77
|
+
title: o?.title ?? r?.title ?? "",
|
|
78
|
+
hireDate: o?.hireDate ?? r?.hireDate ?? null,
|
|
79
|
+
twoPercentShareholder: o?.twoPercentShareholder ?? r?.twoPercentShareholder ?? !1,
|
|
80
|
+
stateWcCovered: o?.stateWcCovered ?? r?.stateWcCovered ?? !1,
|
|
81
|
+
stateWcClassCode: o?.stateWcClassCode ?? r?.stateWcClassCode ?? ""
|
|
82
82
|
}),
|
|
83
|
-
[
|
|
84
|
-
),
|
|
85
|
-
resolver:
|
|
83
|
+
[o, r]
|
|
84
|
+
), m = ue({
|
|
85
|
+
resolver: me(E),
|
|
86
86
|
mode: v,
|
|
87
|
-
shouldFocusError:
|
|
87
|
+
shouldFocusError: K,
|
|
88
88
|
defaultValues: j,
|
|
89
89
|
values: j,
|
|
90
90
|
resetOptions: { keepDirtyValues: !0 }
|
|
91
|
-
}),
|
|
92
|
-
baseSubmitHandler:
|
|
93
|
-
error:
|
|
94
|
-
setError:
|
|
95
|
-
} =
|
|
96
|
-
showTwoPercentShareholder:
|
|
97
|
-
showStateWc:
|
|
98
|
-
}),
|
|
91
|
+
}), $ = le({ control: m.control, name: "stateWcCovered" }), U = he(), k = pe(), L = be(), [z, x] = ce(!1), Y = U.isPending || k.isPending || L.isPending || z, {
|
|
92
|
+
baseSubmitHandler: X,
|
|
93
|
+
error: Z,
|
|
94
|
+
setError: ee
|
|
95
|
+
} = qe("JobForm"), T = Fe(e ? [p, S, w, F] : [], { submitError: Z, setSubmitError: ee }), te = Ae(N, m.control), oe = je(te, {
|
|
96
|
+
showTwoPercentShareholder: D,
|
|
97
|
+
showStateWc: b
|
|
98
|
+
}), re = async (C) => {
|
|
99
99
|
let I;
|
|
100
|
-
return await new Promise((
|
|
101
|
-
|
|
102
|
-
async (
|
|
103
|
-
await
|
|
104
|
-
const
|
|
105
|
-
if (!
|
|
106
|
-
throw new
|
|
107
|
-
const V = s.stateWcCovered ? s.stateWcClassCode : null, n =
|
|
108
|
-
compId:
|
|
109
|
-
effectiveDate:
|
|
110
|
-
}))
|
|
111
|
-
|
|
112
|
-
|
|
100
|
+
return await new Promise((R) => {
|
|
101
|
+
m.handleSubmit(
|
|
102
|
+
async (ie) => {
|
|
103
|
+
await X(ie, async (s) => {
|
|
104
|
+
const G = C?.employeeId ?? e;
|
|
105
|
+
if (!G)
|
|
106
|
+
throw new d("employeeId is required to submit a job");
|
|
107
|
+
const V = s.stateWcCovered ? s.stateWcClassCode : null, n = c && s.hireDate ? s.hireDate : C?.hireDate ?? o?.hireDate ?? null, J = h ? s.title : void 0, B = !l && o?.primary === !0 && !!n && n !== o.hireDate ? (u ?? []).filter((t) => !t.primary && t.currentCompensationUuid).map((t) => ({
|
|
108
|
+
compId: t.currentCompensationUuid,
|
|
109
|
+
effectiveDate: t.compensations?.find((H) => H.uuid === t.currentCompensationUuid)?.effectiveDate
|
|
110
|
+
})).filter(
|
|
111
|
+
(t) => !!t.effectiveDate && t.effectiveDate > n
|
|
112
|
+
) : [];
|
|
113
|
+
let g;
|
|
114
|
+
if (l) {
|
|
113
115
|
if (!n)
|
|
114
|
-
throw new
|
|
115
|
-
|
|
116
|
+
throw new d(
|
|
117
|
+
c ? "hireDate is required to create a job" : "hireDate is required to create a job. Pass it via JobSubmitOptions when withHireDateField is false."
|
|
116
118
|
);
|
|
117
119
|
if (J === void 0)
|
|
118
|
-
throw new
|
|
120
|
+
throw new d(
|
|
119
121
|
"title is required to create a job. Set withTitleField: true (the default) on useJobForm for create flows."
|
|
120
122
|
);
|
|
121
|
-
const
|
|
123
|
+
const t = await U.mutateAsync({
|
|
122
124
|
request: {
|
|
123
|
-
employeeId:
|
|
125
|
+
employeeId: G,
|
|
124
126
|
jobsCreateRequestBody: {
|
|
125
127
|
title: J,
|
|
126
128
|
hireDate: n,
|
|
@@ -130,17 +132,17 @@ function at({
|
|
|
130
132
|
}
|
|
131
133
|
}
|
|
132
134
|
});
|
|
133
|
-
if (!
|
|
134
|
-
throw new
|
|
135
|
-
|
|
135
|
+
if (!t.job)
|
|
136
|
+
throw new d("Job creation failed");
|
|
137
|
+
g = t.job;
|
|
136
138
|
} else {
|
|
137
|
-
if (!
|
|
138
|
-
throw new
|
|
139
|
-
const
|
|
139
|
+
if (!o)
|
|
140
|
+
throw new d("Cannot update job: no matching job on file");
|
|
141
|
+
const t = await k.mutateAsync({
|
|
140
142
|
request: {
|
|
141
|
-
jobId:
|
|
143
|
+
jobId: o.uuid,
|
|
142
144
|
jobsUpdateRequestBody: {
|
|
143
|
-
version:
|
|
145
|
+
version: o.version,
|
|
144
146
|
title: J,
|
|
145
147
|
hireDate: n ?? void 0,
|
|
146
148
|
twoPercentShareholder: s.twoPercentShareholder,
|
|
@@ -149,30 +151,28 @@ function at({
|
|
|
149
151
|
}
|
|
150
152
|
}
|
|
151
153
|
});
|
|
152
|
-
if (!
|
|
153
|
-
throw new
|
|
154
|
-
if (
|
|
154
|
+
if (!t.job)
|
|
155
|
+
throw new d("Job update failed");
|
|
156
|
+
if (g = t.job, B.length > 0) {
|
|
155
157
|
x(!0);
|
|
156
158
|
try {
|
|
157
|
-
const
|
|
158
|
-
(
|
|
159
|
+
const ne = ((await p.refetch()).data?.jobs ?? []).flatMap(
|
|
160
|
+
(f) => f.compensations ?? []
|
|
159
161
|
);
|
|
160
162
|
await Promise.all(
|
|
161
|
-
|
|
162
|
-
const
|
|
163
|
-
|
|
164
|
-
const ce = !d.effectiveDate || d.effectiveDate < n ? n : d.effectiveDate;
|
|
165
|
-
return [
|
|
163
|
+
B.flatMap((f) => {
|
|
164
|
+
const O = ne.find((de) => de.uuid === f.compId);
|
|
165
|
+
return O?.version ? [
|
|
166
166
|
L.mutateAsync({
|
|
167
167
|
request: {
|
|
168
|
-
compensationId:
|
|
168
|
+
compensationId: f.compId,
|
|
169
169
|
compensationsUpdateRequestBody: {
|
|
170
|
-
version:
|
|
171
|
-
effectiveDate:
|
|
170
|
+
version: O.version,
|
|
171
|
+
effectiveDate: f.effectiveDate
|
|
172
172
|
}
|
|
173
173
|
}
|
|
174
174
|
})
|
|
175
|
-
];
|
|
175
|
+
] : [];
|
|
176
176
|
})
|
|
177
177
|
);
|
|
178
178
|
} finally {
|
|
@@ -181,48 +181,48 @@ function at({
|
|
|
181
181
|
}
|
|
182
182
|
}
|
|
183
183
|
I = {
|
|
184
|
-
mode:
|
|
185
|
-
data:
|
|
184
|
+
mode: l ? "create" : "update",
|
|
185
|
+
data: g
|
|
186
186
|
};
|
|
187
|
-
}),
|
|
187
|
+
}), R();
|
|
188
188
|
},
|
|
189
189
|
() => {
|
|
190
|
-
|
|
190
|
+
R();
|
|
191
191
|
}
|
|
192
192
|
)();
|
|
193
193
|
}), I;
|
|
194
|
-
},
|
|
195
|
-
return
|
|
194
|
+
}, se = e ? p.isLoading || S.isLoading || w.isLoading : !1, ae = ye(m);
|
|
195
|
+
return se || e && (!u || !W) ? { isLoading: !0, errorHandling: T } : {
|
|
196
196
|
isLoading: !1,
|
|
197
197
|
data: {
|
|
198
|
-
currentJob:
|
|
199
|
-
jobs:
|
|
200
|
-
employee:
|
|
198
|
+
currentJob: o,
|
|
199
|
+
jobs: u,
|
|
200
|
+
employee: W,
|
|
201
201
|
currentWorkAddress: y,
|
|
202
|
-
showTwoPercentShareholder:
|
|
203
|
-
showStateWc:
|
|
202
|
+
showTwoPercentShareholder: D,
|
|
203
|
+
showStateWc: b
|
|
204
204
|
},
|
|
205
205
|
status: {
|
|
206
|
-
isPending:
|
|
207
|
-
mode:
|
|
206
|
+
isPending: Y,
|
|
207
|
+
mode: l ? "create" : "update"
|
|
208
208
|
},
|
|
209
|
-
actions: { onSubmit:
|
|
209
|
+
actions: { onSubmit: re },
|
|
210
210
|
errorHandling: T,
|
|
211
211
|
form: {
|
|
212
212
|
Fields: {
|
|
213
|
-
Title: h ?
|
|
214
|
-
HireDate:
|
|
215
|
-
TwoPercentShareholder:
|
|
216
|
-
StateWcCovered:
|
|
217
|
-
StateWcClassCode:
|
|
213
|
+
Title: h ? Pe : void 0,
|
|
214
|
+
HireDate: c ? ge : void 0,
|
|
215
|
+
TwoPercentShareholder: D ? Je : void 0,
|
|
216
|
+
StateWcCovered: b ? De : void 0,
|
|
217
|
+
StateWcClassCode: b && $ ? We : void 0
|
|
218
218
|
},
|
|
219
|
-
fieldsMetadata:
|
|
220
|
-
hookFormInternals:
|
|
221
|
-
getFormSubmissionValues:
|
|
219
|
+
fieldsMetadata: oe,
|
|
220
|
+
hookFormInternals: ae,
|
|
221
|
+
getFormSubmissionValues: Me(m, E)
|
|
222
222
|
}
|
|
223
223
|
};
|
|
224
224
|
}
|
|
225
225
|
export {
|
|
226
|
-
|
|
226
|
+
st as useJobForm
|
|
227
227
|
};
|
|
228
228
|
//# sourceMappingURL=useJobForm.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useJobForm.js","sources":["../../../../../../src/components/Employee/Compensation/shared/useJobForm/useJobForm.tsx"],"sourcesContent":["import type { ComponentType } from 'react'\nimport { useMemo, useState } from 'react'\nimport { useForm, useWatch } from 'react-hook-form'\nimport type { UseFormProps } from 'react-hook-form'\nimport { zodResolver } from '@hookform/resolvers/zod'\nimport type { Job } from '@gusto/embedded-api/models/components/job'\nimport type { Employee } from '@gusto/embedded-api/models/components/employee'\nimport type { EmployeeWorkAddress } from '@gusto/embedded-api/models/components/employeeworkaddress'\nimport { useJobsAndCompensationsGetJobs } from '@gusto/embedded-api/react-query/jobsAndCompensationsGetJobs'\nimport { useJobsAndCompensationsCreateJobMutation } from '@gusto/embedded-api/react-query/jobsAndCompensationsCreateJob'\nimport { useJobsAndCompensationsUpdateMutation } from '@gusto/embedded-api/react-query/jobsAndCompensationsUpdate'\nimport { useJobsAndCompensationsUpdateCompensationMutation } from '@gusto/embedded-api/react-query/jobsAndCompensationsUpdateCompensation'\nimport { useEmployeeAddressesGetWorkAddresses } from '@gusto/embedded-api/react-query/employeeAddressesGetWorkAddresses'\nimport { useEmployeesGet } from '@gusto/embedded-api/react-query/employeesGet'\nimport { useFederalTaxDetailsGet } from '@gusto/embedded-api/react-query/federalTaxDetailsGet'\nimport {\n createJobSchema,\n type JobOptionalFieldsToRequire,\n type JobFormData,\n type JobFormOutputs,\n} from './jobSchema'\nimport {\n JobTitleField,\n HireDateField,\n TwoPercentShareholderField,\n StateWcCoveredField,\n StateWcClassCodeField,\n} from './fields'\nimport type {\n JobTitleFieldProps,\n HireDateFieldProps,\n TwoPercentShareholderFieldProps,\n StateWcCoveredFieldProps,\n StateWcClassCodeFieldProps,\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 { withFlags } from '@/partner-hook-utils/form/withFlags'\nimport { composeErrorHandler } from '@/partner-hook-utils/composeErrorHandler'\nimport type {\n BaseFormHookReady,\n FieldMetadata,\n FieldsMetadata,\n HookLoadingResult,\n HookSubmitResult,\n} from '@/partner-hook-utils/types'\nimport { useBaseSubmit } from '@/components/Base/useBaseSubmit'\nimport { SDKInternalError } from '@/types/sdkError'\nimport { WA_RISK_CLASS_CODES, type WARiskClassCode } from '@/models/WA_RISK_CODES'\n\n/**\n * Optional values supplied to {@link useJobForm}'s `actions.onSubmit` at submit time.\n *\n * @remarks\n * Use these when a value isn't sourced from a rendered field — typically\n * because the hook was configured with `withHireDateField: false`, or because\n * the employee being saved was created in the same submit chain and the\n * `employeeId` wasn't known at hook construction.\n *\n * @public\n */\nexport interface JobSubmitOptions {\n /** Override the `employeeId` configured at hook construction. Useful when the employee is created in the same submit chain. */\n employeeId?: string\n /**\n * Supply `hireDate` at submit time rather than via a rendered field. Use\n * with `withHireDateField: false` for screens that derive hireDate from\n * external context (e.g. the employee's `startDate` during onboarding).\n * Falls back to the loaded job's `hireDate` on update mode when omitted;\n * required (or sourced from a default) on create mode.\n */\n hireDate?: string\n}\n\n/**\n * Configuration options for {@link useJobForm}.\n *\n * @remarks\n * Presence or absence of `jobId` selects the API verb — see the `jobId` field\n * description. `employeeId` is optional so the hook can be composed alongside\n * an employee-creation step; supply it at submit time via\n * {@link JobSubmitOptions.employeeId} in that case.\n *\n * @public\n */\nexport interface UseJobFormProps {\n /** UUID of the employee whose job is being created or edited. May be omitted when the employee is created in the same submit chain — supply the value via {@link JobSubmitOptions.employeeId} at submit time. */\n employeeId?: string\n /** Present → update mode (PUT /v1/jobs/:id with `version`). Omitted → create mode (POST /v1/employees/:id/jobs). */\n jobId?: string\n /** Override fields that are optional on a given mode to be required. See {@link JobOptionalFieldsToRequire}. */\n optionalFieldsToRequire?: JobOptionalFieldsToRequire\n /** Pre-fill form values. Server data takes precedence on update mode. */\n defaultValues?: Partial<JobFormData>\n /** Passed through to react-hook-form. Defaults to `'onSubmit'`. */\n validationMode?: UseFormProps['mode']\n /** Auto-focus the first invalid field on submit. Set to `false` when using `composeSubmitHandler` so submit-time focus is coordinated across multiple forms. Defaults to `true`. */\n shouldFocusError?: boolean\n /**\n * When `false`, hides `Fields.HireDate` (becomes `undefined`) and removes\n * `hireDate` from schema validation. Supply the value via\n * {@link JobSubmitOptions.hireDate} at submit time, or rely on the loaded\n * job's existing value on update. Use this when the date is driven by\n * external context rather than user input (e.g. the employee's `startDate`).\n * Defaults to `true`.\n */\n withHireDateField?: boolean\n /**\n * When `false`, hides `Fields.Title` (becomes `undefined`), removes\n * `title` from schema validation, and skips sending `title` on PUT/POST.\n * Use this when another form owns the title field — e.g. compensation\n * edit surfaces render the title via `CompFields.Title` because title\n * lives on compensation in the API (`job.title` is just a denormalized\n * snapshot of the primary comp's title). Defaults to `true` so the\n * standalone job-creation flow still gathers a title for the create\n * body.\n */\n withTitleField?: boolean\n}\n\n/**\n * Pre-bound field components exposed on `useJobForm().form.Fields`.\n *\n * @remarks\n * Each property is either the field component or `undefined`. A field is\n * `undefined` when conditions for rendering it aren't met — see each member\n * for its visibility rule. Always null-check conditional fields (e.g.\n * `{Fields.TwoPercentShareholder && <Fields.TwoPercentShareholder ... />}`)\n * before rendering.\n *\n * @public\n */\nexport interface JobFormFields {\n /** Bound to `title`. Job title text input. `undefined` when `withTitleField: false`. */\n Title: ComponentType<JobTitleFieldProps> | undefined\n /** Bound to `hireDate`. Hire date picker. `undefined` when `withHireDateField: false`. */\n HireDate: ComponentType<HireDateFieldProps> | undefined\n /** Bound to `twoPercentShareholder`. S-Corp 2% shareholder checkbox. `undefined` when the company is not taxable as an S-Corp (see `data.showTwoPercentShareholder`). */\n TwoPercentShareholder: ComponentType<TwoPercentShareholderFieldProps> | undefined\n /** Bound to `stateWcCovered`. Washington state workers' compensation coverage radio group. `undefined` when the active work address is not in Washington (see `data.showStateWc`). */\n StateWcCovered: ComponentType<StateWcCoveredFieldProps> | undefined\n /** Bound to `stateWcClassCode`. Washington state workers' compensation risk class code select. `undefined` when the active work address is not in Washington or when `stateWcCovered` is `false`. */\n StateWcClassCode: ComponentType<StateWcClassCodeFieldProps> | undefined\n}\n\n/**\n * Ready-state shape returned by {@link useJobForm} once data has loaded.\n *\n * @remarks\n * Discriminated by `isLoading: false`. Extends\n * {@link BaseFormHookReady} with the job-specific `data`, `status`,\n * `actions`, and `form.Fields` shape.\n *\n * @public\n */\nexport interface UseJobFormReady extends BaseFormHookReady<\n JobFieldsMetadata,\n JobFormData,\n JobFormFields\n> {\n /** Job-specific data payload: the loaded job (if any), the employee's other jobs, the employee record, the active work address, and presentation flags for conditional fields. */\n data: {\n /** The job row loaded for update; `null` in create mode. */\n currentJob: Job | null\n /** All jobs for the employee, when employeeId is set. Useful for screen-level cross-checks across jobs. */\n jobs: Job[] | undefined\n /** The loaded employee record, or `null` when `employeeId` was omitted. */\n employee: Employee | null\n /** The employee's active work address, or `null` when none is set. */\n currentWorkAddress: EmployeeWorkAddress | null\n /** True when the company is taxable as an S-Corp; use this to decide whether to render `TwoPercentShareholder`. */\n showTwoPercentShareholder: boolean\n /**\n * True when the active work-address state is WA; use this to decide whether to render\n * `StateWcCovered`. `Fields.StateWcClassCode` is additionally gated on `stateWcCovered === true`,\n * so most callers only need to check `Fields.StateWcCovered` / `Fields.StateWcClassCode`\n * truthiness rather than this flag directly.\n */\n showStateWc: boolean\n }\n /** Submission state. `isPending` is `true` while any in-flight mutation (including the secondary-compensation correction block) hasn't settled. `mode` reflects whether the next submit will create or update. */\n status: { isPending: boolean; mode: 'create' | 'update' }\n /** Submit actions exposed by the hook. */\n actions: {\n /** Validates the form, runs the appropriate create/update mutation, and resolves to a {@link HookSubmitResult} containing the saved job. Resolves to `undefined` on validation failure or mutation error. */\n onSubmit: (options?: JobSubmitOptions) => Promise<HookSubmitResult<Job> | undefined>\n }\n}\n\nfunction findJob(jobs: Job[] | undefined, jobId: string | undefined): Job | null {\n if (!jobs || !jobId) return null\n return jobs.find(j => j.uuid === jobId) ?? null\n}\n\n/** @internal */\nfunction buildJobFieldsMetadata(\n base: Record<keyof JobFormData, FieldMetadata>,\n {\n showTwoPercentShareholder,\n showStateWc,\n }: { showTwoPercentShareholder: boolean; showStateWc: boolean },\n) {\n return {\n title: base.title,\n hireDate: base.hireDate,\n twoPercentShareholder: withFlags(base.twoPercentShareholder, {\n isDisabled: !showTwoPercentShareholder,\n }),\n stateWcCovered: withOptions<boolean>(\n withFlags(base.stateWcCovered, { isDisabled: !showStateWc }),\n [\n { label: 'Yes', value: 'true' },\n { label: 'No', value: 'false' },\n ],\n [true, false],\n ),\n stateWcClassCode: withOptions<WARiskClassCode>(\n withFlags(base.stateWcClassCode, { isDisabled: !showStateWc }),\n WA_RISK_CLASS_CODES.map(({ code, description }) => ({\n value: code,\n label: `${code}: ${description}`,\n })),\n WA_RISK_CLASS_CODES,\n ),\n } satisfies FieldsMetadata\n}\n\n/**\n * Headless hook for creating or updating an employee's job — title, hire date, S-Corp 2% shareholder flag, and Washington state workers' compensation fields.\n *\n * @remarks\n * Companion hook to `useCompensationForm`. Jobs and their compensations are\n * separate entities in the Gusto API and this hook focuses exclusively on\n * the job side. Presence of `jobId` selects the verb:\n *\n * | Hook config | Mode | API call |\n * | ----------- | ---- | -------- |\n * | `{ employeeId, jobId }` | update | `PUT /v1/jobs/:jobId` (with `version`) |\n * | `{ employeeId }` (no `jobId`) | create | `POST /v1/employees/:employeeId/jobs` |\n * | `{}` + submit `employeeId` | create | `POST /v1/employees/:options.employeeId/jobs` |\n *\n * Creating a job auto-creates a stub compensation. To update the stub in the\n * same flow, capture `currentCompensationUuid` (and the compensation's\n * `version` from `compensations[]`) from the create response and thread them\n * into `useCompensationForm.actions.onSubmit({ jobId, compensationId, compensationVersion })`.\n *\n * When the primary job's `hireDate` changes, secondary compensation effective\n * dates are corrected after the PUT; `isPending` stays `true` through that.\n *\n * @param input - {@link UseJobFormProps} — `employeeId`, `jobId` (toggle create/update), and configuration for required-field overrides, default values, and which fields the hook renders.\n * @returns A {@link HookLoadingResult} while data is loading, or a {@link UseJobFormReady} once ready.\n * @public\n *\n * @example\n * ```tsx\n * import { useJobForm, SDKFormProvider } from '@gusto/embedded-react-sdk'\n *\n * function JobForm({ employeeId }: { employeeId: string }) {\n * const job = useJobForm({ employeeId })\n * if (job.isLoading) return null\n *\n * const { Fields } = job.form\n * return (\n * <form onSubmit={e => { e.preventDefault(); job.actions.onSubmit() }}>\n * <SDKFormProvider formHookResult={job}>\n * {Fields.Title && <Fields.Title label=\"Job title\" />}\n * {Fields.HireDate && <Fields.HireDate label=\"Hire date\" />}\n * {Fields.TwoPercentShareholder && (\n * <Fields.TwoPercentShareholder label=\"2% S-Corp shareholder\" />\n * )}\n * </SDKFormProvider>\n * <button type=\"submit\" disabled={job.status.isPending}>Save</button>\n * </form>\n * )\n * }\n * ```\n */\nexport function useJobForm({\n employeeId,\n jobId,\n optionalFieldsToRequire,\n defaultValues: partnerDefaults,\n validationMode = 'onSubmit',\n shouldFocusError = true,\n withHireDateField = true,\n withTitleField = true,\n}: UseJobFormProps): HookLoadingResult | UseJobFormReady {\n const jobsQuery = useJobsAndCompensationsGetJobs(\n { employeeId: employeeId ?? '' },\n { enabled: !!employeeId },\n )\n const addressesQuery = useEmployeeAddressesGetWorkAddresses(\n { employeeId: employeeId ?? '' },\n { enabled: !!employeeId },\n )\n const employeeQuery = useEmployeesGet({ employeeId: employeeId ?? '' }, { enabled: !!employeeId })\n\n const employeeJobs = jobsQuery.data?.jobs\n const workAddresses = addressesQuery.data?.employeeWorkAddressesList\n const currentWorkAddress = workAddresses?.find(address => address.active) ?? null\n const employee = employeeQuery.data?.employee ?? null\n const companyUuid = employee?.companyUuid\n\n const taxQuery = useFederalTaxDetailsGet(\n { companyId: companyUuid ?? '' },\n { enabled: !!companyUuid },\n )\n const federalTaxDetails = taxQuery.data?.federalTaxDetails\n const showTwoPercentShareholder = federalTaxDetails?.taxableAsScorp === true\n const showStateWc = currentWorkAddress?.state === 'WA'\n\n const currentJob = useMemo(() => findJob(employeeJobs, jobId), [employeeJobs, jobId])\n const isCreateMode = !jobId\n const mode = isCreateMode ? 'create' : 'update'\n\n const [schema, metadataConfig] = useMemo(\n () => createJobSchema({ mode, optionalFieldsToRequire, withHireDateField, withTitleField }),\n [mode, optionalFieldsToRequire, withHireDateField, withTitleField],\n )\n\n const resolvedDefaults: JobFormData = useMemo(\n () => ({\n title: currentJob?.title ?? partnerDefaults?.title ?? '',\n hireDate: currentJob?.hireDate ?? partnerDefaults?.hireDate ?? null,\n twoPercentShareholder:\n currentJob?.twoPercentShareholder ?? partnerDefaults?.twoPercentShareholder ?? false,\n stateWcCovered: currentJob?.stateWcCovered ?? partnerDefaults?.stateWcCovered ?? false,\n stateWcClassCode: currentJob?.stateWcClassCode ?? partnerDefaults?.stateWcClassCode ?? '',\n }),\n [currentJob, partnerDefaults],\n )\n\n const formMethods = useForm<JobFormData, unknown, JobFormOutputs>({\n resolver: zodResolver(schema),\n mode: validationMode,\n shouldFocusError,\n defaultValues: resolvedDefaults,\n values: resolvedDefaults,\n resetOptions: { keepDirtyValues: true },\n })\n\n const watchedStateWcCovered = useWatch({ control: formMethods.control, name: 'stateWcCovered' })\n\n const createJobMutation = useJobsAndCompensationsCreateJobMutation()\n const updateJobMutation = useJobsAndCompensationsUpdateMutation()\n const updateSecondaryCompMutation = useJobsAndCompensationsUpdateCompensationMutation()\n // Tracks the post-primary-PUT corrective block (jobs refetch + parallel\n // secondary comp PUTs). No single mutation hook reports `isPending` for the\n // whole window — the refetch isn't a mutation, and `Promise.all` over one\n // mutation hook makes its `isPending` track the latest-settled call — so we\n // OR this in to keep the spinner solid through it.\n const [isCorrectingSecondaries, setIsCorrectingSecondaries] = useState(false)\n const isPending =\n createJobMutation.isPending ||\n updateJobMutation.isPending ||\n updateSecondaryCompMutation.isPending ||\n isCorrectingSecondaries\n\n const {\n baseSubmitHandler,\n error: submitError,\n setError: setSubmitError,\n } = useBaseSubmit('JobForm')\n\n const queriesForErrors = employeeId ? [jobsQuery, addressesQuery, employeeQuery, taxQuery] : []\n const errorHandling = composeErrorHandler(queriesForErrors, { submitError, setSubmitError })\n\n const baseMetadata = useDeriveFieldsMetadata(metadataConfig, formMethods.control)\n const fieldsMetadata = buildJobFieldsMetadata(baseMetadata, {\n showTwoPercentShareholder,\n showStateWc,\n })\n\n const onSubmit = async (\n options?: JobSubmitOptions,\n ): Promise<HookSubmitResult<Job> | undefined> => {\n let submitResult: HookSubmitResult<Job> | undefined\n\n await new Promise<void>(resolve => {\n void formMethods.handleSubmit(\n async (data: JobFormOutputs) => {\n await baseSubmitHandler(data, async payload => {\n const resolvedEmployeeId = options?.employeeId ?? employeeId\n if (!resolvedEmployeeId) {\n throw new SDKInternalError('employeeId is required to submit a job')\n }\n\n const stateWcClassCode = payload.stateWcCovered ? payload.stateWcClassCode : null\n\n // Mirror the work/home address pattern: when the field is rendered\n // the payload value wins; when it isn't, fall back to a submit-time\n // override (`options.hireDate`), then to the loaded job's existing\n // value on update mode. Create mode requires a resolved value —\n // hireDate is mandatory on POST /v1/employees/:id/jobs.\n const resolvedHireDate =\n withHireDateField && payload.hireDate\n ? payload.hireDate\n : (options?.hireDate ?? currentJob?.hireDate ?? null)\n\n // When the title field is suppressed (steady-state edits drive\n // title through useCompensationForm), omit it from the body so\n // the server preserves the existing value rather than clobbering\n // it with whatever sat in form state.\n const titleToSend = withTitleField ? payload.title : undefined\n\n // When a primary job's hire_date is PUT and the value actually\n // changes, the API unconditionally overwrites every secondary's\n // current-compensation effective_date to match the new hire_date —\n // even when the secondary's original effective_date was already on\n // or after the new hire_date. Read those originals now so we can\n // PUT them back below; by the time we re-fetch they'll be gone.\n const shouldCorrectSecondaries =\n !isCreateMode &&\n currentJob?.primary === true &&\n !!resolvedHireDate &&\n resolvedHireDate !== currentJob.hireDate\n const secondaryJobEffectiveDates = shouldCorrectSecondaries\n ? (employeeJobs ?? [])\n .filter(j => !j.primary && j.currentCompensationUuid)\n .map(j => ({\n compId: j.currentCompensationUuid!,\n effectiveDate: j.compensations?.find(c => c.uuid === j.currentCompensationUuid)\n ?.effectiveDate,\n }))\n : []\n\n let updatedJob: Job\n\n if (isCreateMode) {\n if (!resolvedHireDate) {\n throw new SDKInternalError(\n withHireDateField\n ? 'hireDate is required to create a job'\n : 'hireDate is required to create a job. Pass it via JobSubmitOptions when withHireDateField is false.',\n )\n }\n if (titleToSend === undefined) {\n throw new SDKInternalError(\n 'title is required to create a job. Set withTitleField: true (the default) on useJobForm for create flows.',\n )\n }\n const result = await createJobMutation.mutateAsync({\n request: {\n employeeId: resolvedEmployeeId,\n jobsCreateRequestBody: {\n title: titleToSend,\n hireDate: resolvedHireDate,\n twoPercentShareholder: payload.twoPercentShareholder,\n stateWcCovered: payload.stateWcCovered,\n stateWcClassCode,\n },\n },\n })\n if (!result.job) {\n throw new SDKInternalError('Job creation failed')\n }\n updatedJob = result.job\n } else {\n if (!currentJob) {\n throw new SDKInternalError('Cannot update job: no matching job on file')\n }\n const result = await updateJobMutation.mutateAsync({\n request: {\n jobId: currentJob.uuid,\n jobsUpdateRequestBody: {\n version: currentJob.version as string,\n title: titleToSend,\n hireDate: resolvedHireDate ?? undefined,\n twoPercentShareholder: payload.twoPercentShareholder,\n stateWcCovered: payload.stateWcCovered,\n stateWcClassCode,\n },\n },\n })\n if (!result.job) {\n throw new SDKInternalError('Job update failed')\n }\n updatedJob = result.job\n\n // The primary PUT above clobbered each secondary's\n // current-compensation effective_date. Refetch jobs for the\n // bumped versions, then PUT each secondary back to\n // max(originalEffectiveDate, newHireDate) in parallel — the\n // requests are independent (different compensation_id, separate\n // versions), and `Promise.all` still surfaces the first\n // rejection through the surrounding baseSubmitHandler's catch.\n if (shouldCorrectSecondaries && secondaryJobEffectiveDates.length > 0) {\n setIsCorrectingSecondaries(true)\n try {\n const refreshed = await jobsQuery.refetch()\n const freshComps = (refreshed.data?.jobs ?? []).flatMap(\n j => j.compensations ?? [],\n )\n await Promise.all(\n secondaryJobEffectiveDates.flatMap(entry => {\n const freshComp = freshComps.find(c => c.uuid === entry.compId)\n if (!freshComp?.version) return []\n\n const desired =\n !entry.effectiveDate || entry.effectiveDate < resolvedHireDate\n ? resolvedHireDate\n : entry.effectiveDate\n\n return [\n updateSecondaryCompMutation.mutateAsync({\n request: {\n compensationId: entry.compId,\n compensationsUpdateRequestBody: {\n version: freshComp.version,\n effectiveDate: desired,\n },\n },\n }),\n ]\n }),\n )\n } finally {\n setIsCorrectingSecondaries(false)\n }\n }\n }\n\n submitResult = {\n mode: isCreateMode ? 'create' : 'update',\n data: updatedJob,\n }\n })\n resolve()\n },\n () => {\n resolve()\n },\n )()\n })\n\n return submitResult\n }\n\n const isDataLoading = employeeId\n ? jobsQuery.isLoading || addressesQuery.isLoading || employeeQuery.isLoading\n : false\n\n const hookFormInternals = useHookFormInternals(formMethods)\n\n if (isDataLoading || (employeeId && (!employeeJobs || !employee))) {\n return { isLoading: true as const, errorHandling }\n }\n\n return {\n isLoading: false as const,\n data: {\n currentJob,\n jobs: employeeJobs,\n employee,\n currentWorkAddress,\n showTwoPercentShareholder,\n showStateWc,\n },\n status: {\n isPending,\n mode: isCreateMode ? 'create' : 'update',\n },\n actions: { onSubmit },\n errorHandling,\n form: {\n Fields: {\n Title: withTitleField ? JobTitleField : undefined,\n HireDate: withHireDateField ? HireDateField : undefined,\n TwoPercentShareholder: showTwoPercentShareholder ? TwoPercentShareholderField : undefined,\n StateWcCovered: showStateWc ? StateWcCoveredField : undefined,\n StateWcClassCode: showStateWc && watchedStateWcCovered ? StateWcClassCodeField : undefined,\n },\n fieldsMetadata,\n hookFormInternals,\n getFormSubmissionValues: createGetFormSubmissionValues(formMethods, schema),\n },\n }\n}\n\n/**\n * Discriminated union returned by {@link useJobForm}.\n *\n * @remarks\n * Branch on `isLoading` to narrow to either {@link HookLoadingResult} or\n * {@link UseJobFormReady}.\n *\n * @public\n */\nexport type UseJobFormResult = HookLoadingResult | UseJobFormReady\n\n/**\n * Shape of the per-field metadata exposed at `useJobForm().form.fieldsMetadata`.\n *\n * @remarks\n * Maps each field name in {@link JobFormData} to its presentation metadata —\n * including the registered `name`, whether the field is required or disabled,\n * and (for select-like fields) the option list.\n *\n * @public\n */\nexport type JobFieldsMetadata = ReturnType<typeof buildJobFieldsMetadata>\n"],"names":["findJob","jobs","jobId","j","buildJobFieldsMetadata","base","showTwoPercentShareholder","showStateWc","withFlags","withOptions","WA_RISK_CLASS_CODES","code","description","useJobForm","employeeId","optionalFieldsToRequire","partnerDefaults","validationMode","shouldFocusError","withHireDateField","withTitleField","jobsQuery","useJobsAndCompensationsGetJobs","addressesQuery","useEmployeeAddressesGetWorkAddresses","employeeQuery","useEmployeesGet","employeeJobs","currentWorkAddress","address","employee","companyUuid","taxQuery","useFederalTaxDetailsGet","currentJob","useMemo","isCreateMode","mode","schema","metadataConfig","createJobSchema","resolvedDefaults","formMethods","useForm","zodResolver","watchedStateWcCovered","useWatch","createJobMutation","useJobsAndCompensationsCreateJobMutation","updateJobMutation","useJobsAndCompensationsUpdateMutation","updateSecondaryCompMutation","useJobsAndCompensationsUpdateCompensationMutation","isCorrectingSecondaries","setIsCorrectingSecondaries","useState","isPending","baseSubmitHandler","submitError","setSubmitError","useBaseSubmit","errorHandling","composeErrorHandler","baseMetadata","useDeriveFieldsMetadata","fieldsMetadata","onSubmit","options","submitResult","resolve","data","payload","resolvedEmployeeId","SDKInternalError","stateWcClassCode","resolvedHireDate","titleToSend","shouldCorrectSecondaries","secondaryJobEffectiveDates","c","updatedJob","result","freshComps","entry","freshComp","desired","isDataLoading","hookFormInternals","useHookFormInternals","JobTitleField","HireDateField","TwoPercentShareholderField","StateWcCoveredField","StateWcClassCodeField","createGetFormSubmissionValues"],"mappings":";;;;;;;;;;;;;;;;;;;;;AA+LA,SAASA,GAAQC,GAAyBC,GAAuC;AAC/E,SAAI,CAACD,KAAQ,CAACC,IAAc,OACrBD,EAAK,KAAK,CAAAE,MAAKA,EAAE,SAASD,CAAK,KAAK;AAC7C;AAGA,SAASE,GACPC,GACA;AAAA,EACE,2BAAAC;AAAA,EACA,aAAAC;AACF,GACA;AACA,SAAO;AAAA,IACL,OAAOF,EAAK;AAAA,IACZ,UAAUA,EAAK;AAAA,IACf,uBAAuBG,EAAUH,EAAK,uBAAuB;AAAA,MAC3D,YAAY,CAACC;AAAA,IAAA,CACd;AAAA,IACD,gBAAgBG;AAAA,MACdD,EAAUH,EAAK,gBAAgB,EAAE,YAAY,CAACE,GAAa;AAAA,MAC3D;AAAA,QACE,EAAE,OAAO,OAAO,OAAO,OAAA;AAAA,QACvB,EAAE,OAAO,MAAM,OAAO,QAAA;AAAA,MAAQ;AAAA,MAEhC,CAAC,IAAM,EAAK;AAAA,IAAA;AAAA,IAEd,kBAAkBE;AAAA,MAChBD,EAAUH,EA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A,MACA,yBAAyBO,GAA8BpD,GAAaJ,CAAM;AAAA,IAAA;AAAA,EAC5E;AAEJ;"}
|
|
1
|
+
{"version":3,"file":"useJobForm.js","sources":["../../../../../../src/components/Employee/Compensation/shared/useJobForm/useJobForm.tsx"],"sourcesContent":["import type { ComponentType } from 'react'\nimport { useMemo, useState } from 'react'\nimport { useForm, useWatch } from 'react-hook-form'\nimport type { UseFormProps } from 'react-hook-form'\nimport { zodResolver } from '@hookform/resolvers/zod'\nimport type { Job } from '@gusto/embedded-api/models/components/job'\nimport type { Employee } from '@gusto/embedded-api/models/components/employee'\nimport type { EmployeeWorkAddress } from '@gusto/embedded-api/models/components/employeeworkaddress'\nimport { useJobsAndCompensationsGetJobs } from '@gusto/embedded-api/react-query/jobsAndCompensationsGetJobs'\nimport { useJobsAndCompensationsCreateJobMutation } from '@gusto/embedded-api/react-query/jobsAndCompensationsCreateJob'\nimport { useJobsAndCompensationsUpdateMutation } from '@gusto/embedded-api/react-query/jobsAndCompensationsUpdate'\nimport { useJobsAndCompensationsUpdateCompensationMutation } from '@gusto/embedded-api/react-query/jobsAndCompensationsUpdateCompensation'\nimport { useEmployeeAddressesGetWorkAddresses } from '@gusto/embedded-api/react-query/employeeAddressesGetWorkAddresses'\nimport { useEmployeesGet } from '@gusto/embedded-api/react-query/employeesGet'\nimport { useFederalTaxDetailsGet } from '@gusto/embedded-api/react-query/federalTaxDetailsGet'\nimport {\n createJobSchema,\n type JobOptionalFieldsToRequire,\n type JobFormData,\n type JobFormOutputs,\n} from './jobSchema'\nimport {\n JobTitleField,\n HireDateField,\n TwoPercentShareholderField,\n StateWcCoveredField,\n StateWcClassCodeField,\n} from './fields'\nimport type {\n JobTitleFieldProps,\n HireDateFieldProps,\n TwoPercentShareholderFieldProps,\n StateWcCoveredFieldProps,\n StateWcClassCodeFieldProps,\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 { withFlags } from '@/partner-hook-utils/form/withFlags'\nimport { composeErrorHandler } from '@/partner-hook-utils/composeErrorHandler'\nimport type {\n BaseFormHookReady,\n FieldMetadata,\n FieldsMetadata,\n HookLoadingResult,\n HookSubmitResult,\n} from '@/partner-hook-utils/types'\nimport { useBaseSubmit } from '@/components/Base/useBaseSubmit'\nimport { SDKInternalError } from '@/types/sdkError'\nimport { WA_RISK_CLASS_CODES, type WARiskClassCode } from '@/models/WA_RISK_CODES'\n\n/**\n * Optional values supplied to {@link useJobForm}'s `actions.onSubmit` at submit time.\n *\n * @remarks\n * Use these when a value isn't sourced from a rendered field — typically\n * because the hook was configured with `withHireDateField: false`, or because\n * the employee being saved was created in the same submit chain and the\n * `employeeId` wasn't known at hook construction.\n *\n * @public\n */\nexport interface JobSubmitOptions {\n /** Override the `employeeId` configured at hook construction. Useful when the employee is created in the same submit chain. */\n employeeId?: string\n /**\n * Supply `hireDate` at submit time rather than via a rendered field. Use\n * with `withHireDateField: false` for screens that derive hireDate from\n * external context (e.g. the employee's `startDate` during onboarding).\n * Falls back to the loaded job's `hireDate` on update mode when omitted;\n * required (or sourced from a default) on create mode.\n */\n hireDate?: string\n}\n\n/**\n * Configuration options for {@link useJobForm}.\n *\n * @remarks\n * Presence or absence of `jobId` selects the API verb — see the `jobId` field\n * description. `employeeId` is optional so the hook can be composed alongside\n * an employee-creation step; supply it at submit time via\n * {@link JobSubmitOptions.employeeId} in that case.\n *\n * @public\n */\nexport interface UseJobFormProps {\n /** UUID of the employee whose job is being created or edited. May be omitted when the employee is created in the same submit chain — supply the value via {@link JobSubmitOptions.employeeId} at submit time. */\n employeeId?: string\n /** Present → update mode (PUT /v1/jobs/:id with `version`). Omitted → create mode (POST /v1/employees/:id/jobs). */\n jobId?: string\n /** Override fields that are optional on a given mode to be required. See {@link JobOptionalFieldsToRequire}. */\n optionalFieldsToRequire?: JobOptionalFieldsToRequire\n /** Pre-fill form values. Server data takes precedence on update mode. */\n defaultValues?: Partial<JobFormData>\n /** Passed through to react-hook-form. Defaults to `'onSubmit'`. */\n validationMode?: UseFormProps['mode']\n /** Auto-focus the first invalid field on submit. Set to `false` when using `composeSubmitHandler` so submit-time focus is coordinated across multiple forms. Defaults to `true`. */\n shouldFocusError?: boolean\n /**\n * When `false`, hides `Fields.HireDate` (becomes `undefined`) and removes\n * `hireDate` from schema validation. Supply the value via\n * {@link JobSubmitOptions.hireDate} at submit time, or rely on the loaded\n * job's existing value on update. Use this when the date is driven by\n * external context rather than user input (e.g. the employee's `startDate`).\n * Defaults to `true`.\n */\n withHireDateField?: boolean\n /**\n * When `false`, hides `Fields.Title` (becomes `undefined`), removes\n * `title` from schema validation, and skips sending `title` on PUT/POST.\n * Use this when another form owns the title field — e.g. compensation\n * edit surfaces render the title via `CompFields.Title` because title\n * lives on compensation in the API (`job.title` is just a denormalized\n * snapshot of the primary comp's title). Defaults to `true` so the\n * standalone job-creation flow still gathers a title for the create\n * body.\n */\n withTitleField?: boolean\n}\n\n/**\n * Pre-bound field components exposed on `useJobForm().form.Fields`.\n *\n * @remarks\n * Each property is either the field component or `undefined`. A field is\n * `undefined` when conditions for rendering it aren't met — see each member\n * for its visibility rule. Always null-check conditional fields (e.g.\n * `{Fields.TwoPercentShareholder && <Fields.TwoPercentShareholder ... />}`)\n * before rendering.\n *\n * @public\n */\nexport interface JobFormFields {\n /** Bound to `title`. Job title text input. `undefined` when `withTitleField: false`. */\n Title: ComponentType<JobTitleFieldProps> | undefined\n /** Bound to `hireDate`. Hire date picker. `undefined` when `withHireDateField: false`. */\n HireDate: ComponentType<HireDateFieldProps> | undefined\n /** Bound to `twoPercentShareholder`. S-Corp 2% shareholder checkbox. `undefined` when the company is not taxable as an S-Corp (see `data.showTwoPercentShareholder`). */\n TwoPercentShareholder: ComponentType<TwoPercentShareholderFieldProps> | undefined\n /** Bound to `stateWcCovered`. Washington state workers' compensation coverage radio group. `undefined` when the active work address is not in Washington (see `data.showStateWc`). */\n StateWcCovered: ComponentType<StateWcCoveredFieldProps> | undefined\n /** Bound to `stateWcClassCode`. Washington state workers' compensation risk class code select. `undefined` when the active work address is not in Washington or when `stateWcCovered` is `false`. */\n StateWcClassCode: ComponentType<StateWcClassCodeFieldProps> | undefined\n}\n\n/**\n * Ready-state shape returned by {@link useJobForm} once data has loaded.\n *\n * @remarks\n * Discriminated by `isLoading: false`. Extends\n * {@link BaseFormHookReady} with the job-specific `data`, `status`,\n * `actions`, and `form.Fields` shape.\n *\n * @public\n */\nexport interface UseJobFormReady extends BaseFormHookReady<\n JobFieldsMetadata,\n JobFormData,\n JobFormFields\n> {\n /** Job-specific data payload: the loaded job (if any), the employee's other jobs, the employee record, the active work address, and presentation flags for conditional fields. */\n data: {\n /** The job row loaded for update; `null` in create mode. */\n currentJob: Job | null\n /** All jobs for the employee, when employeeId is set. Useful for screen-level cross-checks across jobs. */\n jobs: Job[] | undefined\n /** The loaded employee record, or `null` when `employeeId` was omitted. */\n employee: Employee | null\n /** The employee's active work address, or `null` when none is set. */\n currentWorkAddress: EmployeeWorkAddress | null\n /** True when the company is taxable as an S-Corp; use this to decide whether to render `TwoPercentShareholder`. */\n showTwoPercentShareholder: boolean\n /**\n * True when the active work-address state is WA; use this to decide whether to render\n * `StateWcCovered`. `Fields.StateWcClassCode` is additionally gated on `stateWcCovered === true`,\n * so most callers only need to check `Fields.StateWcCovered` / `Fields.StateWcClassCode`\n * truthiness rather than this flag directly.\n */\n showStateWc: boolean\n }\n /** Submission state. `isPending` is `true` while any in-flight mutation (including the secondary-compensation correction block) hasn't settled. `mode` reflects whether the next submit will create or update. */\n status: { isPending: boolean; mode: 'create' | 'update' }\n /** Submit actions exposed by the hook. */\n actions: {\n /** Validates the form, runs the appropriate create/update mutation, and resolves to a {@link HookSubmitResult} containing the saved job. Resolves to `undefined` on validation failure or mutation error. */\n onSubmit: (options?: JobSubmitOptions) => Promise<HookSubmitResult<Job> | undefined>\n }\n}\n\nfunction findJob(jobs: Job[] | undefined, jobId: string | undefined): Job | null {\n if (!jobs || !jobId) return null\n return jobs.find(j => j.uuid === jobId) ?? null\n}\n\n/** @internal */\nfunction buildJobFieldsMetadata(\n base: Record<keyof JobFormData, FieldMetadata>,\n {\n showTwoPercentShareholder,\n showStateWc,\n }: { showTwoPercentShareholder: boolean; showStateWc: boolean },\n) {\n return {\n title: base.title,\n hireDate: base.hireDate,\n twoPercentShareholder: withFlags(base.twoPercentShareholder, {\n isDisabled: !showTwoPercentShareholder,\n }),\n stateWcCovered: withOptions<boolean>(\n withFlags(base.stateWcCovered, { isDisabled: !showStateWc }),\n [\n { label: 'Yes', value: 'true' },\n { label: 'No', value: 'false' },\n ],\n [true, false],\n ),\n stateWcClassCode: withOptions<WARiskClassCode>(\n withFlags(base.stateWcClassCode, { isDisabled: !showStateWc }),\n WA_RISK_CLASS_CODES.map(({ code, description }) => ({\n value: code,\n label: `${code}: ${description}`,\n })),\n WA_RISK_CLASS_CODES,\n ),\n } satisfies FieldsMetadata\n}\n\n/**\n * Headless hook for creating or updating an employee's job — title, hire date, S-Corp 2% shareholder flag, and Washington state workers' compensation fields.\n *\n * @remarks\n * Companion hook to `useCompensationForm`. Jobs and their compensations are\n * separate entities in the Gusto API and this hook focuses exclusively on\n * the job side. Presence of `jobId` selects the verb:\n *\n * | Hook config | Mode | API call |\n * | ----------- | ---- | -------- |\n * | `{ employeeId, jobId }` | update | `PUT /v1/jobs/:jobId` (with `version`) |\n * | `{ employeeId }` (no `jobId`) | create | `POST /v1/employees/:employeeId/jobs` |\n * | `{}` + submit `employeeId` | create | `POST /v1/employees/:options.employeeId/jobs` |\n *\n * Creating a job auto-creates a stub compensation. To update the stub in the\n * same flow, capture `currentCompensationUuid` (and the compensation's\n * `version` from `compensations[]`) from the create response and thread them\n * into `useCompensationForm.actions.onSubmit({ jobId, compensationId, compensationVersion })`.\n *\n * When the primary job's `hireDate` changes, secondary compensation effective\n * dates are corrected after the PUT; `isPending` stays `true` through that.\n *\n * @param input - {@link UseJobFormProps} — `employeeId`, `jobId` (toggle create/update), and configuration for required-field overrides, default values, and which fields the hook renders.\n * @returns A {@link HookLoadingResult} while data is loading, or a {@link UseJobFormReady} once ready.\n * @public\n *\n * @example\n * ```tsx\n * import { useJobForm, SDKFormProvider } from '@gusto/embedded-react-sdk'\n *\n * function JobForm({ employeeId }: { employeeId: string }) {\n * const job = useJobForm({ employeeId })\n * if (job.isLoading) return null\n *\n * const { Fields } = job.form\n * return (\n * <form onSubmit={e => { e.preventDefault(); job.actions.onSubmit() }}>\n * <SDKFormProvider formHookResult={job}>\n * {Fields.Title && <Fields.Title label=\"Job title\" />}\n * {Fields.HireDate && <Fields.HireDate label=\"Hire date\" />}\n * {Fields.TwoPercentShareholder && (\n * <Fields.TwoPercentShareholder label=\"2% S-Corp shareholder\" />\n * )}\n * </SDKFormProvider>\n * <button type=\"submit\" disabled={job.status.isPending}>Save</button>\n * </form>\n * )\n * }\n * ```\n */\nexport function useJobForm({\n employeeId,\n jobId,\n optionalFieldsToRequire,\n defaultValues: partnerDefaults,\n validationMode = 'onSubmit',\n shouldFocusError = true,\n withHireDateField = true,\n withTitleField = true,\n}: UseJobFormProps): HookLoadingResult | UseJobFormReady {\n const jobsQuery = useJobsAndCompensationsGetJobs(\n { employeeId: employeeId ?? '' },\n { enabled: !!employeeId },\n )\n const addressesQuery = useEmployeeAddressesGetWorkAddresses(\n { employeeId: employeeId ?? '' },\n { enabled: !!employeeId },\n )\n const employeeQuery = useEmployeesGet({ employeeId: employeeId ?? '' }, { enabled: !!employeeId })\n\n const employeeJobs = jobsQuery.data?.jobs\n const workAddresses = addressesQuery.data?.employeeWorkAddressesList\n const currentWorkAddress = workAddresses?.find(address => address.active) ?? null\n const employee = employeeQuery.data?.employee ?? null\n const companyUuid = employee?.companyUuid\n\n const taxQuery = useFederalTaxDetailsGet(\n { companyId: companyUuid ?? '' },\n { enabled: !!companyUuid },\n )\n const federalTaxDetails = taxQuery.data?.federalTaxDetails\n const showTwoPercentShareholder = federalTaxDetails?.taxableAsScorp === true\n const showStateWc = currentWorkAddress?.state === 'WA'\n\n const currentJob = useMemo(() => findJob(employeeJobs, jobId), [employeeJobs, jobId])\n const isCreateMode = !jobId\n const mode = isCreateMode ? 'create' : 'update'\n\n const [schema, metadataConfig] = useMemo(\n () => createJobSchema({ mode, optionalFieldsToRequire, withHireDateField, withTitleField }),\n [mode, optionalFieldsToRequire, withHireDateField, withTitleField],\n )\n\n const resolvedDefaults: JobFormData = useMemo(\n () => ({\n title: currentJob?.title ?? partnerDefaults?.title ?? '',\n hireDate: currentJob?.hireDate ?? partnerDefaults?.hireDate ?? null,\n twoPercentShareholder:\n currentJob?.twoPercentShareholder ?? partnerDefaults?.twoPercentShareholder ?? false,\n stateWcCovered: currentJob?.stateWcCovered ?? partnerDefaults?.stateWcCovered ?? false,\n stateWcClassCode: currentJob?.stateWcClassCode ?? partnerDefaults?.stateWcClassCode ?? '',\n }),\n [currentJob, partnerDefaults],\n )\n\n const formMethods = useForm<JobFormData, unknown, JobFormOutputs>({\n resolver: zodResolver(schema),\n mode: validationMode,\n shouldFocusError,\n defaultValues: resolvedDefaults,\n values: resolvedDefaults,\n resetOptions: { keepDirtyValues: true },\n })\n\n const watchedStateWcCovered = useWatch({ control: formMethods.control, name: 'stateWcCovered' })\n\n const createJobMutation = useJobsAndCompensationsCreateJobMutation()\n const updateJobMutation = useJobsAndCompensationsUpdateMutation()\n const updateSecondaryCompMutation = useJobsAndCompensationsUpdateCompensationMutation()\n // Tracks the post-primary-PUT corrective block (jobs refetch + parallel\n // secondary comp PUTs). No single mutation hook reports `isPending` for the\n // whole window — the refetch isn't a mutation, and `Promise.all` over one\n // mutation hook makes its `isPending` track the latest-settled call — so we\n // OR this in to keep the spinner solid through it.\n const [isCorrectingSecondaries, setIsCorrectingSecondaries] = useState(false)\n const isPending =\n createJobMutation.isPending ||\n updateJobMutation.isPending ||\n updateSecondaryCompMutation.isPending ||\n isCorrectingSecondaries\n\n const {\n baseSubmitHandler,\n error: submitError,\n setError: setSubmitError,\n } = useBaseSubmit('JobForm')\n\n const queriesForErrors = employeeId ? [jobsQuery, addressesQuery, employeeQuery, taxQuery] : []\n const errorHandling = composeErrorHandler(queriesForErrors, { submitError, setSubmitError })\n\n const baseMetadata = useDeriveFieldsMetadata(metadataConfig, formMethods.control)\n const fieldsMetadata = buildJobFieldsMetadata(baseMetadata, {\n showTwoPercentShareholder,\n showStateWc,\n })\n\n const onSubmit = async (\n options?: JobSubmitOptions,\n ): Promise<HookSubmitResult<Job> | undefined> => {\n let submitResult: HookSubmitResult<Job> | undefined\n\n await new Promise<void>(resolve => {\n void formMethods.handleSubmit(\n async (data: JobFormOutputs) => {\n await baseSubmitHandler(data, async payload => {\n const resolvedEmployeeId = options?.employeeId ?? employeeId\n if (!resolvedEmployeeId) {\n throw new SDKInternalError('employeeId is required to submit a job')\n }\n\n const stateWcClassCode = payload.stateWcCovered ? payload.stateWcClassCode : null\n\n // Mirror the work/home address pattern: when the field is rendered\n // the payload value wins; when it isn't, fall back to a submit-time\n // override (`options.hireDate`), then to the loaded job's existing\n // value on update mode. Create mode requires a resolved value —\n // hireDate is mandatory on POST /v1/employees/:id/jobs.\n const resolvedHireDate =\n withHireDateField && payload.hireDate\n ? payload.hireDate\n : (options?.hireDate ?? currentJob?.hireDate ?? null)\n\n // When the title field is suppressed (steady-state edits drive\n // title through useCompensationForm), omit it from the body so\n // the server preserves the existing value rather than clobbering\n // it with whatever sat in form state.\n const titleToSend = withTitleField ? payload.title : undefined\n\n // When a primary job's hire_date is PUT and the value actually\n // changes, the API unconditionally overwrites every secondary's\n // current-compensation effective_date to match the new hire_date.\n // That's already the outcome we want for a secondary whose\n // effective_date was before the new hire_date, so there's nothing\n // to correct there. It's only wrong for a secondary whose\n // effective_date was already on or after the new hire_date — the\n // API clobbers that one too, erasing a deliberately future-dated\n // comp. Read those originals now so we can restore them below; by\n // the time we re-fetch they'll be gone.\n const shouldCorrectSecondaries =\n !isCreateMode &&\n currentJob?.primary === true &&\n !!resolvedHireDate &&\n resolvedHireDate !== currentJob.hireDate\n const secondariesNeedingRestore = shouldCorrectSecondaries\n ? (employeeJobs ?? [])\n .filter(j => !j.primary && j.currentCompensationUuid)\n .map(j => ({\n compId: j.currentCompensationUuid!,\n effectiveDate: j.compensations?.find(c => c.uuid === j.currentCompensationUuid)\n ?.effectiveDate,\n }))\n .filter(\n (entry): entry is { compId: string; effectiveDate: string } =>\n !!entry.effectiveDate && entry.effectiveDate > resolvedHireDate,\n )\n : []\n\n let updatedJob: Job\n\n if (isCreateMode) {\n if (!resolvedHireDate) {\n throw new SDKInternalError(\n withHireDateField\n ? 'hireDate is required to create a job'\n : 'hireDate is required to create a job. Pass it via JobSubmitOptions when withHireDateField is false.',\n )\n }\n if (titleToSend === undefined) {\n throw new SDKInternalError(\n 'title is required to create a job. Set withTitleField: true (the default) on useJobForm for create flows.',\n )\n }\n const result = await createJobMutation.mutateAsync({\n request: {\n employeeId: resolvedEmployeeId,\n jobsCreateRequestBody: {\n title: titleToSend,\n hireDate: resolvedHireDate,\n twoPercentShareholder: payload.twoPercentShareholder,\n stateWcCovered: payload.stateWcCovered,\n stateWcClassCode,\n },\n },\n })\n if (!result.job) {\n throw new SDKInternalError('Job creation failed')\n }\n updatedJob = result.job\n } else {\n if (!currentJob) {\n throw new SDKInternalError('Cannot update job: no matching job on file')\n }\n const result = await updateJobMutation.mutateAsync({\n request: {\n jobId: currentJob.uuid,\n jobsUpdateRequestBody: {\n version: currentJob.version as string,\n title: titleToSend,\n hireDate: resolvedHireDate ?? undefined,\n twoPercentShareholder: payload.twoPercentShareholder,\n stateWcCovered: payload.stateWcCovered,\n stateWcClassCode,\n },\n },\n })\n if (!result.job) {\n throw new SDKInternalError('Job update failed')\n }\n updatedJob = result.job\n\n // The primary PUT above clobbered every secondary's\n // current-compensation effective_date to the new hire_date,\n // including the ones that needed to stay where they were.\n // Refetch jobs for the bumped versions, then restore just those\n // secondaries in parallel — the requests are independent\n // (different compensation_id, separate versions), and\n // `Promise.all` still surfaces the first rejection through the\n // surrounding baseSubmitHandler's catch.\n if (secondariesNeedingRestore.length > 0) {\n setIsCorrectingSecondaries(true)\n try {\n const refreshed = await jobsQuery.refetch()\n const freshComps = (refreshed.data?.jobs ?? []).flatMap(\n j => j.compensations ?? [],\n )\n await Promise.all(\n secondariesNeedingRestore.flatMap(entry => {\n const freshComp = freshComps.find(c => c.uuid === entry.compId)\n if (!freshComp?.version) return []\n\n return [\n updateSecondaryCompMutation.mutateAsync({\n request: {\n compensationId: entry.compId,\n compensationsUpdateRequestBody: {\n version: freshComp.version,\n effectiveDate: entry.effectiveDate,\n },\n },\n }),\n ]\n }),\n )\n } finally {\n setIsCorrectingSecondaries(false)\n }\n }\n }\n\n submitResult = {\n mode: isCreateMode ? 'create' : 'update',\n data: updatedJob,\n }\n })\n resolve()\n },\n () => {\n resolve()\n },\n )()\n })\n\n return submitResult\n }\n\n const isDataLoading = employeeId\n ? jobsQuery.isLoading || addressesQuery.isLoading || employeeQuery.isLoading\n : false\n\n const hookFormInternals = useHookFormInternals(formMethods)\n\n if (isDataLoading || (employeeId && (!employeeJobs || !employee))) {\n return { isLoading: true as const, errorHandling }\n }\n\n return {\n isLoading: false as const,\n data: {\n currentJob,\n jobs: employeeJobs,\n employee,\n currentWorkAddress,\n showTwoPercentShareholder,\n showStateWc,\n },\n status: {\n isPending,\n mode: isCreateMode ? 'create' : 'update',\n },\n actions: { onSubmit },\n errorHandling,\n form: {\n Fields: {\n Title: withTitleField ? JobTitleField : undefined,\n HireDate: withHireDateField ? HireDateField : undefined,\n TwoPercentShareholder: showTwoPercentShareholder ? TwoPercentShareholderField : undefined,\n StateWcCovered: showStateWc ? StateWcCoveredField : undefined,\n StateWcClassCode: showStateWc && watchedStateWcCovered ? StateWcClassCodeField : undefined,\n },\n fieldsMetadata,\n hookFormInternals,\n getFormSubmissionValues: createGetFormSubmissionValues(formMethods, schema),\n },\n }\n}\n\n/**\n * Discriminated union returned by {@link useJobForm}.\n *\n * @remarks\n * Branch on `isLoading` to narrow to either {@link HookLoadingResult} or\n * {@link UseJobFormReady}.\n *\n * @public\n */\nexport type UseJobFormResult = HookLoadingResult | UseJobFormReady\n\n/**\n * Shape of the per-field metadata exposed at `useJobForm().form.fieldsMetadata`.\n *\n * @remarks\n * Maps each field name in {@link JobFormData} to its presentation metadata —\n * including the registered `name`, whether the field is required or disabled,\n * and (for select-like fields) the option list.\n *\n * @public\n */\nexport type JobFieldsMetadata = ReturnType<typeof buildJobFieldsMetadata>\n"],"names":["findJob","jobs","jobId","j","buildJobFieldsMetadata","base","showTwoPercentShareholder","showStateWc","withFlags","withOptions","WA_RISK_CLASS_CODES","code","description","useJobForm","employeeId","optionalFieldsToRequire","partnerDefaults","validationMode","shouldFocusError","withHireDateField","withTitleField","jobsQuery","useJobsAndCompensationsGetJobs","addressesQuery","useEmployeeAddressesGetWorkAddresses","employeeQuery","useEmployeesGet","employeeJobs","currentWorkAddress","address","employee","companyUuid","taxQuery","useFederalTaxDetailsGet","currentJob","useMemo","isCreateMode","mode","schema","metadataConfig","createJobSchema","resolvedDefaults","formMethods","useForm","zodResolver","watchedStateWcCovered","useWatch","createJobMutation","useJobsAndCompensationsCreateJobMutation","updateJobMutation","useJobsAndCompensationsUpdateMutation","updateSecondaryCompMutation","useJobsAndCompensationsUpdateCompensationMutation","isCorrectingSecondaries","setIsCorrectingSecondaries","useState","isPending","baseSubmitHandler","submitError","setSubmitError","useBaseSubmit","errorHandling","composeErrorHandler","baseMetadata","useDeriveFieldsMetadata","fieldsMetadata","onSubmit","options","submitResult","resolve","data","payload","resolvedEmployeeId","SDKInternalError","stateWcClassCode","resolvedHireDate","titleToSend","secondariesNeedingRestore","c","entry","updatedJob","result","freshComps","freshComp","isDataLoading","hookFormInternals","useHookFormInternals","JobTitleField","HireDateField","TwoPercentShareholderField","StateWcCoveredField","StateWcClassCode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,CAACG,KAC9C,EAAE,WAAW,IAAe,eAAA+B,EAAA,IAG9B;AAAA,IACL,WAAW;AAAA,IACX,MAAM;AAAA,MACJ,YAAA3B;AAAA,MACA,MAAMP;AAAA,MACN,UAAAG;AAAA,MACA,oBAAAF;AAAA,MACA,2BAAAtB;AAAA,MACA,aAAAC;AAAA,IAAA;AAAA,IAEF,QAAQ;AAAA,MACN,WAAAiD;AAAA,MACA,MAAMpB,IAAe,WAAW;AAAA,IAAA;AAAA,IAElC,SAAS,EAAE,UAAA8B,GAAA;AAAA,IACX,eAAAL;AAAA,IACA,MAAM;AAAA,MACJ,QAAQ;AAAA,QACN,OAAOzC,IAAiBmE,KAAgB;AAAA,QACxC,UAAUpE,IAAoBqE,KAAgB;AAAA,QAC9C,uBAAuBlF,IAA4BmF,KAA6B;AAAA,QAChF,gBAAgBlF,IAAcmF,KAAsB;AAAA,QACpD,kBAAkBnF,KAAesC,IAAwB8C,KAAwB;AAAA,MAAA;AAAA,MAEnF,gBAAA1B;AAAA,MACA,mBAAAoB;AAAA,MACA,yBAAyBO,GAA8BlD,GAAaJ,CAAM;AAAA,IAAA;AAAA,EAC5E;AAEJ;"}
|
package/dist/components/Employee/Documents/onboarding/DocumentSigner/DocumentList/DocumentList.d.ts
CHANGED
|
@@ -15,6 +15,10 @@ export interface DocumentListProps extends BaseComponentInterface<'Employee.Docu
|
|
|
15
15
|
* Fetches the employee's forms and renders the list of documents that still
|
|
16
16
|
* require signing along with a continue action once everything is signed.
|
|
17
17
|
*
|
|
18
|
+
* Each form's description is rendered as returned by the API, unless the `dictionary` prop
|
|
19
|
+
* supplies a `forms.<name>.description` override for that form's `name` (e.g.
|
|
20
|
+
* `forms.employee_direct_deposit.description`).
|
|
21
|
+
*
|
|
18
22
|
* @events
|
|
19
23
|
* | Event | Description | Data |
|
|
20
24
|
* | ----- | ----------- | ---- |
|
package/dist/components/Employee/Documents/onboarding/DocumentSigner/DocumentList/DocumentList.js
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import { jsx as o, jsxs as
|
|
2
|
-
import { useEmployeeFormsListSuspense as
|
|
3
|
-
import { Head as
|
|
4
|
-
import { List as
|
|
1
|
+
import { jsx as o, jsxs as E } from "react/jsx-runtime";
|
|
2
|
+
import { useEmployeeFormsListSuspense as a } from "@gusto/embedded-api/react-query/employeeFormsList";
|
|
3
|
+
import { Head as F } from "./Head.js";
|
|
4
|
+
import { List as S } from "./List.js";
|
|
5
5
|
import { Actions as h } from "./Actions.js";
|
|
6
|
-
import { DocumentListProvider as
|
|
7
|
-
import { BaseComponent as
|
|
8
|
-
import { useBase as
|
|
9
|
-
import { useI18n as O } from "../../../../../../i18n/I18n.js";
|
|
6
|
+
import { DocumentListProvider as g } from "./useDocumentList.js";
|
|
7
|
+
import { BaseComponent as D } from "../../../../../Base/Base.js";
|
|
8
|
+
import { useBase as L } from "../../../../../Base/useBase.js";
|
|
9
|
+
import { useComponentDictionary as y, useI18n as O } from "../../../../../../i18n/I18n.js";
|
|
10
10
|
import { componentEvents as i } from "../../../../../../shared/constants.js";
|
|
11
11
|
import { Flex as _ } from "../../../../../Common/Flex/Flex.js";
|
|
12
|
-
function
|
|
13
|
-
return /* @__PURE__ */ o(
|
|
12
|
+
function G(e) {
|
|
13
|
+
return /* @__PURE__ */ o(D, { ...e, children: /* @__PURE__ */ o(v, { ...e }) });
|
|
14
14
|
}
|
|
15
|
-
function v({ employeeId: e, className: s, children: t }) {
|
|
16
|
-
O("Employee.DocumentSigner");
|
|
17
|
-
const { onEvent: m } =
|
|
15
|
+
function v({ employeeId: e, className: s, children: t, dictionary: u }) {
|
|
16
|
+
y("Employee.DocumentSigner", u), O("Employee.DocumentSigner");
|
|
17
|
+
const { onEvent: m } = L(), { data: c, error: l } = a({ employeeId: e }), r = c.forms, p = r.every((n) => !n.requiresSigning);
|
|
18
18
|
return /* @__PURE__ */ o("section", { className: s, children: /* @__PURE__ */ o(
|
|
19
|
-
|
|
19
|
+
g,
|
|
20
20
|
{
|
|
21
21
|
value: {
|
|
22
22
|
employeeForms: r,
|
|
23
|
-
hasSignedAllForms:
|
|
23
|
+
hasSignedAllForms: p,
|
|
24
24
|
handleContinue: () => {
|
|
25
25
|
m(i.EMPLOYEE_FORMS_DONE);
|
|
26
26
|
},
|
|
@@ -28,17 +28,17 @@ function v({ employeeId: e, className: s, children: t }) {
|
|
|
28
28
|
const f = r.find((d) => d.uuid === n.uuid);
|
|
29
29
|
m(i.EMPLOYEE_VIEW_FORM_TO_SIGN, { uuid: n.uuid, name: f?.name });
|
|
30
30
|
},
|
|
31
|
-
documentListError:
|
|
31
|
+
documentListError: l
|
|
32
32
|
},
|
|
33
|
-
children: t || /* @__PURE__ */
|
|
34
|
-
/* @__PURE__ */ o(a, {}),
|
|
33
|
+
children: t || /* @__PURE__ */ E(_, { flexDirection: "column", children: [
|
|
35
34
|
/* @__PURE__ */ o(F, {}),
|
|
35
|
+
/* @__PURE__ */ o(S, {}),
|
|
36
36
|
/* @__PURE__ */ o(h, {})
|
|
37
37
|
] })
|
|
38
38
|
}
|
|
39
39
|
) });
|
|
40
40
|
}
|
|
41
41
|
export {
|
|
42
|
-
|
|
42
|
+
G as DocumentList
|
|
43
43
|
};
|
|
44
44
|
//# sourceMappingURL=DocumentList.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DocumentList.js","sources":["../../../../../../../src/components/Employee/Documents/onboarding/DocumentSigner/DocumentList/DocumentList.tsx"],"sourcesContent":["import { useEmployeeFormsListSuspense } from '@gusto/embedded-api/react-query/employeeFormsList'\nimport { type Form } from '@gusto/embedded-api/models/components/form'\nimport { Head } from './Head'\nimport { List } from './List'\nimport { Actions } from './Actions'\nimport { DocumentListProvider } from './useDocumentList'\nimport { BaseComponent, type BaseComponentInterface } from '@/components/Base/Base'\nimport { useBase } from '@/components/Base/useBase'\nimport { useI18n } from '@/i18n'\nimport { componentEvents } from '@/shared/constants'\nimport { Flex } from '@/components/Common'\n\n/**\n * Props for {@link DocumentList}.\n *\n * @public\n */\nexport interface DocumentListProps extends BaseComponentInterface<'Employee.DocumentSigner'> {\n /** The associated employee identifier. */\n employeeId: string\n}\n\n/**\n * Lists the employee's documents pending signature.\n *\n * @remarks\n * Fetches the employee's forms and renders the list of documents that still\n * require signing along with a continue action once everything is signed.\n *\n * @events\n * | Event | Description | Data |\n * | ----- | ----------- | ---- |\n * | `employee/forms/view` | Fired when a form's \"Sign\" action is selected | `{ uuid: string; name?: string }` |\n * | `employee/forms/done` | Fired when all required forms have been signed and the parent flow can advance | — |\n *\n * @param props - See {@link DocumentListProps}.\n * @returns The employee document list.\n * @public\n */\nexport function DocumentList(props: DocumentListProps) {\n return (\n <BaseComponent {...props}>\n <Root {...props} />\n </BaseComponent>\n )\n}\n\nfunction Root({ employeeId, className, children }: DocumentListProps) {\n useI18n('Employee.DocumentSigner')\n const { onEvent } = useBase()\n\n const { data, error: documentListError } = useEmployeeFormsListSuspense({ employeeId })\n const employeeForms = data.forms!\n\n const hasSignedAllForms = employeeForms.every(employeeForm => !employeeForm.requiresSigning)\n\n const handleRequestFormToSign = (data: Form) => {\n const fullForm = employeeForms.find(f => f.uuid === data.uuid)\n onEvent(componentEvents.EMPLOYEE_VIEW_FORM_TO_SIGN, { uuid: data.uuid, name: fullForm?.name })\n }\n\n const handleContinue = () => {\n onEvent(componentEvents.EMPLOYEE_FORMS_DONE)\n }\n\n return (\n <section className={className}>\n <DocumentListProvider\n value={{\n employeeForms,\n hasSignedAllForms,\n handleContinue,\n handleRequestFormToSign,\n documentListError,\n }}\n >\n {children ? (\n children\n ) : (\n <Flex flexDirection=\"column\">\n <Head />\n <List />\n <Actions />\n </Flex>\n )}\n </DocumentListProvider>\n </section>\n )\n}\n"],"names":["DocumentList","props","jsx","BaseComponent","Root","employeeId","className","children","useI18n","onEvent","useBase","data","documentListError","useEmployeeFormsListSuspense","employeeForms","hasSignedAllForms","employeeForm","DocumentListProvider","componentEvents","fullForm","f","jsxs","Flex","Head","List","Actions"],"mappings":";;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"DocumentList.js","sources":["../../../../../../../src/components/Employee/Documents/onboarding/DocumentSigner/DocumentList/DocumentList.tsx"],"sourcesContent":["import { useEmployeeFormsListSuspense } from '@gusto/embedded-api/react-query/employeeFormsList'\nimport { type Form } from '@gusto/embedded-api/models/components/form'\nimport { Head } from './Head'\nimport { List } from './List'\nimport { Actions } from './Actions'\nimport { DocumentListProvider } from './useDocumentList'\nimport { BaseComponent, type BaseComponentInterface } from '@/components/Base/Base'\nimport { useBase } from '@/components/Base/useBase'\nimport { useI18n, useComponentDictionary } from '@/i18n'\nimport { componentEvents } from '@/shared/constants'\nimport { Flex } from '@/components/Common'\n\n/**\n * Props for {@link DocumentList}.\n *\n * @public\n */\nexport interface DocumentListProps extends BaseComponentInterface<'Employee.DocumentSigner'> {\n /** The associated employee identifier. */\n employeeId: string\n}\n\n/**\n * Lists the employee's documents pending signature.\n *\n * @remarks\n * Fetches the employee's forms and renders the list of documents that still\n * require signing along with a continue action once everything is signed.\n *\n * Each form's description is rendered as returned by the API, unless the `dictionary` prop\n * supplies a `forms.<name>.description` override for that form's `name` (e.g.\n * `forms.employee_direct_deposit.description`).\n *\n * @events\n * | Event | Description | Data |\n * | ----- | ----------- | ---- |\n * | `employee/forms/view` | Fired when a form's \"Sign\" action is selected | `{ uuid: string; name?: string }` |\n * | `employee/forms/done` | Fired when all required forms have been signed and the parent flow can advance | — |\n *\n * @param props - See {@link DocumentListProps}.\n * @returns The employee document list.\n * @public\n */\nexport function DocumentList(props: DocumentListProps) {\n return (\n <BaseComponent {...props}>\n <Root {...props} />\n </BaseComponent>\n )\n}\n\nfunction Root({ employeeId, className, children, dictionary }: DocumentListProps) {\n useComponentDictionary('Employee.DocumentSigner', dictionary)\n useI18n('Employee.DocumentSigner')\n const { onEvent } = useBase()\n\n const { data, error: documentListError } = useEmployeeFormsListSuspense({ employeeId })\n const employeeForms = data.forms!\n\n const hasSignedAllForms = employeeForms.every(employeeForm => !employeeForm.requiresSigning)\n\n const handleRequestFormToSign = (data: Form) => {\n const fullForm = employeeForms.find(f => f.uuid === data.uuid)\n onEvent(componentEvents.EMPLOYEE_VIEW_FORM_TO_SIGN, { uuid: data.uuid, name: fullForm?.name })\n }\n\n const handleContinue = () => {\n onEvent(componentEvents.EMPLOYEE_FORMS_DONE)\n }\n\n return (\n <section className={className}>\n <DocumentListProvider\n value={{\n employeeForms,\n hasSignedAllForms,\n handleContinue,\n handleRequestFormToSign,\n documentListError,\n }}\n >\n {children ? (\n children\n ) : (\n <Flex flexDirection=\"column\">\n <Head />\n <List />\n <Actions />\n </Flex>\n )}\n </DocumentListProvider>\n </section>\n )\n}\n"],"names":["DocumentList","props","jsx","BaseComponent","Root","employeeId","className","children","dictionary","useComponentDictionary","useI18n","onEvent","useBase","data","documentListError","useEmployeeFormsListSuspense","employeeForms","hasSignedAllForms","employeeForm","DocumentListProvider","componentEvents","fullForm","f","jsxs","Flex","Head","List","Actions"],"mappings":";;;;;;;;;;;AA2CO,SAASA,EAAaC,GAA0B;AACrD,SACE,gBAAAC,EAACC,KAAe,GAAGF,GACjB,4BAACG,GAAA,EAAM,GAAGH,GAAO,EAAA,CACnB;AAEJ;AAEA,SAASG,EAAK,EAAE,YAAAC,GAAY,WAAAC,GAAW,UAAAC,GAAU,YAAAC,KAAiC;AAChF,EAAAC,EAAuB,2BAA2BD,CAAU,GAC5DE,EAAQ,yBAAyB;AACjC,QAAM,EAAE,SAAAC,EAAA,IAAYC,EAAA,GAEd,EAAE,MAAAC,GAAM,OAAOC,EAAA,IAAsBC,EAA6B,EAAE,YAAAV,GAAY,GAChFW,IAAgBH,EAAK,OAErBI,IAAoBD,EAAc,MAAM,CAAAE,MAAgB,CAACA,EAAa,eAAe;AAW3F,SACE,gBAAAhB,EAAC,aAAQ,WAAAI,GACP,UAAA,gBAAAJ;AAAA,IAACiB;AAAA,IAAA;AAAA,MACC,OAAO;AAAA,QACL,eAAAH;AAAA,QACA,mBAAAC;AAAA,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