@tesouro/embedded-components-react 0.11.179 → 0.11.180

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 (83) hide show
  1. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/data-access/dist/index.js +24 -23
  2. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/data-access/dist/index10.js +16 -18
  3. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/data-access/dist/index11.js +3 -3
  4. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/data-access/dist/index12.js +5 -7
  5. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/data-access/dist/index13.js +2 -2
  6. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/data-access/dist/index14.js +4 -3
  7. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/data-access/dist/index15.js +13 -27
  8. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/data-access/dist/index16.js +34 -19
  9. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/data-access/dist/index17.js +23 -16
  10. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/data-access/dist/index18.js +26 -12
  11. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/data-access/dist/index19.js +12 -57
  12. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/data-access/dist/index2.js +34 -85
  13. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/data-access/dist/index20.js +48 -29
  14. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/data-access/dist/index21.js +36 -20
  15. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/data-access/dist/index22.js +20 -18
  16. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/data-access/dist/index23.js +14 -37
  17. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/data-access/dist/index24.js +31 -14
  18. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/data-access/dist/index25.js +26 -2
  19. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/data-access/dist/index26.js +2 -0
  20. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/data-access/dist/index3.js +90 -20
  21. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/data-access/dist/index4.js +30 -8
  22. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/data-access/dist/index5.js +8 -74
  23. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/data-access/dist/index6.js +60 -19
  24. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/data-access/dist/index7.js +6 -5
  25. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/data-access/dist/index8.js +12 -17
  26. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/data-access/dist/index9.js +20 -12
  27. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index.js +7 -7
  28. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index10.js +17 -36
  29. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index11.js +42 -54
  30. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index12.js +89 -6
  31. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index13.js +5 -21
  32. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index14.js +15 -92
  33. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index15.js +103 -10
  34. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index16.js +10 -9
  35. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index17.js +8 -7
  36. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index18.js +7 -9
  37. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index19.js +11 -29
  38. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index20.js +24 -24
  39. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index21.js +22 -14
  40. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index22.js +14 -137
  41. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index23.js +139 -13
  42. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index24.js +12 -18
  43. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index25.js +15 -32
  44. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index26.js +39 -108
  45. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index27.js +96 -80
  46. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index28.js +94 -3
  47. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index29.js +4 -57
  48. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index30.js +56 -116
  49. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index31.js +114 -197
  50. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index32.js +194 -75
  51. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index33.js +75 -67
  52. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index34.js +69 -111
  53. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index35.js +108 -459
  54. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index36.js +450 -102
  55. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index37.js +117 -9
  56. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index38.js +8 -85
  57. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index39.js +73 -67
  58. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index4.js +1 -1
  59. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index40.js +71 -246
  60. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index41.js +251 -40
  61. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index42.js +38 -237
  62. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index43.js +244 -21
  63. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index44.js +21 -529
  64. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index45.js +530 -4
  65. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index46.js +4 -44
  66. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index47.js +41 -242
  67. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index48.js +245 -3
  68. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index49.js +3 -5
  69. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index50.js +4 -63
  70. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index51.js +64 -1
  71. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index52.js +1 -0
  72. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index9.js +6 -18
  73. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/ui/dist/index3.js +7 -3
  74. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/data-access/dist/lib/invalidatePayableQueries/approvalDecisionQueries.js +22 -19
  75. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/data-access/dist/lib/invalidatePayableQueries/invalidatePayableQueries.js +20 -20
  76. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/data-access/dist/lib/queryKeys.js +32 -21
  77. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/lib/BillPayWidget/BillsTab.js +1 -1
  78. package/dist/libs/tesouro-embedded-components-react/shared/approval-policy/feature/dist/index.js +4 -4
  79. package/dist/libs/tesouro-embedded-components-react/shared/data-access/dist/index.js +42 -42
  80. package/dist/libs/tesouro-embedded-components-react/shared/data-access/dist/lib/rest/@tanstack/react-query.gen.js +237 -215
  81. package/dist/libs/tesouro-embedded-components-react/shared/data-access/dist/lib/rest/sdk.gen.js +151 -135
  82. package/dist/libs/tesouro-embedded-components-react/shared/feature/dist/lib/analytics/build-info.js +1 -1
  83. package/package.json +1 -1
@@ -3,117 +3,465 @@
3
3
  "use client";
4
4
  "use client";
5
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 ee } from "../../../../shared/data-access/dist/lib/scopes.js";
8
+ import "../../../../shared/data-access/dist/index.js";
6
9
  import "../../../../shared/ui/dist/index.js";
