@tesouro/embedded-components-react 0.5.303 → 0.5.305

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 (52) hide show
  1. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index.js +9 -9
  2. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index12.js +7 -7
  3. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index13.js +10 -9
  4. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index14.js +8 -7
  5. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index15.js +7 -8
  6. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index16.js +8 -28
  7. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index17.js +24 -157
  8. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index18.js +20 -13
  9. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index19.js +13 -34
  10. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index20.js +153 -89
  11. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index21.js +17 -83
  12. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index22.js +23 -3
  13. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index23.js +42 -55
  14. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index24.js +93 -107
  15. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index25.js +77 -185
  16. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index26.js +3 -80
  17. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index27.js +55 -72
  18. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index28.js +111 -113
  19. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index29.js +184 -463
  20. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index3.js +14 -4
  21. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index30.js +78 -11
  22. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index31.js +61 -74
  23. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index32.js +115 -80
  24. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index33.js +449 -216
  25. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index34.js +116 -42
  26. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index35.js +11 -249
  27. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index36.js +85 -23
  28. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index37.js +80 -648
  29. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index38.js +240 -4
  30. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index39.js +44 -40
  31. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index4.js +38 -15
  32. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index40.js +242 -240
  33. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index41.js +25 -3
  34. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index42.js +538 -3
  35. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index43.js +3 -66
  36. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index44.js +42 -1
  37. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index45.js +239 -0
  38. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index46.js +3 -0
  39. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index47.js +5 -0
  40. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index48.js +67 -0
  41. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index49.js +1 -0
  42. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index5.js +227 -38
  43. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index6.js +82 -224
  44. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index7.js +45 -82
  45. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index8.js +4 -47
  46. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index9.js +1 -1
  47. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/ui/dist/index.js +2 -2
  48. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/ui/dist/index29.js +1 -1
  49. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/ui/dist/index31.js +2 -2
  50. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/lib/BillPayWidgetNative/BillsTab.js +6 -6
  51. package/dist/libs/tesouro-embedded-components-react/shared/feature/dist/lib/analytics/build-info.js +1 -1
  52. package/package.json +1 -1
@@ -3,238 +3,471 @@
3
3
  "use client";
4
4
  "use client";
5
5
  import { toast as e } from "../../../../../../packages/shared-ui-shadcn/dist/index.js";
6
- import { extractApiErrorMessage as t } from "../../../../shared/util/dist/lib/apiErrors.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";
7
9
  import "../../../../shared/ui/dist/index.js";
8
- import { BILL_CREATE_MESSAGE_LABELS_EN as n } from "./index25.js";
9
- import { encodeFileToBase64 as r } from "./index30.js";
10
- import { mapBillFormToPayload as i, mapLineItemsToPayload as a, mapPayableAmountFieldsToPayload as o } from "./index31.js";
11
- import { validateBillCompleteness as s, validateBillTotalIsPayable as c, validateBillTotals as l, validateBillValues as u, validateLineItems as d, validateStoredAmountDue as ee } from "./index32.js";
12
- import { useReplacePayableLineItemsMutation as f } from "../../data-access/dist/index4.js";
13
- import { useCreatePayableMutation as p } from "../../data-access/dist/index8.js";
14
- import { useDeletePayableFileMutation as m } from "../../data-access/dist/index9.js";
15
- import { useSubmitPayableForApprovalMutation as h } from "../../data-access/dist/index14.js";
16
- import { useUpdatePayableMutation as g } from "../../data-access/dist/index15.js";
17
- import { useValidatePayableMutation as te } from "../../data-access/dist/index16.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 "./index29.js";
13
+ import { usePayableSuggestionsQuery as i } from "../../data-access/dist/index19.js";
18
14
  import "../../data-access/dist/index.js";
