@tesouro/embedded-components-react 0.11.129 → 0.11.131

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 (59) hide show
  1. package/dist/fixtures/index.d.ts +4 -4
  2. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/data-access/dist/index.js +5 -4
  3. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/data-access/dist/index21.js +20 -17
  4. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/data-access/dist/index22.js +14 -37
  5. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/data-access/dist/index23.js +31 -14
  6. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/data-access/dist/index24.js +26 -2
  7. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/data-access/dist/index25.js +2 -0
  8. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index.js +7 -7
  9. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index10.js +35 -12
  10. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index11.js +57 -65
  11. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index12.js +6 -11
  12. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index13.js +20 -8
  13. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index14.js +97 -7
  14. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index15.js +10 -10
  15. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index16.js +10 -29
  16. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index17.js +7 -27
  17. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index18.js +8 -18
  18. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index19.js +24 -139
  19. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index20.js +24 -13
  20. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index21.js +14 -17
  21. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index22.js +130 -27
  22. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index23.js +17 -100
  23. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index24.js +21 -82
  24. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index25.js +41 -3
  25. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index26.js +98 -53
  26. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index27.js +82 -113
  27. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index28.js +3 -193
  28. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index29.js +57 -81
  29. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index30.js +110 -66
  30. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index31.js +190 -111
  31. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index32.js +71 -456
  32. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index33.js +69 -114
  33. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index34.js +113 -8
  34. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index35.js +458 -79
  35. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index36.js +116 -79
  36. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index37.js +10 -256
  37. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index38.js +78 -36
  38. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index39.js +73 -236
  39. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index4.js +1 -1
  40. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index40.js +256 -21
  41. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index41.js +43 -516
  42. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index42.js +245 -4
  43. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index43.js +20 -40
  44. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index44.js +497 -211
  45. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index45.js +3 -2
  46. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index46.js +40 -3
  47. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index47.js +235 -57
  48. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index48.js +2 -0
  49. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index49.js +5 -0
  50. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index50.js +64 -0
  51. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index51.js +1 -0
  52. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index6.js +4 -47
  53. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index7.js +13 -4
  54. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index8.js +8 -13
  55. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index9.js +18 -9
  56. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/ui/dist/index3.js +44 -34
  57. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/lib/BillPayWidget/BillsTab.js +1 -1
  58. package/dist/libs/tesouro-embedded-components-react/shared/feature/dist/lib/analytics/build-info.js +1 -1
  59. package/package.json +1 -1
@@ -1,88 +1,467 @@
1
- import { parseDecimalAmountToMinorUnits as e } from "../../../../shared/util/dist/lib/parseDecimalAmountToMinorUnits.js";
2
- import "../../../../shared/util/dist/index.js";
3
- import "../../../util/dist/index.js";
1
+ "use client";
2
+ "use client";
3
+ "use client";
4
+ "use client";
5
+ import { toast as e } from "../../../../../../packages/shared-ui-shadcn/dist/index.js";
6
+ import { hasAnyScope as t } from "../../../../shared/data-access/dist/lib/hasAnyScope.js";
7
+ import { Scope as ee } 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 n } from "../../../../shared/feature/dist/lib/WidgetProvider/hooks.js";
11
+ import "../../../../shared/feature/dist/index.js";
12
+ import { VENDOR_SECTION_PROPS_LABELS_EN as r } from "./index31.js";
13
+ import { usePayableSuggestionsQuery as i } from "../../data-access/dist/index20.js";
14
+ import "../../data-access/dist/index.js";
15
+ import { resolvePaymentInstructionsGestures as a } from "./index17.js";
16
+ import { COUNTERPART_MESSAGE_LABELS_EN as o } from "../../../../shared/counterpart-management/feature/dist/lib/labels.js";
17
+ import { counterpartFormBankAccountToCreatePayload as te, counterpartFormBankAccountToUpdatePayload as ne, getAchInstructions as s, getCounterpartEmail as re, getCounterpartName as ie, getPayableAchInstructions as ae, hasCounterpartFormErrors as oe, isAchCompatibleBankAccount as c, resolveCounterpartBankAccountWrite as se, validateAchFormValues as ce, validateCounterpartForm as le } from "../../../../shared/counterpart-management/feature/dist/lib/helpers.js";
18
+ import { useCounterpartsQuery as ue } from "../../../../shared/counterpart-management/data-access/dist/index3.js";
19
+ import { useCreateCounterpartBankAccountMutation as de, useUpdateCounterpartBankAccountMutation as fe } from "../../../../shared/counterpart-management/data-access/dist/index4.js";
20
+ import { useCounterpartDetails as pe } from "../../../../shared/counterpart-management/feature/dist/lib/useCounterpartDetails.js";
21
+ import { useCounterpartForm as me } from "../../../../shared/counterpart-management/feature/dist/lib/useCounterpartForm.js";
22
+ import "../../../../shared/counterpart-management/feature/dist/index.js";
23
+ import { buildVendorPrefill as he, canAutoCreateVendor as ge, toCounterpartRawData as _e } from "./index33.js";
24
+ import { VendorInlineForm as ve } from "./index34.js";
25
+ import { useCallback as l, useEffect as u, useLayoutEffect as ye, useMemo as d, useRef as f, useState as p } from "react";
26
+ import { jsx as be } from "react/jsx-runtime";
4
27
  // ../../libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index35.js
