@tesouro/embedded-components-react 0.11.235 → 0.11.236

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/README.md +2 -2
  2. package/dist/index.css +12 -0
  3. package/dist/index.d.ts +24 -0
  4. package/dist/lib/ReceivablesWidget.d.ts +24 -0
  5. package/dist/lib/WidgetSuite.d.ts +24 -0
  6. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index.js +6 -6
  7. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index31.js +198 -118
  8. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index32.js +76 -194
  9. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index33.js +67 -75
  10. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index34.js +111 -69
  11. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index35.js +459 -108
  12. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index36.js +101 -449
  13. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index37.js +9 -117
  14. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index38.js +85 -8
  15. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index39.js +67 -73
  16. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index40.js +246 -71
  17. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index41.js +40 -251
  18. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index42.js +237 -38
  19. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index43.js +21 -244
  20. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index44.js +529 -21
  21. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index45.js +4 -530
  22. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index46.js +44 -4
  23. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index47.js +242 -41
  24. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index48.js +3 -245
  25. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index49.js +5 -3
  26. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index50.js +63 -4
  27. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index51.js +1 -64
  28. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/lib/BillPayWidget/BillsTab.js +1 -1
  29. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/lib/ReceivablesWidget/ReceivablesWidget.js +386 -354
  30. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/lib/ReceivablesWidget/labels.js +1 -0
  31. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/lib/ReceivablesWidget/useReceivableActions.js +1 -1
  32. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/lib/ReceivablesWidget/useReceivableDetails.js +1 -1
  33. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/lib/ReceivablesWidget/useReceivableForm.js +260 -258
  34. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/lib/ReceivablesWidget/useReceivablesWidget.js +219 -179
  35. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index.js +26 -25
  36. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index19.js +15 -0
  37. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index32.js +31 -40
  38. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index33.js +18 -17
  39. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index34.js +40 -8
  40. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index35.js +30 -63
  41. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index36.js +463 -27
  42. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index37.js +15 -29
  43. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index38.js +8 -18
  44. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index39.js +18 -18
  45. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index40.js +19 -30
  46. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index41.js +15 -66
  47. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index42.js +66 -391
  48. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index43.js +148 -2
  49. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index44.js +173 -43
  50. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index45.js +3 -71
  51. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index46.js +37 -432
  52. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index47.js +66 -188
  53. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index48.js +455 -22
  54. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index49.js +191 -5
  55. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index50.js +23 -0
  56. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index51.js +5 -265
  57. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index53.js +261 -125
  58. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index54.js +2 -27
  59. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index55.js +122 -230
  60. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index56.js +27 -3
  61. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index57.js +216 -224
  62. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index58.js +3 -30
  63. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index59.js +228 -168
  64. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index60.js +29 -21
  65. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index61.js +152 -109
  66. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index62.js +22 -2
  67. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index63.js +140 -43
  68. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index64.js +2 -0
  69. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index65.js +47 -0
  70. package/dist/libs/tesouro-embedded-components-react/shared/feature/dist/document-preview.js +1 -0
  71. package/dist/libs/tesouro-embedded-components-react/shared/feature/dist/lib/analytics/build-info.js +1 -1
  72. package/dist/libs/tesouro-embedded-components-react/shared/feature/dist/lib/document/documentPreview.js +122 -0
  73. package/package.json +1 -1
  74. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index52.js +0 -1
  75. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index52.js +0 -2
@@ -2,115 +2,466 @@
2
2
  "use client";
3
3
  "use client";
4
4
  "use client";