19
- import { useCallback as _, useRef as ne, useState as v } from "react";
15
+ import { resolvePaymentInstructionsGestures as a } from "./index15.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 c, getCounterpartName as re, getPayableAchInstructions as ie, hasCounterpartFormErrors as ae, isAchCompatibleBankAccount as l, resolveCounterpartBankAccountWrite as oe, validateAchFormValues as se, validateCounterpartForm as ce } from "../../../../shared/counterpart-management/feature/dist/lib/helpers.js";
18
+ import { useCounterpartsQuery as le } from "../../../../shared/counterpart-management/data-access/dist/index3.js";
19
+ import { useCreateCounterpartBankAccountMutation as ue, useUpdateCounterpartBankAccountMutation as de } from "../../../../shared/counterpart-management/data-access/dist/index5.js";
20
+ import { useCounterpartDetails as fe } from "../../../../shared/counterpart-management/feature/dist/lib/useCounterpartDetails.js";
21
+ import { useCounterpartForm as pe } from "../../../../shared/counterpart-management/feature/dist/lib/useCounterpartForm.js";
22
+ import "../../../../shared/counterpart-management/feature/dist/index.js";
23
+ import { buildVendorPrefill as me, canAutoCreateVendor as he, toCounterpartRawData as ge } from "./index31.js";
24
+ import { VendorInlineForm as _e } from "./index32.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";
20
27
  //#region ../../libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index33.js
21
- var y = {
22
- document_id: "invoiceNumber",
23
- issued_at: "invoiceDate",
24
- due_date: "dueDate",
25
- counterpart_id: "vendor",
26
- purchase_order_number: "poNumber"
27
- }, b = { tax_amount: "tax" };
28
- function x(e) {
29
- return e.type === "type_error.none.not_allowed" || e.msg === "none is not an allowed value";
30
- }
31
- var re = "pending-vendor";
32
- function S(e) {
33
- return !!t(e)?.includes("line_items_enabled");
34
- }
35
- function ie(e) {
36
- return !!t(e)?.includes("A vendor could not be linked or created for this payable");
37
- }
38
- function C(e, t = n) {
39
- let r = {}, i = {}, a = [];
40
- for (let n of e) {
41
- let e = n.loc[0] ?? t.unknownValidationField, o = y[e], s = b[e], c = x(n) ? t.requiredField : n.msg;
42
- o ? r[o] = c : s ? i[s] = c : a.push(t.unmappedValidationError(e, c));
43
- }
44
- return a.length && (r.form = a.join(" ")), {
45
- formErrors: r,
46
- totalsErrors: Object.keys(i).length ? i : void 0
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 ?? ""
47
38
  };
48
39
  }
49
- function ae(e, t) {
50
- if (!e && !t) return;
51
- let n = {}, r = /* @__PURE__ */ new Set([...Object.keys(e ?? {}), ...Object.keys(t ?? {})]);
52
- for (let i of r) n[i] = {
53
- ...e?.[i],
54
- ...t?.[i]
55
- };
56
- return n;
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)) ?? s(e);
57
45
  }
