@gusto/embedded-react-sdk 0.54.1 → 0.55.1
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 +28 -0
- package/dist/components/Common/TaxInputs/TaxInputs.js +65 -64
- package/dist/components/Common/TaxInputs/TaxInputs.js.map +1 -1
- package/dist/components/Common/UI/Breadcrumbs/Breadcrumbs.js +1 -1
- package/dist/components/Common/UI/FileInput/FileInput.js +1 -1
- package/dist/components/Common/UI/ProgressBar/ProgressBar.js +4 -4
- package/dist/components/Common/UI/Select/Select.module.scss.js +5 -5
- package/dist/components/Company/AssignSignatory/CreateSignatory/useCreateSignatory.js +3 -4
- package/dist/components/Company/AssignSignatory/CreateSignatory/useCreateSignatory.js.map +1 -1
- package/dist/components/Company/AssignSignatory/InviteSignatory/useInviteSignatory.js +3 -4
- package/dist/components/Company/AssignSignatory/InviteSignatory/useInviteSignatory.js.map +1 -1
- package/dist/components/Company/AssignSignatory/useAssignSignatory.js +5 -6
- package/dist/components/Company/AssignSignatory/useAssignSignatory.js.map +1 -1
- package/dist/components/Company/BankAccount/BankAccountForm/context.js +3 -4
- package/dist/components/Company/BankAccount/BankAccountForm/context.js.map +1 -1
- package/dist/components/Company/DocumentSigner/DocumentList/useDocumentList.js +3 -4
- package/dist/components/Company/DocumentSigner/DocumentList/useDocumentList.js.map +1 -1
- package/dist/components/Company/FederalTaxes/useFederalTaxes.js +5 -6
- package/dist/components/Company/FederalTaxes/useFederalTaxes.js.map +1 -1
- package/dist/components/Company/Industry/Context.js +6 -7
- package/dist/components/Company/Industry/Context.js.map +1 -1
- package/dist/components/Company/Locations/LocationForm/useLocationForm.js +3 -4
- package/dist/components/Company/Locations/LocationForm/useLocationForm.js.map +1 -1
- package/dist/components/Company/Locations/LocationsList/useLocationsList.js +3 -4
- package/dist/components/Company/Locations/LocationsList/useLocationsList.js.map +1 -1
- package/dist/components/Company/OnboardingFlow/OnboardingFlow.d.ts +1 -1
- package/dist/components/Company/OnboardingFlow/OnboardingFlow.js +21 -15
- package/dist/components/Company/OnboardingFlow/OnboardingFlow.js.map +1 -1
- package/dist/components/Company/OnboardingFlow/OnboardingFlowComponents.d.ts +8 -0
- package/dist/components/Company/OnboardingFlow/OnboardingFlowComponents.js +12 -5
- package/dist/components/Company/OnboardingFlow/OnboardingFlowComponents.js.map +1 -1
- package/dist/components/Company/OnboardingOverview/context.js +3 -4
- package/dist/components/Company/OnboardingOverview/context.js.map +1 -1
- package/dist/components/Company/StateTaxes/StateTaxesForm/context.js +3 -4
- package/dist/components/Company/StateTaxes/StateTaxesForm/context.js.map +1 -1
- package/dist/components/Company/StateTaxes/StateTaxesList/context.js +3 -4
- package/dist/components/Company/StateTaxes/StateTaxesList/context.js.map +1 -1
- package/dist/components/Company/StateTaxes/TaxRateManagement/context.js +3 -4
- package/dist/components/Company/StateTaxes/TaxRateManagement/context.js.map +1 -1
- package/dist/components/Contractor/Payments/CreateHistoricalPayment/CreateHistoricalPayment.d.ts +4 -2
- package/dist/components/Contractor/Payments/CreateHistoricalPayment/CreateHistoricalPayment.js +148 -117
- package/dist/components/Contractor/Payments/CreateHistoricalPayment/CreateHistoricalPayment.js.map +1 -1
- package/dist/components/Contractor/Payments/CreatePayment/PreviewPresentation.js +56 -55
- package/dist/components/Contractor/Payments/CreatePayment/PreviewPresentation.js.map +1 -1
- package/dist/components/Contractor/Payments/CreatePaymentFlow/CreatePaymentFlow.d.ts +1 -1
- package/dist/components/Contractor/Payments/CreatePaymentFlow/CreatePaymentFlow.js +15 -12
- package/dist/components/Contractor/Payments/CreatePaymentFlow/CreatePaymentFlow.js.map +1 -1
- package/dist/components/Contractor/Payments/HistoricalPaymentFlow/HistoricalPaymentFlow.d.ts +69 -0
- package/dist/components/Contractor/Payments/HistoricalPaymentFlow/HistoricalPaymentFlow.js +48 -0
- package/dist/components/Contractor/Payments/HistoricalPaymentFlow/HistoricalPaymentFlow.js.map +1 -0
- package/dist/components/Contractor/Payments/HistoricalPaymentFlow/HistoricalPaymentFlowComponents.d.ts +20 -0
- package/dist/components/Contractor/Payments/HistoricalPaymentFlow/HistoricalPaymentFlowComponents.js +25 -0
- package/dist/components/Contractor/Payments/HistoricalPaymentFlow/HistoricalPaymentFlowComponents.js.map +1 -0
- package/dist/components/Contractor/Payments/HistoricalPaymentFlow/historicalPaymentMachine.d.ts +20 -0
- package/dist/components/Contractor/Payments/HistoricalPaymentFlow/historicalPaymentMachine.js +24 -0
- package/dist/components/Contractor/Payments/HistoricalPaymentFlow/historicalPaymentMachine.js.map +1 -0
- package/dist/components/Contractor/Payments/HistoricalPaymentFlow/index.d.ts +2 -0
- package/dist/components/Contractor/Payments/HistoricalPaymentSummary/HistoricalPaymentSummary.js +16 -15
- package/dist/components/Contractor/Payments/HistoricalPaymentSummary/HistoricalPaymentSummary.js.map +1 -1
- package/dist/components/Contractor/Payments/PaymentFlow/PaymentFlowComponents.d.ts +2 -0
- package/dist/components/Contractor/Payments/PaymentFlow/PaymentFlowComponents.js +36 -23
- package/dist/components/Contractor/Payments/PaymentFlow/PaymentFlowComponents.js.map +1 -1
- package/dist/components/Contractor/Payments/PaymentFlow/paymentStateMachine.d.ts +10 -8
- package/dist/components/Contractor/Payments/PaymentFlow/paymentStateMachine.js +46 -25
- package/dist/components/Contractor/Payments/PaymentFlow/paymentStateMachine.js.map +1 -1
- package/dist/components/Contractor/Payments/PaymentHistory/PaymentHistoryPresentation.js +53 -52
- package/dist/components/Contractor/Payments/PaymentHistory/PaymentHistoryPresentation.js.map +1 -1
- package/dist/components/Contractor/Payments/PaymentStatement/PaymentStatementPresentation.js +37 -47
- package/dist/components/Contractor/Payments/PaymentStatement/PaymentStatementPresentation.js.map +1 -1
- package/dist/components/Contractor/Payments/PaymentsList/PaymentsList.js +47 -44
- package/dist/components/Contractor/Payments/PaymentsList/PaymentsList.js.map +1 -1
- package/dist/components/Contractor/Payments/PaymentsList/PaymentsListPresentation.d.ts +2 -1
- package/dist/components/Contractor/Payments/PaymentsList/PaymentsListPresentation.js +65 -53
- package/dist/components/Contractor/Payments/PaymentsList/PaymentsListPresentation.js.map +1 -1
- package/dist/components/Contractor/Payments/PaymentsList/PaymentsListPresentation.module.scss.js +6 -4
- package/dist/components/Contractor/Payments/PaymentsList/PaymentsListPresentation.module.scss.js.map +1 -1
- package/dist/components/Contractor/Payments/ViewPaymentFlow/ViewPaymentFlow.d.ts +1 -1
- package/dist/components/Contractor/Payments/ViewPaymentFlow/ViewPaymentFlow.js +22 -19
- package/dist/components/Contractor/Payments/ViewPaymentFlow/ViewPaymentFlow.js.map +1 -1
- package/dist/components/Contractor/Payments/shared/PaymentSummaryBlock/PaymentSummaryBlock.d.ts +2 -8
- package/dist/components/Contractor/Payments/shared/PaymentSummaryBlock/PaymentSummaryBlock.js +43 -42
- package/dist/components/Contractor/Payments/shared/PaymentSummaryBlock/PaymentSummaryBlock.js.map +1 -1
- package/dist/components/Contractor/Payments/shared/paymentAmounts.d.ts +32 -0
- package/dist/components/Contractor/Payments/shared/paymentAmounts.js +11 -0
- package/dist/components/Contractor/Payments/shared/paymentAmounts.js.map +1 -0
- package/dist/components/Contractor/Payments/shared/paymentAmounts.test.d.ts +1 -0
- package/dist/components/Contractor/Payments/shared/usePaymentAmountsEditor.d.ts +13 -4
- package/dist/components/Contractor/Payments/shared/usePaymentAmountsEditor.js +43 -38
- package/dist/components/Contractor/Payments/shared/usePaymentAmountsEditor.js.map +1 -1
- package/dist/components/Contractor/exports/contractorManagement.d.ts +1 -0
- package/dist/components/Contractor/exports/contractorManagement.js +34 -32
- package/dist/components/Contractor/exports/contractorManagement.js.map +1 -1
- package/dist/components/Contractor/shared/SelectContractors/SelectContractors.d.ts +6 -1
- package/dist/components/Contractor/shared/SelectContractors/SelectContractors.js +13 -12
- package/dist/components/Contractor/shared/SelectContractors/SelectContractors.js.map +1 -1
- package/dist/components/Contractor/shared/SelectContractors/useSelectContractors.d.ts +5 -1
- package/dist/components/Contractor/shared/SelectContractors/useSelectContractors.js +34 -32
- package/dist/components/Contractor/shared/SelectContractors/useSelectContractors.js.map +1 -1
- package/dist/components/Employee/Documents/onboarding/DocumentSigner/DocumentList/useDocumentList.js +3 -4
- package/dist/components/Employee/Documents/onboarding/DocumentSigner/DocumentList/useDocumentList.js.map +1 -1
- package/dist/components/Employee/FederalTaxes/shared/FederalTaxesView.js +1 -1
- package/dist/components/Employee/PaymentMethod/management/PaymentMethodBankForm.js +4 -4
- package/dist/components/Employee/PaymentMethod/onboarding/BankForm.js +4 -4
- package/dist/components/Flow/Flow.js +1 -1
- package/dist/components/Payroll/GrossUpModal/GrossUpModal.js +2 -3
- package/dist/components/Payroll/GrossUpModal/GrossUpModal.js.map +1 -1
- package/dist/components/Payroll/usePreparedPayrollData.js +8 -9
- package/dist/components/Payroll/usePreparedPayrollData.js.map +1 -1
- package/dist/contexts/GustoProvider/GustoProviderCustomUIAdapter.d.ts +6 -0
- package/dist/contexts/GustoProvider/GustoProviderCustomUIAdapter.js +36 -34
- package/dist/contexts/GustoProvider/GustoProviderCustomUIAdapter.js.map +1 -1
- package/dist/contexts/UnstableFeaturesProvider/UnstableFeaturesProvider.d.ts +22 -0
- package/dist/contexts/UnstableFeaturesProvider/UnstableFeaturesProvider.js +14 -0
- package/dist/contexts/UnstableFeaturesProvider/UnstableFeaturesProvider.js.map +1 -0
- package/dist/contexts/UnstableFeaturesProvider/WithUnstableFeature.d.ts +19 -0
- package/dist/contexts/UnstableFeaturesProvider/WithUnstableFeature.js +8 -0
- package/dist/contexts/UnstableFeaturesProvider/WithUnstableFeature.js.map +1 -0
- package/dist/contexts/UnstableFeaturesProvider/useUnstableFeature.d.ts +41 -0
- package/dist/contexts/UnstableFeaturesProvider/useUnstableFeature.js +14 -0
- package/dist/contexts/UnstableFeaturesProvider/useUnstableFeature.js.map +1 -0
- package/dist/contexts/index.d.ts +1 -0
- package/dist/i18n/en/Contractor.Payments.CreateHistoricalPayment.json.js +34 -32
- package/dist/i18n/en/Contractor.Payments.CreateHistoricalPayment.json.js.map +1 -1
- package/dist/i18n/en/Contractor.Payments.PaymentsList.json.js +20 -18
- package/dist/i18n/en/Contractor.Payments.PaymentsList.json.js.map +1 -1
- package/dist/i18n/en/common.json.d.ts +0 -21
- package/dist/i18n/types.d.ts +10 -2
- package/dist/shared/constants.d.ts +2 -0
- package/dist/shared/constants.js +1 -0
- package/dist/shared/constants.js.map +1 -1
- package/dist/style.css +1 -1
- package/dist/test-utils/renderWithProviders.d.ts +4 -1
- package/dist/test-utils/tableQueries.d.ts +9 -0
- package/docs/guides/endpoint-inventory.json +7 -0
- package/package.json +20 -20
|
@@ -3,6 +3,11 @@ export interface SelectContractorsProps {
|
|
|
3
3
|
companyId: string;
|
|
4
4
|
/** Called with the currently selected contractor ids whenever the selection changes. */
|
|
5
5
|
onSelectionChange: (selectedIds: string[]) => void;
|
|
6
|
+
/**
|
|
7
|
+
* Seeds selection state on mount. Pass the caller's own previously-selected ids to survive
|
|
8
|
+
* this component unmounting and remounting (e.g. behind a "Back" button).
|
|
9
|
+
*/
|
|
10
|
+
initialSelectedIds?: Iterable<string>;
|
|
6
11
|
/** Overrides the default empty-state title shown when no contractors match. */
|
|
7
12
|
emptyStateTitle?: string;
|
|
8
13
|
/** Overrides the default empty-state description shown when no contractors match. */
|
|
@@ -16,4 +21,4 @@ export interface SelectContractorsProps {
|
|
|
16
21
|
*
|
|
17
22
|
* @internal
|
|
18
23
|
*/
|
|
19
|
-
export declare function SelectContractors({ companyId, onSelectionChange, emptyStateTitle, emptyStateDescription, }: SelectContractorsProps): import("react").JSX.Element;
|
|
24
|
+
export declare function SelectContractors({ companyId, onSelectionChange, initialSelectedIds, emptyStateTitle, emptyStateDescription, }: SelectContractorsProps): import("react").JSX.Element;
|
|
@@ -1,23 +1,24 @@
|
|
|
1
1
|
import { jsx as o } from "react/jsx-runtime";
|
|
2
|
-
import { useMemo as
|
|
3
|
-
import { useSelectContractors as
|
|
4
|
-
import { SelectContractorsPresentation as
|
|
2
|
+
import { useMemo as d, useEffect as u } from "react";
|
|
3
|
+
import { useSelectContractors as m } from "./useSelectContractors.js";
|
|
4
|
+
import { SelectContractorsPresentation as f } from "./SelectContractorsPresentation.js";
|
|
5
5
|
import { BaseLayout as s } from "../../../Base/Base.js";
|
|
6
6
|
import "../../../Base/useBase.js";
|
|
7
|
-
function
|
|
7
|
+
function L({
|
|
8
8
|
companyId: a,
|
|
9
9
|
onSelectionChange: n,
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
initialSelectedIds: c,
|
|
11
|
+
emptyStateTitle: l,
|
|
12
|
+
emptyStateDescription: i
|
|
12
13
|
}) {
|
|
13
|
-
const e =
|
|
14
|
+
const e = m(a, c), r = e.isLoading ? null : [...e.selectedIds].sort().join(","), t = d(
|
|
14
15
|
() => r === null ? null : r.split(",").filter(Boolean),
|
|
15
16
|
[r]
|
|
16
17
|
);
|
|
17
|
-
return
|
|
18
|
+
return u(() => {
|
|
18
19
|
t !== null && n(t);
|
|
19
20
|
}, [t, n]), e.isLoading ? /* @__PURE__ */ o(s, { isLoading: !0, error: e.errorHandling.errors }) : /* @__PURE__ */ o(s, { error: e.errorHandling.errors, children: /* @__PURE__ */ o(
|
|
20
|
-
|
|
21
|
+
f,
|
|
21
22
|
{
|
|
22
23
|
contractors: e.data.contractors,
|
|
23
24
|
selectedIds: e.selectedIds,
|
|
@@ -28,12 +29,12 @@ function I({
|
|
|
28
29
|
onSearchClear: e.actions.onSearchClear,
|
|
29
30
|
pagination: e.pagination,
|
|
30
31
|
isFetching: e.status.isFetching,
|
|
31
|
-
emptyStateTitle:
|
|
32
|
-
emptyStateDescription:
|
|
32
|
+
emptyStateTitle: l,
|
|
33
|
+
emptyStateDescription: i
|
|
33
34
|
}
|
|
34
35
|
) });
|
|
35
36
|
}
|
|
36
37
|
export {
|
|
37
|
-
|
|
38
|
+
L as SelectContractors
|
|
38
39
|
};
|
|
39
40
|
//# sourceMappingURL=SelectContractors.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SelectContractors.js","sources":["../../../../../src/components/Contractor/shared/SelectContractors/SelectContractors.tsx"],"sourcesContent":["import { useEffect, useMemo } from 'react'\nimport { useSelectContractors } from './useSelectContractors'\nimport { SelectContractorsPresentation } from './SelectContractorsPresentation'\nimport { BaseLayout } from '@/components/Base'\n\n/** @internal */\nexport interface SelectContractorsProps {\n companyId: string\n /** Called with the currently selected contractor ids whenever the selection changes. */\n onSelectionChange: (selectedIds: string[]) => void\n /** Overrides the default empty-state title shown when no contractors match. */\n emptyStateTitle?: string\n /** Overrides the default empty-state description shown when no contractors match. */\n emptyStateDescription?: string\n}\n\n/**\n * Multi-select contractor table. Fetches and filters eligible contractors via\n * {@link useSelectContractors} and reports the current selection through\n * `onSelectionChange` rather than emitting an SDK event — the composing\n * screen is responsible for translating the selection into its own events.\n *\n * @internal\n */\nexport function SelectContractors({\n companyId,\n onSelectionChange,\n emptyStateTitle,\n emptyStateDescription,\n}: SelectContractorsProps) {\n const result = useSelectContractors(companyId)\n\n const selectedIdsKey = result.isLoading ? null : [...result.selectedIds].sort().join(',')\n\n const selectedIds = useMemo(\n () => (selectedIdsKey === null ? null : selectedIdsKey.split(',').filter(Boolean)),\n [selectedIdsKey],\n )\n\n useEffect(() => {\n if (selectedIds === null) return\n onSelectionChange(selectedIds)\n }, [selectedIds, onSelectionChange])\n\n if (result.isLoading) {\n return <BaseLayout isLoading error={result.errorHandling.errors} />\n }\n\n return (\n <BaseLayout error={result.errorHandling.errors}>\n <SelectContractorsPresentation\n contractors={result.data.contractors}\n selectedIds={result.selectedIds}\n searchValue={result.searchValue}\n onSelect={result.actions.onSelect}\n onSelectAll={result.actions.onSelectAll}\n onSearchChange={result.actions.onSearchChange}\n onSearchClear={result.actions.onSearchClear}\n pagination={result.pagination}\n isFetching={result.status.isFetching}\n emptyStateTitle={emptyStateTitle}\n emptyStateDescription={emptyStateDescription}\n />\n </BaseLayout>\n )\n}\n"],"names":["SelectContractors","companyId","onSelectionChange","emptyStateTitle","emptyStateDescription","result","useSelectContractors","selectedIdsKey","selectedIds","useMemo","useEffect","BaseLayout","jsx","SelectContractorsPresentation"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"SelectContractors.js","sources":["../../../../../src/components/Contractor/shared/SelectContractors/SelectContractors.tsx"],"sourcesContent":["import { useEffect, useMemo } from 'react'\nimport { useSelectContractors } from './useSelectContractors'\nimport { SelectContractorsPresentation } from './SelectContractorsPresentation'\nimport { BaseLayout } from '@/components/Base'\n\n/** @internal */\nexport interface SelectContractorsProps {\n companyId: string\n /** Called with the currently selected contractor ids whenever the selection changes. */\n onSelectionChange: (selectedIds: string[]) => void\n /**\n * Seeds selection state on mount. Pass the caller's own previously-selected ids to survive\n * this component unmounting and remounting (e.g. behind a \"Back\" button).\n */\n initialSelectedIds?: Iterable<string>\n /** Overrides the default empty-state title shown when no contractors match. */\n emptyStateTitle?: string\n /** Overrides the default empty-state description shown when no contractors match. */\n emptyStateDescription?: string\n}\n\n/**\n * Multi-select contractor table. Fetches and filters eligible contractors via\n * {@link useSelectContractors} and reports the current selection through\n * `onSelectionChange` rather than emitting an SDK event — the composing\n * screen is responsible for translating the selection into its own events.\n *\n * @internal\n */\nexport function SelectContractors({\n companyId,\n onSelectionChange,\n initialSelectedIds,\n emptyStateTitle,\n emptyStateDescription,\n}: SelectContractorsProps) {\n const result = useSelectContractors(companyId, initialSelectedIds)\n\n const selectedIdsKey = result.isLoading ? null : [...result.selectedIds].sort().join(',')\n\n const selectedIds = useMemo(\n () => (selectedIdsKey === null ? null : selectedIdsKey.split(',').filter(Boolean)),\n [selectedIdsKey],\n )\n\n useEffect(() => {\n if (selectedIds === null) return\n onSelectionChange(selectedIds)\n }, [selectedIds, onSelectionChange])\n\n if (result.isLoading) {\n return <BaseLayout isLoading error={result.errorHandling.errors} />\n }\n\n return (\n <BaseLayout error={result.errorHandling.errors}>\n <SelectContractorsPresentation\n contractors={result.data.contractors}\n selectedIds={result.selectedIds}\n searchValue={result.searchValue}\n onSelect={result.actions.onSelect}\n onSelectAll={result.actions.onSelectAll}\n onSearchChange={result.actions.onSearchChange}\n onSearchClear={result.actions.onSearchClear}\n pagination={result.pagination}\n isFetching={result.status.isFetching}\n emptyStateTitle={emptyStateTitle}\n emptyStateDescription={emptyStateDescription}\n />\n </BaseLayout>\n )\n}\n"],"names":["SelectContractors","companyId","onSelectionChange","initialSelectedIds","emptyStateTitle","emptyStateDescription","result","useSelectContractors","selectedIdsKey","selectedIds","useMemo","useEffect","BaseLayout","jsx","SelectContractorsPresentation"],"mappings":";;;;;;AA6BO,SAASA,EAAkB;AAAA,EAChC,WAAAC;AAAA,EACA,mBAAAC;AAAA,EACA,oBAAAC;AAAA,EACA,iBAAAC;AAAA,EACA,uBAAAC;AACF,GAA2B;AACzB,QAAMC,IAASC,EAAqBN,GAAWE,CAAkB,GAE3DK,IAAiBF,EAAO,YAAY,OAAO,CAAC,GAAGA,EAAO,WAAW,EAAE,OAAO,KAAK,GAAG,GAElFG,IAAcC;AAAA,IAClB,MAAOF,MAAmB,OAAO,OAAOA,EAAe,MAAM,GAAG,EAAE,OAAO,OAAO;AAAA,IAChF,CAACA,CAAc;AAAA,EAAA;AAQjB,SALAG,EAAU,MAAM;AACd,IAAIF,MAAgB,QACpBP,EAAkBO,CAAW;AAAA,EAC/B,GAAG,CAACA,GAAaP,CAAiB,CAAC,GAE/BI,EAAO,8BACDM,GAAA,EAAW,WAAS,IAAC,OAAON,EAAO,cAAc,QAAQ,IAIjE,gBAAAO,EAACD,GAAA,EAAW,OAAON,EAAO,cAAc,QACtC,UAAA,gBAAAO;AAAA,IAACC;AAAA,IAAA;AAAA,MACC,aAAaR,EAAO,KAAK;AAAA,MACzB,aAAaA,EAAO;AAAA,MACpB,aAAaA,EAAO;AAAA,MACpB,UAAUA,EAAO,QAAQ;AAAA,MACzB,aAAaA,EAAO,QAAQ;AAAA,MAC5B,gBAAgBA,EAAO,QAAQ;AAAA,MAC/B,eAAeA,EAAO,QAAQ;AAAA,MAC9B,YAAYA,EAAO;AAAA,MACnB,YAAYA,EAAO,OAAO;AAAA,MAC1B,iBAAAF;AAAA,MACA,uBAAAC;AAAA,IAAA;AAAA,EAAA,GAEJ;AAEJ;"}
|
|
@@ -53,6 +53,10 @@ export type UseSelectContractorsResult = HookLoadingResult | UseSelectContractor
|
|
|
53
53
|
* all pages, not just the current page slice — "select all" means every
|
|
54
54
|
* matching contractor, including ones scrolled off-screen.
|
|
55
55
|
*
|
|
56
|
+
* `initialSelectedIds` seeds selection state and is only read on mount. Pass the caller's own
|
|
57
|
+
* previously-selected ids here to survive an unmount/remount (e.g. a "Back" button that swaps
|
|
58
|
+
* this component out for another screen and back).
|
|
59
|
+
*
|
|
56
60
|
* @internal
|
|
57
61
|
*/
|
|
58
|
-
export declare function useSelectContractors(companyId: string): UseSelectContractorsResult;
|
|
62
|
+
export declare function useSelectContractors(companyId: string, initialSelectedIds?: Iterable<string>): UseSelectContractorsResult;
|
|
@@ -1,49 +1,51 @@
|
|
|
1
|
-
import { useState as
|
|
2
|
-
import { useContractorsList as
|
|
3
|
-
import { useGustoEmbeddedContext as
|
|
4
|
-
import { useQueries as
|
|
5
|
-
import { useClientPagination as
|
|
6
|
-
import { composeErrorHandler as
|
|
7
|
-
import { ContractorOnboardingStatus as
|
|
8
|
-
import { getContractorDisplayName as
|
|
1
|
+
import { useState as I, useMemo as _, useCallback as C } from "react";
|
|
2
|
+
import { useContractorsList as N, buildContractorsListQuery as O } from "@gusto/embedded-api/react-query/contractorsList";
|
|
3
|
+
import { useGustoEmbeddedContext as v } from "@gusto/embedded-api/react-query/_context";
|
|
4
|
+
import { useQueries as D } from "@tanstack/react-query";
|
|
5
|
+
import { useClientPagination as G } from "../../../../hooks/useClientPagination/useClientPagination.js";
|
|
6
|
+
import { composeErrorHandler as Q } from "../../../../partner-hook-utils/composeErrorHandler.js";
|
|
7
|
+
import { ContractorOnboardingStatus as H } from "../../../../shared/constants.js";
|
|
8
|
+
import { getContractorDisplayName as U } from "../helpers.js";
|
|
9
9
|
const h = 100;
|
|
10
|
-
function
|
|
11
|
-
return e.isActive && e.onboardingStatus ===
|
|
10
|
+
function V(e) {
|
|
11
|
+
return e.isActive && e.onboardingStatus === H.ONBOARDING_COMPLETED;
|
|
12
12
|
}
|
|
13
13
|
function S(e, u) {
|
|
14
|
-
return
|
|
14
|
+
return U(e).toLowerCase().includes(u.toLowerCase());
|
|
15
15
|
}
|
|
16
|
-
function
|
|
17
|
-
const
|
|
16
|
+
function K(e, u) {
|
|
17
|
+
const P = v(), [b, l] = I(
|
|
18
|
+
() => new Set(u)
|
|
19
|
+
), d = N({
|
|
18
20
|
companyUuid: e,
|
|
19
21
|
page: 1,
|
|
20
22
|
per: h
|
|
21
|
-
}), { data: n, isFetching: g } = d,
|
|
22
|
-
queries: Array.from({ length: Math.max(0,
|
|
23
|
-
...
|
|
23
|
+
}), { data: n, isFetching: g } = d, w = Number(n?.httpMeta.response.headers.get("x-total-pages") ?? 1), a = D({
|
|
24
|
+
queries: Array.from({ length: Math.max(0, w - 1) }, (t, o) => ({
|
|
25
|
+
...O(P, {
|
|
24
26
|
companyUuid: e,
|
|
25
27
|
page: o + 2,
|
|
26
28
|
per: h
|
|
27
29
|
}),
|
|
28
30
|
enabled: !!n
|
|
29
31
|
}))
|
|
30
|
-
}),
|
|
32
|
+
}), E = !n && g || a.some((t) => !t.data && t.isFetching), m = Q([d, ...a]), s = _(() => n ? [
|
|
31
33
|
...n.contractors ?? [],
|
|
32
34
|
...a.flatMap((o) => o.data?.contractors ?? [])
|
|
33
|
-
].filter(
|
|
34
|
-
data:
|
|
35
|
-
pagination:
|
|
35
|
+
].filter(V) : [], [n, a]), {
|
|
36
|
+
data: L,
|
|
37
|
+
pagination: A,
|
|
36
38
|
searchValue: c,
|
|
37
39
|
actions: f
|
|
38
|
-
} =
|
|
40
|
+
} = G(s, {
|
|
39
41
|
searchPredicate: S,
|
|
40
42
|
defaultItemsPerPage: 25
|
|
41
|
-
}),
|
|
43
|
+
}), x = g || a.some((t) => t.isFetching), F = new Set(s.map((t) => t.uuid)), M = new Set([...b].filter((t) => F.has(t))), R = C((t, o) => {
|
|
42
44
|
l((i) => {
|
|
43
45
|
const r = new Set(i);
|
|
44
46
|
return o ? r.add(t.uuid) : r.delete(t.uuid), r;
|
|
45
47
|
});
|
|
46
|
-
}, []),
|
|
48
|
+
}, []), y = C(
|
|
47
49
|
(t) => {
|
|
48
50
|
const o = c ? s.filter((i) => S(i, c)) : s;
|
|
49
51
|
l((i) => {
|
|
@@ -55,20 +57,20 @@ function J(e) {
|
|
|
55
57
|
},
|
|
56
58
|
[s, c]
|
|
57
59
|
);
|
|
58
|
-
return
|
|
60
|
+
return E ? {
|
|
59
61
|
isLoading: !0,
|
|
60
62
|
errorHandling: m
|
|
61
63
|
} : {
|
|
62
64
|
isLoading: !1,
|
|
63
|
-
data: { contractors:
|
|
64
|
-
status: { isFetching:
|
|
65
|
+
data: { contractors: L },
|
|
66
|
+
status: { isFetching: x },
|
|
65
67
|
eligibleCount: s.length,
|
|
66
|
-
selectedIds:
|
|
67
|
-
pagination:
|
|
68
|
+
selectedIds: M,
|
|
69
|
+
pagination: A,
|
|
68
70
|
searchValue: c,
|
|
69
71
|
actions: {
|
|
70
|
-
onSelect:
|
|
71
|
-
onSelectAll:
|
|
72
|
+
onSelect: R,
|
|
73
|
+
onSelectAll: y,
|
|
72
74
|
onSearchChange: f.onSearchChange,
|
|
73
75
|
onSearchClear: f.onSearchClear
|
|
74
76
|
},
|
|
@@ -76,7 +78,7 @@ function J(e) {
|
|
|
76
78
|
};
|
|
77
79
|
}
|
|
78
80
|
export {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
+
V as isEligibleContractor,
|
|
82
|
+
K as useSelectContractors
|
|
81
83
|
};
|
|
82
84
|
//# sourceMappingURL=useSelectContractors.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSelectContractors.js","sources":["../../../../../src/components/Contractor/shared/SelectContractors/useSelectContractors.ts"],"sourcesContent":["import { useCallback, useMemo, useState } from 'react'\nimport {\n buildContractorsListQuery,\n useContractorsList,\n} from '@gusto/embedded-api/react-query/contractorsList'\nimport { useGustoEmbeddedContext } from '@gusto/embedded-api/react-query/_context'\nimport { useQueries } from '@tanstack/react-query'\nimport type { Contractor } from '@gusto/embedded-api/models/components/contractor'\nimport { useClientPagination } from '@/hooks/useClientPagination/useClientPagination'\nimport { composeErrorHandler } from '@/partner-hook-utils/composeErrorHandler'\nimport { ContractorOnboardingStatus } from '@/shared/constants'\nimport type { HookLoadingResult, BaseHookReady } from '@/partner-hook-utils/types'\nimport type { PaginationControlProps } from '@/components/Common/PaginationControl/PaginationControlTypes'\nimport { getContractorDisplayName } from '@/components/Contractor/shared/helpers'\n\nconst SERVER_MAX_PER_PAGE = 100\n\n/** @internal */\nexport function isEligibleContractor(contractor: Contractor): boolean {\n return (\n contractor.isActive &&\n contractor.onboardingStatus === ContractorOnboardingStatus.ONBOARDING_COMPLETED\n )\n}\n\nfunction matchesContractorSearch(contractor: Contractor, query: string): boolean {\n return getContractorDisplayName(contractor).toLowerCase().includes(query.toLowerCase())\n}\n\n/**\n * Ready state of {@link useSelectContractors}.\n *\n * @internal\n */\nexport interface UseSelectContractorsReady extends BaseHookReady<\n { contractors: Contractor[] },\n { isFetching: boolean }\n> {\n /**\n * Count of eligible (active + onboarded) contractors across every page.\n * Unaffected by the current search — see `pagination.totalCount` for the\n * eligible-and-search-matching count instead.\n */\n eligibleCount: number\n /**\n * Currently selected contractor uuids. Always a subset of the current\n * eligible contractors: uuids for contractors that become ineligible or\n * disappear from the list on a refetch are dropped automatically.\n */\n selectedIds: Set<string>\n /** Pagination controls for the client-paginated, search-filtered contractor list. */\n pagination: PaginationControlProps\n /** Current search value. */\n searchValue: string\n /** Selection and search actions. */\n actions: {\n /** Selects or deselects a single contractor. */\n onSelect: (contractor: Contractor, checked: boolean) => void\n /** Selects or deselects every eligible contractor in the current search scope, across all pages. */\n onSelectAll: (checked: boolean) => void\n /** Updates the search value. */\n onSearchChange: (value: string) => void\n /** Clears the search value. */\n onSearchClear: () => void\n }\n}\n\n/** @internal */\nexport type UseSelectContractorsResult = HookLoadingResult | UseSelectContractorsReady\n\n/**\n * Fetches every contractor page up front, filters to active + onboarded\n * contractors, and owns client-side pagination, search, and selection state\n * over the result.\n *\n * @remarks\n * `actions.onSelectAll` scopes to the full eligible, search-filtered list across\n * all pages, not just the current page slice — \"select all\" means every\n * matching contractor, including ones scrolled off-screen.\n *\n * @internal\n */\nexport function useSelectContractors(companyId: string): UseSelectContractorsResult {\n const gustoClient = useGustoEmbeddedContext()\n const [rawSelectedIds, setRawSelectedIds] = useState<Set<string>>(() => new Set())\n\n const firstPageQuery = useContractorsList({\n companyUuid: companyId,\n page: 1,\n per: SERVER_MAX_PER_PAGE,\n })\n const { data: firstPage, isFetching: isFirstPageFetching } = firstPageQuery\n\n const totalServerPages = Number(firstPage?.httpMeta.response.headers.get('x-total-pages') ?? 1)\n\n // No explicit concurrency cap: typical embedded customers are <100\n // contractors (one server page, zero extra requests). For larger companies\n // the browser's per-origin connection limit (~6) acts as the natural\n // ceiling. If this ever needs to support thousands of contractors,\n // reconsider — either a server-side eligibility filter or a paginated\n // fetch-as-you-scroll strategy would be the right escape hatches.\n const restPageResults = useQueries({\n queries: Array.from({ length: Math.max(0, totalServerPages - 1) }, (_, i) => ({\n ...buildContractorsListQuery(gustoClient, {\n companyUuid: companyId,\n page: i + 2,\n per: SERVER_MAX_PER_PAGE,\n }),\n enabled: !!firstPage,\n })),\n })\n\n const isLoading =\n (!firstPage && isFirstPageFetching) || restPageResults.some(r => !r.data && r.isFetching)\n\n const errorHandling = composeErrorHandler([firstPageQuery, ...restPageResults])\n\n const eligibleContractors = useMemo<Contractor[]>(() => {\n if (!firstPage) return []\n const contractors = [\n ...(firstPage.contractors ?? []),\n ...restPageResults.flatMap(r => r.data?.contractors ?? []),\n ]\n return contractors.filter(isEligibleContractor)\n }, [firstPage, restPageResults])\n\n const {\n data: filteredContractors,\n pagination,\n searchValue,\n actions: paginationActions,\n } = useClientPagination(eligibleContractors, {\n searchPredicate: matchesContractorSearch,\n defaultItemsPerPage: 25,\n })\n\n const isFetching = isFirstPageFetching || restPageResults.some(r => r.isFetching)\n\n const validContractorIds = new Set(eligibleContractors.map(contractor => contractor.uuid))\n const selectedIds = new Set([...rawSelectedIds].filter(uuid => validContractorIds.has(uuid)))\n\n const onSelect = useCallback((contractor: Contractor, checked: boolean) => {\n setRawSelectedIds(prev => {\n const next = new Set(prev)\n if (checked) next.add(contractor.uuid)\n else next.delete(contractor.uuid)\n return next\n })\n }, [])\n\n const onSelectAll = useCallback(\n (checked: boolean) => {\n const scope = searchValue\n ? eligibleContractors.filter(contractor => matchesContractorSearch(contractor, searchValue))\n : eligibleContractors\n setRawSelectedIds(prev => {\n const next = new Set(prev)\n for (const contractor of scope) {\n if (checked) next.add(contractor.uuid)\n else next.delete(contractor.uuid)\n }\n return next\n })\n },\n [eligibleContractors, searchValue],\n )\n\n if (isLoading) {\n return {\n isLoading: true,\n errorHandling,\n }\n }\n\n return {\n isLoading: false,\n data: { contractors: filteredContractors },\n status: { isFetching },\n eligibleCount: eligibleContractors.length,\n selectedIds,\n pagination,\n searchValue,\n actions: {\n onSelect,\n onSelectAll,\n onSearchChange: paginationActions.onSearchChange,\n onSearchClear: paginationActions.onSearchClear,\n },\n errorHandling,\n }\n}\n"],"names":["SERVER_MAX_PER_PAGE","isEligibleContractor","contractor","ContractorOnboardingStatus","matchesContractorSearch","query","getContractorDisplayName","useSelectContractors","companyId","gustoClient","useGustoEmbeddedContext","rawSelectedIds","setRawSelectedIds","useState","firstPageQuery","useContractorsList","firstPage","isFirstPageFetching","totalServerPages","restPageResults","useQueries","_","i","buildContractorsListQuery","isLoading","r","errorHandling","composeErrorHandler","eligibleContractors","useMemo","filteredContractors","pagination","searchValue","paginationActions","useClientPagination","isFetching","validContractorIds","selectedIds","uuid","onSelect","useCallback","checked","prev","next","onSelectAll","scope"],"mappings":";;;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AA,IACV,eAAeP,EAAoB;AAAA,IACnC,aAAAS;AAAA,IACA,YAAAN;AAAA,IACA,aAAAC;AAAA,IACA,SAAS;AAAA,MACP,UAAAO;AAAA,MACA,aAAAK;AAAA,MACA,gBAAgBX,EAAkB;AAAA,MAClC,eAAeA,EAAkB;AAAA,IAAA;AAAA,IAEnC,eAAAP;AAAA,EAAA;AAEJ;"}
|
|
1
|
+
{"version":3,"file":"useSelectContractors.js","sources":["../../../../../src/components/Contractor/shared/SelectContractors/useSelectContractors.ts"],"sourcesContent":["import { useCallback, useMemo, useState } from 'react'\nimport {\n buildContractorsListQuery,\n useContractorsList,\n} from '@gusto/embedded-api/react-query/contractorsList'\nimport { useGustoEmbeddedContext } from '@gusto/embedded-api/react-query/_context'\nimport { useQueries } from '@tanstack/react-query'\nimport type { Contractor } from '@gusto/embedded-api/models/components/contractor'\nimport { useClientPagination } from '@/hooks/useClientPagination/useClientPagination'\nimport { composeErrorHandler } from '@/partner-hook-utils/composeErrorHandler'\nimport { ContractorOnboardingStatus } from '@/shared/constants'\nimport type { HookLoadingResult, BaseHookReady } from '@/partner-hook-utils/types'\nimport type { PaginationControlProps } from '@/components/Common/PaginationControl/PaginationControlTypes'\nimport { getContractorDisplayName } from '@/components/Contractor/shared/helpers'\n\nconst SERVER_MAX_PER_PAGE = 100\n\n/** @internal */\nexport function isEligibleContractor(contractor: Contractor): boolean {\n return (\n contractor.isActive &&\n contractor.onboardingStatus === ContractorOnboardingStatus.ONBOARDING_COMPLETED\n )\n}\n\nfunction matchesContractorSearch(contractor: Contractor, query: string): boolean {\n return getContractorDisplayName(contractor).toLowerCase().includes(query.toLowerCase())\n}\n\n/**\n * Ready state of {@link useSelectContractors}.\n *\n * @internal\n */\nexport interface UseSelectContractorsReady extends BaseHookReady<\n { contractors: Contractor[] },\n { isFetching: boolean }\n> {\n /**\n * Count of eligible (active + onboarded) contractors across every page.\n * Unaffected by the current search — see `pagination.totalCount` for the\n * eligible-and-search-matching count instead.\n */\n eligibleCount: number\n /**\n * Currently selected contractor uuids. Always a subset of the current\n * eligible contractors: uuids for contractors that become ineligible or\n * disappear from the list on a refetch are dropped automatically.\n */\n selectedIds: Set<string>\n /** Pagination controls for the client-paginated, search-filtered contractor list. */\n pagination: PaginationControlProps\n /** Current search value. */\n searchValue: string\n /** Selection and search actions. */\n actions: {\n /** Selects or deselects a single contractor. */\n onSelect: (contractor: Contractor, checked: boolean) => void\n /** Selects or deselects every eligible contractor in the current search scope, across all pages. */\n onSelectAll: (checked: boolean) => void\n /** Updates the search value. */\n onSearchChange: (value: string) => void\n /** Clears the search value. */\n onSearchClear: () => void\n }\n}\n\n/** @internal */\nexport type UseSelectContractorsResult = HookLoadingResult | UseSelectContractorsReady\n\n/**\n * Fetches every contractor page up front, filters to active + onboarded\n * contractors, and owns client-side pagination, search, and selection state\n * over the result.\n *\n * @remarks\n * `actions.onSelectAll` scopes to the full eligible, search-filtered list across\n * all pages, not just the current page slice — \"select all\" means every\n * matching contractor, including ones scrolled off-screen.\n *\n * `initialSelectedIds` seeds selection state and is only read on mount. Pass the caller's own\n * previously-selected ids here to survive an unmount/remount (e.g. a \"Back\" button that swaps\n * this component out for another screen and back).\n *\n * @internal\n */\nexport function useSelectContractors(\n companyId: string,\n initialSelectedIds?: Iterable<string>,\n): UseSelectContractorsResult {\n const gustoClient = useGustoEmbeddedContext()\n const [rawSelectedIds, setRawSelectedIds] = useState<Set<string>>(\n () => new Set(initialSelectedIds),\n )\n\n const firstPageQuery = useContractorsList({\n companyUuid: companyId,\n page: 1,\n per: SERVER_MAX_PER_PAGE,\n })\n const { data: firstPage, isFetching: isFirstPageFetching } = firstPageQuery\n\n const totalServerPages = Number(firstPage?.httpMeta.response.headers.get('x-total-pages') ?? 1)\n\n // No explicit concurrency cap: typical embedded customers are <100\n // contractors (one server page, zero extra requests). For larger companies\n // the browser's per-origin connection limit (~6) acts as the natural\n // ceiling. If this ever needs to support thousands of contractors,\n // reconsider — either a server-side eligibility filter or a paginated\n // fetch-as-you-scroll strategy would be the right escape hatches.\n const restPageResults = useQueries({\n queries: Array.from({ length: Math.max(0, totalServerPages - 1) }, (_, i) => ({\n ...buildContractorsListQuery(gustoClient, {\n companyUuid: companyId,\n page: i + 2,\n per: SERVER_MAX_PER_PAGE,\n }),\n enabled: !!firstPage,\n })),\n })\n\n const isLoading =\n (!firstPage && isFirstPageFetching) || restPageResults.some(r => !r.data && r.isFetching)\n\n const errorHandling = composeErrorHandler([firstPageQuery, ...restPageResults])\n\n const eligibleContractors = useMemo<Contractor[]>(() => {\n if (!firstPage) return []\n const contractors = [\n ...(firstPage.contractors ?? []),\n ...restPageResults.flatMap(r => r.data?.contractors ?? []),\n ]\n return contractors.filter(isEligibleContractor)\n }, [firstPage, restPageResults])\n\n const {\n data: filteredContractors,\n pagination,\n searchValue,\n actions: paginationActions,\n } = useClientPagination(eligibleContractors, {\n searchPredicate: matchesContractorSearch,\n defaultItemsPerPage: 25,\n })\n\n const isFetching = isFirstPageFetching || restPageResults.some(r => r.isFetching)\n\n const validContractorIds = new Set(eligibleContractors.map(contractor => contractor.uuid))\n const selectedIds = new Set([...rawSelectedIds].filter(uuid => validContractorIds.has(uuid)))\n\n const onSelect = useCallback((contractor: Contractor, checked: boolean) => {\n setRawSelectedIds(prev => {\n const next = new Set(prev)\n if (checked) next.add(contractor.uuid)\n else next.delete(contractor.uuid)\n return next\n })\n }, [])\n\n const onSelectAll = useCallback(\n (checked: boolean) => {\n const scope = searchValue\n ? eligibleContractors.filter(contractor => matchesContractorSearch(contractor, searchValue))\n : eligibleContractors\n setRawSelectedIds(prev => {\n const next = new Set(prev)\n for (const contractor of scope) {\n if (checked) next.add(contractor.uuid)\n else next.delete(contractor.uuid)\n }\n return next\n })\n },\n [eligibleContractors, searchValue],\n )\n\n if (isLoading) {\n return {\n isLoading: true,\n errorHandling,\n }\n }\n\n return {\n isLoading: false,\n data: { contractors: filteredContractors },\n status: { isFetching },\n eligibleCount: eligibleContractors.length,\n selectedIds,\n pagination,\n searchValue,\n actions: {\n onSelect,\n onSelectAll,\n onSearchChange: paginationActions.onSearchChange,\n onSearchClear: paginationActions.onSearchClear,\n },\n errorHandling,\n }\n}\n"],"names":["SERVER_MAX_PER_PAGE","isEligibleContractor","contractor","ContractorOnboardingStatus","matchesContractorSearch","query","getContractorDisplayName","useSelectContractors","companyId","initialSelectedIds","gustoClient","useGustoEmbeddedContext","rawSelectedIds","setRawSelectedIds","useState","firstPageQuery","useContractorsList","firstPage","isFirstPageFetching","totalServerPages","restPageResults","useQueries","_","i","buildContractorsListQuery","isLoading","r","errorHandling","composeErrorHandler","eligibleContractors","useMemo","filteredContractors","pagination","searchValue","paginationActions","useClientPagination","isFetching","validContractorIds","selectedIds","uuid","onSelect","useCallback","checked","prev","next","onSelectAll","scope"],"mappings":";;;;;;;;AAeA,MAAMA,IAAsB;AAGrB,SAASC,EAAqBC,GAAiC;AACpE,SACEA,EAAW,YACXA,EAAW,qBAAqBC,EAA2B;AAE/D;AAEA,SAASC,EAAwBF,GAAwBG,GAAwB;AAC/E,SAAOC,EAAyBJ,CAAU,EAAE,YAAA,EAAc,SAASG,EAAM,aAAa;AACxF;AA2DO,SAASE,EACdC,GACAC,GAC4B;AAC5B,QAAMC,IAAcC,EAAA,GACd,CAACC,GAAgBC,CAAiB,IAAIC;AAAA,IAC1C,MAAM,IAAI,IAAIL,CAAkB;AAAA,EAAA,GAG5BM,IAAiBC,EAAmB;AAAA,IACxC,aAAaR;AAAA,IACb,MAAM;AAAA,IACN,KAAKR;AAAA,EAAA,CACN,GACK,EAAE,MAAMiB,GAAW,YAAYC,MAAwBH,GAEvDI,IAAmB,OAAOF,GAAW,SAAS,SAAS,QAAQ,IAAI,eAAe,KAAK,CAAC,GAQxFG,IAAkBC,EAAW;AAAA,IACjC,SAAS,MAAM,KAAK,EAAE,QAAQ,KAAK,IAAI,GAAGF,IAAmB,CAAC,EAAA,GAAK,CAACG,GAAGC,OAAO;AAAA,MAC5E,GAAGC,EAA0Bd,GAAa;AA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AAqB;AACpB,YAAMI,IAAQb,IACVJ,EAAoB,OAAO,OAAczB,EAAwBF,GAAY+B,CAAW,CAAC,IACzFJ;AACJ,MAAAhB,EAAkB,CAAA8B,MAAQ;AACxB,cAAMC,IAAO,IAAI,IAAID,CAAI;AACzB,mBAAWzC,KAAc4C;AACvB,UAAIJ,IAASE,EAAK,IAAI1C,EAAW,IAAI,IAChC0C,EAAK,OAAO1C,EAAW,IAAI;AAElC,eAAO0C;AAAA,MACT,CAAC;AAAA,IACH;AAAA,IACA,CAACf,GAAqBI,CAAW;AAAA,EAAA;AAGnC,SAAIR,IACK;AAAA,IACL,WAAW;AAAA,IACX,eAAAE;AAAA,EAAA,IAIG;AAAA,IACL,WAAW;AAAA,IACX,MAAM,EAAE,aAAaI,EAAA;AAAA,IACrB,QAAQ,EAAE,YAAAK,EAAA;AAAA,IACV,eAAeP,EAAoB;AAAA,IACnC,aAAAS;AAAA,IACA,YAAAN;AAAA,IACA,aAAAC;AAAA,IACA,SAAS;AAAA,MACP,UAAAO;AAAA,MACA,aAAAK;AAAA,MACA,gBAAgBX,EAAkB;AAAA,MAClC,eAAeA,EAAkB;AAAA,IAAA;AAAA,IAEnC,eAAAP;AAAA,EAAA;AAEJ;"}
|
package/dist/components/Employee/Documents/onboarding/DocumentSigner/DocumentList/useDocumentList.js
CHANGED
|
@@ -11,11 +11,10 @@ import "@gusto/embedded-api/models/errors/unprocessableentityerror";
|
|
|
11
11
|
import "@gusto/embedded-api/models/errors/httpclienterrors";
|
|
12
12
|
import "../../../../../../shared/constants.js";
|
|
13
13
|
import "../../../../../../contexts/ComponentAdapter/useComponentContext.js";
|
|
14
|
-
import "../../../../../../contexts/LoadingIndicatorProvider/useLoadingIndicator.js";
|
|
15
14
|
import { createCompoundContext as t } from "../../../../../Base/createCompoundContext.js";
|
|
16
|
-
const [
|
|
15
|
+
const [d, a] = t("DocumentListContext");
|
|
17
16
|
export {
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
a as DocumentListProvider,
|
|
18
|
+
d as useDocumentList
|
|
20
19
|
};
|
|
21
20
|
//# sourceMappingURL=useDocumentList.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDocumentList.js","sources":["../../../../../../../src/components/Employee/Documents/onboarding/DocumentSigner/DocumentList/useDocumentList.ts"],"sourcesContent":["import type { Form } from '@gusto/embedded-api/models/components/form'\nimport { createCompoundContext } from '@/components/Base'\n\ntype DocumentListContextType = {\n employeeForms: Form[]\n hasSignedAllForms: boolean\n handleContinue: () => void\n handleRequestFormToSign: (form: Form) => void\n documentListError: Error | null\n formToSign?: Form\n}\n\nconst [useDocumentList, DocumentListProvider] =\n createCompoundContext<DocumentListContextType>('DocumentListContext')\nexport { useDocumentList, DocumentListProvider }\n"],"names":["useDocumentList","DocumentListProvider","createCompoundContext"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useDocumentList.js","sources":["../../../../../../../src/components/Employee/Documents/onboarding/DocumentSigner/DocumentList/useDocumentList.ts"],"sourcesContent":["import type { Form } from '@gusto/embedded-api/models/components/form'\nimport { createCompoundContext } from '@/components/Base'\n\ntype DocumentListContextType = {\n employeeForms: Form[]\n hasSignedAllForms: boolean\n handleContinue: () => void\n handleRequestFormToSign: (form: Form) => void\n documentListError: Error | null\n formToSign?: Form\n}\n\nconst [useDocumentList, DocumentListProvider] =\n createCompoundContext<DocumentListContextType>('DocumentListContext')\nexport { useDocumentList, DocumentListProvider }\n"],"names":["useDocumentList","DocumentListProvider","createCompoundContext"],"mappings":";;;;;;;;;;;;;;AAYA,MAAM,CAACA,GAAiBC,CAAoB,IAC1CC,EAA+C,qBAAqB;"}
|
|
@@ -3,10 +3,10 @@ import { useTranslation as x, Trans as s } from "react-i18next";
|
|
|
3
3
|
import { BaseLayout as b } from "../../../Base/Base.js";
|
|
4
4
|
import "../../../Base/useBase.js";
|
|
5
5
|
import { Form as I } from "../../../Common/Form/Form.js";
|
|
6
|
+
import { Flex as l } from "../../../Common/Flex/Flex.js";
|
|
6
7
|
import { SDKFormProvider as R } from "../../../../partner-hook-utils/form/SDKFormProvider.js";
|
|
7
8
|
import { useComponentContext as D } from "../../../../contexts/ComponentAdapter/useComponentContext.js";
|
|
8
9
|
import { useI18n as F, useComponentDictionary as S } from "../../../../i18n/I18n.js";
|
|
9
|
-
import { Flex as l } from "../../../Common/Flex/Flex.js";
|
|
10
10
|
function Q({
|
|
11
11
|
federalTaxes: r,
|
|
12
12
|
onSubmit: d,
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { jsxs as M, jsx as n } from "react/jsx-runtime";
|
|
2
2
|
import { useTranslation as s } from "react-i18next";
|
|
3
3
|
import { useManagementBankFormDictionary as p } from "./useFormDictionary.js";
|
|
4
|
-
import {
|
|
4
|
+
import { Flex as c } from "../../../Common/Flex/Flex.js";
|
|
5
|
+
import { useComponentContext as _ } from "../../../../contexts/ComponentAdapter/useComponentContext.js";
|
|
5
6
|
import { componentEvents as t } from "../../../../shared/constants.js";
|
|
6
|
-
import { Flex as _ } from "../../../Common/Flex/Flex.js";
|
|
7
7
|
import { BankFormBody as l } from "../shared/BankFormBody/BankFormBody.js";
|
|
8
8
|
function F({
|
|
9
9
|
employeeId: e,
|
|
10
10
|
onEvent: o,
|
|
11
11
|
...m
|
|
12
12
|
}) {
|
|
13
|
-
const r = p(), { t: a } = s("Employee.Management.PaymentMethodBankForm"), i =
|
|
14
|
-
return /* @__PURE__ */ M(
|
|
13
|
+
const r = p(), { t: a } = s("Employee.Management.PaymentMethodBankForm"), i = _();
|
|
14
|
+
return /* @__PURE__ */ M(c, { flexDirection: "column", gap: 32, children: [
|
|
15
15
|
/* @__PURE__ */ n(i.Heading, { as: "h1", styledAs: "h2", children: a("title") }),
|
|
16
16
|
/* @__PURE__ */ n(
|
|
17
17
|
l,
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { jsxs as c, jsx as n } from "react/jsx-runtime";
|
|
2
2
|
import { useTranslation as p } from "react-i18next";
|
|
3
3
|
import { useOnboardingBankFormDictionary as d } from "./useFormDictionary.js";
|
|
4
|
-
import {
|
|
4
|
+
import { Flex as l } from "../../../Common/Flex/Flex.js";
|
|
5
|
+
import { useComponentContext as f } from "../../../../contexts/ComponentAdapter/useComponentContext.js";
|
|
5
6
|
import { componentEvents as r } from "../../../../shared/constants.js";
|
|
6
|
-
import { Flex as f } from "../../../Common/Flex/Flex.js";
|
|
7
7
|
import { BankFormBody as C } from "../shared/BankFormBody/BankFormBody.js";
|
|
8
8
|
function F({ employeeId: t, onEvent: o, ...m }) {
|
|
9
|
-
const e = d(), { t: i } = p("Employee.PaymentMethod"), a =
|
|
10
|
-
return /* @__PURE__ */ c(
|
|
9
|
+
const e = d(), { t: i } = p("Employee.PaymentMethod"), a = f();
|
|
10
|
+
return /* @__PURE__ */ c(l, { flexDirection: "column", gap: 32, children: [
|
|
11
11
|
/* @__PURE__ */ n(a.Heading, { as: "h1", styledAs: "h2", children: i("addBankAccountFormTitle") }),
|
|
12
12
|
/* @__PURE__ */ n(
|
|
13
13
|
C,
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { jsx as o, jsxs as f } from "react/jsx-runtime";
|
|
2
2
|
import { Suspense as u } from "react";
|
|
3
3
|
import { useMachine as h } from "react-robot";
|
|
4
|
+
import { Flex as s } from "../Common/Flex/Flex.js";
|
|
4
5
|
import { FlowContext as x } from "./useFlow.js";
|
|
5
6
|
import { FlowHeader as F } from "./FlowHeader.js";
|
|
6
7
|
import { useLoadingIndicator as v } from "../../contexts/LoadingIndicatorProvider/useLoadingIndicator.js";
|
|
7
|
-
import { Flex as s } from "../Common/Flex/Flex.js";
|
|
8
8
|
const E = 40;
|
|
9
9
|
function H() {
|
|
10
10
|
const { LoadingIndicator: n } = v();
|
|
@@ -18,13 +18,12 @@ import "@gusto/embedded-api/models/errors/httpclienterrors";
|
|
|
18
18
|
import { formatNumberAsCurrency as L } from "../../../helpers/formattedStrings.js";
|
|
19
19
|
import "../../../shared/constants.js";
|
|
20
20
|
import { useComponentContext as V } from "../../../contexts/ComponentAdapter/useComponentContext.js";
|
|
21
|
-
import "../../../contexts/LoadingIndicatorProvider/useLoadingIndicator.js";
|
|
22
21
|
import { useI18n as E } from "../../../i18n/I18n.js";
|
|
23
22
|
import { NumberInputField as T } from "../../Common/Fields/NumberInputField/NumberInputField.js";
|
|
24
23
|
const q = P.object({
|
|
25
24
|
netPay: P.number().positive()
|
|
26
25
|
});
|
|
27
|
-
function
|
|
26
|
+
function pe({ isOpen: n, onCalculateGrossUp: w, onApply: A, onCancel: d }) {
|
|
28
27
|
E("Payroll.GrossUpModal");
|
|
29
28
|
const { t: r } = k("Payroll.GrossUpModal"), { Modal: M, Heading: u, Text: p, Button: i, Alert: f } = V(), { baseSubmitHandler: y } = H(), N = R(null), [l, c] = o(null), [h, m] = o(null), [g, b] = o(!1), [x, v] = o(!1), s = U({
|
|
30
29
|
resolver: z(q),
|
|
@@ -111,6 +110,6 @@ function fe({ isOpen: n, onCalculateGrossUp: w, onApply: A, onCancel: d }) {
|
|
|
111
110
|
);
|
|
112
111
|
}
|
|
113
112
|
export {
|
|
114
|
-
|
|
113
|
+
pe as GrossUpModal
|
|
115
114
|
};
|
|
116
115
|
//# sourceMappingURL=GrossUpModal.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GrossUpModal.js","sources":["../../../../src/components/Payroll/GrossUpModal/GrossUpModal.tsx"],"sourcesContent":["import { useEffect, useRef, useState } from 'react'\nimport { FormProvider, useForm } from 'react-hook-form'\nimport { useTranslation } from 'react-i18next'\nimport { z } from 'zod'\nimport { zodResolver } from '@hookform/resolvers/zod'\nimport type { GrossUpModalProps } from './GrossUpModalTypes'\nimport styles from './GrossUpModal.module.scss'\nimport { ActionsLayout, Flex, NumberInputField } from '@/components/Common'\nimport { useBase } from '@/components/Base'\nimport { useComponentContext } from '@/contexts/ComponentAdapter/useComponentContext'\nimport { useI18n } from '@/i18n'\nimport { formatNumberAsCurrency } from '@/helpers/formattedStrings'\n\nconst GrossUpFormSchema = z.object({\n netPay: z.number().positive(),\n})\n\ntype GrossUpFormValues = z.infer<typeof GrossUpFormSchema>\n\n/** @internal */\nexport function GrossUpModal({ isOpen, onCalculateGrossUp, onApply, onCancel }: GrossUpModalProps) {\n useI18n('Payroll.GrossUpModal')\n const { t } = useTranslation('Payroll.GrossUpModal')\n const { Modal, Heading, Text, Button, Alert } = useComponentContext()\n const { baseSubmitHandler } = useBase()\n const modalContainerRef = useRef<HTMLDivElement>(null)\n\n const [calculatedGrossUp, setCalculatedGrossUp] = useState<string | null>(null)\n const [errorMessage, setErrorMessage] = useState<string | null>(null)\n const [isCalculating, setIsCalculating] = useState(false)\n const [isApplying, setIsApplying] = useState(false)\n\n const formHandlers = useForm<GrossUpFormValues>({\n resolver: zodResolver(GrossUpFormSchema),\n defaultValues: { netPay: 0 },\n })\n\n useEffect(() => {\n if (!isOpen) {\n formHandlers.reset({ netPay: 0 })\n setCalculatedGrossUp(null)\n setErrorMessage(null)\n }\n }, [isOpen, formHandlers.reset])\n\n const handleCalculate = async (data: GrossUpFormValues) => {\n setErrorMessage(null)\n setCalculatedGrossUp(null)\n setIsCalculating(true)\n\n await baseSubmitHandler(null, async () => {\n try {\n const result = await onCalculateGrossUp(data.netPay)\n\n if (result) {\n setCalculatedGrossUp(result)\n } else {\n setErrorMessage(t('errorMessage'))\n }\n } finally {\n setIsCalculating(false)\n }\n })\n }\n\n const handleApply = async () => {\n if (calculatedGrossUp) {\n setIsApplying(true)\n await baseSubmitHandler(null, async () => {\n try {\n await onApply(calculatedGrossUp)\n } finally {\n setIsApplying(false)\n }\n })\n }\n }\n\n return (\n <Modal\n isOpen={isOpen}\n onClose={onCancel}\n containerRef={modalContainerRef}\n footer={\n <ActionsLayout>\n <Button\n variant=\"primary\"\n isDisabled={!calculatedGrossUp}\n onClick={handleApply}\n isLoading={isApplying}\n >\n {t('applyCta')}\n </Button>\n <Button variant=\"secondary\" onClick={onCancel}>\n {t('cancelCta')}\n </Button>\n </ActionsLayout>\n }\n >\n <FormProvider {...formHandlers}>\n <div className={styles.header}>\n <Heading as=\"h2\" styledAs=\"h3\">\n {t('title')}\n </Heading>\n <Text variant=\"supporting\" as=\"p\">\n {t('description')}\n </Text>\n </div>\n\n <div className={styles.content}>\n {errorMessage && (\n <div className={styles.alert}>\n <Alert label={errorMessage} status=\"error\" disableScrollIntoView />\n </div>\n )}\n\n <div className={styles.alert}>\n <Alert label={t('warning')} status=\"warning\" disableScrollIntoView />\n </div>\n\n <Flex flexDirection=\"row\" gap={8}>\n <NumberInputField\n name=\"netPay\"\n label={t('netPayLabel')}\n format=\"currency\"\n errorMessage={t('validations.netPay')}\n min={0}\n isRequired\n />\n <Button\n variant=\"secondary\"\n className={styles.calculateButton}\n isDisabled={isCalculating}\n onClick={formHandlers.handleSubmit(handleCalculate)}\n >\n {isCalculating ? t('calculatingCta') : t('calculateCta')}\n </Button>\n </Flex>\n\n {calculatedGrossUp && (\n <>\n <div className={styles.result}>\n <Text size=\"sm\" variant=\"supporting\" weight=\"semibold\">\n {t('grossPayResult')}\n </Text>\n <Heading as=\"h3\">{formatNumberAsCurrency(parseFloat(calculatedGrossUp))}</Heading>\n </div>\n </>\n )}\n </div>\n </FormProvider>\n </Modal>\n )\n}\n"],"names":["GrossUpFormSchema","z","GrossUpModal","isOpen","onCalculateGrossUp","onApply","onCancel","useI18n","t","useTranslation","Modal","Heading","Text","Button","Alert","useComponentContext","baseSubmitHandler","useBase","modalContainerRef","useRef","calculatedGrossUp","setCalculatedGrossUp","useState","errorMessage","setErrorMessage","isCalculating","setIsCalculating","isApplying","setIsApplying","formHandlers","useForm","zodResolver","useEffect","handleCalculate","data","result","jsx","ActionsLayout","jsxs","FormProvider","styles","Flex","NumberInputField","Fragment"],"mappings":"
|
|
1
|
+
{"version":3,"file":"GrossUpModal.js","sources":["../../../../src/components/Payroll/GrossUpModal/GrossUpModal.tsx"],"sourcesContent":["import { useEffect, useRef, useState } from 'react'\nimport { FormProvider, useForm } from 'react-hook-form'\nimport { useTranslation } from 'react-i18next'\nimport { z } from 'zod'\nimport { zodResolver } from '@hookform/resolvers/zod'\nimport type { GrossUpModalProps } from './GrossUpModalTypes'\nimport styles from './GrossUpModal.module.scss'\nimport { ActionsLayout, Flex, NumberInputField } from '@/components/Common'\nimport { useBase } from '@/components/Base'\nimport { useComponentContext } from '@/contexts/ComponentAdapter/useComponentContext'\nimport { useI18n } from '@/i18n'\nimport { formatNumberAsCurrency } from '@/helpers/formattedStrings'\n\nconst GrossUpFormSchema = z.object({\n netPay: z.number().positive(),\n})\n\ntype GrossUpFormValues = z.infer<typeof GrossUpFormSchema>\n\n/** @internal */\nexport function GrossUpModal({ isOpen, onCalculateGrossUp, onApply, onCancel }: GrossUpModalProps) {\n useI18n('Payroll.GrossUpModal')\n const { t } = useTranslation('Payroll.GrossUpModal')\n const { Modal, Heading, Text, Button, Alert } = useComponentContext()\n const { baseSubmitHandler } = useBase()\n const modalContainerRef = useRef<HTMLDivElement>(null)\n\n const [calculatedGrossUp, setCalculatedGrossUp] = useState<string | null>(null)\n const [errorMessage, setErrorMessage] = useState<string | null>(null)\n const [isCalculating, setIsCalculating] = useState(false)\n const [isApplying, setIsApplying] = useState(false)\n\n const formHandlers = useForm<GrossUpFormValues>({\n resolver: zodResolver(GrossUpFormSchema),\n defaultValues: { netPay: 0 },\n })\n\n useEffect(() => {\n if (!isOpen) {\n formHandlers.reset({ netPay: 0 })\n setCalculatedGrossUp(null)\n setErrorMessage(null)\n }\n }, [isOpen, formHandlers.reset])\n\n const handleCalculate = async (data: GrossUpFormValues) => {\n setErrorMessage(null)\n setCalculatedGrossUp(null)\n setIsCalculating(true)\n\n await baseSubmitHandler(null, async () => {\n try {\n const result = await onCalculateGrossUp(data.netPay)\n\n if (result) {\n setCalculatedGrossUp(result)\n } else {\n setErrorMessage(t('errorMessage'))\n }\n } finally {\n setIsCalculating(false)\n }\n })\n }\n\n const handleApply = async () => {\n if (calculatedGrossUp) {\n setIsApplying(true)\n await baseSubmitHandler(null, async () => {\n try {\n await onApply(calculatedGrossUp)\n } finally {\n setIsApplying(false)\n }\n })\n }\n }\n\n return (\n <Modal\n isOpen={isOpen}\n onClose={onCancel}\n containerRef={modalContainerRef}\n footer={\n <ActionsLayout>\n <Button\n variant=\"primary\"\n isDisabled={!calculatedGrossUp}\n onClick={handleApply}\n isLoading={isApplying}\n >\n {t('applyCta')}\n </Button>\n <Button variant=\"secondary\" onClick={onCancel}>\n {t('cancelCta')}\n </Button>\n </ActionsLayout>\n }\n >\n <FormProvider {...formHandlers}>\n <div className={styles.header}>\n <Heading as=\"h2\" styledAs=\"h3\">\n {t('title')}\n </Heading>\n <Text variant=\"supporting\" as=\"p\">\n {t('description')}\n </Text>\n </div>\n\n <div className={styles.content}>\n {errorMessage && (\n <div className={styles.alert}>\n <Alert label={errorMessage} status=\"error\" disableScrollIntoView />\n </div>\n )}\n\n <div className={styles.alert}>\n <Alert label={t('warning')} status=\"warning\" disableScrollIntoView />\n </div>\n\n <Flex flexDirection=\"row\" gap={8}>\n <NumberInputField\n name=\"netPay\"\n label={t('netPayLabel')}\n format=\"currency\"\n errorMessage={t('validations.netPay')}\n min={0}\n isRequired\n />\n <Button\n variant=\"secondary\"\n className={styles.calculateButton}\n isDisabled={isCalculating}\n onClick={formHandlers.handleSubmit(handleCalculate)}\n >\n {isCalculating ? t('calculatingCta') : t('calculateCta')}\n </Button>\n </Flex>\n\n {calculatedGrossUp && (\n <>\n <div className={styles.result}>\n <Text size=\"sm\" variant=\"supporting\" weight=\"semibold\">\n {t('grossPayResult')}\n </Text>\n <Heading as=\"h3\">{formatNumberAsCurrency(parseFloat(calculatedGrossUp))}</Heading>\n </div>\n </>\n )}\n </div>\n </FormProvider>\n </Modal>\n )\n}\n"],"names":["GrossUpFormSchema","z","GrossUpModal","isOpen","onCalculateGrossUp","onApply","onCancel","useI18n","t","useTranslation","Modal","Heading","Text","Button","Alert","useComponentContext","baseSubmitHandler","useBase","modalContainerRef","useRef","calculatedGrossUp","setCalculatedGrossUp","useState","errorMessage","setErrorMessage","isCalculating","setIsCalculating","isApplying","setIsApplying","formHandlers","useForm","zodResolver","useEffect","handleCalculate","data","result","jsx","ActionsLayout","jsxs","FormProvider","styles","Flex","NumberInputField","Fragment"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAaA,MAAMA,IAAoBC,EAAE,OAAO;AAAA,EACjC,QAAQA,EAAE,OAAA,EAAS,SAAA;AACrB,CAAC;AAKM,SAASC,GAAa,EAAE,QAAAC,GAAQ,oBAAAC,GAAoB,SAAAC,GAAS,UAAAC,KAA+B;AACjG,EAAAC,EAAQ,sBAAsB;AAC9B,QAAM,EAAE,GAAAC,EAAA,IAAMC,EAAe,sBAAsB,GAC7C,EAAE,OAAAC,GAAO,SAAAC,GAAS,MAAAC,GAAM,QAAAC,GAAQ,OAAAC,EAAA,IAAUC,EAAA,GAC1C,EAAE,mBAAAC,EAAA,IAAsBC,EAAA,GACxBC,IAAoBC,EAAuB,IAAI,GAE/C,CAACC,GAAmBC,CAAoB,IAAIC,EAAwB,IAAI,GACxE,CAACC,GAAcC,CAAe,IAAIF,EAAwB,IAAI,GAC9D,CAACG,GAAeC,CAAgB,IAAIJ,EAAS,EAAK,GAClD,CAACK,GAAYC,CAAa,IAAIN,EAAS,EAAK,GAE5CO,IAAeC,EAA2B;AAAA,IAC9C,UAAUC,EAAY/B,CAAiB;AAAA,IACvC,eAAe,EAAE,QAAQ,EAAA;AAAA,EAAE,CAC5B;AAED,EAAAgC,EAAU,MAAM;AACd,IAAK7B,MACH0B,EAAa,MAAM,EAAE,QAAQ,EAAA,CAAG,GAChCR,EAAqB,IAAI,GACzBG,EAAgB,IAAI;AAAA,EAExB,GAAG,CAACrB,GAAQ0B,EAAa,KAAK,CAAC;AAE/B,QAAMI,IAAkB,OAAOC,MAA4B;AACzD,IAAAV,EAAgB,IAAI,GACpBH,EAAqB,IAAI,GACzBK,EAAiB,EAAI,GAErB,MAAMV,EAAkB,MAAM,YAA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N;"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useState as M, useRef as
|
|
1
|
+
import { useState as M, useRef as y, useMemo as _, useCallback as m, useEffect as b } from "react";
|
|
2
2
|
import { usePayrollsPrepareMutation as L } from "@gusto/embedded-api/react-query/payrollsPrepare";
|
|
3
3
|
import { usePaySchedulesGet as D } from "@gusto/embedded-api/react-query/paySchedulesGet";
|
|
4
4
|
import { UnprocessableEntityError as T } from "@gusto/embedded-api/models/errors/unprocessableentityerror";
|
|
@@ -13,16 +13,15 @@ import "@gusto/embedded-api/models/errors/sdkvalidationerror";
|
|
|
13
13
|
import "@gusto/embedded-api/models/errors/httpclienterrors";
|
|
14
14
|
import "../../shared/constants.js";
|
|
15
15
|
import "../../contexts/ComponentAdapter/useComponentContext.js";
|
|
16
|
-
import "../../contexts/LoadingIndicatorProvider/useLoadingIndicator.js";
|
|
17
16
|
import { retryAsync as x } from "../../helpers/retryAsync.js";
|
|
18
|
-
const q = 4, v = 1500, B = (e) => e instanceof T ? e.errors.some((r) => r.category === "invalid_operation") : !1,
|
|
17
|
+
const q = 4, v = 1500, B = (e) => e instanceof T ? e.errors.some((r) => r.category === "invalid_operation") : !1, V = ({
|
|
19
18
|
companyId: e,
|
|
20
19
|
payrollId: r,
|
|
21
20
|
employeeUuids: a,
|
|
22
21
|
sortBy: n,
|
|
23
22
|
onDataReady: l
|
|
24
23
|
}) => {
|
|
25
|
-
const { mutateAsync:
|
|
24
|
+
const { mutateAsync: c, isPending: p } = L(), [o, f] = M(), t = y(!1), u = y(!1), { baseSubmitHandler: d } = w(), h = _(() => a?.join(",") ?? "", [a]), { data: S, isLoading: E } = D(
|
|
26
25
|
{
|
|
27
26
|
companyId: e,
|
|
28
27
|
payScheduleId: o?.payPeriod?.payScheduleUuid || ""
|
|
@@ -30,8 +29,8 @@ const q = 4, v = 1500, B = (e) => e instanceof T ? e.errors.some((r) => r.catego
|
|
|
30
29
|
{
|
|
31
30
|
enabled: !!o?.payPeriod?.payScheduleUuid
|
|
32
31
|
}
|
|
33
|
-
), P =
|
|
34
|
-
const i = await
|
|
32
|
+
), P = m(async () => {
|
|
33
|
+
const i = await c({
|
|
35
34
|
request: {
|
|
36
35
|
companyId: e,
|
|
37
36
|
payrollId: r,
|
|
@@ -42,7 +41,7 @@ const q = 4, v = 1500, B = (e) => e instanceof T ? e.errors.some((r) => r.catego
|
|
|
42
41
|
}
|
|
43
42
|
});
|
|
44
43
|
f(i.payrollPrepared), i.payrollPrepared && (t.current = !0, l?.(i.payrollPrepared));
|
|
45
|
-
}, [e, r,
|
|
44
|
+
}, [e, r, c, h, n, l]), s = m(async () => {
|
|
46
45
|
await d(
|
|
47
46
|
null,
|
|
48
47
|
() => x(P, {
|
|
@@ -55,7 +54,7 @@ const q = 4, v = 1500, B = (e) => e instanceof T ? e.errors.some((r) => r.catego
|
|
|
55
54
|
b(() => {
|
|
56
55
|
u.current || (u.current = !0, s());
|
|
57
56
|
}, [s]);
|
|
58
|
-
const g =
|
|
57
|
+
const g = p && !t.current, R = p && t.current, A = g || E;
|
|
59
58
|
return {
|
|
60
59
|
handlePreparePayroll: s,
|
|
61
60
|
preparedPayroll: o,
|
|
@@ -66,6 +65,6 @@ const q = 4, v = 1500, B = (e) => e instanceof T ? e.errors.some((r) => r.catego
|
|
|
66
65
|
};
|
|
67
66
|
};
|
|
68
67
|
export {
|
|
69
|
-
|
|
68
|
+
V as usePreparedPayrollData
|
|
70
69
|
};
|
|
71
70
|
//# sourceMappingURL=usePreparedPayrollData.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePreparedPayrollData.js","sources":["../../../src/components/Payroll/usePreparedPayrollData.ts"],"sourcesContent":["import { useState, useEffect, useCallback, useRef, useMemo } from 'react'\nimport { usePayrollsPrepareMutation } from '@gusto/embedded-api/react-query/payrollsPrepare'\nimport { usePaySchedulesGet } from '@gusto/embedded-api/react-query/paySchedulesGet'\nimport type { PayrollPrepared } from '@gusto/embedded-api/models/components/payrollshow'\nimport type { PayScheduleShow } from '@gusto/embedded-api/models/components/payscheduleshow'\nimport { UnprocessableEntityError } from '@gusto/embedded-api/models/errors/unprocessableentityerror'\nimport { useBase } from '../Base'\nimport { retryAsync } from '@/helpers/retryAsync'\n\ninterface UsePreparedPayrollDataParams {\n companyId: string\n payrollId: string\n employeeUuids?: string[]\n sortBy?: string\n onDataReady?: (preparedPayroll: PayrollPrepared) => void\n}\n\ninterface UsePreparedPayrollDataReturn {\n handlePreparePayroll: () => Promise<void>\n preparedPayroll: PayrollPrepared | undefined\n paySchedule: PayScheduleShow | undefined\n isLoading: boolean\n isPaginating: boolean\n hasInitialData: boolean\n}\n\nconst PREPARE_MAX_ATTEMPTS = 4\nconst PREPARE_RETRY_DELAY_MS = 1500\n\nconst isPayrollBeingProcessedError = (error: unknown): boolean => {\n if (!(error instanceof UnprocessableEntityError)) return false\n return error.errors.some(e => e.category === 'invalid_operation')\n}\n\n/**\n * Wraps the prepare-payroll mutation and pay-schedule fetch, retrying while the payroll is still being processed.\n *\n * @remarks\n * Fires the prepare call once on mount, then exposes `handlePreparePayroll` for callers that need to re-prepare\n * (e.g. after sort or pagination changes). Distinguishes initial loading from subsequent pagination via\n * `isLoading` and `isPaginating`, and surfaces the pay schedule for the prepared payroll's pay period.\n *\n * @param params - The company and payroll identifiers, plus optional employee filter, sort, and ready callback.\n * @returns The prepared payroll, its pay schedule, loading flags, and a `handlePreparePayroll` callback to re-run.\n * @internal\n */\nexport const usePreparedPayrollData = ({\n companyId,\n payrollId,\n employeeUuids,\n sortBy,\n onDataReady,\n}: UsePreparedPayrollDataParams): UsePreparedPayrollDataReturn => {\n const { mutateAsync: preparePayroll, isPending: isPreparePayrollPending } =\n usePayrollsPrepareMutation()\n const [preparedPayroll, setPreparedPayroll] = useState<PayrollPrepared | undefined>()\n const hasInitialDataRef = useRef(false)\n const hasFiredRef = useRef(false)\n const { baseSubmitHandler } = useBase()\n\n const employeeUuidsKey = useMemo(() => employeeUuids?.join(',') ?? '', [employeeUuids])\n\n const { data: payScheduleData, isLoading: isPayScheduleLoading } = usePaySchedulesGet(\n {\n companyId,\n payScheduleId: preparedPayroll?.payPeriod?.payScheduleUuid || '',\n },\n {\n enabled: !!preparedPayroll?.payPeriod?.payScheduleUuid,\n },\n )\n\n const executePrepare = useCallback(async () => {\n const result = await preparePayroll({\n request: {\n companyId,\n payrollId,\n sortBy,\n requestBody: {\n employeeUuids,\n },\n },\n })\n setPreparedPayroll(result.payrollPrepared)\n if (result.payrollPrepared) {\n hasInitialDataRef.current = true\n onDataReady?.(result.payrollPrepared)\n }\n }, [companyId, payrollId, preparePayroll, employeeUuidsKey, sortBy, onDataReady])\n\n const handlePreparePayroll = useCallback(async () => {\n await baseSubmitHandler(null, () =>\n retryAsync(executePrepare, {\n maxAttempts: PREPARE_MAX_ATTEMPTS,\n delayMs: PREPARE_RETRY_DELAY_MS,\n shouldRetry: isPayrollBeingProcessedError,\n }),\n )\n }, [baseSubmitHandler, executePrepare])\n\n useEffect(() => {\n if (hasFiredRef.current) return\n hasFiredRef.current = true\n void handlePreparePayroll()\n }, [handlePreparePayroll])\n\n const isInitialLoading = isPreparePayrollPending && !hasInitialDataRef.current\n const isPaginating = isPreparePayrollPending && hasInitialDataRef.current\n const isLoading = isInitialLoading || isPayScheduleLoading\n\n return {\n handlePreparePayroll,\n preparedPayroll,\n paySchedule: payScheduleData?.payScheduleShow,\n isLoading,\n isPaginating,\n hasInitialData: hasInitialDataRef.current,\n }\n}\n"],"names":["PREPARE_MAX_ATTEMPTS","PREPARE_RETRY_DELAY_MS","isPayrollBeingProcessedError","error","UnprocessableEntityError","e","usePreparedPayrollData","companyId","payrollId","employeeUuids","sortBy","onDataReady","preparePayroll","isPreparePayrollPending","usePayrollsPrepareMutation","preparedPayroll","setPreparedPayroll","useState","hasInitialDataRef","useRef","hasFiredRef","baseSubmitHandler","useBase","employeeUuidsKey","useMemo","payScheduleData","isPayScheduleLoading","usePaySchedulesGet","executePrepare","useCallback","result","handlePreparePayroll","retryAsync","useEffect","isInitialLoading","isPaginating","isLoading"],"mappings":"
|
|
1
|
+
{"version":3,"file":"usePreparedPayrollData.js","sources":["../../../src/components/Payroll/usePreparedPayrollData.ts"],"sourcesContent":["import { useState, useEffect, useCallback, useRef, useMemo } from 'react'\nimport { usePayrollsPrepareMutation } from '@gusto/embedded-api/react-query/payrollsPrepare'\nimport { usePaySchedulesGet } from '@gusto/embedded-api/react-query/paySchedulesGet'\nimport type { PayrollPrepared } from '@gusto/embedded-api/models/components/payrollshow'\nimport type { PayScheduleShow } from '@gusto/embedded-api/models/components/payscheduleshow'\nimport { UnprocessableEntityError } from '@gusto/embedded-api/models/errors/unprocessableentityerror'\nimport { useBase } from '../Base'\nimport { retryAsync } from '@/helpers/retryAsync'\n\ninterface UsePreparedPayrollDataParams {\n companyId: string\n payrollId: string\n employeeUuids?: string[]\n sortBy?: string\n onDataReady?: (preparedPayroll: PayrollPrepared) => void\n}\n\ninterface UsePreparedPayrollDataReturn {\n handlePreparePayroll: () => Promise<void>\n preparedPayroll: PayrollPrepared | undefined\n paySchedule: PayScheduleShow | undefined\n isLoading: boolean\n isPaginating: boolean\n hasInitialData: boolean\n}\n\nconst PREPARE_MAX_ATTEMPTS = 4\nconst PREPARE_RETRY_DELAY_MS = 1500\n\nconst isPayrollBeingProcessedError = (error: unknown): boolean => {\n if (!(error instanceof UnprocessableEntityError)) return false\n return error.errors.some(e => e.category === 'invalid_operation')\n}\n\n/**\n * Wraps the prepare-payroll mutation and pay-schedule fetch, retrying while the payroll is still being processed.\n *\n * @remarks\n * Fires the prepare call once on mount, then exposes `handlePreparePayroll` for callers that need to re-prepare\n * (e.g. after sort or pagination changes). Distinguishes initial loading from subsequent pagination via\n * `isLoading` and `isPaginating`, and surfaces the pay schedule for the prepared payroll's pay period.\n *\n * @param params - The company and payroll identifiers, plus optional employee filter, sort, and ready callback.\n * @returns The prepared payroll, its pay schedule, loading flags, and a `handlePreparePayroll` callback to re-run.\n * @internal\n */\nexport const usePreparedPayrollData = ({\n companyId,\n payrollId,\n employeeUuids,\n sortBy,\n onDataReady,\n}: UsePreparedPayrollDataParams): UsePreparedPayrollDataReturn => {\n const { mutateAsync: preparePayroll, isPending: isPreparePayrollPending } =\n usePayrollsPrepareMutation()\n const [preparedPayroll, setPreparedPayroll] = useState<PayrollPrepared | undefined>()\n const hasInitialDataRef = useRef(false)\n const hasFiredRef = useRef(false)\n const { baseSubmitHandler } = useBase()\n\n const employeeUuidsKey = useMemo(() => employeeUuids?.join(',') ?? '', [employeeUuids])\n\n const { data: payScheduleData, isLoading: isPayScheduleLoading } = usePaySchedulesGet(\n {\n companyId,\n payScheduleId: preparedPayroll?.payPeriod?.payScheduleUuid || '',\n },\n {\n enabled: !!preparedPayroll?.payPeriod?.payScheduleUuid,\n },\n )\n\n const executePrepare = useCallback(async () => {\n const result = await preparePayroll({\n request: {\n companyId,\n payrollId,\n sortBy,\n requestBody: {\n employeeUuids,\n },\n },\n })\n setPreparedPayroll(result.payrollPrepared)\n if (result.payrollPrepared) {\n hasInitialDataRef.current = true\n onDataReady?.(result.payrollPrepared)\n }\n }, [companyId, payrollId, preparePayroll, employeeUuidsKey, sortBy, onDataReady])\n\n const handlePreparePayroll = useCallback(async () => {\n await baseSubmitHandler(null, () =>\n retryAsync(executePrepare, {\n maxAttempts: PREPARE_MAX_ATTEMPTS,\n delayMs: PREPARE_RETRY_DELAY_MS,\n shouldRetry: isPayrollBeingProcessedError,\n }),\n )\n }, [baseSubmitHandler, executePrepare])\n\n useEffect(() => {\n if (hasFiredRef.current) return\n hasFiredRef.current = true\n void handlePreparePayroll()\n }, [handlePreparePayroll])\n\n const isInitialLoading = isPreparePayrollPending && !hasInitialDataRef.current\n const isPaginating = isPreparePayrollPending && hasInitialDataRef.current\n const isLoading = isInitialLoading || isPayScheduleLoading\n\n return {\n handlePreparePayroll,\n preparedPayroll,\n paySchedule: payScheduleData?.payScheduleShow,\n isLoading,\n isPaginating,\n hasInitialData: hasInitialDataRef.current,\n }\n}\n"],"names":["PREPARE_MAX_ATTEMPTS","PREPARE_RETRY_DELAY_MS","isPayrollBeingProcessedError","error","UnprocessableEntityError","e","usePreparedPayrollData","companyId","payrollId","employeeUuids","sortBy","onDataReady","preparePayroll","isPreparePayrollPending","usePayrollsPrepareMutation","preparedPayroll","setPreparedPayroll","useState","hasInitialDataRef","useRef","hasFiredRef","baseSubmitHandler","useBase","employeeUuidsKey","useMemo","payScheduleData","isPayScheduleLoading","usePaySchedulesGet","executePrepare","useCallback","result","handlePreparePayroll","retryAsync","useEffect","isInitialLoading","isPaginating","isLoading"],"mappings":";;;;;;;;;;;;;;;;AA0BA,MAAMA,IAAuB,GACvBC,IAAyB,MAEzBC,IAA+B,CAACC,MAC9BA,aAAiBC,IAChBD,EAAM,OAAO,KAAK,CAAAE,MAAKA,EAAE,aAAa,mBAAmB,IADP,IAgB9CC,IAAyB,CAAC;AAAA,EACrC,WAAAC;AAAA,EACA,WAAAC;AAAA,EACA,eAAAC;AAAA,EACA,QAAAC;AAAA,EACA,aAAAC;AACF,MAAkE;AAChE,QAAM,EAAE,aAAaC,GAAgB,WAAWC,EAAA,IAC9CC,EAAA,GACI,CAACC,GAAiBC,CAAkB,IAAIC,EAAA,GACxCC,IAAoBC,EAAO,EAAK,GAChCC,IAAcD,EAAO,EAAK,GAC1B,EAAE,mBAAAE,EAAA,IAAsBC,EAAA,GAExBC,IAAmBC,EAAQ,MAAMf,GAAe,KAAK,GAAG,KAAK,IAAI,CAACA,CAAa,CAAC,GAEhF,EAAE,MAAMgB,GAAiB,WAAWC,MAAyBC;AAAA,IACjE;AAAA,MACE,WAAApB;AAAA,MACA,eAAeQ,GAAiB,WAAW,mBAAmB;AAAA,IAAA;AAAA,IAEhE;AAAA,MACE,SAAS,CAAC,CAACA,GAAiB,WAAW;AAAA,IAAA;AAAA,EACzC,GAGIa,IAAiBC,EAAY,YAAY;AAC7C,UAAMC,IAAS,MAAMlB,EAAe;AAAA,MAClC,SAAS;AAAA,QACP,WAAAL;AAAA,QACA,WAAAC;AAAA,QACA,QAAAE;AAAA,QACA,aAAa;AAAA,UACX,eAAAD;AAAA,QAAA;AAAA,MACF;AAAA,IACF,CACD;AACD,IAAAO,EAAmBc,EAAO,eAAe,GACrCA,EAAO,oBACTZ,EAAkB,UAAU,IAC5BP,IAAcmB,EAAO,eAAe;AAAA,EAExC,GAAG,CAACvB,GAAWC,GAAWI,GAAgBW,GAAkBb,GAAQC,CAAW,CAAC,GAE1EoB,IAAuBF,EAAY,YAAY;AACnD,UAAMR;AAAA,MAAkB;AAAA,MAAM,MAC5BW,EAAWJ,GAAgB;AAAA,QACzB,aAAa5B;AAAA,QACb,SAASC;AAAA,QACT,aAAaC;AAAA,MAAA,CACd;AAAA,IAAA;AAAA,EAEL,GAAG,CAACmB,GAAmBO,CAAc,CAAC;AAEtC,EAAAK,EAAU,MAAM;AACd,IAAIb,EAAY,YAChBA,EAAY,UAAU,IACjBW,EAAA;AAAA,EACP,GAAG,CAACA,CAAoB,CAAC;AAEzB,QAAMG,IAAmBrB,KAA2B,CAACK,EAAkB,SACjEiB,IAAetB,KAA2BK,EAAkB,SAC5DkB,IAAYF,KAAoBR;AAEtC,SAAO;AAAA,IACL,sBAAAK;AAAA,IACA,iBAAAhB;AAAA,IACA,aAAaU,GAAiB;AAAA,IAC9B,WAAAW;AAAA,IACA,cAAAD;AAAA,IACA,gBAAgBjB,EAAkB;AAAA,EAAA;AAEtC;"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { default as React, JSX, ReactNode } from 'react';
|
|
2
2
|
import { QueryClient } from '@tanstack/react-query';
|
|
3
3
|
import { ComponentsContextType } from '../ComponentAdapter/useComponentContext';
|
|
4
|
+
import { UnstableFeatures } from '../UnstableFeaturesProvider/useUnstableFeature';
|
|
4
5
|
import { GustoSDKTheme } from '../ThemeProvider/theme';
|
|
5
6
|
import { GlobalResourceDictionary } from '../../types/Helpers';
|
|
6
7
|
import { SDKHooks } from '../../types/hooks';
|
|
@@ -54,6 +55,11 @@ export interface GustoBaseProviderProps {
|
|
|
54
55
|
LoaderComponent?: ({ children }: {
|
|
55
56
|
children?: ReactNode;
|
|
56
57
|
}) => JSX.Element;
|
|
58
|
+
/**
|
|
59
|
+
* Opt-in flags for alpha SDK functionality. See {@link UnstableFeatures}.
|
|
60
|
+
* @alpha
|
|
61
|
+
*/
|
|
62
|
+
unstableFeatures?: UnstableFeatures;
|
|
57
63
|
}
|
|
58
64
|
/**
|
|
59
65
|
* Props for {@link GustoProviderCustomUIAdapter}.
|