5
- import { Button as e } from "../../../../../../packages/shared-ui-shadcn/dist/index.js";
6
- import { getStateOptions as t } from "../../../../shared/util/dist/lib/usStates.js";
7
- import "../../../../shared/util/dist/index.js";
8
- import { AchFieldGroup as n } from "../../../../shared/counterpart-management/ui/dist/index5.js";
9
- import { CounterpartFormFields as r, countErrors as i, useFocusFirstInvalidField as a } from "../../../../shared/counterpart-management/ui/dist/index10.js";
10
- import "../../../../shared/counterpart-management/ui/dist/index.js";
5
+ import { toast as e } from "../../../../../../node_modules/sonner/dist/index.js";
6
+ import { hasAnyScope as t } from "../../../../shared/data-access/dist/lib/hasAnyScope.js";
7
+ import { Scope as n } from "../../../../shared/data-access/dist/lib/scopes.js";
8
+ import "../../../../shared/data-access/dist/index.js";
9
+ import "../../../../shared/ui/dist/index.js";
10
+ import { useWidgetConfig as r } from "../../../../shared/feature/dist/lib/WidgetProvider/hooks.js";
11
+ import "../../../../shared/feature/dist/index.js";
12
+ import { COUNTERPART_MESSAGE_LABELS_EN as i } from "../../../../shared/counterpart-management/feature/dist/lib/labels.js";
13
+ import { counterpartFormBankAccountToCreatePayload as ee, counterpartFormBankAccountToUpdatePayload as te, getAchInstructions as a, getCounterpartEmail as o, getCounterpartName as s, getPayableAchInstructions as c, hasCounterpartFormErrors as ne, isAchCompatibleBankAccount as l, resolveCounterpartBankAccountWrite as re, validateAchFormValues as ie, validateCounterpartForm as ae } from "../../../../shared/counterpart-management/feature/dist/lib/helpers.js";
14
+ import { useCounterpartsQuery as oe } from "../../../../shared/counterpart-management/data-access/dist/index3.js";
15
+ import { useCreateCounterpartBankAccountMutation as se, useUpdateCounterpartBankAccountMutation as ce } from "../../../../shared/counterpart-management/data-access/dist/index4.js";
16
+ import { useCounterpartDetails as le } from "../../../../shared/counterpart-management/feature/dist/lib/useCounterpartDetails.js";
17
+ import { useCounterpartForm as ue } from "../../../../shared/counterpart-management/feature/dist/lib/useCounterpartForm.js";
11
18
  import "../../../../shared/counterpart-management/feature/dist/index.js";
12
- import { VendorSearchCombobox as o } from "../../ui/dist/index24.js";
13
- import "../../ui/dist/index.js";
14
- import { mergeVendorInlineFormLabels as s } from "./index32.js";
15
- import { useMemo as c } from "react";
16
- import { jsx as l, jsxs as u } from "react/jsx-runtime";
19
+ import { VENDOR_SECTION_PROPS_LABELS_EN as de } from "./index31.js";
20
+ import { usePayableSuggestionsQuery as fe } from "../../data-access/dist/index21.js";
21
+ import "../../data-access/dist/index.js";
22
+ import { resolvePaymentInstructionsGestures as pe } from "./index18.js";
23
+ import { buildVendorPrefill as me, canAutoCreateVendor as he, toCounterpartRawData as ge } from "./index33.js";
24
+ import { VendorInlineForm as _e } from "./index34.js";
25
+ import { useCallback as u, useEffect as d, useLayoutEffect as ve, useMemo as f, useRef as p, useState as m } from "react";
26
+ import { jsx as ye } from "react/jsx-runtime";
17
27
  // ../../libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index35.js
