@gusto/embedded-react-sdk 0.55.3 → 0.55.4
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 +23 -0
- package/dist/components/Common/DataView/DataCards/DataCards.d.ts +2 -1
- package/dist/components/Common/DataView/DataCards/DataCards.js +63 -54
- package/dist/components/Common/DataView/DataCards/DataCards.js.map +1 -1
- package/dist/components/Common/DataView/DataCards/DataCards.module.scss.js +14 -12
- package/dist/components/Common/DataView/DataCards/DataCards.module.scss.js.map +1 -1
- package/dist/components/Common/DataView/DataTable/DataTable.d.ts +2 -1
- package/dist/components/Common/DataView/DataTable/DataTable.js +75 -66
- package/dist/components/Common/DataView/DataTable/DataTable.js.map +1 -1
- package/dist/components/Common/DataView/DataTable/DataTable.module.scss.js +8 -4
- package/dist/components/Common/DataView/DataTable/DataTable.module.scss.js.map +1 -1
- package/dist/components/Common/DataView/DataView.js +18 -17
- package/dist/components/Common/DataView/DataView.js.map +1 -1
- package/dist/components/Company/AssignSignatory/CreateSignatory/useCreateSignatory.js +3 -6
- package/dist/components/Company/AssignSignatory/CreateSignatory/useCreateSignatory.js.map +1 -1
- package/dist/components/Company/AssignSignatory/InviteSignatory/useInviteSignatory.js +3 -6
- package/dist/components/Company/AssignSignatory/InviteSignatory/useInviteSignatory.js.map +1 -1
- package/dist/components/Company/AssignSignatory/useAssignSignatory.js +5 -8
- package/dist/components/Company/AssignSignatory/useAssignSignatory.js.map +1 -1
- package/dist/components/Company/BankAccount/BankAccountForm/context.js +3 -6
- package/dist/components/Company/BankAccount/BankAccountForm/context.js.map +1 -1
- package/dist/components/Company/DocumentSigner/DocumentList/useDocumentList.js +3 -6
- package/dist/components/Company/DocumentSigner/DocumentList/useDocumentList.js.map +1 -1
- package/dist/components/Company/FederalTaxes/useFederalTaxes.js +8 -11
- package/dist/components/Company/FederalTaxes/useFederalTaxes.js.map +1 -1
- package/dist/components/Company/Industry/Context.js +6 -9
- package/dist/components/Company/Industry/Context.js.map +1 -1
- package/dist/components/Company/Locations/LocationForm/useLocationForm.js +3 -6
- package/dist/components/Company/Locations/LocationForm/useLocationForm.js.map +1 -1
- package/dist/components/Company/Locations/LocationsList/List.js +27 -25
- package/dist/components/Company/Locations/LocationsList/List.js.map +1 -1
- package/dist/components/Company/Locations/LocationsList/LocationsList.js +41 -36
- package/dist/components/Company/Locations/LocationsList/LocationsList.js.map +1 -1
- package/dist/components/Company/Locations/LocationsList/useLocationsList.d.ts +1 -0
- package/dist/components/Company/Locations/LocationsList/useLocationsList.js +3 -6
- package/dist/components/Company/Locations/LocationsList/useLocationsList.js.map +1 -1
- package/dist/components/Company/OnboardingOverview/context.js +3 -6
- package/dist/components/Company/OnboardingOverview/context.js.map +1 -1
- package/dist/components/Company/StateTaxes/StateTaxesForm/Form.d.ts +9 -2
- package/dist/components/Company/StateTaxes/StateTaxesForm/Form.js +19 -18
- package/dist/components/Company/StateTaxes/StateTaxesForm/Form.js.map +1 -1
- package/dist/components/Company/StateTaxes/StateTaxesForm/StateTaxesForm.js +63 -62
- package/dist/components/Company/StateTaxes/StateTaxesForm/StateTaxesForm.js.map +1 -1
- package/dist/components/Company/StateTaxes/StateTaxesForm/context.js +3 -6
- package/dist/components/Company/StateTaxes/StateTaxesForm/context.js.map +1 -1
- package/dist/components/Company/StateTaxes/StateTaxesList/context.js +3 -6
- package/dist/components/Company/StateTaxes/StateTaxesList/context.js.map +1 -1
- package/dist/components/Company/StateTaxes/TaxRateManagement/AddTaxRateDialog.js +69 -65
- package/dist/components/Company/StateTaxes/TaxRateManagement/AddTaxRateDialog.js.map +1 -1
- package/dist/components/Company/StateTaxes/TaxRateManagement/context.js +3 -6
- package/dist/components/Company/StateTaxes/TaxRateManagement/context.js.map +1 -1
- package/dist/components/Company/StateTaxes/TaxRateManagement/toHistoryRows.js +30 -23
- package/dist/components/Company/StateTaxes/TaxRateManagement/toHistoryRows.js.map +1 -1
- package/dist/components/Company/StateTaxes/shared/RequirementFields.d.ts +8 -4
- package/dist/components/Company/StateTaxes/shared/RequirementFields.js +13 -12
- package/dist/components/Company/StateTaxes/shared/RequirementFields.js.map +1 -1
- package/dist/components/Company/StateTaxes/shared/prepareRequirements.d.ts +29 -0
- package/dist/components/Company/StateTaxes/shared/prepareRequirements.js +24 -0
- package/dist/components/Company/StateTaxes/shared/prepareRequirements.js.map +1 -0
- package/dist/components/Company/StateTaxes/shared/prepareRequirements.test.d.ts +1 -0
- package/dist/components/Contractor/Payments/PaymentsList/PaymentsList.js +68 -55
- package/dist/components/Contractor/Payments/PaymentsList/PaymentsList.js.map +1 -1
- package/dist/components/Contractor/Payments/PaymentsList/PaymentsListPresentation.js +36 -35
- package/dist/components/Contractor/Payments/PaymentsList/PaymentsListPresentation.js.map +1 -1
- package/dist/components/Employee/Documents/onboarding/DocumentSigner/DocumentList/useDocumentList.js +3 -6
- package/dist/components/Employee/Documents/onboarding/DocumentSigner/DocumentList/useDocumentList.js.map +1 -1
- package/dist/components/Employee/Paystubs/management/PaystubsCard/PaystubsCard.js +84 -96
- package/dist/components/Employee/Paystubs/management/PaystubsCard/PaystubsCard.js.map +1 -1
- package/dist/components/Flow/Flow.js +22 -22
- package/dist/components/Flow/Flow.js.map +1 -1
- package/dist/components/Flow/useFlow.js +3 -3
- package/dist/components/InformationRequests/InformationRequests.d.ts +1 -1
- package/dist/components/InformationRequests/InformationRequests.js +68 -53
- package/dist/components/InformationRequests/InformationRequests.js.map +1 -1
- package/dist/components/Payroll/GrossUpModal/GrossUpModal.js +2 -3
- package/dist/components/Payroll/GrossUpModal/GrossUpModal.js.map +1 -1
- package/dist/components/Payroll/OffCycleCreation/OffCycleCreation.js +52 -50
- package/dist/components/Payroll/OffCycleCreation/OffCycleCreation.js.map +1 -1
- package/dist/components/Payroll/OffCycleCreation/OffCycleCreationPresentation.d.ts +1 -1
- package/dist/components/Payroll/OffCycleCreation/OffCycleCreationPresentation.js +86 -67
- package/dist/components/Payroll/OffCycleCreation/OffCycleCreationPresentation.js.map +1 -1
- package/dist/components/Payroll/OffCycleCreation/OffCycleCreationTypes.d.ts +4 -0
- package/dist/components/Payroll/OffCycleDeductionsSetting/OffCycleDeductionsSetting.d.ts +1 -1
- package/dist/components/Payroll/OffCycleDeductionsSetting/OffCycleDeductionsSetting.js +26 -21
- package/dist/components/Payroll/OffCycleDeductionsSetting/OffCycleDeductionsSetting.js.map +1 -1
- package/dist/components/Payroll/OffCyclePayPeriodDateForm/OffCyclePayPeriodDateFormPresentation.d.ts +8 -1
- package/dist/components/Payroll/OffCyclePayPeriodDateForm/OffCyclePayPeriodDateFormPresentation.js +29 -17
- package/dist/components/Payroll/OffCyclePayPeriodDateForm/OffCyclePayPeriodDateFormPresentation.js.map +1 -1
- package/dist/components/Payroll/OffCycleTaxWithholdingTable/OffCycleTaxWithholdingTable.js +21 -18
- package/dist/components/Payroll/OffCycleTaxWithholdingTable/OffCycleTaxWithholdingTable.js.map +1 -1
- package/dist/components/Payroll/OffCycleTaxWithholdingTable/OffCycleTaxWithholdingTable.module.scss.js +9 -7
- package/dist/components/Payroll/OffCycleTaxWithholdingTable/OffCycleTaxWithholdingTable.module.scss.js.map +1 -1
- package/dist/components/Payroll/OffCycleTaxWithholdingTable/OffCycleTaxWithholdingTableTypes.d.ts +2 -0
- package/dist/components/Payroll/OffCycleTaxWithholdingTable/OffCycleTaxWithholdingTableTypes.js.map +1 -1
- package/dist/components/Payroll/PayrollConfiguration/PayrollConfiguration.js +193 -191
- package/dist/components/Payroll/PayrollConfiguration/PayrollConfiguration.js.map +1 -1
- package/dist/components/Payroll/PayrollConfiguration/usePayrollConfigurationData.d.ts +3 -2
- package/dist/components/Payroll/PayrollConfiguration/usePayrollConfigurationData.js +31 -31
- package/dist/components/Payroll/PayrollConfiguration/usePayrollConfigurationData.js.map +1 -1
- package/dist/components/Payroll/PayrollEditEmployee/PayrollEditEmployeePresentation.js +254 -243
- package/dist/components/Payroll/PayrollEditEmployee/PayrollEditEmployeePresentation.js.map +1 -1
- package/dist/components/Payroll/PayrollHistory/PayrollHistory.js +83 -76
- package/dist/components/Payroll/PayrollHistory/PayrollHistory.js.map +1 -1
- package/dist/components/Payroll/PayrollHistory/PayrollHistoryPresentation.js +23 -22
- package/dist/components/Payroll/PayrollHistory/PayrollHistoryPresentation.js.map +1 -1
- package/dist/components/Payroll/PayrollList/PayrollList.js +108 -97
- package/dist/components/Payroll/PayrollList/PayrollList.js.map +1 -1
- package/dist/components/Payroll/PayrollList/PayrollListPresentation.js +38 -37
- package/dist/components/Payroll/PayrollList/PayrollListPresentation.js.map +1 -1
- package/dist/components/Payroll/PayrollOverview/PayrollOverview.js +176 -167
- package/dist/components/Payroll/PayrollOverview/PayrollOverview.js.map +1 -1
- package/dist/components/Payroll/PayrollOverview/PayrollOverviewPresentation.d.ts +2 -1
- package/dist/components/Payroll/PayrollOverview/PayrollOverviewPresentation.js +173 -164
- package/dist/components/Payroll/PayrollOverview/PayrollOverviewPresentation.js.map +1 -1
- package/dist/components/Payroll/usePreparedPayrollData.js +12 -15
- package/dist/components/Payroll/usePreparedPayrollData.js.map +1 -1
- package/dist/helpers/openPdfInNewTab.d.ts +15 -0
- package/dist/helpers/openPdfInNewTab.js +28 -0
- package/dist/helpers/openPdfInNewTab.js.map +1 -0
- package/dist/i18n/en/Company.StateTaxes.json.js +1 -1
- package/dist/i18n/en/Payroll.OffCycleCreation.json.js +11 -9
- package/dist/i18n/en/Payroll.OffCycleCreation.json.js.map +1 -1
- package/dist/i18n/en/Payroll.OffCycleTaxWithholding.json.js +7 -7
- package/dist/i18n/en/Payroll.PayrollEditEmployee.json.js +29 -27
- package/dist/i18n/en/Payroll.PayrollEditEmployee.json.js.map +1 -1
- package/dist/i18n/en/Payroll.PayrollOverview.json.js +43 -41
- package/dist/i18n/en/Payroll.PayrollOverview.json.js.map +1 -1
- package/dist/i18n/types.d.ts +20 -0
- package/dist/style.css +1 -1
- package/package.json +17 -17
|
@@ -1,110 +1,114 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { useState as z, useMemo as
|
|
1
|
+
import { jsx as a, jsxs as j } from "react/jsx-runtime";
|
|
2
|
+
import { useState as z, useMemo as s, useEffect as V } from "react";
|
|
3
3
|
import { useForm as H, FormProvider as I } from "react-hook-form";
|
|
4
4
|
import { zodResolver as K } from "@hookform/resolvers/zod";
|
|
5
|
-
import { z as
|
|
6
|
-
import { useTranslation as
|
|
5
|
+
import { z as b } from "zod";
|
|
6
|
+
import { useTranslation as y } from "react-i18next";
|
|
7
7
|
import { buildRequirementSchema as M } from "../shared/buildRequirementSchema.js";
|
|
8
8
|
import { RequirementFields as U } from "../shared/RequirementFields.js";
|
|
9
9
|
import { getUniqueRhfKey as w } from "../shared/rhfKey.js";
|
|
10
10
|
import { isRequirementApplicable as W } from "../shared/applicableIf.js";
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
|
|
11
|
+
import { prepareRequirements as Y, isRequirementSetEditable as B } from "../shared/prepareRequirements.js";
|
|
12
|
+
import { stringifyRequirementValue as G } from "../shared/requirementValue.js";
|
|
13
|
+
import { useTaxRateManagement as J } from "./context.js";
|
|
14
|
+
import { Flex as N } from "../../../Common/Flex/Flex.js";
|
|
15
|
+
import { useComponentContext as Q } from "../../../../contexts/ComponentAdapter/useComponentContext.js";
|
|
16
|
+
import { useDateFormatter as X } from "../../../../hooks/useDateFormatter.js";
|
|
17
|
+
import { SelectField as Z } from "../../../Common/Fields/SelectField/SelectField.js";
|
|
18
|
+
function _(r) {
|
|
18
19
|
if (r.length === 0) return null;
|
|
19
|
-
const
|
|
20
|
-
(o,
|
|
20
|
+
const n = [...r].sort(
|
|
21
|
+
(o, m) => (o.effectiveFrom ?? "").localeCompare(m.effectiveFrom ?? "")
|
|
21
22
|
);
|
|
22
|
-
return
|
|
23
|
+
return n[n.length - 1] ?? null;
|
|
23
24
|
}
|
|
24
|
-
function
|
|
25
|
-
const
|
|
25
|
+
function he({ isOpen: r, state: n, group: o, onClose: m }) {
|
|
26
|
+
const u = Q(), g = X(), { t } = y("Company.StateTaxes", { keyPrefix: "manageRates" }), { t: F } = y("Company.StateTaxes", { keyPrefix: "form" }), { t: q } = y("common", { keyPrefix: "statesHash" }), { handleAddRate: x, isPendingUpdate: D } = J(), [k, v] = z(!1), i = s(() => _(o.candidateSets), [o.candidateSets]), l = s(
|
|
26
27
|
() => o.candidateSets.map((e) => e.effectiveFrom).filter((e) => typeof e == "string").sort(),
|
|
27
28
|
[o.candidateSets]
|
|
28
|
-
),
|
|
29
|
-
() =>
|
|
30
|
-
[
|
|
31
|
-
),
|
|
32
|
-
() =>
|
|
33
|
-
|
|
34
|
-
|
|
29
|
+
), c = s(
|
|
30
|
+
() => Y(i?.requirements ?? []),
|
|
31
|
+
[i]
|
|
32
|
+
), { shape: R, defaults: S } = s(
|
|
33
|
+
() => M(c, F),
|
|
34
|
+
[c, F]
|
|
35
|
+
), A = s(
|
|
36
|
+
() => b.object({
|
|
37
|
+
effectiveFrom: b.string().min(1),
|
|
38
|
+
fields: b.object(R)
|
|
35
39
|
}),
|
|
36
|
-
[
|
|
37
|
-
),
|
|
40
|
+
[R]
|
|
41
|
+
), p = s(
|
|
38
42
|
() => ({
|
|
39
|
-
effectiveFrom:
|
|
40
|
-
fields:
|
|
43
|
+
effectiveFrom: i?.effectiveFrom ?? l[0] ?? "",
|
|
44
|
+
fields: S
|
|
41
45
|
}),
|
|
42
|
-
[
|
|
43
|
-
),
|
|
46
|
+
[i, l, S]
|
|
47
|
+
), h = H({ resolver: K(A), defaultValues: p });
|
|
44
48
|
V(() => {
|
|
45
|
-
r &&
|
|
46
|
-
}, [r,
|
|
47
|
-
const C =
|
|
48
|
-
if (!
|
|
49
|
-
const T = { fields: e.fields },
|
|
50
|
-
|
|
49
|
+
r && h.reset(p);
|
|
50
|
+
}, [r, p]);
|
|
51
|
+
const C = h.handleSubmit(async (e) => {
|
|
52
|
+
if (!i?.key) return;
|
|
53
|
+
const T = { fields: e.fields }, E = c.map((f, d) => ({ req: f, index: d })).filter(({ req: f }) => W(f, "fields", T));
|
|
54
|
+
v(!0);
|
|
51
55
|
try {
|
|
52
|
-
await
|
|
53
|
-
|
|
56
|
+
await x(
|
|
57
|
+
i.key,
|
|
54
58
|
e.effectiveFrom,
|
|
55
|
-
|
|
56
|
-
key:
|
|
57
|
-
value:
|
|
59
|
+
E.map(({ req: d, index: L }) => ({
|
|
60
|
+
key: d.key,
|
|
61
|
+
value: G(
|
|
62
|
+
e.fields[w(d, L, c)]
|
|
63
|
+
)
|
|
58
64
|
}))
|
|
59
|
-
) &&
|
|
65
|
+
) && m();
|
|
60
66
|
} finally {
|
|
61
|
-
|
|
67
|
+
v(!1);
|
|
62
68
|
}
|
|
63
|
-
}), P = (
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
return /* @__PURE__ */ s(
|
|
67
|
-
d.Dialog,
|
|
69
|
+
}), P = B(i?.requirements ?? []);
|
|
70
|
+
return /* @__PURE__ */ a(
|
|
71
|
+
u.Dialog,
|
|
68
72
|
{
|
|
69
73
|
isOpen: r,
|
|
70
|
-
onClose:
|
|
74
|
+
onClose: m,
|
|
71
75
|
onPrimaryActionClick: () => {
|
|
72
76
|
C();
|
|
73
77
|
},
|
|
74
78
|
isPrimaryActionLoading: k || D,
|
|
75
|
-
primaryActionLabel:
|
|
76
|
-
closeActionLabel:
|
|
77
|
-
title:
|
|
78
|
-
state:
|
|
79
|
+
primaryActionLabel: t("saveRateCta"),
|
|
80
|
+
closeActionLabel: t("cancelCta"),
|
|
81
|
+
title: t("addRateDialogTitle", {
|
|
82
|
+
state: q(n)
|
|
79
83
|
}),
|
|
80
|
-
children: /* @__PURE__ */
|
|
81
|
-
/* @__PURE__ */
|
|
82
|
-
/* @__PURE__ */
|
|
83
|
-
|
|
84
|
+
children: /* @__PURE__ */ a(I, { ...h, children: /* @__PURE__ */ j(N, { flexDirection: "column", gap: 20, alignItems: "stretch", children: [
|
|
85
|
+
/* @__PURE__ */ a(u.Text, { size: "sm", children: t("addRateDialogDescription") }),
|
|
86
|
+
/* @__PURE__ */ a(
|
|
87
|
+
Z,
|
|
84
88
|
{
|
|
85
89
|
name: "effectiveFrom",
|
|
86
|
-
label:
|
|
87
|
-
placeholder:
|
|
90
|
+
label: t("effectiveDateLabel"),
|
|
91
|
+
placeholder: t("effectiveDatePlaceholder"),
|
|
88
92
|
isRequired: !0,
|
|
89
|
-
isDisabled:
|
|
90
|
-
options:
|
|
93
|
+
isDisabled: l.length === 0,
|
|
94
|
+
options: l.map((e) => ({
|
|
91
95
|
value: e,
|
|
92
|
-
label:
|
|
96
|
+
label: g.formatLongWithYear(e)
|
|
93
97
|
}))
|
|
94
98
|
}
|
|
95
99
|
),
|
|
96
|
-
P ? /* @__PURE__ */
|
|
100
|
+
P ? /* @__PURE__ */ a(
|
|
97
101
|
U,
|
|
98
102
|
{
|
|
99
|
-
requirements:
|
|
103
|
+
requirements: i?.requirements,
|
|
100
104
|
requirementSetKey: "fields"
|
|
101
105
|
}
|
|
102
|
-
) : /* @__PURE__ */
|
|
106
|
+
) : /* @__PURE__ */ a(u.Alert, { status: "info", label: t("noEditableFieldsTitle"), children: t("noEditableFieldsDescription") })
|
|
103
107
|
] }) })
|
|
104
108
|
}
|
|
105
109
|
);
|
|
106
110
|
}
|
|
107
111
|
export {
|
|
108
|
-
|
|
112
|
+
he as AddTaxRateDialog
|
|
109
113
|
};
|
|
110
114
|
//# sourceMappingURL=AddTaxRateDialog.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AddTaxRateDialog.js","sources":["../../../../../src/components/Company/StateTaxes/TaxRateManagement/AddTaxRateDialog.tsx"],"sourcesContent":["import { useEffect, useMemo, useState } from 'react'\nimport { FormProvider, useForm } from 'react-hook-form'\nimport { zodResolver } from '@hookform/resolvers/zod'\nimport { z } from 'zod'\nimport { useTranslation } from 'react-i18next'\nimport { buildRequirementSchema } from '../shared/buildRequirementSchema'\nimport { RequirementFields } from '../shared/RequirementFields'\nimport { getUniqueRhfKey } from '../shared/rhfKey'\nimport { isRequirementApplicable, type StateTaxesFormValues } from '../shared/applicableIf'\nimport { stringifyRequirementValue } from '../shared/requirementValue'\nimport { useTaxRateManagement, type TaxRateKeyGroup } from './context'\nimport { Flex, SelectField } from '@/components/Common'\nimport { useComponentContext } from '@/contexts/ComponentAdapter/useComponentContext'\nimport { useDateFormatter } from '@/hooks/useDateFormatter'\nimport type { STATES_ABBR } from '@/shared/constants'\n\ninterface AddTaxRateDialogProps {\n isOpen: boolean\n state: string\n group: TaxRateKeyGroup\n onClose: () => void\n}\n\nfunction latestSet(sets: TaxRateKeyGroup['candidateSets']) {\n if (sets.length === 0) return null\n const sorted = [...sets].sort((a, b) =>\n (a.effectiveFrom ?? '').localeCompare(b.effectiveFrom ?? ''),\n )\n return sorted[sorted.length - 1] ?? null\n}\n\n/** @internal */\nexport function AddTaxRateDialog({ isOpen, state, group, onClose }: AddTaxRateDialogProps) {\n const Components = useComponentContext()\n const dateFormatter = useDateFormatter()\n const { t } = useTranslation('Company.StateTaxes', { keyPrefix: 'manageRates' })\n const { t: tForm } = useTranslation('Company.StateTaxes', { keyPrefix: 'form' })\n const { t: statesHash } = useTranslation('common', { keyPrefix: 'statesHash' })\n const { handleAddRate, isPendingUpdate } = useTaxRateManagement()\n const [isSubmitting, setIsSubmitting] = useState(false)\n\n const templateSet = useMemo(() => latestSet(group.candidateSets), [group.candidateSets])\n\n const availableDates = useMemo(\n () =>\n group.candidateSets\n .map(candidate => candidate.effectiveFrom)\n .filter((date): date is string => typeof date === 'string')\n .sort(),\n [group.candidateSets],\n )\n\n const { shape, defaults } = useMemo(\n () => buildRequirementSchema(
|
|
1
|
+
{"version":3,"file":"AddTaxRateDialog.js","sources":["../../../../../src/components/Company/StateTaxes/TaxRateManagement/AddTaxRateDialog.tsx"],"sourcesContent":["import { useEffect, useMemo, useState } from 'react'\nimport { FormProvider, useForm } from 'react-hook-form'\nimport { zodResolver } from '@hookform/resolvers/zod'\nimport { z } from 'zod'\nimport { useTranslation } from 'react-i18next'\nimport { buildRequirementSchema } from '../shared/buildRequirementSchema'\nimport { RequirementFields } from '../shared/RequirementFields'\nimport { getUniqueRhfKey } from '../shared/rhfKey'\nimport { isRequirementApplicable, type StateTaxesFormValues } from '../shared/applicableIf'\nimport { isRequirementSetEditable, prepareRequirements } from '../shared/prepareRequirements'\nimport { stringifyRequirementValue } from '../shared/requirementValue'\nimport { useTaxRateManagement, type TaxRateKeyGroup } from './context'\nimport { Flex, SelectField } from '@/components/Common'\nimport { useComponentContext } from '@/contexts/ComponentAdapter/useComponentContext'\nimport { useDateFormatter } from '@/hooks/useDateFormatter'\nimport type { STATES_ABBR } from '@/shared/constants'\n\ninterface AddTaxRateDialogProps {\n isOpen: boolean\n state: string\n group: TaxRateKeyGroup\n onClose: () => void\n}\n\nfunction latestSet(sets: TaxRateKeyGroup['candidateSets']) {\n if (sets.length === 0) return null\n const sorted = [...sets].sort((a, b) =>\n (a.effectiveFrom ?? '').localeCompare(b.effectiveFrom ?? ''),\n )\n return sorted[sorted.length - 1] ?? null\n}\n\n/** @internal */\nexport function AddTaxRateDialog({ isOpen, state, group, onClose }: AddTaxRateDialogProps) {\n const Components = useComponentContext()\n const dateFormatter = useDateFormatter()\n const { t } = useTranslation('Company.StateTaxes', { keyPrefix: 'manageRates' })\n const { t: tForm } = useTranslation('Company.StateTaxes', { keyPrefix: 'form' })\n const { t: statesHash } = useTranslation('common', { keyPrefix: 'statesHash' })\n const { handleAddRate, isPendingUpdate } = useTaxRateManagement()\n const [isSubmitting, setIsSubmitting] = useState(false)\n\n const templateSet = useMemo(() => latestSet(group.candidateSets), [group.candidateSets])\n\n const availableDates = useMemo(\n () =>\n group.candidateSets\n .map(candidate => candidate.effectiveFrom)\n .filter((date): date is string => typeof date === 'string')\n .sort(),\n [group.candidateSets],\n )\n\n const preparedRequirements = useMemo(\n () => prepareRequirements(templateSet?.requirements ?? []),\n [templateSet],\n )\n\n const { shape, defaults } = useMemo(\n () => buildRequirementSchema(preparedRequirements, tForm),\n [preparedRequirements, tForm],\n )\n\n const dynamicSchema = useMemo(\n () =>\n z.object({\n effectiveFrom: z.string().min(1),\n fields: z.object(shape),\n }),\n [shape],\n )\n\n type FormShape = z.infer<typeof dynamicSchema>\n\n const defaultValues = useMemo<FormShape>(\n () => ({\n effectiveFrom: templateSet?.effectiveFrom ?? availableDates[0] ?? '',\n fields: defaults,\n }),\n [templateSet, availableDates, defaults],\n )\n\n const methods = useForm<FormShape>({ resolver: zodResolver(dynamicSchema), defaultValues })\n\n useEffect(() => {\n if (isOpen) methods.reset(defaultValues)\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [isOpen, defaultValues])\n\n const handleSubmit = methods.handleSubmit(async data => {\n if (!templateSet?.key) return\n const formValues: StateTaxesFormValues = { fields: data.fields }\n const applicableRequirements = preparedRequirements\n .map((req, index) => ({ req, index }))\n .filter(({ req }) => isRequirementApplicable(req, 'fields', formValues))\n\n setIsSubmitting(true)\n try {\n const success = await handleAddRate(\n templateSet.key,\n data.effectiveFrom,\n applicableRequirements.map(({ req, index }) => ({\n key: req.key as string,\n value: stringifyRequirementValue(\n data.fields[getUniqueRhfKey(req, index, preparedRequirements)],\n ),\n })),\n )\n if (success) onClose()\n } finally {\n setIsSubmitting(false)\n }\n })\n\n const hasEditableFields = isRequirementSetEditable(templateSet?.requirements ?? [])\n\n return (\n <Components.Dialog\n isOpen={isOpen}\n onClose={onClose}\n onPrimaryActionClick={() => {\n void handleSubmit()\n }}\n isPrimaryActionLoading={isSubmitting || isPendingUpdate}\n primaryActionLabel={t('saveRateCta')}\n closeActionLabel={t('cancelCta')}\n title={t('addRateDialogTitle', {\n state: statesHash(state as (typeof STATES_ABBR)[number]),\n })}\n >\n <FormProvider {...methods}>\n <Flex flexDirection=\"column\" gap={20} alignItems=\"stretch\">\n <Components.Text size=\"sm\">{t('addRateDialogDescription')}</Components.Text>\n <SelectField\n name=\"effectiveFrom\"\n label={t('effectiveDateLabel')}\n placeholder={t('effectiveDatePlaceholder')}\n isRequired\n isDisabled={availableDates.length === 0}\n options={availableDates.map(date => ({\n value: date,\n label: dateFormatter.formatLongWithYear(date),\n }))}\n />\n {hasEditableFields ? (\n <RequirementFields\n requirements={templateSet?.requirements}\n requirementSetKey=\"fields\"\n />\n ) : (\n <Components.Alert status=\"info\" label={t('noEditableFieldsTitle')}>\n {t('noEditableFieldsDescription')}\n </Components.Alert>\n )}\n </Flex>\n </FormProvider>\n </Components.Dialog>\n )\n}\n"],"names":["latestSet","sets","sorted","a","b","AddTaxRateDialog","isOpen","state","group","onClose","Components","useComponentContext","dateFormatter","useDateFormatter","useTranslation","tForm","statesHash","handleAddRate","isPendingUpdate","useTaxRateManagement","isSubmitting","setIsSubmitting","useState","templateSet","useMemo","availableDates","candidate","date","preparedRequirements","prepareRequirements","shape","defaults","buildRequirementSchema","dynamicSchema","z","defaultValues","methods","useForm","zodResolver","useEffect","handleSubmit","data","formValues","applicableRequirements","req","index","isRequirementApplicable","stringifyRequirementValue","getUniqueRhfKey","hasEditableFields","isRequirementSetEditable","jsx","FormProvider","jsxs","Flex","SelectField","RequirementFields"],"mappings":";;;;;;;;;;;;;;;;;AAwBA,SAASA,EAAUC,GAAwC;AACzD,MAAIA,EAAK,WAAW,EAAG,QAAO;AAC9B,QAAMC,IAAS,CAAC,GAAGD,CAAI,EAAE;AAAA,IAAK,CAACE,GAAGC,OAC/BD,EAAE,iBAAiB,IAAI,cAAcC,EAAE,iBAAiB,EAAE;AAAA,EAAA;AAE7D,SAAOF,EAAOA,EAAO,SAAS,CAAC,KAAK;AACtC;AAGO,SAASG,GAAiB,EAAE,QAAAC,GAAQ,OAAAC,GAAO,OAAAC,GAAO,SAAAC,KAAkC;AACzF,QAAMC,IAAaC,EAAA,GACbC,IAAgBC,EAAA,GAChB,EAAE,MAAMC,EAAe,sBAAsB,EAAE,WAAW,eAAe,GACzE,EAAE,GAAGC,MAAUD,EAAe,sBAAsB,EAAE,WAAW,QAAQ,GACzE,EAAE,GAAGE,MAAeF,EAAe,UAAU,EAAE,WAAW,cAAc,GACxE,EAAE,eAAAG,GAAe,iBAAAC,EAAA,IAAoBC,EAAA,GACrC,CAACC,GAAcC,CAAe,IAAIC,EAAS,EAAK,GAEhDC,IAAcC,EAAQ,MAAMxB,EAAUQ,EAAM,aAAa,GAAG,CAACA,EAAM,aAAa,CAAC,GAEjFiB,IAAiBD;AAAA,IACrB,MACEhB,EAAM,cACH,IAAI,OAAakB,EAAU,aAAa,EACxC,OAAO,CAACC,MAAyB,OAAOA,KAAS,QAAQ,EACzD,KAAA;AAAA,IACL,CAACnB,EAAM,aAAa;AAAA,EAAA,GAGhBoB,IAAuBJ;AAAA,IAC3B,MAAMK,EAAoBN,GAAa,gBAAgB,EAAE;AAAA,IACzD,CAACA,CAAW;AAAA,EAAA,GAGR,EAAE,OAAAO,GAAO,UAAAC,EAAA,IAAaP;AAAA,IAC1B,MAAMQ,EAAuBJ,GAAsBb,CAAK;AAAA,IACxD,CAACa,GAAsBb,CAAK;AAAA,EAAA,GAGxBkB,IAAgBT;AAAA,IACpB,MACEU,EAAE,OAAO;AAAA,MACP,eAAeA,EAAE,SAAS,IAAI,CAAC;AAAA,MAC/B,QAAQA,EAAE,OAAOJ,CAAK;AAAA,IAAA,CACvB;AAAA,IACH,CAACA,CAAK;AAAA,EAAA,GAKFK,IAAgBX;AAAA,IACpB,OAAO;AAAA,MACL,eAAeD,GAAa,iBAAiBE,EAAe,CAAC,KAAK;AAAA,MAClE,QAAQM;AAAA,IAAA;AAAA,IAEV,CAACR,GAAaE,GAAgBM,CAAQ;AAAA,EAAA,GAGlCK,IAAUC,EAAmB,EAAE,UAAUC,EAAYL,CAAa,GAAG,eAAAE,GAAe;AAE1F,EAAAI,EAAU,MAAM;AACd,IAAIjC,KAAQ8B,EAAQ,MAAMD,CAAa;AAAA,EAEzC,GAAG,CAAC7B,GAAQ6B,CAAa,CAAC;AAE1B,QAAMK,IAAeJ,EAAQ,aAAa,OAAMK,MAAQ;AACtD,QAAI,CAAClB,GAAa,IAAK;AACvB,UAAMmB,IAAmC,EAAE,QAAQD,EAAK,OAAA,GAClDE,IAAyBf,EAC5B,IAAI,CAACgB,GAAKC,OAAW,EAAE,KAAAD,GAAK,OAAAC,EAAA,EAAQ,EACpC,OAAO,CAAC,EAAE,KAAAD,EAAA,MAAUE,EAAwBF,GAAK,UAAUF,CAAU,CAAC;AAEzE,IAAArB,EAAgB,EAAI;AACpB,QAAI;AAWF,MAVgB,MAAMJ;AAAA,QACpBM,EAAY;AAAA,QACZkB,EAAK;AAAA,QACLE,EAAuB,IAAI,CAAC,EAAE,KAAAC,GAAK,OAAAC,SAAa;AAAA,UAC9C,KAAKD,EAAI;AAAA,UACT,OAAOG;AAAA,YACLN,EAAK,OAAOO,EAAgBJ,GAAKC,GAAOjB,CAAoB,CAAC;AAAA,UAAA;AAAA,QAC/D,EACA;AAAA,MAAA,KAESnB,EAAA;AAAA,IACf,UAAA;AACE,MAAAY,EAAgB,EAAK;AAAA,IACvB;AAAA,EACF,CAAC,GAEK4B,IAAoBC,EAAyB3B,GAAa,gBAAgB,CAAA,CAAE;AAElF,SACE,gBAAA4B;AAAA,IAACzC,EAAW;AAAA,IAAX;AAAA,MACC,QAAAJ;AAAA,MACA,SAAAG;AAAA,MACA,sBAAsB,MAAM;AAC1B,QAAK+B,EAAA;AAAA,MACP;AAAA,MACA,wBAAwBpB,KAAgBF;AAAA,MACxC,oBAAoB,EAAE,aAAa;AAAA,MACnC,kBAAkB,EAAE,WAAW;AAAA,MAC/B,OAAO,EAAE,sBAAsB;AAAA,QAC7B,OAAOF,EAAWT,CAAqC;AAAA,MAAA,CACxD;AAAA,MAED,UAAA,gBAAA4C,EAACC,GAAA,EAAc,GAAGhB,GAChB,UAAA,gBAAAiB,EAACC,GAAA,EAAK,eAAc,UAAS,KAAK,IAAI,YAAW,WAC/C,UAAA;AAAA,QAAA,gBAAAH,EAACzC,EAAW,MAAX,EAAgB,MAAK,MAAM,UAAA,EAAE,0BAA0B,GAAE;AAAA,QAC1D,gBAAAyC;AAAA,UAACI;AAAA,UAAA;AAAA,YACC,MAAK;AAAA,YACL,OAAO,EAAE,oBAAoB;AAAA,YAC7B,aAAa,EAAE,0BAA0B;AAAA,YACzC,YAAU;AAAA,YACV,YAAY9B,EAAe,WAAW;AAAA,YACtC,SAASA,EAAe,IAAI,CAAAE,OAAS;AAAA,cACnC,OAAOA;AAAA,cACP,OAAOf,EAAc,mBAAmBe,CAAI;AAAA,YAAA,EAC5C;AAAA,UAAA;AAAA,QAAA;AAAA,QAEHsB,IACC,gBAAAE;AAAA,UAACK;AAAA,UAAA;AAAA,YACC,cAAcjC,GAAa;AAAA,YAC3B,mBAAkB;AAAA,UAAA;AAAA,QAAA,IAGpB,gBAAA4B,EAACzC,EAAW,OAAX,EAAiB,QAAO,QAAO,OAAO,EAAE,uBAAuB,GAC7D,UAAA,EAAE,6BAA6B,EAAA,CAClC;AAAA,MAAA,EAAA,CAEJ,EAAA,CACF;AAAA,IAAA;AAAA,EAAA;AAGN;"}
|
|
@@ -9,15 +9,12 @@ import "@gusto/embedded-api/models/errors/gustoembeddederror";
|
|
|
9
9
|
import "@gusto/embedded-api/models/errors/sdkvalidationerror";
|
|
10
10
|
import "@gusto/embedded-api/models/errors/unprocessableentityerror";
|
|
11
11
|
import "@gusto/embedded-api/models/errors/httpclienterrors";
|
|
12
|
-
import "dompurify";
|
|
13
|
-
import "../../../../contexts/LocaleProvider/useLocale.js";
|
|
14
12
|
import "../../../../shared/constants.js";
|
|
15
13
|
import "../../../../contexts/ComponentAdapter/useComponentContext.js";
|
|
16
|
-
import "../../../../contexts/LoadingIndicatorProvider/useLoadingIndicator.js";
|
|
17
14
|
import { createCompoundContext as t } from "../../../Base/createCompoundContext.js";
|
|
18
|
-
const [
|
|
15
|
+
const [c, d] = t("TaxRateManagementContext");
|
|
19
16
|
export {
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
d as TaxRateManagementProvider,
|
|
18
|
+
c as useTaxRateManagement
|
|
22
19
|
};
|
|
23
20
|
//# sourceMappingURL=context.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.js","sources":["../../../../../src/components/Company/StateTaxes/TaxRateManagement/context.ts"],"sourcesContent":["import type { TaxRequirementSet } from '@gusto/embedded-api/models/components/taxrequirementset'\nimport { createCompoundContext } from '@/components/Base'\n\n/**\n * A state's effective-dated requirement sets for a single key, grouped for history display,\n * plus any future-dated candidate sets available to schedule against.\n *\n * @internal\n */\nexport interface TaxRateKeyGroup {\n key: string\n label?: string\n sets: TaxRequirementSet[]\n candidateSets: TaxRequirementSet[]\n}\n\ninterface TaxRateManagementContextType {\n state: string\n groups: TaxRateKeyGroup[]\n isPendingUpdate: boolean\n handleCancel: () => void\n handleAddRate: (\n key: string,\n effectiveFrom: string,\n requirements: { key: string; value: string }[],\n ) => Promise<boolean>\n}\n\nconst [useTaxRateManagement, TaxRateManagementProvider] =\n createCompoundContext<TaxRateManagementContextType>('TaxRateManagementContext')\n\nexport { useTaxRateManagement, TaxRateManagementProvider }\n"],"names":["useTaxRateManagement","TaxRateManagementProvider","createCompoundContext"],"mappings":"
|
|
1
|
+
{"version":3,"file":"context.js","sources":["../../../../../src/components/Company/StateTaxes/TaxRateManagement/context.ts"],"sourcesContent":["import type { TaxRequirementSet } from '@gusto/embedded-api/models/components/taxrequirementset'\nimport { createCompoundContext } from '@/components/Base'\n\n/**\n * A state's effective-dated requirement sets for a single key, grouped for history display,\n * plus any future-dated candidate sets available to schedule against.\n *\n * @internal\n */\nexport interface TaxRateKeyGroup {\n key: string\n label?: string\n sets: TaxRequirementSet[]\n candidateSets: TaxRequirementSet[]\n}\n\ninterface TaxRateManagementContextType {\n state: string\n groups: TaxRateKeyGroup[]\n isPendingUpdate: boolean\n handleCancel: () => void\n handleAddRate: (\n key: string,\n effectiveFrom: string,\n requirements: { key: string; value: string }[],\n ) => Promise<boolean>\n}\n\nconst [useTaxRateManagement, TaxRateManagementProvider] =\n createCompoundContext<TaxRateManagementContextType>('TaxRateManagementContext')\n\nexport { useTaxRateManagement, TaxRateManagementProvider }\n"],"names":["useTaxRateManagement","TaxRateManagementProvider","createCompoundContext"],"mappings":";;;;;;;;;;;;;;AA4BA,MAAM,CAACA,GAAsBC,CAAyB,IACpDC,EAAoD,0BAA0B;"}
|
|
@@ -1,34 +1,41 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { getUniqueRhfKey as i } from "../shared/rhfKey.js";
|
|
2
|
+
import { formatDateToStringDate as m } from "../../../../helpers/dateFormatting.js";
|
|
3
|
+
function v(r) {
|
|
4
|
+
return typeof r.effectiveFrom == "string" && r.effectiveFrom.length > 0;
|
|
4
5
|
}
|
|
5
|
-
function
|
|
6
|
-
const
|
|
7
|
-
(
|
|
6
|
+
function F(r) {
|
|
7
|
+
const n = m(/* @__PURE__ */ new Date()) ?? "", s = r.filter(v).sort((e, t) => e.effectiveFrom.localeCompare(t.effectiveFrom)), c = s.reduce(
|
|
8
|
+
(e, t, o) => t.effectiveFrom <= n ? o : e,
|
|
8
9
|
-1
|
|
9
10
|
);
|
|
10
|
-
return
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
!
|
|
14
|
-
|
|
11
|
+
return s.map((e, t) => {
|
|
12
|
+
const o = {}, a = e.requirements ?? [];
|
|
13
|
+
a.forEach((f, u) => {
|
|
14
|
+
!f.key || f.editable === !1 || (o[i(f, u, a)] = f.value === null || f.value === void 0 ? "" : String(f.value));
|
|
15
|
+
});
|
|
16
|
+
const l = t === c ? "current" : t > c ? "scheduled" : "historical";
|
|
15
17
|
return {
|
|
16
|
-
id: `${
|
|
17
|
-
effectiveFrom:
|
|
18
|
-
status:
|
|
19
|
-
values:
|
|
18
|
+
id: `${e.key ?? "set"}-${e.effectiveFrom}-${t}`,
|
|
19
|
+
effectiveFrom: e.effectiveFrom,
|
|
20
|
+
status: l,
|
|
21
|
+
values: o
|
|
20
22
|
};
|
|
21
23
|
});
|
|
22
24
|
}
|
|
23
|
-
function
|
|
24
|
-
const
|
|
25
|
-
for (const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
function h(r) {
|
|
26
|
+
const n = /* @__PURE__ */ new Map();
|
|
27
|
+
for (const s of r) {
|
|
28
|
+
const c = s.requirements ?? [];
|
|
29
|
+
c.forEach((e, t) => {
|
|
30
|
+
if (!e.key || e.editable === !1) return;
|
|
31
|
+
const o = i(e, t, c);
|
|
32
|
+
n.has(o) || n.set(o, { key: o, label: e.label });
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
return Array.from(n.values());
|
|
29
36
|
}
|
|
30
37
|
export {
|
|
31
|
-
|
|
32
|
-
|
|
38
|
+
h as extractRequirementColumns,
|
|
39
|
+
F as toHistoryRows
|
|
33
40
|
};
|
|
34
41
|
//# sourceMappingURL=toHistoryRows.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toHistoryRows.js","sources":["../../../../../src/components/Company/StateTaxes/TaxRateManagement/toHistoryRows.ts"],"sourcesContent":["import type { TaxRequirementSet } from '@gusto/embedded-api/models/components/taxrequirementset'\nimport { formatDateToStringDate } from '@/helpers/dateFormatting'\n\n/** @internal */\nexport type HistoryRowStatus = 'current' | 'scheduled' | 'historical'\n\n/** @internal */\nexport interface HistoryRow {\n id: string\n effectiveFrom: string\n status: HistoryRowStatus\n values: Record<string, string>\n}\n\n/** @internal */\nexport interface RequirementColumn {\n key: string\n label?: string\n}\n\nfunction isEffectiveDated(\n set: TaxRequirementSet,\n): set is TaxRequirementSet & { effectiveFrom: string } {\n return typeof set.effectiveFrom === 'string' && set.effectiveFrom.length > 0\n}\n\n/**\n * Tags each effective-dated requirement set for a key as current, scheduled (future), or\n * historical (past), relative to today.\n *\n * @internal\n */\nexport function toHistoryRows(sets: TaxRequirementSet[]): HistoryRow[] {\n const today = formatDateToStringDate(new Date()) ?? ''\n const sorted = sets\n .filter(isEffectiveDated)\n .sort((a, b) => a.effectiveFrom.localeCompare(b.effectiveFrom))\n\n const currentIndex = sorted.reduce(\n (acc, set, idx) => (set.effectiveFrom <= today ? idx : acc),\n -1,\n )\n\n return sorted.map((set, idx) => {\n const values: Record<string, string> = {}\n
|
|
1
|
+
{"version":3,"file":"toHistoryRows.js","sources":["../../../../../src/components/Company/StateTaxes/TaxRateManagement/toHistoryRows.ts"],"sourcesContent":["import type { TaxRequirementSet } from '@gusto/embedded-api/models/components/taxrequirementset'\nimport { getUniqueRhfKey } from '../shared/rhfKey'\nimport { formatDateToStringDate } from '@/helpers/dateFormatting'\n\n/** @internal */\nexport type HistoryRowStatus = 'current' | 'scheduled' | 'historical'\n\n/** @internal */\nexport interface HistoryRow {\n id: string\n effectiveFrom: string\n status: HistoryRowStatus\n values: Record<string, string>\n}\n\n/** @internal */\nexport interface RequirementColumn {\n key: string\n label?: string\n}\n\nfunction isEffectiveDated(\n set: TaxRequirementSet,\n): set is TaxRequirementSet & { effectiveFrom: string } {\n return typeof set.effectiveFrom === 'string' && set.effectiveFrom.length > 0\n}\n\n/**\n * Tags each effective-dated requirement set for a key as current, scheduled (future), or\n * historical (past), relative to today.\n *\n * @internal\n */\nexport function toHistoryRows(sets: TaxRequirementSet[]): HistoryRow[] {\n const today = formatDateToStringDate(new Date()) ?? ''\n const sorted = sets\n .filter(isEffectiveDated)\n .sort((a, b) => a.effectiveFrom.localeCompare(b.effectiveFrom))\n\n const currentIndex = sorted.reduce(\n (acc, set, idx) => (set.effectiveFrom <= today ? idx : acc),\n -1,\n )\n\n return sorted.map((set, idx) => {\n const values: Record<string, string> = {}\n const requirements = set.requirements ?? []\n requirements.forEach((requirement, reqIndex) => {\n if (!requirement.key || requirement.editable === false) return\n values[getUniqueRhfKey(requirement, reqIndex, requirements)] =\n requirement.value === null || requirement.value === undefined\n ? ''\n : String(requirement.value)\n })\n const status: HistoryRowStatus =\n idx === currentIndex ? 'current' : idx > currentIndex ? 'scheduled' : 'historical'\n return {\n id: `${set.key ?? 'set'}-${set.effectiveFrom}-${idx}`,\n effectiveFrom: set.effectiveFrom,\n status,\n values,\n }\n })\n}\n\n/**\n * Builds the union of editable requirement keys/labels across a set of requirement sets,\n * in first-seen order, for use as dynamic table columns.\n *\n * @internal\n */\nexport function extractRequirementColumns(sets: TaxRequirementSet[]): RequirementColumn[] {\n const seen = new Map<string, RequirementColumn>()\n for (const set of sets) {\n const requirements = set.requirements ?? []\n requirements.forEach((requirement, index) => {\n if (!requirement.key || requirement.editable === false) return\n const columnKey = getUniqueRhfKey(requirement, index, requirements)\n if (!seen.has(columnKey)) {\n seen.set(columnKey, { key: columnKey, label: requirement.label })\n }\n })\n }\n return Array.from(seen.values())\n}\n"],"names":["isEffectiveDated","set","toHistoryRows","sets","today","formatDateToStringDate","sorted","a","b","currentIndex","acc","idx","values","requirements","requirement","reqIndex","getUniqueRhfKey","status","extractRequirementColumns","seen","index","columnKey"],"mappings":";;AAqBA,SAASA,EACPC,GACsD;AACtD,SAAO,OAAOA,EAAI,iBAAkB,YAAYA,EAAI,cAAc,SAAS;AAC7E;AAQO,SAASC,EAAcC,GAAyC;AACrE,QAAMC,IAAQC,EAAuB,oBAAI,KAAA,CAAM,KAAK,IAC9CC,IAASH,EACZ,OAAOH,CAAgB,EACvB,KAAK,CAACO,GAAGC,MAAMD,EAAE,cAAc,cAAcC,EAAE,aAAa,CAAC,GAE1DC,IAAeH,EAAO;AAAA,IAC1B,CAACI,GAAKT,GAAKU,MAASV,EAAI,iBAAiBG,IAAQO,IAAMD;AAAA,IACvD;AAAA,EAAA;AAGF,SAAOJ,EAAO,IAAI,CAACL,GAAKU,MAAQ;AAC9B,UAAMC,IAAiC,CAAA,GACjCC,IAAeZ,EAAI,gBAAgB,CAAA;AACzC,IAAAY,EAAa,QAAQ,CAACC,GAAaC,MAAa;AAC9C,MAAI,CAACD,EAAY,OAAOA,EAAY,aAAa,OACjDF,EAAOI,EAAgBF,GAAaC,GAAUF,CAAY,CAAC,IACzDC,EAAY,UAAU,QAAQA,EAAY,UAAU,SAChD,KACA,OAAOA,EAAY,KAAK;AAAA,IAChC,CAAC;AACD,UAAMG,IACJN,MAAQF,IAAe,YAAYE,IAAMF,IAAe,cAAc;AACxE,WAAO;AAAA,MACL,IAAI,GAAGR,EAAI,OAAO,KAAK,IAAIA,EAAI,aAAa,IAAIU,CAAG;AAAA,MACnD,eAAeV,EAAI;AAAA,MACnB,QAAAgB;AAAA,MACA,QAAAL;AAAA,IAAA;AAAA,EAEJ,CAAC;AACH;AAQO,SAASM,EAA0Bf,GAAgD;AACxF,QAAMgB,wBAAW,IAAA;AACjB,aAAWlB,KAAOE,GAAM;AACtB,UAAMU,IAAeZ,EAAI,gBAAgB,CAAA;AACzC,IAAAY,EAAa,QAAQ,CAACC,GAAaM,MAAU;AAC3C,UAAI,CAACN,EAAY,OAAOA,EAAY,aAAa,GAAO;AACxD,YAAMO,IAAYL,EAAgBF,GAAaM,GAAOP,CAAY;AAClE,MAAKM,EAAK,IAAIE,CAAS,KACrBF,EAAK,IAAIE,GAAW,EAAE,KAAKA,GAAW,OAAOP,EAAY,OAAO;AAAA,IAEpE,CAAC;AAAA,EACH;AACA,SAAO,MAAM,KAAKK,EAAK,OAAA,CAAQ;AACjC;"}
|
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
import { TaxRequirement } from '@gusto/embedded-api/models/components/taxrequirement';
|
|
2
2
|
interface RequirementFieldsProps {
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* Requirements to render as inputs, nested under `requirementSetKey` in the form's RHF path.
|
|
5
|
+
* Non-editable requirements, and requirements resolved as never-applicable against a
|
|
6
|
+
* non-editable sibling, are dropped via {@link prepareRequirements} before rendering.
|
|
7
|
+
*/
|
|
4
8
|
requirements: TaxRequirement[] | undefined;
|
|
5
9
|
/** RHF path segment the requirements are nested under, e.g. `taxrates` or `fields`. */
|
|
6
10
|
requirementSetKey: string;
|
|
7
11
|
}
|
|
8
12
|
/**
|
|
9
13
|
* Renders one form field per editable, currently-applicable requirement, filtering
|
|
10
|
-
* out
|
|
11
|
-
*
|
|
12
|
-
*
|
|
14
|
+
* out requirements with no `key` (the API doesn't guarantee one, and without it there's no stable
|
|
15
|
+
* form path to register) and requirements whose `applicableIf` constraints aren't satisfied by
|
|
16
|
+
* the form's current values.
|
|
13
17
|
*
|
|
14
18
|
* @internal
|
|
15
19
|
*/
|
|
@@ -1,24 +1,25 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { useFormContext as
|
|
3
|
-
import { getUniqueRhfKey as
|
|
1
|
+
import { jsx as e, Fragment as n } from "react/jsx-runtime";
|
|
2
|
+
import { useFormContext as a, useWatch as f } from "react-hook-form";
|
|
3
|
+
import { getUniqueRhfKey as u } from "./rhfKey.js";
|
|
4
4
|
import { isRequirementApplicable as c } from "./applicableIf.js";
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
import { prepareRequirements as l } from "./prepareRequirements.js";
|
|
6
|
+
import { QuestionInput as d } from "../../../Common/TaxInputs/TaxInputs.js";
|
|
7
|
+
function F({ requirements: i, requirementSetKey: r }) {
|
|
8
|
+
const { control: m } = a(), s = f({ control: m }), o = l(i ?? []);
|
|
9
|
+
return /* @__PURE__ */ e(n, { children: o.flatMap((t, p) => t.key ? c(t, r, s) ? [
|
|
10
|
+
/* @__PURE__ */ e(n, { children: /* @__PURE__ */ e(
|
|
11
|
+
d,
|
|
11
12
|
{
|
|
12
13
|
requirement: {
|
|
13
14
|
...t,
|
|
14
|
-
key: `${
|
|
15
|
+
key: `${r}.${u(t, p, o)}`
|
|
15
16
|
},
|
|
16
17
|
questionType: t.metadata?.type ?? "Text"
|
|
17
18
|
}
|
|
18
|
-
) }, `${t.key}-${
|
|
19
|
+
) }, `${t.key}-${p}`)
|
|
19
20
|
] : [] : []) });
|
|
20
21
|
}
|
|
21
22
|
export {
|
|
22
|
-
|
|
23
|
+
F as RequirementFields
|
|
23
24
|
};
|
|
24
25
|
//# sourceMappingURL=RequirementFields.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RequirementFields.js","sources":["../../../../../src/components/Company/StateTaxes/shared/RequirementFields.tsx"],"sourcesContent":["import { Fragment } from 'react/jsx-runtime'\nimport { useFormContext, useWatch } from 'react-hook-form'\nimport type { TaxRequirement } from '@gusto/embedded-api/models/components/taxrequirement'\nimport { getUniqueRhfKey } from './rhfKey'\nimport { isRequirementApplicable, type StateTaxesFormValues } from './applicableIf'\nimport { QuestionInput } from '@/components/Common/TaxInputs/TaxInputs'\n\ninterface RequirementFieldsProps {\n
|
|
1
|
+
{"version":3,"file":"RequirementFields.js","sources":["../../../../../src/components/Company/StateTaxes/shared/RequirementFields.tsx"],"sourcesContent":["import { Fragment } from 'react/jsx-runtime'\nimport { useFormContext, useWatch } from 'react-hook-form'\nimport type { TaxRequirement } from '@gusto/embedded-api/models/components/taxrequirement'\nimport { getUniqueRhfKey } from './rhfKey'\nimport { isRequirementApplicable, type StateTaxesFormValues } from './applicableIf'\nimport { prepareRequirements } from './prepareRequirements'\nimport { QuestionInput } from '@/components/Common/TaxInputs/TaxInputs'\n\ninterface RequirementFieldsProps {\n /**\n * Requirements to render as inputs, nested under `requirementSetKey` in the form's RHF path.\n * Non-editable requirements, and requirements resolved as never-applicable against a\n * non-editable sibling, are dropped via {@link prepareRequirements} before rendering.\n */\n requirements: TaxRequirement[] | undefined\n /** RHF path segment the requirements are nested under, e.g. `taxrates` or `fields`. */\n requirementSetKey: string\n}\n\n/**\n * Renders one form field per editable, currently-applicable requirement, filtering\n * out requirements with no `key` (the API doesn't guarantee one, and without it there's no stable\n * form path to register) and requirements whose `applicableIf` constraints aren't satisfied by\n * the form's current values.\n *\n * @internal\n */\nexport function RequirementFields({ requirements, requirementSetKey }: RequirementFieldsProps) {\n const { control } = useFormContext()\n const watchedValues = useWatch({ control }) as StateTaxesFormValues\n const preparedRequirements = prepareRequirements(requirements ?? [])\n\n return (\n <>\n {preparedRequirements.flatMap((requirement, index) => {\n if (!requirement.key) return []\n if (!isRequirementApplicable(requirement, requirementSetKey, watchedValues)) return []\n return [\n <Fragment key={`${requirement.key}-${index}`}>\n <QuestionInput\n requirement={{\n ...requirement,\n key: `${requirementSetKey}.${getUniqueRhfKey(requirement, index, preparedRequirements)}`,\n }}\n questionType={requirement.metadata?.type ?? 'Text'}\n />\n </Fragment>,\n ]\n })}\n </>\n )\n}\n"],"names":["RequirementFields","requirements","requirementSetKey","control","useFormContext","watchedValues","useWatch","preparedRequirements","prepareRequirements","jsx","Fragment","requirement","index","isRequirementApplicable","QuestionInput","getUniqueRhfKey"],"mappings":";;;;;;AA2BO,SAASA,EAAkB,EAAE,cAAAC,GAAc,mBAAAC,KAA6C;AAC7F,QAAM,EAAE,SAAAC,EAAA,IAAYC,EAAA,GACdC,IAAgBC,EAAS,EAAE,SAAAH,GAAS,GACpCI,IAAuBC,EAAoBP,KAAgB,EAAE;AAEnE,SACE,gBAAAQ,EAAAC,GAAA,EACG,UAAAH,EAAqB,QAAQ,CAACI,GAAaC,MACrCD,EAAY,MACZE,EAAwBF,GAAaT,GAAmBG,CAAa,IACnE;AAAA,IACL,gBAAAI,EAACC,GAAA,EACC,UAAA,gBAAAD;AAAA,MAACK;AAAA,MAAA;AAAA,QACC,aAAa;AAAA,UACX,GAAGH;AAAA,UACH,KAAK,GAAGT,CAAiB,IAAIa,EAAgBJ,GAAaC,GAAOL,CAAoB,CAAC;AAAA,QAAA;AAAA,QAExF,cAAcI,EAAY,UAAU,QAAQ;AAAA,MAAA;AAAA,IAAA,KANjC,GAAGA,EAAY,GAAG,IAAIC,CAAK,EAQ1C;AAAA,EAAA,IAVkF,CAAA,IADvD,CAAA,CAa9B,EAAA,CACH;AAEJ;"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { TaxRequirement } from '@gusto/embedded-api/models/components/taxrequirement';
|
|
2
|
+
/**
|
|
3
|
+
* Resolves each requirement's `applicableIf` constraints against non-editable (system/agency-set)
|
|
4
|
+
* siblings, and drops requirements that can never become applicable — mirroring gws-flows'
|
|
5
|
+
* `TaxRequirements::Edit.prepare_requirements`, which performs this same resolution server-side
|
|
6
|
+
* before Rails renders its own edit view.
|
|
7
|
+
*
|
|
8
|
+
* @remarks
|
|
9
|
+
* A constraint referencing an editable sibling is left untouched, since it can only be resolved
|
|
10
|
+
* dynamically against the user's current form input (see {@link isRequirementApplicable}). A
|
|
11
|
+
* constraint referencing a non-editable sibling is resolved once here, against that sibling's
|
|
12
|
+
* fetched `value`, since a non-editable value can never change over the lifetime of the form:
|
|
13
|
+
* - If the sibling's value satisfies the constraint, the constraint is dropped (the requirement
|
|
14
|
+
* is always applicable).
|
|
15
|
+
* - If it doesn't, the whole requirement is dropped — it can never become applicable.
|
|
16
|
+
*
|
|
17
|
+
* Non-editable requirements are dropped unconditionally, since they never become form fields.
|
|
18
|
+
*
|
|
19
|
+
* @internal
|
|
20
|
+
*/
|
|
21
|
+
export declare function prepareRequirements(requirements: TaxRequirement[]): TaxRequirement[];
|
|
22
|
+
/**
|
|
23
|
+
* Whether a requirement set has anything left to edit once {@link prepareRequirements} resolves
|
|
24
|
+
* non-editable-sibling constraints and drops non-editable/unsatisfiable requirements — mirroring
|
|
25
|
+
* gws-flows' `TaxRequirements::Edit.set_editable?`.
|
|
26
|
+
*
|
|
27
|
+
* @internal
|
|
28
|
+
*/
|
|
29
|
+
export declare function isRequirementSetEditable(requirements: TaxRequirement[]): boolean;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
function s(n) {
|
|
2
|
+
return n.flatMap((t) => {
|
|
3
|
+
if (t.editable === !1) return [];
|
|
4
|
+
const l = t.applicableIf ?? [], a = [];
|
|
5
|
+
for (const e of l) {
|
|
6
|
+
const i = n.find((o) => o.key === e.key);
|
|
7
|
+
if (!i || i.editable !== !1) {
|
|
8
|
+
a.push(e);
|
|
9
|
+
continue;
|
|
10
|
+
}
|
|
11
|
+
if (i.value !== e.value)
|
|
12
|
+
return [];
|
|
13
|
+
}
|
|
14
|
+
return [{ ...t, applicableIf: a }];
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
function r(n) {
|
|
18
|
+
return s(n).length > 0;
|
|
19
|
+
}
|
|
20
|
+
export {
|
|
21
|
+
r as isRequirementSetEditable,
|
|
22
|
+
s as prepareRequirements
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=prepareRequirements.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prepareRequirements.js","sources":["../../../../../src/components/Company/StateTaxes/shared/prepareRequirements.ts"],"sourcesContent":["import type { TaxRequirement } from '@gusto/embedded-api/models/components/taxrequirement'\n\n/**\n * Resolves each requirement's `applicableIf` constraints against non-editable (system/agency-set)\n * siblings, and drops requirements that can never become applicable — mirroring gws-flows'\n * `TaxRequirements::Edit.prepare_requirements`, which performs this same resolution server-side\n * before Rails renders its own edit view.\n *\n * @remarks\n * A constraint referencing an editable sibling is left untouched, since it can only be resolved\n * dynamically against the user's current form input (see {@link isRequirementApplicable}). A\n * constraint referencing a non-editable sibling is resolved once here, against that sibling's\n * fetched `value`, since a non-editable value can never change over the lifetime of the form:\n * - If the sibling's value satisfies the constraint, the constraint is dropped (the requirement\n * is always applicable).\n * - If it doesn't, the whole requirement is dropped — it can never become applicable.\n *\n * Non-editable requirements are dropped unconditionally, since they never become form fields.\n *\n * @internal\n */\nexport function prepareRequirements(requirements: TaxRequirement[]): TaxRequirement[] {\n return requirements.flatMap(requirement => {\n if (requirement.editable === false) return []\n\n const constraints = requirement.applicableIf ?? []\n const resolvedConstraints: typeof constraints = []\n\n for (const constraint of constraints) {\n const sibling = requirements.find(candidate => candidate.key === constraint.key)\n\n if (!sibling || sibling.editable !== false) {\n resolvedConstraints.push(constraint)\n continue\n }\n\n if (sibling.value === constraint.value) continue\n\n return []\n }\n\n return [{ ...requirement, applicableIf: resolvedConstraints }]\n })\n}\n\n/**\n * Whether a requirement set has anything left to edit once {@link prepareRequirements} resolves\n * non-editable-sibling constraints and drops non-editable/unsatisfiable requirements — mirroring\n * gws-flows' `TaxRequirements::Edit.set_editable?`.\n *\n * @internal\n */\nexport function isRequirementSetEditable(requirements: TaxRequirement[]): boolean {\n return prepareRequirements(requirements).length > 0\n}\n"],"names":["prepareRequirements","requirements","requirement","constraints","resolvedConstraints","constraint","sibling","candidate","isRequirementSetEditable"],"mappings":"AAqBO,SAASA,EAAoBC,GAAkD;AACpF,SAAOA,EAAa,QAAQ,CAAAC,MAAe;AACzC,QAAIA,EAAY,aAAa,GAAO,QAAO,CAAA;AAE3C,UAAMC,IAAcD,EAAY,gBAAgB,CAAA,GAC1CE,IAA0C,CAAA;AAEhD,eAAWC,KAAcF,GAAa;AACpC,YAAMG,IAAUL,EAAa,KAAK,OAAaM,EAAU,QAAQF,EAAW,GAAG;AAE/E,UAAI,CAACC,KAAWA,EAAQ,aAAa,IAAO;AAC1C,QAAAF,EAAoB,KAAKC,CAAU;AACnC;AAAA,MACF;AAEA,UAAIC,EAAQ,UAAUD,EAAW;AAEjC,eAAO,CAAA;AAAA,IACT;AAEA,WAAO,CAAC,EAAE,GAAGH,GAAa,cAAcE,GAAqB;AAAA,EAC/D,CAAC;AACH;AASO,SAASI,EAAyBP,GAAyC;AAChF,SAAOD,EAAoBC,CAAY,EAAE,SAAS;AACpD;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|