58
- function w({ payableId: t, form: y, counterpartId: b, isVendorPending: x, onVendorIncomplete: w, clearCounterpart: T, prepareVendorForSave: E, onSaved: D, onPayableCreated: O, readSavedStatus: k, onDraftSaved: A, onFinalized: j, labels: M }) {
59
- let N = {
60
- ...n,
61
- ...M
62
- }, [P, F] = v(), I = t ?? P, [L, R] = v(), oe = _(() => R(void 0), []), [z, B] = v(!1), se = _(() => B(!0), []), [V, H] = v(), U = ne(!1), [ce, le] = v(0), W = _(() => le((e) => e + 1), []), G = p(), K = m(), q = g(), J = f(), Y = te(), X = h(), Z = _(() => y.isTotalsDirty ? l(y.discount, y.tax, y.totalOverride, N) : void 0, [y, N]), Q = _(() => {
63
- let t = u(y.values, N), n = d(y.lineItems, N), r = Z();
64
- return y.setErrors(t), y.setLineItemErrors(n), y.setTotalsErrors(r), !t && !n && !r || (n && e.error(N.lineItemsNeedAttention), W(), !1);
46
+ function _({ payableId: s, 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 = {
48
+ ...r,
49
+ ...Ae
50
+ }, je = Ae?.messages, C = f(() => ({
51
+ ...o,
52
+ ...je
53
+ }), [je]), { initResponse: Me } = n(), Ne = t(Me?.scopes, [ee.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, Ue] = m(h), j = p(A);
54
+ j.current = A;
55
+ let M = p(h), [We, N] = m(), [Ge, Ke] = m(), qe = Ge?.bankAccountId, P = p(void 0), Je = p(l), [Ye, Xe] = m(!1), [Ze, Qe] = m(!1), F = p(void 0), I = u(() => {
56
+ k(!1), Ue(h), M.current = h, N(void 0);
57
+ }, []), L = u((e) => {
58
+ Xe(!0), Ee(e);
59
+ }, [Ee]), $e = i(s, { enabled: !y && !!s && !l && !_ }), R = $e.data?.suggested_counterpart?.id, et = v?.name;
60
+ d(() => {
61
+ !y && !Ye && !l && !_ && R && L(R);
65
62
  }, [
63
+ l,
64
+ _,
66
65
  y,
67
- N,
68
- W,
69
- Z
70
- ]), $ = _(async (e, t, n) => {
71
- let s = !I && L ? {
72
- base64EncodedFile: await r(L),
73
- fileName: L.name
74
- } : void 0, c = y.isTotalsDirty ? {
75
- discount: y.discount,
76
- tax: y.tax,
77
- total: y.totalOverride
78
- } : void 0, l = i({
79
- values: y.values,
80
- initialLineItems: I ? void 0 : y.lineItems,
81
- counterpartId: t ?? b,
82
- clearCounterpart: T,
83
- counterpartBankAccountId: e,
84
- currentTotals: {
85
- discount: y.discount,
86
- tax: y.tax,
87
- total: y.totalOverride
88
- },
89
- lineItems: y.lineItems,
90
- editedTotals: c,
91
- document: s
92
- }), u = n ? {
93
- ...l,
94
- counterpart_raw_data: n
95
- } : l, d = I;
96
- if (d ? await q.mutateAsync({
97
- path: { payable_id: d },
98
- body: u
99
- }) : (d = (await G.mutateAsync({ body: u }))?.id, d && (F(d), O?.(d), s && R(void 0))), !d) throw Error("Payable was created without an id");
100
- if (z) {
101
- try {
102
- await K.mutateAsync({ path: { payable_id: d } });
103
- } catch {}
104
- B(!1);
66
+ Ye,
67
+ R,
68
+ L
69
+ ]), d(() => {
70
+ Je.current !== l && (Je.current = l, I(), Ke((e) => e?.counterpartId === l ? e : void 0));
71
+ }, [l, I]), 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, M.current), rt = !y && (E === "edit" || E === "create" && !!z), V = le({
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
84
+ });
85
+ d(() => {
86
+ V.isPlaceholderData || (Ie.current = T);
87
+ }, [T, V.isPlaceholderData]);
88
+ let it = V.isPlaceholderData && Ie.current !== T, H = fe({
89
+ selectedId: l,
90
+ enabled: Ne
91
+ }), at = ue(), ot = de(), U = pe({
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: re(e),
106
+ email: c(e),
107
+ methodLabel: S.paymentMethodLoading,
108
+ hasPaymentInstructions: !1
109
+ };
110
+ if (H.isBankAccountsError) return {
111
+ name: re(e),
112
+ email: c(e),
113
+ methodLabel: S.paymentMethodUnavailable,
114
+ hasPaymentInstructions: !1
115
+ };
116
+ let t = ie(H.bankAccounts);
117
+ return {
118
+ name: re(e),
119
+ email: c(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.paymentInstructionsValue,
148
+ S.pendingVendorDescription,
149
+ S.pendingVendorIncompleteDescription
150
+ ]), ft = !!K && !tt, q = l === _ ? we : void 0, J = f(() => Ce(H.bankAccounts, q), [H.bankAccounts, q]), pt = f(() => ie(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(() => {
151
+ lt(), Le(void 0), D(!1), P.current = void 0;
152
+ }, [lt]), X = u((e) => {
153
+ if (D(!1), P.current = void 0, e === "edit") Ve(l), ct();
154
+ else {
155
+ st();
156
+ let e = w.trim();
157
+ W((t) => ({
158
+ ...t,
159
+ entityType: "organization",
160
+ legalName: e || z?.legalName || t.legalName,
161
+ email: z?.email || t.email,
162
+ phone: z?.phone || t.phone,
163
+ address: z?.address ?? t.address
164
+ })), Ue(B ?? h), N(void 0), M.current = h;
105
165
  }
106
- return await J.mutateAsync({
107
- path: { payable_id: d },
108
- body: { data: a(y.lineItems) }
109
- }), c && await q.mutateAsync({
110
- path: { payable_id: d },
111
- body: o({
112
- lineItems: y.lineItems,
113
- editedTotals: c
114
- })
115
- }), d;
166
+ Le(e);
167
+ }, [
168
+ l,
169
+ B,
170
+ st,
171
+ ct,
172
+ w,
173
+ W,
174
+ z
175
+ ]), _t = U.revealErrors, vt = u(() => {
176
+ Xe(!0), X("create"), _t();
177
+ let e = B ? se(B, C) : {};
178
+ Object.keys(e).length && N(e);
179
+ }, [
180
+ B,
181
+ C,
182
+ X,
183
+ _t
184
+ ]), yt = p(!1), bt = !yt.current && !y && b && Te && !_ && !R && !Ye && ft, xt = bt && !$e.isLoading;
185
+ ve(() => {
186
+ xt && (yt.current = !0, vt());
187
+ }, [vt, xt]);
188
+ let St = u(() => {
189
+ let e = J ? Se(J) : h;
190
+ M.current = e, Ue(e), N(void 0), k(!0);
191
+ }, [J]), Ct = u((e) => {
192
+ let t = {
193
+ ...j.current,
194
+ ...e
195
+ };
196
+ j.current = t, Ue(t);
197
+ let ee = se(t, C);
198
+ N((e) => {
199
+ if (!e) return e;
200
+ let t = { ...e };
201
+ for (let e of Object.keys(t)) ee[e] || delete t[e];
202
+ return Object.keys(t).length ? t : void 0;
203
+ });
204
+ }, [C]), wt = u(() => {
205
+ nt ? x(I) : I();
116
206
  }, [
117
- b,
118
- T,
119
- G,
120
- K,
121
- z,
122
- y.discount,
123
- y.isTotalsDirty,
124
- y.lineItems,
125
- y.tax,
126
- y.totalOverride,
127
- y.values,
128
- O,
129
207
  I,
130
- J,
131
- L,
132
- q
133
- ]), ue = _(async () => {
134
- I && (await K.mutateAsync({ path: { payable_id: I } }), B(!1));
135
- }, [K, I]);
136
- return {
137
- saveDraft: _(async () => {
138
- if (!U.current && Q()) {
139
- U.current = !0, H("draft");
140
- try {
141
- let t = await E?.({ allowIncompleteVendor: !0 });
142
- if (t && !t.ok) return;
143
- let n = await $(t?.counterpartBankAccountId, t?.counterpartId, t?.counterpartRawData);
144
- y.setErrors(void 0), D?.(n), A?.(n);
145
- let r = await k?.();
146
- return e.success(r === "draft" ? N.submittedDemoted : N.draftSaved), n;
147
- } catch (e) {
148
- y.setSaveFailureMessage(S(e) ? N.discountTaxBlockedByLineItems : N.saveFailed), W();
149
- return;
150
- } finally {
151
- H(void 0), U.current = !1;
152
- }
208
+ x,
209
+ nt
210
+ ]), Z = u(() => {
211
+ Y(), I();
212
+ }, [I, Y]), Q = He || nt, $ = u((e) => {
213
+ let t = () => {
214
+ Z(), e();
215
+ };
216
+ Q ? x(t) : t();
217
+ }, [
218
+ x,
219
+ Z,
220
+ Q
221
+ ]), Tt = u(() => {
222
+ Q ? x(Z) : Z();
223
+ }, [
224
+ x,
225
+ Z,
226
+ Q
227
+ ]), Et = u(async ({ closeOnSuccess: t = !0, allowIncompleteVendor: ee = !1 } = {}) => {
228
+ if (ee && E === "create" && !P.current) {
229
+ let e = j.current, t = ce({
230
+ ...dt,
231
+ bankAccount: e
232
+ }, "create", C, "vendor");
233
+ if (ae(t)) return He || !g(e, B ?? h) ? {
234
+ ok: !0,
235
+ counterpartRawData: ge(dt, e, v)
236
+ } : { ok: !0 };
237
+ }
238
+ let n = l, r = !1, i = j.current;
239
+ if (!g(i, M.current)) {
240
+ let e = se(i, C);
241
+ if (Object.keys(e).length > 0) return N(e), E !== "create" && k(!0), { ok: !1 };
242
+ }
243
+ if (E === "edit" && ht) return { ok: !1 };
244
+ if (E) {
245
+ if (E === "create" && P.current) n = P.current;
246
+ else {
247
+ let e = await ut();
248
+ if (!e.ok) return { ok: !1 };
249
+ E === "create" ? (n = e.counterpartId, P.current = n) : n = e.counterpartId ?? n;
153
250
  }
154
- }, [
155
- y,
156
- Q,
157
- N.discountTaxBlockedByLineItems,
158
- N.draftSaved,
159
- N.saveFailed,
160
- N.submittedDemoted,
161
- A,
162
- D,
163
- k,
164
- E,
165
- $,
166
- W
167
- ]),
168
- finalize: _(async () => {
169
- if (U.current) return;
170
- let t = d(y.lineItems, N), n = u(y.values, N), r = Z(), i = c(y.total, N), a = y.isTotalsDirty ? ee(y.totalOverride, N) : void 0, o = r || i || a ? {
171
- ...a,
172
- ...i,
173
- ...r
174
- } : void 0, { formErrors: l, lineItemErrors: f } = s(y.values, b ?? (x ? re : void 0), y.lineItems, N), p = ae(f, t);
175
- y.setLineItemErrors(p), y.setTotalsErrors(o);
176
- let m = {
177
- ...l,
178
- ...n
251
+ E === "create" && (r = !0);
252
+ }
253
+ if (!n) return { ok: !0 };
254
+ let a = H.isBankAccountsLoading || H.isBankAccountsFetching || H.isBankAccountsError;
255
+ if (g(i, M.current)) {
256
+ let e = qe ?? q;
257
+ return e ? (t && (k(!1), E && Y()), r && L(n), {
258
+ ok: !0,
259
+ counterpartId: n,
260
+ counterpartBankAccountId: e
261
+ }) : r ? (t && Y(), L(n), {
262
+ ok: !0,
263
+ counterpartId: n
264
+ }) : a ? { ok: !1 } : (t && (k(!1), E && Y()), {
265
+ ok: !0,
266
+ counterpartId: n,
267
+ counterpartBankAccountId: pt
268
+ });
269
+ }
270
+ if (a) return { ok: !1 };
271
+ N(void 0);
272
+ let o = oe(H.bankAccounts, qe ?? J?.id), s;
273
+ try {
274
+ o.kind === "update" ? (await ot.mutateAsync({
275
+ path: {
276
+ counterpart_id: n,
277
+ bank_account_id: o.bankAccountId
278
+ },
279
+ body: ne(i, { includeAchDefaults: o.includeAchDefaults })
280
+ }), s = o.bankAccountId) : s = (await at.mutateAsync({
281
+ path: { counterpart_id: n },
282
+ body: te(i, { isDefaultForCurrency: o.isDefaultForCurrency })
283
+ }))?.id;
284
+ } catch {
285
+ return e.error(S.bankAccountSaveFailed), {
286
+ ok: !1,
287
+ counterpartId: n
179
288
  };
180
- if (y.setErrors(Object.keys(m).length ? m : void 0), t && e.error(N.lineItemsNeedAttention), p || o || Object.keys(m).length) {
181
- m.vendor && w?.(), W();
182
- return;
183
- }
184
- U.current = !0, H("finalize");
289
+ }
290
+ return M.current = i, Ke(s ? {
291
+ counterpartId: n,
292
+ bankAccountId: s
293
+ } : void 0), t && (k(!1), E && Y()), r && L(n), {
294
+ ok: !0,
295
+ counterpartId: n,
296
+ counterpartBankAccountId: s
297
+ };
298
+ }, [
299
+ Y,
300
+ l,
301
+ at,
302
+ H.bankAccounts,
303
+ H.isBankAccountsError,
304
+ H.isBankAccountsFetching,
305
+ H.isBankAccountsLoading,
306
+ B,
307
+ v,
308
+ E,
309
+ dt,
310
+ He,
311
+ ht,
312
+ q,
313
+ C,
314
+ pt,
315
+ L,
316
+ J,
317
+ ut,
318
+ ot,
319
+ qe
320
+ ]), Dt = u((e) => {
321
+ if (F.current) return F.current;
322
+ let t = (async () => {
323
+ Qe(!0);
185
324
  try {
186
- let t;
187
- try {
188
- let e = await E?.();
189
- if (e && !e.ok) return;
190
- t = await $(e?.counterpartBankAccountId, e?.counterpartId);
191
- } catch (e) {
192
- y.setSaveFailureMessage(S(e) ? N.discountTaxBlockedByLineItems : N.saveFailed), W();
193
- return;
194
- }
195
- D?.(t);
196
- try {
197
- let n = await Y.mutateAsync({ path: { payable_id: t } });
198
- if (n.validation_errors.length) {
199
- let e = C(n.validation_errors, N);
200
- y.setErrors(e.formErrors), y.setTotalsErrors(e.totalsErrors), W();
201
- return;
202
- }
203
- await X.mutateAsync({ path: { payable_id: t } }), y.setErrors(void 0), j?.(t), e.success(N.billFinalized);
204
- } catch (e) {
205
- ie(e) ? y.setErrors({ vendor: N.vendorResolutionFailed }) : y.setSaveFailureMessage(N.finalizeFailed), W();
206
- }
325
+ return await Et(e);
207
326
  } finally {
208
- H(void 0), U.current = !1;
327
+ F.current = void 0, Qe(!1);
328
+ }
329
+ })();
330
+ return F.current = t, t;
331
+ }, [Et]), Ot = u(() => {
332
+ k(!1), E && Y();
333
+ }, [E, Y]), kt = f(() => (V.data?.data ?? []).map((e) => ({
334
+ name: re(e),
335
+ email: c(e),
336
+ onSelect: () => {
337
+ $(() => L(e.id));
338
+ }
339
+ })), [
340
+ V.data,
341
+ $,
342
+ L
343
+ ]), At = u((e) => {
344
+ D(!0), W((t) => e.entityType === "individual" && t.entityType !== "individual" ? {
345
+ ...t,
346
+ ...e,
347
+ firstName: t.firstName || t.legalName,
348
+ legalName: t.legalName
349
+ } : e.entityType === "organization" && t.entityType !== "organization" ? {
350
+ ...t,
351
+ ...e,
352
+ legalName: t.legalName || [t.firstName, t.lastName].filter(Boolean).join(" ")
353
+ } : {
354
+ ...t,
355
+ ...e
356
+ });
357
+ }, [W]), jt = u((e) => {
358
+ D(!0), W((t) => ({
359
+ ...t,
360
+ address: {
361
+ ...t.address,
362
+ ...e
363
+ }
364
+ }));
365
+ }, [W]), Mt = {
366
+ query: w,
367
+ onQueryChange: Pe,
368
+ isLoading: bt || !Te || !Me || !!l && H.isLoading || V.isLoading || V.isFetching && it,
369
+ onAddVendor: () => {
370
+ if (E === "create") {
371
+ let e = w.trim(), [t, ...ee] = e.split(/\s+/);
372
+ W((n) => n.entityType === "individual" ? {
373
+ ...n,
374
+ firstName: t,
375
+ lastName: ee.join(" ")
376
+ } : {
377
+ ...n,
378
+ legalName: e
379
+ }), D(!0);
380
+ return;
209
381
  }
210
- }, [
211
- b,
212
- x,
213
- y,
214
- N,
215
- j,
216
- D,
217
- w,
218
- E,
219
- $,
220
- W,
221
- X,
222
- Z,
223
- Y
224
- ]),
225
- payableId: I,
226
- isSavingDraft: V === "draft",
227
- isFinalizing: V === "finalize",
228
- stagedFile: L,
229
- stageFile: R,
230
- clearStagedFile: oe,
231
- scrollToErrorToken: ce,
232
- isFileDeletionPending: z,
233
- requestFileDeletion: se,
234
- detachFileNow: ue,
235
- isDeletingFile: K.isPending,
236
- hasFileDeletionFailed: K.isError
382
+ $(() => X("create"));
383
+ },
384
+ results: kt
385
+ }, Nt = ke && (E === "create" || !mt) ? {
386
+ isOpen: O,
387
+ values: A,
388
+ errors: We,
389
+ onOpen: St,
390
+ onCancel: wt,
391
+ onChange: Ct
392
+ } : void 0, Pt = E !== "create" && Nt ? {
393
+ ...Nt,
394
+ onOpen: E === "edit" ? () => $(St) : Nt.onOpen,
395
+ canEditExisting: Oe
396
+ } : void 0, Ft = U.isSubmitting || at.isPending || ot.isPending, It = {
397
+ prepareVendorForSave: Dt,
398
+ isVendorSavePending: Ze || Ft,
399
+ hasUnsavedVendorChanges: Q,
400
+ isPendingVendor: !!K && !ft,
401
+ revealIncompleteVendor: ft ? vt : void 0,
402
+ isEditingPayTo: !!E || O,
403
+ activePayToOperation: E ? "vendor" : O ? G?.hasPaymentInstructions ? "existingInstructions" : "missingInstructions" : void 0,
404
+ discardPayToEdits: Z,
405
+ finalizePayToSave: Ot,
406
+ openPaymentInstructions: St,
407
+ paymentInstructions: a(Pt, !!G?.hasPaymentInstructions),
408
+ paymentInstructionsEditor: Pt,
409
+ detailsWarning: gt
410
+ }, Lt = E === "create" && ke ? {
411
+ values: A,
412
+ errors: We,
413
+ onChange: Ct,
414
+ isExtracted: !!(B && g(A, B))
415
+ } : void 0;
416
+ if (E) return {
417
+ mode: "creating",
418
+ summary: G,
419
+ newVendorForm: /* @__PURE__ */ ye(_e, {
420
+ mode: E,
421
+ values: U.values,
422
+ errors: U.errors,
423
+ onChange: At,
424
+ onAddressChange: jt,
425
+ sectionsToExpand: U.sectionsToExpand,
426
+ onAddressExpand: U.expandAddress,
427
+ onCancel: Tt,
428
+ onSave: Dt,
429
+ isSaving: Ft,
430
+ search: rt ? Mt : void 0,
431
+ paymentInstructions: Lt,
432
+ labels: Ae?.inlineForm
433
+ }),
434
+ ...It
435
+ };
436
+ if (G) return {
437
+ mode: "resolved",
438
+ summary: G,
439
+ onEdit: b && !ht ? () => $(() => X("edit")) : void 0,
440
+ ...It
441
+ };
442
+ if (K && !bt) {
443
+ let e = () => $(() => {
444
+ Xe(!0), X("create");
445
+ }), t = b && ke ? {
446
+ isOpen: !1,
447
+ values: A,
448
+ errors: We,
449
+ onOpen: e,
450
+ onChange: Ct,
451
+ onCancel: wt,
452
+ canEditExisting: !0
453
+ } : void 0;
454
+ return {
455
+ mode: "resolved",
456
+ summary: K,
457
+ onEdit: b ? e : void 0,
458
+ error: De,
459
+ ...It,
460
+ showPaymentInstructions: !0,
461
+ paymentInstructions: a(t, K.hasPaymentInstructions),
462
+ paymentInstructionsEditor: t
463
+ };
464
+ }
465
+ return {
466
+ mode: "selecting",
467
+ error: V.isError ? S.searchFailed : H.isError ? S.vendorDetailsFailed : De,
468
+ search: Mt,
469
+ ...It
237
470
  };
238
471
  }
239
472
  //#endregion
240
- export { C as mapValidationErrorsToForm, w as useBillCreateController };
473
+ export { _ as useVendorSectionProps };