18
- function d({ mode: d, values: f, errors: p, onChange: m, onAddressChange: h, onCancel: g, onSave: _, isSaving: v = !1, search: y, paymentInstructions: b, labels: x }) {
19
- let S = c(() => s(x), [x]), C = c(() => t(), []), w = a(p ?? {}), T = i({
20
- ...p,
21
- form: void 0,
22
- bankAccount: void 0
23
- }) + i(b?.errors), E = y?.query.trim() ?? "", D = f.entityType === "individual" ? `${f.firstName} ${f.lastName}`.trim() : f.legalName, O = y && d === "create" ? /* @__PURE__ */ l(o, {
24
- ...y,
25
- onAddVendor: E && E !== D.trim() ? y.onAddVendor : void 0,
26
- selectedLabel: D,
27
- badge: S.newVendorBadge,
28
- helperText: S.unmatchedVendorHelper,
29
- resultsHeading: S.resultsHeading,
30
- addVendorDescription: S.addAsNewVendorDescription,
31
- labels: {
32
- fieldLabel: S.vendorFieldLabel,
33
- addVendorAction: S.addAsNewVendor(E)
34
- }
35
- }) : null;
36
- return /* @__PURE__ */ u("div", {
37
- ref: w,
38
- className: "ttw:flex ttw:flex-col ttw:gap-4",
39
- children: [O, /* @__PURE__ */ u("div", {
40
- className: "ttw:flex ttw:flex-col ttw:gap-6 ttw:rounded-lg ttw:border ttw:border-primary ttw:bg-surface-subtle ttw:p-6 ttw:[&_[data-slot=input]]:bg-background ttw:[&_[data-slot=select-trigger]]:bg-background",
41
- children: [
42
- /* @__PURE__ */ u("div", {
43
- className: "ttw:flex ttw:items-baseline ttw:justify-between ttw:gap-2",
44
- children: [/* @__PURE__ */ l("p", {
45
- className: "ttw:text-base ttw:font-semibold ttw:text-foreground",
46
- children: d === "edit" ? S.editTitle : S.createTitle
47
- }), T > 0 ? /* @__PURE__ */ l("p", {
48
- className: "ttw:text-sm ttw:text-destructive",
49
- children: S.fieldsNeedAttention(T)
50
- }) : null]
51
- }),
52
- y && d === "edit" ? /* @__PURE__ */ l(o, {
53
- ...y,
54
- labels: { fieldLabel: S.switchVendorFieldLabel }
55
- }) : null,
56
- /* @__PURE__ */ l(r, {
57
- mode: d,
58
- counterpartMode: "vendor",
59
- values: f,
60
- errors: p,
61
- stateOptions: C,
62
- onChange: m,
63
- onAddressChange: h,
64
- sections: {
65
- entityType: !0,
66
- profileHeading: !1,
67
- addressHeading: !1,
68
- title: !1,
69
- taxId: !1,
70
- address: !0,
71
- bankAccount: !1
72
- },
73
- labels: { businessNameLabel: S.nameLabel }
74
- }),
75
- b ? /* @__PURE__ */ u("div", {
76
- className: "ttw:flex ttw:flex-col ttw:gap-3",
77
- children: [/* @__PURE__ */ u("div", {
78
- className: "ttw:flex ttw:flex-col ttw:gap-1",
79
- children: [/* @__PURE__ */ l("p", {
80
- className: "ttw:text-sm ttw:font-semibold ttw:text-foreground",
81
- children: S.paymentInstructionsHeading
82
- }), /* @__PURE__ */ l("p", {
83
- className: "ttw:text-sm ttw:text-muted-foreground",
84
- children: b.isExtracted ? S.paymentInstructionsExtracted : S.paymentInstructionsDescription
85
- })]
86
- }), /* @__PURE__ */ l(n, {
87
- idPrefix: "vendor-inline-ach",
88
- values: b.values,
89
- errors: b.errors,
90
- onChange: b.onChange,
91
- labels: S.ach
92
- })]
93
- }) : null,
94
- /* @__PURE__ */ u("div", {
95
- className: "ttw:flex ttw:justify-end ttw:gap-2",
96
- children: [/* @__PURE__ */ l(e, {
97
- type: "button",
98
- variant: "outline",
99
- onClick: g,
100
- "aria-label": S.cancelAriaLabel,
101
- disabled: v,
102
- children: S.cancel
103
- }), _ ? /* @__PURE__ */ l(e, {
104
- type: "button",
105
- onClick: _,
106
- "aria-label": S.saveAriaLabel,
107
- loading: v,
108
- disabled: v,
109
- children: S.save
110
- }) : null]
111
- })
112
- ]
113
- })]
28
+ var be = 10, xe = 300, h = {
29
+ accountHolderName: "",
30
+ routingNumber: "",
31
+ accountNumber: ""
32
+ };
33
+ function Se(e) {
34
+ return {
35
+ accountHolderName: e.account_holder_name ?? "",
36
+ routingNumber: e.routing_number ?? "",
37
+ accountNumber: e.account_number ?? ""
38
+ };
39
+ }
40
+ function g(e, t) {
41
+ return e.accountHolderName.trim() === t.accountHolderName.trim() && e.routingNumber.trim() === t.routingNumber.trim() && e.accountNumber.trim() === t.accountNumber.trim();
42
+ }
43
+ function Ce(e, t) {
44
+ return e?.find((e) => e.id === t && l(e)) ?? a(e);
45
+ }
46
+ function _({ payableId: a, counterpartId: l, payableCounterpartId: _, payableCounterpartBankAccountId: we, isVendorKnown: Te = !0, onCounterpartChange: Ee, requiredError: De, extractedVendor: v, readOnly: y = !1, canEditVendor: b = !0, canEditPaymentInstructions: Oe = !0, canAddPaymentInstructions: ke = !0, confirmDiscard: x = (e) => e(), labels: Ae }) {
47
+ let S = f(() => ({
48
+ ...de,
49
+ ...Ae
50
+ }), [Ae]), je = Ae?.messages, C = f(() => ({
51
+ ...i,
52
+ ...je
53
+ }), [je]), { initResponse: Me } = r(), Ne = t(Me?.scopes, [n.CounterpartReadOrg]), [w, Pe] = m(""), [T, Fe] = m(""), Ie = p(T), [E, Le] = m(), [Re, ze] = m("none"), [Be, Ve] = m(), [He, D] = m(!1), [O, k] = m(!1), [A, j] = m(h), M = p(A);
54
+ M.current = A;
55
+ let N = p(h), [Ue, P] = m(), [We, Ge] = m(), Ke = We?.bankAccountId, F = p(void 0), qe = p(l), [Je, Ye] = m(!1), [Xe, Ze] = m(!1), I = p(void 0), L = u(() => {
56
+ k(!1), j(h), N.current = h, P(void 0);
57
+ }, []), R = u((e) => {
58
+ Ye(!0), Ee(e);
59
+ }, [Ee]), Qe = fe(a, { enabled: !y && !!a && !l && !_ }), $e = Qe.data?.suggested_counterpart?.id, et = v?.name;
60
+ d(() => {
61
+ y || Je || l || _ || !$e || R($e);
62
+ }, [
63
+ l,
64
+ _,
65
+ y,
66
+ Je,
67
+ $e,
68
+ R
69
+ ]), d(() => {
70
+ qe.current !== l && (qe.current = l, L(), Ge((e) => e?.counterpartId === l ? e : void 0));
71
+ }, [l, L]), d(() => {
72
+ let e = setTimeout(() => {
73
+ Fe(w.trim());
74
+ }, xe);
75
+ return () => clearTimeout(e);
76
+ }, [w]);
77
+ let z = f(() => me(v), [v]), B = z?.bankAccount, tt = f(() => he(v), [v]), nt = E === "create" ? !g(A, B ?? h) : O && !g(A, N.current), rt = !y && (E === "edit" || E === "create" && !!z), V = oe({
78
+ sort: "counterpart_name",
79
+ order: "asc",
80
+ limit: be,
81
+ counterpart_name__icontains: T || void 0,
82
+ is_vendor: !0,
83
+ enabled: (rt || !y && !E && !l) && Te && Ne
114
84
  });
85
+ d(() => {
86
+ V.isPlaceholderData || (Ie.current = T);
87
+ }, [T, V.isPlaceholderData]);
88
+ let it = V.isPlaceholderData && Ie.current !== T, H = le({
89
+ selectedId: l,
90
+ enabled: Ne
91
+ }), at = se(), ot = ce(), U = ue({
92
+ view: Re,
93
+ setView: ze,
94
+ selectedId: Be,
95
+ setSelectedId: Ve,
96
+ messages: C,
97
+ counterpartType: "vendor",
98
+ counterpart: H.counterpart,
99
+ primaryAddress: H.primaryAddress,
100
+ includeBankAccount: !1
101
+ }), { openCreate: st, openEdit: ct, close: lt, setValues: W, submit: ut, values: dt } = U, G = f(() => {
102
+ let e = H.counterpart;
103
+ if (!e) return;
104
+ if (H.isBankAccountsLoading) return {
105
+ name: s(e),
106
+ email: o(e),
107
+ methodLabel: S.paymentMethodLoading,
108
+ hasPaymentInstructions: !1
109
+ };
110
+ if (H.isBankAccountsError) return {
111
+ name: s(e),
112
+ email: o(e),
113
+ methodLabel: S.paymentMethodUnavailable,
114
+ hasPaymentInstructions: !1
115
+ };
116
+ let t = c(H.bankAccounts);
117
+ return {
118
+ name: s(e),
119
+ email: o(e),
120
+ methodLabel: t ? S.paymentInstructionsValue(t.account_number?.slice(-4) ?? "") : S.noMethod,
121
+ hasPaymentInstructions: !!t
122
+ };
123
+ }, [
124
+ H.bankAccounts,
125
+ H.counterpart,
126
+ H.isBankAccountsError,
127
+ H.isBankAccountsLoading,
128
+ S
129
+ ]), K = f(() => {
130
+ let e = et?.trim();
131
+ if (!e || l || E) return;
132
+ let t = B?.accountNumber;
133
+ return {
134
+ name: e,
135
+ email: v?.email ?? "",
136
+ description: tt ? S.pendingVendorDescription : S.pendingVendorIncompleteDescription,
137
+ methodLabel: t ? S.paymentInstructionsValue(t.slice(-4)) : "",
138
+ hasPaymentInstructions: !!t
139
+ };
140
+ }, [
141
+ l,
142
+ B?.accountNumber,
143
+ v?.email,
144
+ et,
145
+ E,
146
+ tt,
147
+ S
148
+ ]), ft = !!K && !tt, q = l === _ ? we : void 0, J = f(() => Ce(H.bankAccounts, q), [H.bankAccounts, q]), pt = f(() => c(H.bankAccounts)?.id, [H.bankAccounts]), mt = !H.counterpart || H.isLoading || H.isFetching || H.isError || H.isBankAccountsLoading || H.isBankAccountsFetching || H.isBankAccountsError, ht = mt || H.isAddressesLoading || H.isAddressesFetching || H.isAddressesError, gt = b && !mt && H.isAddressesError ? { onRetry: H.refetchAddresses } : void 0, Y = u(() => {
149
+ lt(), Le(void 0), D(!1), F.current = void 0;
150
+ }, [lt]), X = u((e) => {
151
+ if (D(!1), F.current = void 0, e === "edit") Ve(l), ct();
152
+ else {
153
+ st();
154
+ let e = w.trim();
155
+ W((t) => ({
156
+ ...t,
157
+ entityType: "organization",
158
+ legalName: e || z?.legalName || t.legalName,
159
+ email: z?.email || t.email,
160
+ phone: z?.phone || t.phone,
161
+ address: z?.address ?? t.address
162
+ })), j(B ?? h), P(void 0), N.current = h;
163
+ }
164
+ Le(e);
165
+ }, [
166
+ l,
167
+ B,
168
+ st,
169
+ ct,
170
+ w,
171
+ W,
172
+ z
173
+ ]), _t = U.revealErrors, vt = u(() => {
174
+ Ye(!0), X("create"), _t();
175
+ let e = B ? ie(B, C) : {};
176
+ Object.keys(e).length && P(e);
177
+ }, [
178
+ B,
179
+ C,
180
+ X,
181
+ _t
182
+ ]), yt = p(!1), bt = !yt.current && !y && b && Te && !_ && !$e && !Je && ft, xt = bt && !Qe.isLoading;
183
+ ve(() => {
184
+ xt && (yt.current = !0, vt());
185
+ }, [vt, xt]);
186
+ let St = u(() => {
187
+ let e = J ? Se(J) : h;
188
+ N.current = e, j(e), P(void 0), k(!0);
189
+ }, [J]), Ct = u((e) => {
190
+ let t = {
191
+ ...M.current,
192
+ ...e
193
+ };
194
+ M.current = t, j(t);
195
+ let n = ie(t, C);
196
+ P((e) => {
197
+ if (!e) return e;
198
+ let t = { ...e };
199
+ for (let e of Object.keys(t)) n[e] || delete t[e];
200
+ return Object.keys(t).length ? t : void 0;
201
+ });
202
+ }, [C]), wt = u(() => {
203
+ nt ? x(L) : L();
204
+ }, [
205
+ L,
206
+ x,
207
+ nt
208
+ ]), Z = u(() => {
209
+ Y(), L();
210
+ }, [L, Y]), Q = He || nt, $ = u((e) => {
211
+ let t = () => {
212
+ Z(), e();
213
+ };
214
+ Q ? x(t) : t();
215
+ }, [
216
+ x,
217
+ Z,
218
+ Q
219
+ ]), Tt = u(() => {
220
+ Q ? x(Z) : Z();
221
+ }, [
222
+ x,
223
+ Z,
224
+ Q
225
+ ]), Et = u(async ({ closeOnSuccess: t = !0, allowIncompleteVendor: n = !1 } = {}) => {
226
+ if (n && E === "create" && !F.current) {
227
+ let e = M.current, t = ae({
228
+ ...dt,
229
+ bankAccount: e
230
+ }, C, "vendor");
231
+ if (ne(t)) return He || !g(e, B ?? h) ? {
232
+ ok: !0,
233
+ counterpartRawData: ge(dt, e, v)
234
+ } : { ok: !0 };
235
+ }
236
+ let r = l, i = !1, a = M.current;
237
+ if (!g(a, N.current)) {
238
+ let e = ie(a, C);
239
+ if (Object.keys(e).length > 0) return P(e), E !== "create" && k(!0), { ok: !1 };
240
+ }
241
+ if (E === "edit" && ht) return { ok: !1 };
242
+ if (E) {
243
+ if (E === "create" && F.current) r = F.current;
244
+ else {
245
+ let e = await ut();
246
+ if (!e.ok) return { ok: !1 };
247
+ E === "create" ? (r = e.counterpartId, F.current = r) : r = e.counterpartId ?? r;
248
+ }
249
+ E === "create" && (i = !0);
250
+ }
251
+ if (!r) return { ok: !0 };
252
+ let o = H.isBankAccountsLoading || H.isBankAccountsFetching || H.isBankAccountsError;
253
+ if (g(a, N.current)) {
254
+ let e = Ke ?? q;
255
+ return e ? (t && (k(!1), E && Y()), i && R(r), {
256
+ ok: !0,
257
+ counterpartId: r,
258
+ counterpartBankAccountId: e
259
+ }) : i ? (t && Y(), R(r), {
260
+ ok: !0,
261
+ counterpartId: r
262
+ }) : o ? { ok: !1 } : (t && (k(!1), E && Y()), {
263
+ ok: !0,
264
+ counterpartId: r,
265
+ counterpartBankAccountId: pt
266
+ });
267
+ }
268
+ if (o) return { ok: !1 };
269
+ P(void 0);
270
+ let s = re(H.bankAccounts, Ke ?? J?.id), c;
271
+ try {
272
+ s.kind === "update" ? (await ot.mutateAsync({
273
+ path: {
274
+ counterpart_id: r,
275
+ bank_account_id: s.bankAccountId
276
+ },
277
+ body: te(a, { includeAchDefaults: s.includeAchDefaults })
278
+ }), c = s.bankAccountId) : c = (await at.mutateAsync({
279
+ path: { counterpart_id: r },
280
+ body: ee(a, { isDefaultForCurrency: s.isDefaultForCurrency })
281
+ }))?.id;
282
+ } catch {
283
+ return e.error(S.bankAccountSaveFailed), {
284
+ ok: !1,
285
+ counterpartId: r
286
+ };
287
+ }
288
+ return N.current = a, Ge(c ? {
289
+ counterpartId: r,
290
+ bankAccountId: c
291
+ } : void 0), t && (k(!1), E && Y()), i && R(r), {
292
+ ok: !0,
293
+ counterpartId: r,
294
+ counterpartBankAccountId: c
295
+ };
296
+ }, [
297
+ Y,
298
+ l,
299
+ at,
300
+ H.bankAccounts,
301
+ H.isBankAccountsError,
302
+ H.isBankAccountsFetching,
303
+ H.isBankAccountsLoading,
304
+ B,
305
+ v,
306
+ E,
307
+ dt,
308
+ He,
309
+ ht,
310
+ S.bankAccountSaveFailed,
311
+ q,
312
+ C,
313
+ pt,
314
+ R,
315
+ J,
316
+ ut,
317
+ ot,
318
+ Ke
319
+ ]), Dt = u((e) => {
320
+ if (I.current) return I.current;
321
+ let t = (async () => {
322
+ Ze(!0);
323
+ try {
324
+ return await Et(e);
325
+ } finally {
326
+ I.current = void 0, Ze(!1);
327
+ }
328
+ })();
329
+ return I.current = t, t;
330
+ }, [Et]), Ot = u(() => {
331
+ k(!1), E && Y();
332
+ }, [E, Y]), kt = f(() => (V.data?.data ?? []).map((e) => ({
333
+ name: s(e),
334
+ email: o(e),
335
+ onSelect: () => {
336
+ $(() => R(e.id));
337
+ }
338
+ })), [
339
+ V.data,
340
+ $,
341
+ R
342
+ ]), At = u((e) => {
343
+ D(!0), W((t) => e.entityType === "individual" && t.entityType !== "individual" ? {
344
+ ...t,
345
+ ...e,
346
+ firstName: t.firstName || t.legalName,
347
+ legalName: t.legalName
348
+ } : e.entityType === "organization" && t.entityType !== "organization" ? {
349
+ ...t,
350
+ ...e,
351
+ legalName: t.legalName || [t.firstName, t.lastName].filter(Boolean).join(" ")
352
+ } : {
353
+ ...t,
354
+ ...e
355
+ });
356
+ }, [W]), jt = u((e) => {
357
+ D(!0), W((t) => ({
358
+ ...t,
359
+ address: {
360
+ ...t.address,
361
+ ...e
362
+ }
363
+ }));
364
+ }, [W]), Mt = {
365
+ query: w,
366
+ onQueryChange: Pe,
367
+ isLoading: bt || !Te || !Me || !!l && H.isLoading || V.isLoading || V.isFetching && it,
368
+ onAddVendor: () => {
369
+ if (E === "create") {
370
+ let e = w.trim(), [t, ...n] = e.split(/\s+/);
371
+ W((r) => r.entityType === "individual" ? {
372
+ ...r,
373
+ firstName: t,
374
+ lastName: n.join(" ")
375
+ } : {
376
+ ...r,
377
+ legalName: e
378
+ }), D(!0);
379
+ } else $(() => X("create"));
380
+ },
381
+ results: kt
382
+ }, Nt = ke && (E === "create" || !mt) ? {
383
+ isOpen: O,
384
+ values: A,
385
+ errors: Ue,
386
+ onOpen: St,
387
+ onCancel: wt,
388
+ onChange: Ct
389
+ } : void 0, Pt = E !== "create" && Nt ? {
390
+ ...Nt,
391
+ onOpen: E === "edit" ? () => $(St) : Nt.onOpen,
392
+ canEditExisting: Oe
393
+ } : void 0, Ft = U.isSubmitting || at.isPending || ot.isPending, It = {
394
+ prepareVendorForSave: Dt,
395
+ isVendorSavePending: Xe || Ft,
396
+ hasUnsavedVendorChanges: Q,
397
+ isPendingVendor: !!K && !ft,
398
+ revealIncompleteVendor: ft ? vt : void 0,
399
+ isEditingPayTo: !!E || O,
400
+ activePayToOperation: E ? "vendor" : O ? G?.hasPaymentInstructions ? "existingInstructions" : "missingInstructions" : void 0,
401
+ discardPayToEdits: Z,
402
+ finalizePayToSave: Ot,
403
+ openPaymentInstructions: St,
404
+ paymentInstructions: pe(Pt, !!G?.hasPaymentInstructions),
405
+ paymentInstructionsEditor: Pt,
406
+ detailsWarning: gt
407
+ }, Lt = E === "create" && ke ? {
408
+ values: A,
409
+ errors: Ue,
410
+ onChange: Ct,
411
+ isExtracted: !!(B && g(A, B))
412
+ } : void 0;
413
+ if (E) return {
414
+ mode: "creating",
415
+ summary: G,
416
+ newVendorForm: /* @__PURE__ */ ye(_e, {
417
+ mode: E,
418
+ values: U.values,
419
+ errors: U.errors,
420
+ onChange: At,
421
+ onAddressChange: jt,
422
+ onCancel: Tt,
423
+ onSave: Dt,
424
+ isSaving: Ft,
425
+ search: rt ? Mt : void 0,
426
+ paymentInstructions: Lt,
427
+ labels: Ae?.inlineForm
428
+ }),
429
+ ...It
430
+ };
431
+ if (G) return {
432
+ mode: "resolved",
433
+ summary: G,
434
+ onEdit: b && !ht ? () => $(() => X("edit")) : void 0,
435
+ ...It
436
+ };
437
+ if (K && !bt) {
438
+ let e = () => $(() => {
439
+ Ye(!0), X("create");
440
+ }), t = b && ke ? {
441
+ isOpen: !1,
442
+ values: A,
443
+ errors: Ue,
444
+ onOpen: e,
445
+ onChange: Ct,
446
+ onCancel: wt,
447
+ canEditExisting: !0
448
+ } : void 0;
449
+ return {
450
+ mode: "resolved",
451
+ summary: K,
452
+ onEdit: b ? e : void 0,
453
+ error: De,
454
+ ...It,
455
+ showPaymentInstructions: !0,
456
+ paymentInstructions: pe(t, K.hasPaymentInstructions),
457
+ paymentInstructionsEditor: t
458
+ };
459
+ }
460
+ return {
461
+ mode: "selecting",
462
+ error: V.isError ? S.searchFailed : H.isError ? S.vendorDetailsFailed : De,
463
+ search: Mt,
464
+ ...It
465
+ };
115
466
  }
116
- export { d as VendorInlineForm, d as default };
467
+ export { _ as useVendorSectionProps };