@gusto/embedded-react-sdk 0.46.2 → 0.46.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.
Files changed (172) hide show
  1. package/CHANGELOG.md +67 -0
  2. package/dist/components/Common/DataView/DataTable/DataTable.js +76 -72
  3. package/dist/components/Common/DataView/DataTable/DataTable.js.map +1 -1
  4. package/dist/components/Common/DataView/DataTable/DataTable.module.scss.js +8 -0
  5. package/dist/components/Common/DataView/DataTable/DataTable.module.scss.js.map +1 -0
  6. package/dist/components/Common/DataView/useDataView.d.ts +2 -0
  7. package/dist/components/Common/DataView/useDataView.js.map +1 -1
  8. package/dist/components/Common/DocumentViewer/DocumentViewer.js +10 -10
  9. package/dist/components/Common/DocumentViewer/DocumentViewer.js.map +1 -1
  10. package/dist/components/Common/DocumentViewer/DocumentViewer.module.scss.js +9 -9
  11. package/dist/components/Common/PaginationControl/PaginationControl.js +11 -10
  12. package/dist/components/Common/PaginationControl/PaginationControl.js.map +1 -1
  13. package/dist/components/Common/PaginationControl/PaginationControlTypes.d.ts +1 -1
  14. package/dist/components/Common/UI/DescriptionList/DescriptionList.js +11 -10
  15. package/dist/components/Common/UI/DescriptionList/DescriptionList.js.map +1 -1
  16. package/dist/components/Common/UI/DescriptionList/DescriptionList.module.scss.js +4 -4
  17. package/dist/components/Common/UI/Input/InputTypes.d.ts +1 -1
  18. package/dist/components/Common/UI/Input/InputTypes.js.map +1 -1
  19. package/dist/components/Common/UI/NumberInput/NumberInput.js +51 -48
  20. package/dist/components/Common/UI/NumberInput/NumberInput.js.map +1 -1
  21. package/dist/components/Common/VisuallyHidden/VisuallyHidden.d.ts +1 -1
  22. package/dist/components/Common/VisuallyHidden/VisuallyHidden.js.map +1 -1
  23. package/dist/components/Company/AssignSignatory/CreateSignatory/useCreateSignatory.js +3 -4
  24. package/dist/components/Company/AssignSignatory/CreateSignatory/useCreateSignatory.js.map +1 -1
  25. package/dist/components/Company/AssignSignatory/InviteSignatory/useInviteSignatory.js +3 -4
  26. package/dist/components/Company/AssignSignatory/InviteSignatory/useInviteSignatory.js.map +1 -1
  27. package/dist/components/Company/AssignSignatory/useAssignSignatory.js +5 -6
  28. package/dist/components/Company/AssignSignatory/useAssignSignatory.js.map +1 -1
  29. package/dist/components/Company/BankAccount/BankAccountForm/context.js +3 -4
  30. package/dist/components/Company/BankAccount/BankAccountForm/context.js.map +1 -1
  31. package/dist/components/Company/DocumentSigner/DocumentList/useDocumentList.js +3 -4
  32. package/dist/components/Company/DocumentSigner/DocumentList/useDocumentList.js.map +1 -1
  33. package/dist/components/Company/DocumentSigner/shared/useSignCompanyForm/fields.js +4 -4
  34. package/dist/components/Company/FederalTaxes/useFederalTaxes.js +5 -6
  35. package/dist/components/Company/FederalTaxes/useFederalTaxes.js.map +1 -1
  36. package/dist/components/Company/Industry/Context.js +6 -7
  37. package/dist/components/Company/Industry/Context.js.map +1 -1
  38. package/dist/components/Company/Locations/LocationForm/useLocationForm.js +3 -4
  39. package/dist/components/Company/Locations/LocationForm/useLocationForm.js.map +1 -1
  40. package/dist/components/Company/Locations/LocationsList/useLocationsList.js +3 -4
  41. package/dist/components/Company/Locations/LocationsList/useLocationsList.js.map +1 -1
  42. package/dist/components/Company/OnboardingOverview/context.js +3 -4
  43. package/dist/components/Company/OnboardingOverview/context.js.map +1 -1
  44. package/dist/components/Company/PaySchedule/shared/usePayScheduleForm/fields.js +5 -5
  45. package/dist/components/Company/StateTaxes/StateTaxesForm/context.js +3 -4
  46. package/dist/components/Company/StateTaxes/StateTaxesForm/context.js.map +1 -1
  47. package/dist/components/Company/StateTaxes/StateTaxesList/context.js +3 -4
  48. package/dist/components/Company/StateTaxes/StateTaxesList/context.js.map +1 -1
  49. package/dist/components/Contractor/Address/useAddress.js +5 -6
  50. package/dist/components/Contractor/Address/useAddress.js.map +1 -1
  51. package/dist/components/Contractor/Profile/useContractorProfile.js +33 -34
  52. package/dist/components/Contractor/Profile/useContractorProfile.js.map +1 -1
  53. package/dist/components/Employee/Compensation/management/EditCompensation/EditCompensation.js +14 -11
  54. package/dist/components/Employee/Compensation/management/EditCompensation/EditCompensation.js.map +1 -1
  55. package/dist/components/Employee/Compensation/management/EditPendingCompensation/EditPendingCompensation.js +0 -2
  56. package/dist/components/Employee/Compensation/management/EditPendingCompensation/EditPendingCompensation.js.map +1 -1
  57. package/dist/components/Employee/Compensation/management/ManagementCompensationFormBody.js +18 -18
  58. package/dist/components/Employee/Compensation/management/ManagementCompensationFormBody.js.map +1 -1
  59. package/dist/components/Employee/Compensation/onboarding/JobsList/JobsListPresentation.js +36 -36
  60. package/dist/components/Employee/Compensation/onboarding/JobsList/JobsListPresentation.js.map +1 -1
  61. package/dist/components/Employee/Compensation/shared/useCompensationForm/fields.js +4 -4
  62. package/dist/components/Employee/Compensation/shared/useCompensationForm/useCompensationForm.js +140 -140
  63. package/dist/components/Employee/Compensation/shared/useCompensationForm/useCompensationForm.js.map +1 -1
  64. package/dist/components/Employee/Compensation/shared/useJobForm/fields.js +6 -6
  65. package/dist/components/Employee/Compensation/shared/useJobForm/useJobForm.d.ts +6 -5
  66. package/dist/components/Employee/Compensation/shared/useJobForm/useJobForm.js +162 -131
  67. package/dist/components/Employee/Compensation/shared/useJobForm/useJobForm.js.map +1 -1
  68. package/dist/components/Employee/Dashboard/BasicDetailsView.js +74 -88
  69. package/dist/components/Employee/Dashboard/BasicDetailsView.js.map +1 -1
  70. package/dist/components/Employee/Dashboard/Dashboard.js +53 -51
  71. package/dist/components/Employee/Dashboard/Dashboard.js.map +1 -1
  72. package/dist/components/Employee/Dashboard/DocumentsView.js +17 -10
  73. package/dist/components/Employee/Dashboard/DocumentsView.js.map +1 -1
  74. package/dist/components/Employee/Dashboard/JobAndPayView.js +383 -357
  75. package/dist/components/Employee/Dashboard/JobAndPayView.js.map +1 -1
  76. package/dist/components/Employee/Dashboard/TaxesView.js +114 -101
  77. package/dist/components/Employee/Dashboard/TaxesView.js.map +1 -1
  78. package/dist/components/Employee/Dashboard/getPendingCompensationChanges.js +36 -36
  79. package/dist/components/Employee/Dashboard/getPendingCompensationChanges.js.map +1 -1
  80. package/dist/components/Employee/Deductions/DeductionsForm/StandardDeductionForm.js +57 -57
  81. package/dist/components/Employee/Deductions/DeductionsForm/StandardDeductionForm.js.map +1 -1
  82. package/dist/components/Employee/Deductions/shared/useChildSupportGarnishmentForm/childSupportGarnishmentFormSchema.d.ts +14 -5
  83. package/dist/components/Employee/Deductions/shared/useChildSupportGarnishmentForm/childSupportGarnishmentFormSchema.js +55 -36
  84. package/dist/components/Employee/Deductions/shared/useChildSupportGarnishmentForm/childSupportGarnishmentFormSchema.js.map +1 -1
  85. package/dist/components/Employee/Deductions/shared/useChildSupportGarnishmentForm/fields.js +8 -8
  86. package/dist/components/Employee/Deductions/shared/useChildSupportGarnishmentForm/useChildSupportGarnishmentForm.js +18 -18
  87. package/dist/components/Employee/Deductions/shared/useChildSupportGarnishmentForm/useChildSupportGarnishmentForm.js.map +1 -1
  88. package/dist/components/Employee/Deductions/shared/useDeductionForm/fields.js +4 -4
  89. package/dist/components/Employee/Deductions/shared/useDeductionForm/useDeductionForm.d.ts +3 -3
  90. package/dist/components/Employee/Deductions/shared/useDeductionForm/useDeductionForm.js.map +1 -1
  91. package/dist/components/Employee/Documents/onboarding/DocumentSigner/DocumentList/useDocumentList.js +3 -4
  92. package/dist/components/Employee/Documents/onboarding/DocumentSigner/DocumentList/useDocumentList.js.map +1 -1
  93. package/dist/components/Employee/Documents/shared/useSignEmployeeForm/fields.js +1 -1
  94. package/dist/components/Employee/FederalTaxes/shared/useFederalTaxesForm/fields.js +4 -4
  95. package/dist/components/Employee/HomeAddress/management/HomeAddressView.js +157 -147
  96. package/dist/components/Employee/HomeAddress/management/HomeAddressView.js.map +1 -1
  97. package/dist/components/Employee/HomeAddress/management/useHomeAddressManagement.js +56 -55
  98. package/dist/components/Employee/HomeAddress/management/useHomeAddressManagement.js.map +1 -1
  99. package/dist/components/Employee/PaymentMethod/onboarding/BankForm.js +20 -20
  100. package/dist/components/Employee/PaymentMethod/onboarding/BankForm.js.map +1 -1
  101. package/dist/components/Employee/PaymentMethod/shared/useBankForm/fields.js +1 -1
  102. package/dist/components/Employee/PaymentMethod/shared/useSplitPaymentsForm/splitFieldFactory.d.ts +1 -1
  103. package/dist/components/Employee/PaymentMethod/shared/useSplitPaymentsForm/splitFieldFactory.js +4 -4
  104. package/dist/components/Employee/PaymentMethod/shared/useSplitPaymentsForm/splitFieldFactory.js.map +1 -1
  105. package/dist/components/Employee/Profile/shared/useEmployeeDetailsForm/fields.js +8 -8
  106. package/dist/components/Employee/Profile/shared/useHomeAddressForm/fields.js +5 -5
  107. package/dist/components/Employee/Profile/shared/useHomeAddressForm/homeAddressSchema.d.ts +0 -1
  108. package/dist/components/Employee/Profile/shared/useHomeAddressForm/homeAddressSchema.js +11 -12
  109. package/dist/components/Employee/Profile/shared/useHomeAddressForm/homeAddressSchema.js.map +1 -1
  110. package/dist/components/Employee/Profile/shared/useHomeAddressForm/homeAddressSchema.test.d.ts +1 -0
  111. package/dist/components/Employee/Profile/shared/useHomeAddressForm/useHomeAddressForm.d.ts +6 -1
  112. package/dist/components/Employee/Profile/shared/useHomeAddressForm/useHomeAddressForm.js +95 -94
  113. package/dist/components/Employee/Profile/shared/useHomeAddressForm/useHomeAddressForm.js.map +1 -1
  114. package/dist/components/Employee/Profile/shared/useWorkAddressForm/fields.js +4 -4
  115. package/dist/components/Employee/Profile/shared/useWorkAddressForm/useWorkAddressForm.d.ts +6 -1
  116. package/dist/components/Employee/Profile/shared/useWorkAddressForm/useWorkAddressForm.js +87 -86
  117. package/dist/components/Employee/Profile/shared/useWorkAddressForm/useWorkAddressForm.js.map +1 -1
  118. package/dist/components/Employee/StateTaxes/shared/EmployeeStateTaxesView.js +18 -18
  119. package/dist/components/Employee/StateTaxes/shared/EmployeeStateTaxesView.js.map +1 -1
  120. package/dist/components/Employee/StateTaxes/shared/useEmployeeStateTaxesForm/fieldComponents.js +8 -8
  121. package/dist/components/Employee/Taxes/useTaxes.js +3 -4
  122. package/dist/components/Employee/Taxes/useTaxes.js.map +1 -1
  123. package/dist/components/Employee/WorkAddress/management/WorkAddressView.js +5 -1
  124. package/dist/components/Employee/WorkAddress/management/WorkAddressView.js.map +1 -1
  125. package/dist/components/Employee/WorkAddress/management/useWorkAddressManagement.js +61 -60
  126. package/dist/components/Employee/WorkAddress/management/useWorkAddressManagement.js.map +1 -1
  127. package/dist/components/Payroll/GrossUpModal/GrossUpModal.js +2 -3
  128. package/dist/components/Payroll/GrossUpModal/GrossUpModal.js.map +1 -1
  129. package/dist/components/Payroll/usePreparedPayrollData.js +2 -3
  130. package/dist/components/Payroll/usePreparedPayrollData.js.map +1 -1
  131. package/dist/components/TimeOff/TimeOffManagement/SelectEmployees/SelectEmployeesHoliday.js +6 -7
  132. package/dist/components/TimeOff/TimeOffManagement/SelectEmployees/SelectEmployeesHoliday.js.map +1 -1
  133. package/dist/components/TimeOff/TimeOffManagement/SelectEmployees/SelectEmployeesPresentation.d.ts +1 -1
  134. package/dist/components/TimeOff/TimeOffManagement/SelectEmployees/SelectEmployeesPresentation.js +52 -68
  135. package/dist/components/TimeOff/TimeOffManagement/SelectEmployees/SelectEmployeesPresentation.js.map +1 -1
  136. package/dist/components/TimeOff/TimeOffManagement/SelectEmployees/SelectEmployeesPresentation.module.scss.js +4 -4
  137. package/dist/components/TimeOff/TimeOffManagement/SelectEmployees/SelectEmployeesPresentationTypes.d.ts +0 -11
  138. package/dist/components/TimeOff/TimeOffManagement/SelectEmployees/SelectEmployeesTimeOff.js +137 -163
  139. package/dist/components/TimeOff/TimeOffManagement/SelectEmployees/SelectEmployeesTimeOff.js.map +1 -1
  140. package/dist/components/TimeOff/TimeOffManagement/SelectEmployees/useSelectEmployeesData.js +36 -35
  141. package/dist/components/TimeOff/TimeOffManagement/SelectEmployees/useSelectEmployeesData.js.map +1 -1
  142. package/dist/components/TimeOff/TimeOffPolicyDetail/TimeOffPolicyDetailPresentation.js +34 -34
  143. package/dist/components/TimeOff/TimeOffPolicyDetail/TimeOffPolicyDetailPresentation.js.map +1 -1
  144. package/dist/helpers/breadcrumbHelpers.d.ts +1 -1
  145. package/dist/helpers/breadcrumbHelpers.js.map +1 -1
  146. package/dist/helpers/federalEin.d.ts +1 -0
  147. package/dist/helpers/federalEin.js.map +1 -1
  148. package/dist/helpers/mask.d.ts +8 -4
  149. package/dist/helpers/mask.js.map +1 -1
  150. package/dist/helpers/rem.d.ts +2 -1
  151. package/dist/helpers/rem.js.map +1 -1
  152. package/dist/hooks/useAsyncError.d.ts +1 -0
  153. package/dist/hooks/useAsyncError.js.map +1 -1
  154. package/dist/hooks/useForkRef/useForkRef.d.ts +1 -0
  155. package/dist/hooks/useForkRef/useForkRef.js.map +1 -1
  156. package/dist/i18n/I18n.d.ts +9 -1
  157. package/dist/i18n/I18n.js.map +1 -1
  158. package/dist/i18n/en/Company.TimeOff.EmployeeTable.json.js +14 -14
  159. package/dist/i18n/en/Company.TimeOff.SelectEmployees.json.js +12 -18
  160. package/dist/i18n/en/Company.TimeOff.SelectEmployees.json.js.map +1 -1
  161. package/dist/i18n/en/Employee.Compensation.json.js +24 -24
  162. package/dist/i18n/en/Employee.Dashboard.json.js +22 -20
  163. package/dist/i18n/en/Employee.Dashboard.json.js.map +1 -1
  164. package/dist/i18n/en/Employee.PaymentMethod.json.js +25 -25
  165. package/dist/i18n/en/Employee.StateTaxes.json.js +12 -10
  166. package/dist/i18n/en/Employee.StateTaxes.json.js.map +1 -1
  167. package/dist/style.css +1 -1
  168. package/dist/types/hooks.d.ts +1 -1
  169. package/dist/types/i18next.d.ts +4 -17
  170. package/dist/types/observability.d.ts +1 -1
  171. package/package.json +30 -27
  172. package/dist/components/Employee/Dashboard/CompensationCard.d.ts +0 -13