7
- import { useUpdatePayableMutation as t } 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 "./index32.js";
13
+ import { usePayableSuggestionsQuery as i } from "../../data-access/dist/index21.js";
8
14
  import "../../data-access/dist/index.js";
9
- import { cloneElement as n, isValidElement as r, useCallback as i, useEffect as a, useMemo as o, useRef as s, useState as c } from "react";
15
+ import { resolvePaymentInstructionsGestures as a } from "./index18.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 "./index34.js";
24
+ import { VendorInlineForm as ve } from "./index35.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";
10
27
  // ../../libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index36.js
11
- function l({ vendor: l, payableId: u, linkedCounterpartId: d, linkedBankAccountId: f, canSavePayToEdits: p, readOnly: m, refreshPayable: h, labels: g }) {
12
- let _ = t(), [v, y] = c(!1), b = s(void 0), x = i(async () => {
13
- if (b.current) return b.current;
14
- let t = (async () => {
15
- if (p) {
16
- y(!0);
17
- try {
18
- let t;
19
- try {
20
- t = await l.prepareVendorForSave({ closeOnSuccess: !1 });
21
- } catch {
22
- e.error(g.paymentInstructionsSaveError);
23
- return;
24
- }
25
- if (!t.ok) return;
26
- if (!u) {
27
- l.finalizePayToSave();
28
- return;
29
- }
30
- let n = t.counterpartId && t.counterpartId !== d ? t.counterpartId : void 0, r = t.counterpartBankAccountId && t.counterpartBankAccountId !== f ? t.counterpartBankAccountId : void 0;
31
- if (n || r) {
32
- let t = {
33
- path: { payable_id: u },
34
- body: {
35
- ...n ? { counterpart_id: n } : {},
36
- ...r ? { counterpart_bank_account_id: r } : {}
37
- }
38
- };
39
- try {
40
- await _.mutateAsync(t);
41
- } catch {
42
- try {
43
- await _.mutateAsync(t);
44
- } catch {
45
- e.error(g.paymentInstructionsLinkError);
46
- return;
47
- }
48
- }
49
- l.finalizePayToSave();
50
- return;
51
- }
52
- l.finalizePayToSave(), await h();
53
- } finally {
54
- y(!1);
55
- }
56
- }
57
- })();
58
- b.current = t;
59
- try {
60
- await t;
61
- } finally {
62
- b.current = void 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
+ };
39
+ }
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();
42
+ }
43
+ function we(e, t) {
44
+ return e?.find((e) => e.id === t && c(e)) ?? s(e);
45
+ }
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;
63
163
  }
164
+ Le(e);
64
165
  }, [
65
- p,
66
- g.paymentInstructionsLinkError,
67
- g.paymentInstructionsSaveError,
68
- _,
69
- f,
70
- d,
71
- u,
72
- h,
73
- l
74
- ]), S = o(() => {
75
- if (!p) return l;
76
- if (l.mode === "creating" && r(l.newVendorForm)) return {
77
- ...l,
78
- newVendorForm: n(l.newVendorForm, {
79
- onSave: x,
80
- isSaving: v
81
- })
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
82
193
  };
83
- if (l.mode === "resolved" && l.paymentInstructions) {
84
- let e = {
85
- onSave: x,
86
- isSaving: v
87
- };
88
- return {
89
- ...l,
90
- paymentInstructions: {
91
- ...l.paymentInstructions,
92
- ...e
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;
201
+ });
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
93
276
  },
94
- paymentInstructionsEditor: l.paymentInstructionsEditor && {
95
- ...l.paymentInstructionsEditor,
96
- ...e
97
- }
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
98
286
  };
99
287
  }
100
- return l;
101
- }, [
102
- p,
103
- v,
104
- x,
105
- l
106
- ]);
107
- return a(() => {
108
- m && l.isEditingPayTo && !p && l.discardPayToEdits();
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
+ };
109
296
  }, [
110
- p,
111
- m,
112
- l.discardPayToEdits,
113
- l.isEditingPayTo
114
- ]), {
115
- vendorWithInlineSave: S,
116
- isSavingPayToEdits: v
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
430
+ };
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;
449
+ return {
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
458
+ };
459
+ }
460
+ return {
461
+ mode: "selecting",
462
+ error: V.isError ? S.searchFailed : H.isError ? S.vendorDetailsFailed : Oe,
463
+ search: Mt,
464
+ ...It
117
465
  };
118
466
  }