5
- var t = "USD";
6
- function n(n) {
7
- return e(n, t);
8
- }
9
- function r(e) {
10
- let t = e.trim();
11
- if (!t) return null;
12
- let n = Number(t);
13
- return Number.isFinite(n) && n > 0 ? n : null;
14
- }
15
- function i(e) {
16
- return !!(e.description.trim() || e.glCode.trim() || n(e.price) !== null || n(e.amount) !== null);
17
- }
18
- function a(e) {
19
- return n(e) ?? 0;
20
- }
21
- function o(e) {
22
- let t = Number.parseFloat(e);
23
- return Number.isFinite(t) ? t : 0;
28
+ var xe = 10, Se = 300, m = {
29
+ accountHolderName: "",
30
+ routingNumber: "",
31
+ accountNumber: ""
32
+ };
33
+ function Ce(e) {
34
+ return {
35
+ accountHolderName: e.account_holder_name ?? "",
36
+ routingNumber: e.routing_number ?? "",
37
+ accountNumber: e.account_number ?? ""
38
+ };
24
39
  }
25
- function s(e) {
26
- let t = n(e);
27
- return t === null ? e : c(t);
40
+ function h(e, t) {
41
+ return e.accountHolderName.trim() === t.accountHolderName.trim() && e.routingNumber.trim() === t.routingNumber.trim() && e.accountNumber.trim() === t.accountNumber.trim();
28
42
  }
29
- function c(e) {
30
- return (e / 100).toFixed(2);
43
+ function we(e, t) {
44
+ return e?.find((e) => e.id === t && c(e)) ?? s(e);
31
45
  }
32
- function l({ values: e, initialLineItems: r, counterpartId: i, clearCounterpart: a, counterpartBankAccountId: o, editedTotals: s, currentTotals: c, lineItems: l, document: f, includeBlankPoNumber: p = !0 }) {
33
- let m = { currency: t };
34
- i ? m.counterpart_id = i : a && (m.counterpart_id = null), i ? m.counterpart_bank_account_id = o ?? null : a && (m.counterpart_bank_account_id = null), e.invoiceNumber && (m.document_id = e.invoiceNumber), e.invoiceDate && (m.issued_at = e.invoiceDate), e.dueDate && (m.due_date = e.dueDate);
35
- let h = e.poNumber.trim();
36
- if ((h || p) && (m.purchase_order_number = h || null), f && (m.base64_encoded_file = f.base64EncodedFile, m.file_name = f.fileName), s && (m.discount = n(s.discount) ?? 0, m.tax_amount = n(s.tax) ?? 0, s.total !== void 0 && (m.total_amount = n(s.total) ?? 0)), c && l) {
37
- let e = d(l), t = n(c.tax) ?? 0, r = n(c.discount) ?? 0, i = c.total === void 0 ? (e ?? 0) - r + t : n(c.total) ?? 0;
38
- e !== void 0 && (m.subtotal = e), m.discount = r, m.tax_amount = t, m.total_amount = i;
39
- } else if (r && !("total_amount" in m)) {
40
- let e = u(r, {
41
- tax: s?.tax,
42
- discount: s?.discount
46
+ function g({ payableId: s, counterpartId: c, payableCounterpartId: g, payableCounterpartBankAccountId: Te, isVendorKnown: Ee = !0, onCounterpartChange: De, requiredError: Oe, extractedVendor: _, readOnly: v = !1, canEditVendor: y = !0, canEditPaymentInstructions: ke = !0, canAddPaymentInstructions: Ae = !0, confirmDiscard: b = (e) => e(), labels: x }) {
47
+ let S = d(() => ({
48
+ ...r,
49
+ ...x
50
+ }), [x]), je = x?.messages, C = d(() => ({
51
+ ...o,
52
+ ...je
53
+ }), [je]), { initResponse: Me } = n(), Ne = t(Me?.scopes, [ee.CounterpartReadOrg]), [w, Pe] = p(""), [T, Fe] = p(""), Ie = f(T), [E, Le] = p(), [Re, ze] = p("none"), [Be, Ve] = p(), [He, D] = p(!1), [O, k] = p(!1), [A, Ue] = p(m), j = f(A);
54
+ j.current = A;
55
+ let M = f(m), [We, N] = p(), [Ge, Ke] = p(), qe = Ge?.bankAccountId, P = f(void 0), Je = f(c), [Ye, Xe] = p(!1), [Ze, Qe] = p(!1), F = f(void 0), I = l(() => {
56
+ k(!1), Ue(m), M.current = m, N(void 0);
57
+ }, []), L = l((e) => {
58
+ Xe(!0), De(e);
59
+ }, [De]), $e = i(s, { enabled: !v && !!s && !c && !g }), R = $e.data?.suggested_counterpart?.id, et = _?.name;
60
+ u(() => {
61
+ v || Ye || c || g || !R || L(R);
62
+ }, [
63
+ c,
64
+ g,
65
+ v,
66
+ Ye,
67
+ R,
68
+ L
69
+ ]), u(() => {
70
+ Je.current !== c && (Je.current = c, I(), Ke((e) => e?.counterpartId === c ? e : void 0));
71
+ }, [c, I]), u(() => {
72
+ let e = setTimeout(() => {
73
+ Fe(w.trim());
74
+ }, Se);
75
+ return () => clearTimeout(e);
76
+ }, [w]);
77
+ let z = d(() => he(_), [_]), B = z?.bankAccount, tt = d(() => ge(_), [_]), nt = E === "create" ? !h(A, B ?? m) : O && !h(A, M.current), rt = !v && (E === "edit" || E === "create" && !!z), V = ue({
78
+ sort: "counterpart_name",
79
+ order: "asc",
80
+ limit: xe,
81
+ counterpart_name__icontains: T || void 0,
82
+ is_vendor: !0,
83
+ enabled: (rt || !v && !E && !c) && Ee && Ne
84
+ });
85
+ u(() => {
86
+ V.isPlaceholderData || (Ie.current = T);
87
+ }, [T, V.isPlaceholderData]);
88
+ let it = V.isPlaceholderData && Ie.current !== T, H = pe({
89
+ selectedId: c,
90
+ enabled: Ne
91
+ }), at = de(), ot = fe(), U = me({
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 = d(() => {
102
+ let e = H.counterpart;
103
+ if (!e) return;
104
+ if (H.isBankAccountsLoading) return {
105
+ name: ie(e),
106
+ email: re(e),
107
+ methodLabel: S.paymentMethodLoading,
108
+ hasPaymentInstructions: !1
109
+ };
110
+ if (H.isBankAccountsError) return {
111
+ name: ie(e),
112
+ email: re(e),
113
+ methodLabel: S.paymentMethodUnavailable,
114
+ hasPaymentInstructions: !1
115
+ };
116
+ let t = ae(H.bankAccounts);
117
+ return {
118
+ name: ie(e),
119
+ email: re(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 = d(() => {
130
+ let e = et?.trim();
131
+ if (!e || c || E) return;
132
+ let t = B?.accountNumber;
133
+ return {
134
+ name: e,
135
+ email: _?.email ?? "",
136
+ description: tt ? S.pendingVendorDescription : S.pendingVendorIncompleteDescription,
137
+ methodLabel: t ? S.paymentInstructionsValue(t.slice(-4)) : "",
138
+ hasPaymentInstructions: !!t
139
+ };
140
+ }, [
141
+ c,
142
+ B?.accountNumber,
143
+ _?.email,
144
+ et,
145
+ E,
146
+ tt,
147
+ S
148
+ ]), ft = !!K && !tt, q = c === g ? Te : void 0, J = d(() => we(H.bankAccounts, q), [H.bankAccounts, q]), pt = d(() => ae(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 = y && !mt && H.isAddressesError ? { onRetry: H.refetchAddresses } : void 0, Y = l(() => {
149
+ lt(), Le(void 0), D(!1), P.current = void 0;
150
+ }, [lt]), X = l((e) => {
151
+ if (D(!1), P.current = void 0, e === "edit") Ve(c), 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
+ })), Ue(B ?? m), N(void 0), M.current = m;
163
+ }
164
+ Le(e);
165
+ }, [
166
+ c,
167
+ B,
168
+ st,
169
+ ct,
170
+ w,
171
+ W,
172
+ z
173
+ ]), _t = U.revealErrors, vt = l(() => {
174
+ Xe(!0), X("create"), _t();
175
+ let e = B ? ce(B, C) : {};
176
+ Object.keys(e).length && N(e);
177
+ }, [
178
+ B,
179
+ C,
180
+ X,
181
+ _t
182
+ ]), yt = f(!1), bt = !yt.current && !v && y && Ee && !g && !R && !Ye && ft, xt = bt && !$e.isLoading;
183
+ ye(() => {
184
+ xt && (yt.current = !0, vt());
185
+ }, [vt, xt]);
186
+ let St = l(() => {
187
+ let e = J ? Ce(J) : m;
188
+ M.current = e, Ue(e), N(void 0), k(!0);
189
+ }, [J]), Ct = l((e) => {
190
+ let t = {
191
+ ...j.current,
192
+ ...e
193
+ };
194
+ j.current = t, Ue(t);
195
+ let ee = ce(t, C);
196
+ N((e) => {
197
+ if (!e) return e;
198
+ let t = { ...e };
199
+ for (let e of Object.keys(t)) ee[e] || delete t[e];
200
+ return Object.keys(t).length ? t : void 0;
43
201
  });
44
- e !== void 0 && (m.total_amount = e);
45
- }
46
- return m;
47
- }
48
- function u(e, { tax: t, discount: r }) {
49
- let i = d(e);
50
- if (i !== void 0) return i + (t ? n(t) ?? 0 : 0) - (r ? n(r) ?? 0 : 0);
51
- }
52
- function d(e) {
53
- let t = !1, r = e.reduce((e, r) => {
54
- if (!i(r)) return e;
55
- let a = n(r.amount);
56
- return a === null ? e : (t = !0, e + a);
57
- }, 0);
58
- if (t) return r;
59
- }
60
- function f({ lineItems: e, editedTotals: t }) {
61
- let r = d(e), i = n(t.tax) ?? 0, a = n(t.discount) ?? 0, o = {
62
- discount: a,
63
- tax_amount: i
202
+ }, [C]), wt = l(() => {
203
+ nt ? b(I) : I();
204
+ }, [
205
+ I,
206
+ b,
207
+ nt
208
+ ]), Z = l(() => {
209
+ Y(), I();
210
+ }, [I, Y]), Q = He || nt, $ = l((e) => {
211
+ let t = () => {
212
+ Z(), e();
213
+ };
214
+ Q ? b(t) : t();
215
+ }, [
216
+ b,
217
+ Z,
218
+ Q
219
+ ]), Tt = l(() => {
220
+ Q ? b(Z) : Z();
221
+ }, [
222
+ b,
223
+ Z,
224
+ Q
225
+ ]), Et = l(async ({ closeOnSuccess: t = !0, allowIncompleteVendor: ee = !1 } = {}) => {
226
+ if (ee && E === "create" && !P.current) {
227
+ let e = j.current, t = le({
228
+ ...dt,
229
+ bankAccount: e
230
+ }, C, "vendor");
231
+ if (oe(t)) return He || !h(e, B ?? m) ? {
232
+ ok: !0,
233
+ counterpartRawData: _e(dt, e, _)
234
+ } : { ok: !0 };
235
+ }
236
+ let n = c, r = !1, i = j.current;
237
+ if (!h(i, M.current)) {
238
+ let e = ce(i, C);
239
+ if (Object.keys(e).length > 0) return N(e), E !== "create" && k(!0), { ok: !1 };
240
+ }
241
+ if (E === "edit" && ht) return { ok: !1 };
242
+ if (E) {
243
+ if (E === "create" && P.current) n = P.current;
244
+ else {
245
+ let e = await ut();
246
+ if (!e.ok) return { ok: !1 };
247
+ E === "create" ? (n = e.counterpartId, P.current = n) : n = e.counterpartId ?? n;
248
+ }
249
+ E === "create" && (r = !0);
250
+ }
251
+ if (!n) return { ok: !0 };
252
+ let a = H.isBankAccountsLoading || H.isBankAccountsFetching || H.isBankAccountsError;
253
+ if (h(i, M.current)) {
254
+ let e = qe ?? q;
255
+ return e ? (t && (k(!1), E && Y()), r && L(n), {
256
+ ok: !0,
257
+ counterpartId: n,
258
+ counterpartBankAccountId: e
259
+ }) : r ? (t && Y(), L(n), {
260
+ ok: !0,
261
+ counterpartId: n
262
+ }) : a ? { ok: !1 } : (t && (k(!1), E && Y()), {
263
+ ok: !0,
264
+ counterpartId: n,
265
+ counterpartBankAccountId: pt
266
+ });
267
+ }
268
+ if (a) return { ok: !1 };
269
+ N(void 0);
270
+ let o = se(H.bankAccounts, qe ?? J?.id), s;
271
+ try {
272
+ o.kind === "update" ? (await ot.mutateAsync({
273
+ path: {
274
+ counterpart_id: n,
275
+ bank_account_id: o.bankAccountId
276
+ },
277
+ body: ne(i, { includeAchDefaults: o.includeAchDefaults })
278
+ }), s = o.bankAccountId) : s = (await at.mutateAsync({
279
+ path: { counterpart_id: n },
280
+ body: te(i, { isDefaultForCurrency: o.isDefaultForCurrency })
281
+ }))?.id;
282
+ } catch {
283
+ return e.error(S.bankAccountSaveFailed), {
284
+ ok: !1,
285
+ counterpartId: n
286
+ };
287
+ }
288
+ return M.current = i, Ke(s ? {
289
+ counterpartId: n,
290
+ bankAccountId: s
291
+ } : void 0), t && (k(!1), E && Y()), r && L(n), {
292
+ ok: !0,
293
+ counterpartId: n,
294
+ counterpartBankAccountId: s
295
+ };
296
+ }, [
297
+ Y,
298
+ c,
299
+ at,
300
+ H.bankAccounts,
301
+ H.isBankAccountsError,
302
+ H.isBankAccountsFetching,
303
+ H.isBankAccountsLoading,
304
+ B,
305
+ _,
306
+ E,
307
+ dt,
308
+ He,
309
+ ht,
310
+ S.bankAccountSaveFailed,
311
+ q,
312
+ C,
313
+ pt,
314
+ L,
315
+ J,
316
+ ut,
317
+ ot,
318
+ qe
319
+ ]), Dt = l((e) => {
320
+ if (F.current) return F.current;
321
+ let t = (async () => {
322
+ Qe(!0);
323
+ try {
324
+ return await Et(e);
325
+ } finally {
326
+ F.current = void 0, Qe(!1);
327
+ }
328
+ })();
329
+ return F.current = t, t;
330
+ }, [Et]), Ot = l(() => {
331
+ k(!1), E && Y();
332
+ }, [E, Y]), kt = d(() => (V.data?.data ?? []).map((e) => ({
333
+ name: ie(e),
334
+ email: re(e),
335
+ onSelect: () => {
336
+ $(() => L(e.id));
337
+ }
338
+ })), [
339
+ V.data,
340
+ $,
341
+ L
342
+ ]), At = l((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 = l((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 || !Ee || !Me || !!c && H.isLoading || V.isLoading || V.isFetching && it,
368
+ onAddVendor: () => {
369
+ if (E === "create") {
370
+ let e = w.trim(), [t, ...ee] = e.split(/\s+/);
371
+ W((n) => n.entityType === "individual" ? {
372
+ ...n,
373
+ firstName: t,
374
+ lastName: ee.join(" ")
375
+ } : {
376
+ ...n,
377
+ legalName: e
378
+ }), D(!0);
379
+ } else $(() => X("create"));
380
+ },
381
+ results: kt
382
+ }, Nt = Ae && (E === "create" || !mt) ? {
383
+ isOpen: O,
384
+ values: A,
385
+ errors: We,
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: ke
393
+ } : void 0, Ft = U.isSubmitting || at.isPending || ot.isPending, It = {
394
+ prepareVendorForSave: Dt,
395
+ isVendorSavePending: Ze || 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: a(Pt, !!G?.hasPaymentInstructions),
405
+ paymentInstructionsEditor: Pt,
406
+ detailsWarning: gt
407
+ }, Lt = E === "create" && Ae ? {
408
+ values: A,
409
+ errors: We,
410
+ onChange: Ct,
411
+ isExtracted: !!(B && h(A, B))
412
+ } : void 0;
413
+ if (E) return {
414
+ mode: "creating",
415
+ summary: G,
416
+ newVendorForm: /* @__PURE__ */ be(ve, {
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: x?.inlineForm
428
+ }),
429
+ ...It
64
430
  };
65
- return r !== void 0 && (o.subtotal = r), t.total === void 0 ? r !== void 0 && (o.total_amount = r - a + i) : o.total_amount = n(t.total) ?? 0, o;
66
- }
67
- function p(e) {
68
- return e.filter(i).map((e) => {
69
- let t = n(e.amount), i = r(e.quantity) ?? 1, a = n(e.price) ?? (t === null ? 0 : Math.round(t / i)), o = Math.round(i * a), s = t ?? o;
431
+ if (G) return {
432
+ mode: "resolved",
433
+ summary: G,
434
+ onEdit: y && !ht ? () => $(() => X("edit")) : void 0,
435
+ ...It
436
+ };
437
+ if (K && !bt) {
438
+ let e = () => $(() => {
439
+ Xe(!0), X("create");
440
+ }), t = y && Ae ? {
441
+ isOpen: !1,
442
+ values: A,
443
+ errors: We,
444
+ onOpen: e,
445
+ onChange: Ct,
446
+ onCancel: wt,
447
+ canEditExisting: !0
448
+ } : void 0;
70
449
  return {
71
- name: e.description,
72
- quantity: i,
73
- unit_price: a,
74
- tax: 0,
75
- subtotal: s,
76
- tax_amount: 0,
77
- total: s,
78
- ...e.glCode ? { ledger_account_id: e.glCode } : {}
450
+ mode: "resolved",
451
+ summary: K,
452
+ onEdit: y ? e : void 0,
453
+ error: Oe,
454
+ ...It,
455
+ showPaymentInstructions: !0,
456
+ paymentInstructions: a(t, K.hasPaymentInstructions),
457
+ paymentInstructionsEditor: t
79
458
  };
80
- });
81
- }
82
- function m(e, t) {
83
- return c(Math.round(o(e) * a(t)));
84
- }
85
- function h(e, t, n) {
86
- return c(e.reduce((e, t) => e + a(t.amount), 0) + a(t) - a(n));
459
+ }
460
+ return {
461
+ mode: "selecting",
462
+ error: V.isError ? S.searchFailed : H.isError ? S.vendorDetailsFailed : Oe,
463
+ search: Mt,
464
+ ...It
465
+ };
87
466
  }
88
- export { h as calculateTotal, m as displayLineAmount, i as isPersistableLineItem, l as mapBillFormToPayload, p as mapLineItemsToPayload, f as mapPayableAmountFieldsToPayload, s as normalizeMoneyOnBlur, n as parseMoneyToMinorUnits, r as parseQuantity };
467
+ export { g as useVendorSectionProps };