@@ -1,188 +1,219 @@
1
- import { useMemo as A } from "react";
2
- import { useForm as ee, useWatch as te } from "react-hook-form";
3
- import { zodResolver as oe } from "@hookform/resolvers/zod";
4
- import { useJobsAndCompensationsGetJobs as re } from "@gusto/embedded-api/react-query/jobsAndCompensationsGetJobs";
5
- import { useJobsAndCompensationsCreateJobMutation as se } from "@gusto/embedded-api/react-query/jobsAndCompensationsCreateJob";
6
- import { useJobsAndCompensationsUpdateMutation as ae } from "@gusto/embedded-api/react-query/jobsAndCompensationsUpdate";
7
- import { useEmployeeAddressesGetWorkAddresses as ie } from "@gusto/embedded-api/react-query/employeeAddressesGetWorkAddresses";
8
- import { useEmployeesGet as ne } from "@gusto/embedded-api/react-query/employeesGet";
9
- import { useFederalTaxDetailsGet as de } from "@gusto/embedded-api/react-query/federalTaxDetailsGet";
10
- import { createJobSchema as ce } from "./jobSchema.js";
11
- import { StateWcClassCodeField as le, StateWcCoveredField as ue, TwoPercentShareholderField as me, HireDateField as be, JobTitleField as fe } from "./fields.js";
12
- import { useDeriveFieldsMetadata as he } from "../../../../../partner-hook-utils/form/useDeriveFieldsMetadata.js";
13
- import { useHookFormInternals as Ce } from "../../../../../partner-hook-utils/form/useHookFormInternals.js";
14
- import { createGetFormSubmissionValues as ve } from "../../../../../partner-hook-utils/form/getFormSubmissionValues.js";
15
- import { withOptions as O } from "../../../../../partner-hook-utils/form/withOptions.js";
16
- import { composeErrorHandler as Se } from "../../../../../partner-hook-utils/composeErrorHandler.js";
17
- import { useBaseSubmit as pe } from "../../../../Base/useBaseSubmit.js";
18
- import { SDKInternalError as i } from "../../../../../types/sdkError.js";
19
- import { WA_RISK_CLASS_CODES as V } from "../../../../../models/WA_RISK_CODES.js";
20
- function we(e, s) {
21
- return !e || !s ? null : e.find((m) => m.uuid === s) ?? null;
1
+ import { useMemo as A, useState as le } from "react";
2
+ import { useForm as me, useWatch as fe } from "react-hook-form";
3
+ import { zodResolver as be } from "@hookform/resolvers/zod";
4
+ import { useJobsAndCompensationsGetJobs as he } from "@gusto/embedded-api/react-query/jobsAndCompensationsGetJobs";
5
+ import { useJobsAndCompensationsCreateJobMutation as pe } from "@gusto/embedded-api/react-query/jobsAndCompensationsCreateJob";
6
+ import { useJobsAndCompensationsUpdateMutation as Ce } from "@gusto/embedded-api/react-query/jobsAndCompensationsUpdate";
7
+ import { useJobsAndCompensationsUpdateCompensationMutation as ve } from "@gusto/embedded-api/react-query/jobsAndCompensationsUpdateCompensation";
8
+ import { useEmployeeAddressesGetWorkAddresses as Se } from "@gusto/embedded-api/react-query/employeeAddressesGetWorkAddresses";
9
+ import { useEmployeesGet as we } from "@gusto/embedded-api/react-query/employeesGet";
10
+ import { useFederalTaxDetailsGet as We } from "@gusto/embedded-api/react-query/federalTaxDetailsGet";
11
+ import { createJobSchema as De } from "./jobSchema.js";
12
+ import { StateWcClassCodeField as Je, StateWcCoveredField as Pe, TwoPercentShareholderField as ge, HireDateField as Ae, JobTitleField as ye } from "./fields.js";
13
+ import { useDeriveFieldsMetadata as Me } from "../../../../../partner-hook-utils/form/useDeriveFieldsMetadata.js";
14
+ import { useHookFormInternals as Ee } from "../../../../../partner-hook-utils/form/useHookFormInternals.js";
15
+ import { createGetFormSubmissionValues as Fe } from "../../../../../partner-hook-utils/form/getFormSubmissionValues.js";
16
+ import { withOptions as Q } from "../../../../../partner-hook-utils/form/withOptions.js";
17
+ import { composeErrorHandler as qe } from "../../../../../partner-hook-utils/composeErrorHandler.js";
18
+ import { useBaseSubmit as je } from "../../../../Base/useBaseSubmit.js";
19
+ import { SDKInternalError as c } from "../../../../../types/sdkError.js";
20
+ import { WA_RISK_CLASS_CODES as _ } from "../../../../../models/WA_RISK_CODES.js";
21
+ function Ue(e, n) {
22
+ return !e || !n ? null : e.find((p) => p.uuid === n) ?? null;
22
23
  }
23
- function Ue({
24
+ function rt({
24
25
  employeeId: e,
25
- jobId: s,
26
- optionalFieldsToRequire: m,
27
- defaultValues: a,
28
- validationMode: H = "onSubmit",
29
- shouldFocusError: Q = !0,
30
- withHireDateField: n = !0,
31
- withTitleField: b = !0
26
+ jobId: n,
27
+ optionalFieldsToRequire: p,
28
+ defaultValues: d,
29
+ validationMode: K = "onSubmit",
30
+ shouldFocusError: $ = !0,
31
+ withHireDateField: u = !0,
32
+ withTitleField: C = !0
32
33
  }) {
33
- const v = re(
34
+ const v = he(
34
35
  { employeeId: e ?? "" },
35
36
  { enabled: !!e }
36
- ), S = ie(
37
+ ), w = Se(
37
38
  { employeeId: e ?? "" },
38
39
  { enabled: !!e }
39
- ), p = ne({ employeeId: e ?? "" }, { enabled: !!e }), f = v.data?.jobs, g = S.data?.employeeWorkAddressesList?.find((r) => r.active) ?? null, w = p.data?.employee ?? null, j = w?.companyUuid, y = de(
40
- { companyId: j ?? "" },
41
- { enabled: !!j }
42
- ), W = y.data?.federalTaxDetails?.taxableAsScorp === !0, d = g?.state === "WA", t = A(() => we(f, s), [f, s]), h = !s, F = h ? "create" : "update", [E, R] = A(
43
- () => ce({ mode: F, optionalFieldsToRequire: m, withHireDateField: n, withTitleField: b }),
44
- [F, m, n, b]
45
- ), M = A(
40
+ ), W = we({ employeeId: e ?? "" }, { enabled: !!e }), l = v.data?.jobs, y = w.data?.employeeWorkAddressesList?.find((s) => s.active) ?? null, D = W.data?.employee ?? null, M = D?.companyUuid, E = We(
41
+ { companyId: M ?? "" },
42
+ { enabled: !!M }
43
+ ), J = E.data?.federalTaxDetails?.taxableAsScorp === !0, m = y?.state === "WA", t = A(() => Ue(l, n), [l, n]), f = !n, F = f ? "create" : "update", [q, z] = A(
44
+ () => De({ mode: F, optionalFieldsToRequire: p, withHireDateField: u, withTitleField: C }),
45
+ [F, p, u, C]
46
+ ), j = A(
46
47
  () => ({
47
- title: t?.title ?? a?.title ?? "",
48
- hireDate: t?.hireDate ?? a?.hireDate ?? null,
49
- twoPercentShareholder: t?.twoPercentShareholder ?? a?.twoPercentShareholder ?? !1,
50
- stateWcCovered: t?.stateWcCovered ?? a?.stateWcCovered ?? !1,
51
- stateWcClassCode: t?.stateWcClassCode ?? a?.stateWcClassCode ?? ""
48
+ title: t?.title ?? d?.title ?? "",
49
+ hireDate: t?.hireDate ?? d?.hireDate ?? null,
50
+ twoPercentShareholder: t?.twoPercentShareholder ?? d?.twoPercentShareholder ?? !1,
51
+ stateWcCovered: t?.stateWcCovered ?? d?.stateWcCovered ?? !1,
52
+ stateWcClassCode: t?.stateWcClassCode ?? d?.stateWcClassCode ?? ""
52
53
  }),
53
- [t, a]
54
- ), c = ee({
55
- resolver: oe(E),
56
- mode: H,
57
- shouldFocusError: Q,
58
- defaultValues: M,
59
- values: M,
54
+ [t, d]
55
+ ), b = me({
56
+ resolver: be(q),
57
+ mode: K,
58
+ shouldFocusError: $,
59
+ defaultValues: j,
60
+ values: j,
60
61
  resetOptions: { keepDirtyValues: !0 }
61
- }), U = te({ control: c.control, name: "stateWcCovered" }), q = se(), k = ae(), B = q.isPending || k.isPending, {
62
- baseSubmitHandler: _,
63
- error: K,
64
- setError: $
65
- } = pe("JobForm"), L = Se(e ? [v, S, p, y] : [], { submitError: K, setSubmitError: $ }), z = V.map(({ code: r, description: C }) => ({
66
- value: r,
67
- label: `${r}: ${C}`
68
- })), l = he(R, c.control), I = {
69
- title: l.title,
70
- hireDate: l.hireDate,
62
+ }), N = fe({ control: b.control, name: "stateWcCovered" }), U = pe(), k = Ce(), L = ve(), [Y, x] = le(!1), X = U.isPending || k.isPending || L.isPending || Y, {
63
+ baseSubmitHandler: Z,
64
+ error: ee,
65
+ setError: te
66
+ } = je("JobForm"), T = qe(e ? [v, w, W, E] : [], { submitError: ee, setSubmitError: te }), oe = _.map(({ code: s, description: S }) => ({
67
+ value: s,
68
+ label: `${s}: ${S}`
69
+ })), h = Me(z, b.control), re = {
70
+ title: h.title,
71
+ hireDate: h.hireDate,
71
72
  twoPercentShareholder: {
72
- ...l.twoPercentShareholder,
73
- isDisabled: !W
73
+ ...h.twoPercentShareholder,
74
+ isDisabled: !J
74
75
  },
75
- stateWcCovered: O(
76
- { ...l.stateWcCovered, isDisabled: !d },
76
+ stateWcCovered: Q(
77
+ { ...h.stateWcCovered, isDisabled: !m },
77
78
  [
78
79
  { label: "Yes", value: "true" },
79
80
  { label: "No", value: "false" }
80
81
  ],
81
82
  [!0, !1]
82
83
  ),
83
- stateWcClassCode: O(
84
- { ...l.stateWcClassCode, isDisabled: !d },
85
- z,
86
- V
84
+ stateWcClassCode: Q(
85
+ { ...h.stateWcClassCode, isDisabled: !m },
86
+ oe,
87
+ _
87
88
  )
88
- }, N = async (r) => {
89
- let C;
90
- return await new Promise((x) => {
91
- c.handleSubmit(
92
- async (Z) => {
93
- await _(Z, async (o) => {
94
- const T = r?.employeeId ?? e;
95
- if (!T)
96
- throw new i("employeeId is required to submit a job");
97
- const G = o.stateWcCovered ? o.stateWcClassCode : null, D = n && o.hireDate ? o.hireDate : r?.hireDate ?? t?.hireDate ?? null, J = b ? o.title : void 0;
98
- let P;
99
- if (h) {
100
- if (!D)
101
- throw new i(
102
- n ? "hireDate is required to create a job" : "hireDate is required to create a job. Pass it via JobSubmitOptions when withHireDateField is false."
89
+ }, se = async (s) => {
90
+ let S;
91
+ return await new Promise((I) => {
92
+ b.handleSubmit(
93
+ async (ne) => {
94
+ await Z(ne, async (r) => {
95
+ const G = s?.employeeId ?? e;
96
+ if (!G)
97
+ throw new c("employeeId is required to submit a job");
98
+ const O = r.stateWcCovered ? r.stateWcClassCode : null, a = u && r.hireDate ? r.hireDate : s?.hireDate ?? t?.hireDate ?? null, P = C ? r.title : void 0, R = !f && t?.primary === !0 && !!a && a !== t.hireDate, V = R ? (l ?? []).filter((o) => !o.primary && o.currentCompensationUuid).map((o) => ({
99
+ compId: o.currentCompensationUuid,
100
+ effectiveDate: o.compensations?.find((B) => B.uuid === o.currentCompensationUuid)?.effectiveDate
101
+ })) : [];
102
+ let g;
103
+ if (f) {
104
+ if (!a)
105
+ throw new c(
106
+ u ? "hireDate is required to create a job" : "hireDate is required to create a job. Pass it via JobSubmitOptions when withHireDateField is false."
103
107
  );
104
- if (J === void 0)
105
- throw new i(
108
+ if (P === void 0)
109
+ throw new c(
106
110
  "title is required to create a job. Set withTitleField: true (the default) on useJobForm for create flows."
107
111
  );
108
- const u = await q.mutateAsync({
112
+ const o = await U.mutateAsync({
109
113
  request: {
110
- employeeId: T,
114
+ employeeId: G,
111
115
  jobsCreateRequestBody: {
112
- title: J,
113
- hireDate: D,
114
- twoPercentShareholder: o.twoPercentShareholder,
115
- stateWcCovered: o.stateWcCovered,
116
- stateWcClassCode: G
116
+ title: P,
117
+ hireDate: a,
118
+ twoPercentShareholder: r.twoPercentShareholder,
119
+ stateWcCovered: r.stateWcCovered,
120
+ stateWcClassCode: O
117
121
  }
118
122
  }
119
123
  });
120
- if (!u.job)
121
- throw new i("Job creation failed");
122
- P = u.job;
124
+ if (!o.job)
125
+ throw new c("Job creation failed");
126
+ g = o.job;
123
127
  } else {
124
128
  if (!t)
125
- throw new i("Cannot update job: no matching job on file");
126
- const u = await k.mutateAsync({
129
+ throw new c("Cannot update job: no matching job on file");
130
+ const o = await k.mutateAsync({
127
131
  request: {
128
132
  jobId: t.uuid,
129
133
  jobsUpdateRequestBody: {
130
134
  version: t.version,
131
- title: J,
132
- hireDate: D ?? void 0,
133
- twoPercentShareholder: o.twoPercentShareholder,
134
- stateWcCovered: o.stateWcCovered,
135
- stateWcClassCode: G
135
+ title: P,
136
+ hireDate: a ?? void 0,
137
+ twoPercentShareholder: r.twoPercentShareholder,
138
+ stateWcCovered: r.stateWcCovered,
139
+ stateWcClassCode: O
136
140
  }
137
141
  }
138
142
  });
139
- if (!u.job)
140
- throw new i("Job update failed");
141
- P = u.job;
143
+ if (!o.job)
144
+ throw new c("Job update failed");
145
+ if (g = o.job, R && V.length > 0) {
146
+ x(!0);
147
+ try {
148
+ const de = ((await v.refetch()).data?.jobs ?? []).flatMap(
149
+ (i) => i.compensations ?? []
150
+ );
151
+ await Promise.all(
152
+ V.flatMap((i) => {
153
+ const H = de.find((ue) => ue.uuid === i.compId);
154
+ if (!H?.version) return [];
155
+ const ce = !i.effectiveDate || i.effectiveDate < a ? a : i.effectiveDate;
156
+ return [
157
+ L.mutateAsync({
158
+ request: {
159
+ compensationId: i.compId,
160
+ compensationsUpdateRequestBody: {
161
+ version: H.version,
162
+ effectiveDate: ce
163
+ }
164
+ }
165
+ })
166
+ ];
167
+ })
168
+ );
169
+ } finally {
170
+ x(!1);
171
+ }
172
+ }
142
173
  }
143
- C = {
144
- mode: h ? "create" : "update",
145
- data: P
174
+ S = {
175
+ mode: f ? "create" : "update",
176
+ data: g
146
177
  };
147
- }), x();
178
+ }), I();
148
179
  },
149
180
  () => {
150
- x();
181
+ I();
151
182
  }
152
183
  )();
153
- }), C;
154
- }, Y = e ? v.isLoading || S.isLoading || p.isLoading : !1, X = Ce(c);
155
- return Y || e && (!f || !w) ? { isLoading: !0, errorHandling: L } : {
184
+ }), S;
185
+ }, ae = e ? v.isLoading || w.isLoading || W.isLoading : !1, ie = Ee(b);
186
+ return ae || e && (!l || !D) ? { isLoading: !0, errorHandling: T } : {
156
187
  isLoading: !1,
157
188
  data: {
158
189
  currentJob: t,
159
- jobs: f,
160
- employee: w,
161
- currentWorkAddress: g,
162
- showTwoPercentShareholder: W,
163
- showStateWc: d
190
+ jobs: l,
191
+ employee: D,
192
+ currentWorkAddress: y,
193
+ showTwoPercentShareholder: J,
194
+ showStateWc: m
164
195
  },
165
196
  status: {
166
- isPending: B,
167
- mode: h ? "create" : "update"
197
+ isPending: X,
198
+ mode: f ? "create" : "update"
168
199
  },
169
- actions: { onSubmit: N },
170
- errorHandling: L,
200
+ actions: { onSubmit: se },
201
+ errorHandling: T,
171
202
  form: {
172
203
  Fields: {
173
- Title: b ? fe : void 0,
174
- HireDate: n ? be : void 0,
175
- TwoPercentShareholder: W ? me : void 0,
176
- StateWcCovered: d ? ue : void 0,
177
- StateWcClassCode: d && U ? le : void 0
204
+ Title: C ? ye : void 0,
205
+ HireDate: u ? Ae : void 0,
206
+ TwoPercentShareholder: J ? ge : void 0,
207
+ StateWcCovered: m ? Pe : void 0,
208
+ StateWcClassCode: m && N ? Je : void 0
178
209
  },
179
- fieldsMetadata: I,
180
- hookFormInternals: X,
181
- getFormSubmissionValues: ve(c, E)
210
+ fieldsMetadata: re,
211
+ hookFormInternals: ie,
212
+ getFormSubmissionValues: Fe(b, q)
182
213
  }
183
214
  };
184
215
  }
185
216
  export {
186
- Ue as useJobForm
217
+ rt as useJobForm
187
218
  };
188
219
  //# sourceMappingURL=useJobForm.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useJobForm.js","sources":["../../../../../../src/components/Employee/Compensation/shared/useJobForm/useJobForm.tsx"],"sourcesContent":["import { 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 { 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 { 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 { useDeriveFieldsMetadata } from '@/partner-hook-utils/form/useDeriveFieldsMetadata'\nimport { useHookFormInternals } from '@/partner-hook-utils/form/useHookFormInternals'\nimport { createGetFormSubmissionValues } from '@/partner-hook-utils/form/getFormSubmissionValues'\nimport { withOptions } from '@/partner-hook-utils/form/withOptions'\nimport { composeErrorHandler } from '@/partner-hook-utils/composeErrorHandler'\nimport type {\n BaseFormHookReady,\n FieldsMetadata,\n HookLoadingResult,\n HookSubmitResult,\n} from '@/partner-hook-utils/types'\nimport { useBaseSubmit } from '@/components/Base/useBaseSubmit'\nimport { SDKInternalError } from '@/types/sdkError'\nimport { WA_RISK_CLASS_CODES, type WARiskClassCode } from '@/models/WA_RISK_CODES'\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 partner default) on create mode.\n */\n hireDate?: string\n}\n\nexport interface UseJobFormProps {\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 optionalFieldsToRequire?: JobOptionalFieldsToRequire\n defaultValues?: Partial<JobFormData>\n validationMode?: UseFormProps['mode']\n shouldFocusError?: boolean\n /**\n * When `false`, hides `Fields.HireDate` (becomes `undefined`) and removes\n * `hireDate` from schema validation. Partners supply the value via\n * `JobSubmitOptions.hireDate` at submit time, or rely on the loaded job's\n * existing value on update. Use this when the date is driven by external\n * 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. steady-state\n * compensation edits render title via `CompFields.Title` so a title\n * change is effective-dated alongside the rest of the compensation\n * change, rather than overwriting the job's current title immediately.\n * Defaults to `true`.\n */\n withTitleField?: boolean\n}\n\nexport interface JobFormFields {\n Title: typeof JobTitleField | undefined\n HireDate: typeof HireDateField | undefined\n TwoPercentShareholder: typeof TwoPercentShareholderField | undefined\n StateWcCovered: typeof StateWcCoveredField | undefined\n StateWcClassCode: typeof StateWcClassCodeField | undefined\n}\n\nexport interface UseJobFormReady extends BaseFormHookReady<\n FieldsMetadata,\n JobFormData,\n JobFormFields\n> {\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 employee: Employee | null\n currentWorkAddress: EmployeeWorkAddress | null\n /** True when the company is taxable as an S-Corp; partners use this to decide whether to render `TwoPercentShareholder`. */\n showTwoPercentShareholder: boolean\n /**\n * True when the active work-address state is WA; partners use this to decide whether to render\n * `StateWcCovered`. `Fields.StateWcClassCode` is additionally gated on `stateWcCovered === true`,\n * so partners typically only need to check `Fields.StateWcCovered` / `Fields.StateWcClassCode`\n * truthiness rather than this flag directly.\n */\n showStateWc: boolean\n }\n status: { isPending: boolean; mode: 'create' | 'update' }\n actions: {\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\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 isPending = createJobMutation.isPending || updateJobMutation.isPending\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 stateWcClassCodeOptions = WA_RISK_CLASS_CODES.map(({ code, description }) => ({\n value: code,\n label: `${code}: ${description}`,\n }))\n\n const baseMetadata = useDeriveFieldsMetadata(metadataConfig, formMethods.control)\n const fieldsMetadata = {\n title: baseMetadata.title,\n hireDate: baseMetadata.hireDate,\n twoPercentShareholder: {\n ...baseMetadata.twoPercentShareholder,\n isDisabled: !showTwoPercentShareholder,\n },\n stateWcCovered: withOptions<boolean>(\n { ...baseMetadata.stateWcCovered, isDisabled: !showStateWc },\n [\n { label: 'Yes', value: 'true' },\n { label: 'No', value: 'false' },\n ],\n [true, false],\n ),\n stateWcClassCode: withOptions<WARiskClassCode>(\n { ...baseMetadata.stateWcClassCode, isDisabled: !showStateWc },\n stateWcClassCodeOptions,\n WA_RISK_CLASS_CODES,\n ),\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 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\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\nexport type UseJobFormResult = HookLoadingResult | UseJobFormReady\nexport type JobFieldsMetadata = UseJobFormReady['form']['fieldsMetadata']\n"],"names":["findJob","jobs","jobId","j","useJobForm","employeeId","optionalFieldsToRequire","partnerDefaults","validationMode","shouldFocusError","withHireDateField","withTitleField","jobsQuery","useJobsAndCompensationsGetJobs","addressesQuery","useEmployeeAddressesGetWorkAddresses","employeeQuery","useEmployeesGet","employeeJobs","currentWorkAddress","address","employee","companyUuid","taxQuery","useFederalTaxDetailsGet","showTwoPercentShareholder","showStateWc","currentJob","useMemo","isCreateMode","mode","schema","metadataConfig","createJobSchema","resolvedDefaults","formMethods","useForm","zodResolver","watchedStateWcCovered","useWatch","createJobMutation","useJobsAndCompensationsCreateJobMutation","updateJobMutation","useJobsAndCompensationsUpdateMutation","isPending","baseSubmitHandler","submitError","setSubmitError","useBaseSubmit","errorHandling","composeErrorHandler","stateWcClassCodeOptions","WA_RISK_CLASS_CODES","code","description","baseMetadata","useDeriveFieldsMetadata","fieldsMetadata","withOptions","onSubmit","options","submitResult","resolve","data","payload","resolvedEmployeeId","SDKInternalError","stateWcClassCode","resolvedHireDate","titleToSend","updatedJob","result","isDataLoading","hookFormInternals","useHookFormInternals","JobTitleField","HireDateField","TwoPercentShareholderField","StateWcCoveredField","StateWcClassCodeField","createGetFormSubmissionValues"],"mappings":";;;;;;;;;;;;;;;;;;;AAuHA,SAASA,GAAQC,GAAyBC,GAAuC;AAC/E,SAAI,CAACD,KAAQ,CAACC,IAAc,OACrBD,EAAK,KAAK,CAAAE,MAAKA,EAAE,SAASD,CAAK,KAA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,IAAA;AAAA,IAElC,SAAS,EAAE,UAAA8B,EAAA;AAAA,IACX,eAAAV;AAAA,IACA,MAAM;AAAA,MACJ,QAAQ;AAAA,QACN,OAAOtC,IAAiBgE,KAAgB;AAAA,QACxC,UAAUjE,IAAoBkE,KAAgB;AAAA,QAC9C,uBAAuBnD,IAA4BoD,KAA6B;AAAA,QAChF,gBAAgBnD,IAAcoD,KAAsB;AAAA,QACpD,kBAAkBpD,KAAeY,IAAwByC,KAAwB;AAAA,MAAA;AAAA,MAEnF,gBAAAtB;AAAA,MACA,mBAAAgB;AAAA,MACA,yBAAyBO,GAA8B7C,GAAaJ,CAAM;AAAA,IAAA;AAAA,EAC5E;AAEJ;"}
1
+ {"version":3,"file":"useJobForm.js","sources":["../../../../../../src/components/Employee/Compensation/shared/useJobForm/useJobForm.tsx"],"sourcesContent":["import { 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 { useDeriveFieldsMetadata } from '@/partner-hook-utils/form/useDeriveFieldsMetadata'\nimport { useHookFormInternals } from '@/partner-hook-utils/form/useHookFormInternals'\nimport { createGetFormSubmissionValues } from '@/partner-hook-utils/form/getFormSubmissionValues'\nimport { withOptions } from '@/partner-hook-utils/form/withOptions'\nimport { composeErrorHandler } from '@/partner-hook-utils/composeErrorHandler'\nimport type {\n BaseFormHookReady,\n FieldsMetadata,\n HookLoadingResult,\n HookSubmitResult,\n} from '@/partner-hook-utils/types'\nimport { useBaseSubmit } from '@/components/Base/useBaseSubmit'\nimport { SDKInternalError } from '@/types/sdkError'\nimport { WA_RISK_CLASS_CODES, type WARiskClassCode } from '@/models/WA_RISK_CODES'\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 partner default) on create mode.\n */\n hireDate?: string\n}\n\nexport interface UseJobFormProps {\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 optionalFieldsToRequire?: JobOptionalFieldsToRequire\n defaultValues?: Partial<JobFormData>\n validationMode?: UseFormProps['mode']\n shouldFocusError?: boolean\n /**\n * When `false`, hides `Fields.HireDate` (becomes `undefined`) and removes\n * `hireDate` from schema validation. Partners supply the value via\n * `JobSubmitOptions.hireDate` at submit time, or rely on the loaded job's\n * existing value on update. Use this when the date is driven by external\n * 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\nexport interface JobFormFields {\n Title: typeof JobTitleField | undefined\n HireDate: typeof HireDateField | undefined\n TwoPercentShareholder: typeof TwoPercentShareholderField | undefined\n StateWcCovered: typeof StateWcCoveredField | undefined\n StateWcClassCode: typeof StateWcClassCodeField | undefined\n}\n\nexport interface UseJobFormReady extends BaseFormHookReady<\n FieldsMetadata,\n JobFormData,\n JobFormFields\n> {\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 employee: Employee | null\n currentWorkAddress: EmployeeWorkAddress | null\n /** True when the company is taxable as an S-Corp; partners use this to decide whether to render `TwoPercentShareholder`. */\n showTwoPercentShareholder: boolean\n /**\n * True when the active work-address state is WA; partners use this to decide whether to render\n * `StateWcCovered`. `Fields.StateWcClassCode` is additionally gated on `stateWcCovered === true`,\n * so partners typically only need to check `Fields.StateWcCovered` / `Fields.StateWcClassCode`\n * truthiness rather than this flag directly.\n */\n showStateWc: boolean\n }\n status: { isPending: boolean; mode: 'create' | 'update' }\n actions: {\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\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 stateWcClassCodeOptions = WA_RISK_CLASS_CODES.map(({ code, description }) => ({\n value: code,\n label: `${code}: ${description}`,\n }))\n\n const baseMetadata = useDeriveFieldsMetadata(metadataConfig, formMethods.control)\n const fieldsMetadata = {\n title: baseMetadata.title,\n hireDate: baseMetadata.hireDate,\n twoPercentShareholder: {\n ...baseMetadata.twoPercentShareholder,\n isDisabled: !showTwoPercentShareholder,\n },\n stateWcCovered: withOptions<boolean>(\n { ...baseMetadata.stateWcCovered, isDisabled: !showStateWc },\n [\n { label: 'Yes', value: 'true' },\n { label: 'No', value: 'false' },\n ],\n [true, false],\n ),\n stateWcClassCode: withOptions<WARiskClassCode>(\n { ...baseMetadata.stateWcClassCode, isDisabled: !showStateWc },\n stateWcClassCodeOptions,\n WA_RISK_CLASS_CODES,\n ),\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\nexport type UseJobFormResult = HookLoadingResult | UseJobFormReady\nexport type JobFieldsMetadata = UseJobFormReady['form']['fieldsMetadata']\n"],"names":["findJob","jobs","jobId","j","useJobForm","employeeId","optionalFieldsToRequire","partnerDefaults","validationMode","shouldFocusError","withHireDateField","withTitleField","jobsQuery","useJobsAndCompensationsGetJobs","addressesQuery","useEmployeeAddressesGetWorkAddresses","employeeQuery","useEmployeesGet","employeeJobs","currentWorkAddress","address","employee","companyUuid","taxQuery","useFederalTaxDetailsGet","showTwoPercentShareholder","showStateWc","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","stateWcClassCodeOptions","WA_RISK_CLASS_CODES","code","description","baseMetadata","useDeriveFieldsMetadata","fieldsMetadata","withOptions","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":";;;;;;;;;;;;;;;;;;;;AAyHA,SAASA,GAAQC,GAAyBC,GAAuC;AAC/E,SAAI,CAACD,KAAQ,CAACC,IAAc,OACrBD,EAAK,KAAK,CAAAE,MAAKA,EAAE,SAASD,CAAK,KAAK;AAC7C;AAEO,SAASE,GAAW;AAAA,EACzB,YAAAC;AAAA,EACA,OAAAH;AAAA,EACA,yBAAAI;AAAA,EACA,eAAeC;AAAA,EACf,gBAAAC,IAAiB;AAAA,EACjB,kBAAAC,IAAmB;AAAA,EACnB,mBAAAC,IAAoB;AAAA,EACpB,gBAAAC,IAAiB;AACnB,GAAyD;AACvD,QAAMC,IAAYC;AAAA,IAChB,EAAE,YAAYR,KAAc,GAAA;AAAA,IAC5B,EAAE,SAAS,CAAC,CAACA,EAAA;AAAA,EAAW,GAEpBS,IAAiBC;AAAA,IACrB,EAAE,YAAYV,KAAc,GAAA;AAAA,IAC5B,EAAE,SAAS,CAAC,CAACA,EAAA;AAAA,EAAW,GAEpBW,IAAgBC,GAAgB,EAAE,YAAYZ,KAAc,GAAA,GAAM,EAAE,SAAS,CAAC,CAACA,GAAY,GAE3Fa,IAAeN,EAAU,MAAM,MAE/BO,IADgBL,EAA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