119
- export { l as usePayToSave };
467
+ export { g as useVendorSectionProps };
@@ -1,11 +1,119 @@
1
+ "use client";
2
+ "use client";
3
+ "use client";
4
+ "use client";
5
+ import { toast as e } from "../../../../../../node_modules/sonner/dist/index.js";
6
+ import "../../../../shared/ui/dist/index.js";
7
+ import { useUpdatePayableMutation as t } from "../../data-access/dist/index17.js";
8
+ import "../../data-access/dist/index.js";
9
+ import { cloneElement as n, isValidElement as r, useCallback as i, useEffect as a, useMemo as o, useRef as s, useState as c } from "react";
1
10
  // ../../libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index37.js
2
- function e(e) {
3
- return new Promise((t, n) => {
4
- let r = new FileReader();
5
- r.onerror = () => n(r.error ?? /* @__PURE__ */ Error("Failed to read file")), r.onload = () => {
6
- let e = r.result;
7
- typeof e == "string" ? t(e.slice(e.indexOf(",") + 1)) : n(/* @__PURE__ */ Error("Failed to read file as a data URL"));
8
- }, r.readAsDataURL(e);
9
- });
11
+ function l({ vendor: l, payableId: u, linkedCounterpartId: d, linkedBankAccountId: f, canSavePayToEdits: p, readOnly: m, refreshPayable: h, labels: g }) {
12
+ let _ = t(), [v, y] = c(!1), b = s(void 0), x = i(async () => {
13
+ if (b.current) return b.current;
14
+ let t = (async () => {
15
+ if (p) {
16
+ y(!0);
17
+ try {
18
+ let t;
19
+ try {
20
+ t = await l.prepareVendorForSave({ closeOnSuccess: !1 });
21
+ } catch {
22
+ e.error(g.paymentInstructionsSaveError);
23
+ return;
24
+ }
25
+ if (!t.ok) return;
26
+ if (!u) {
27
+ l.finalizePayToSave();
28
+ return;
29
+ }
30
+ let n = t.counterpartId && t.counterpartId !== d ? t.counterpartId : void 0, r = t.counterpartBankAccountId && t.counterpartBankAccountId !== f ? t.counterpartBankAccountId : void 0;
31
+ if (n || r) {
32
+ let t = {
33
+ path: { payable_id: u },
34
+ body: {
35
+ ...n ? { counterpart_id: n } : {},
36
+ ...r ? { counterpart_bank_account_id: r } : {}
37
+ }
38
+ };
39
+ try {
40
+ await _.mutateAsync(t);
41
+ } catch {
42
+ try {
43
+ await _.mutateAsync(t);
44
+ } catch {
45
+ e.error(g.paymentInstructionsLinkError);
46
+ return;
47
+ }
48
+ }
49
+ l.finalizePayToSave();
50
+ return;
51
+ }
52
+ l.finalizePayToSave(), await h();
53
+ } finally {
54
+ y(!1);
55
+ }
56
+ }
57
+ })();
58
+ b.current = t;
59
+ try {
60
+ await t;
61
+ } finally {
62
+ b.current = void 0;
63
+ }
64
+ }, [
65
+ p,
66
+ g.paymentInstructionsLinkError,
67
+ g.paymentInstructionsSaveError,
68
+ _,
69
+ f,
70
+ d,
71
+ u,
72
+ h,
73
+ l
74
+ ]), S = o(() => {
75
+ if (!p) return l;
76
+ if (l.mode === "creating" && r(l.newVendorForm)) return {
77
+ ...l,
78
+ newVendorForm: n(l.newVendorForm, {
79
+ onSave: x,
80
+ isSaving: v
81
+ })
82
+ };
83
+ if (l.mode === "resolved" && l.paymentInstructions) {
84
+ let e = {
85
+ onSave: x,
86
+ isSaving: v
87
+ };
88
+ return {
89
+ ...l,
90
+ paymentInstructions: {
91
+ ...l.paymentInstructions,
92
+ ...e
93
+ },
94
+ paymentInstructionsEditor: l.paymentInstructionsEditor && {
95
+ ...l.paymentInstructionsEditor,
96
+ ...e
97
+ }
98
+ };
99
+ }
100
+ return l;
101
+ }, [
102
+ p,
103
+ v,
104
+ x,
105
+ l
106
+ ]);
107
+ return a(() => {
108
+ m && l.isEditingPayTo && !p && l.discardPayToEdits();
109
+ }, [
110
+ p,
111
+ m,
112
+ l.discardPayToEdits,
113
+ l.isEditingPayTo
114
+ ]), {
115
+ vendorWithInlineSave: S,
116
+ isSavingPayToEdits: v
117
+ };
10
118
  }
11
- export { e as encodeFileToBase64 };
119
+ export { l as usePayToSave };