@tesouro/embedded-components-react 0.4.28 → 0.4.30

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 (93) hide show
  1. package/dist/index.js +1 -1
  2. package/dist/lib/BillPayWidget.js +1 -1
  3. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/data-access/dist/index.js +2 -2
  4. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/data-access/dist/index16.js +15 -82
  5. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/data-access/dist/index17.js +87 -25
  6. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/data-access/dist/index18.js +36 -0
  7. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index.js +12 -12
  8. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index10.js +5 -70
  9. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index11.js +64 -37
  10. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index12.js +38 -110
  11. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index13.js +104 -73
  12. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index14.js +87 -7
  13. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index15.js +7 -21
  14. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index16.js +17 -22
  15. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index17.js +23 -63
  16. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index18.js +66 -2
  17. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index19.js +2 -77
  18. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index20.js +78 -3
  19. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index21.js +4 -5
  20. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index22.js +5 -4
  21. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index23.js +3 -32
  22. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index24.js +30 -39
  23. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index25.js +37 -166
  24. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index26.js +164 -39
  25. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index27.js +48 -1
  26. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index28.js +1 -50
  27. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index29.js +45 -11
  28. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index30.js +13 -8
  29. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index31.js +8 -14
  30. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index32.js +7 -59
  31. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index33.js +64 -8
  32. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index34.js +8 -24
  33. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index35.js +18 -136
  34. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index36.js +139 -16
  35. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index37.js +24 -4
  36. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index38.js +4 -41
  37. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index39.js +39 -88
  38. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index40.js +79 -85
  39. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index41.js +96 -3
  40. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index42.js +3 -49
  41. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index43.js +47 -119
  42. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index44.js +135 -33
  43. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index45.js +33 -186
  44. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index46.js +186 -75
  45. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index47.js +75 -21
  46. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index48.js +22 -232
  47. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index49.js +223 -210
  48. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index5.js +14 -25
  49. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index50.js +202 -103
  50. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index51.js +121 -13
  51. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index52.js +12 -47
  52. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index53.js +47 -31
  53. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index54.js +27 -198
  54. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index55.js +198 -30
  55. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index56.js +30 -234
  56. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index57.js +240 -19
  57. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index58.js +19 -425
  58. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index59.js +433 -4
  59. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index6.js +25 -24
  60. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index60.js +4 -38
  61. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index61.js +35 -218
  62. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index62.js +224 -3
  63. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index63.js +3 -4
  64. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index64.js +2 -44
  65. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index65.js +46 -1
  66. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index66.js +1 -8
  67. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index67.js +6 -10
  68. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index68.js +10 -110
  69. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index69.js +112 -3
  70. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index7.js +21 -57
  71. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index70.js +3 -127
  72. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index71.js +124 -8
  73. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index72.js +8 -7
  74. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index73.js +8 -46
  75. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index74.js +43 -18
  76. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index75.js +20 -28
  77. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index76.js +27 -82
  78. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index77.js +83 -47
  79. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index78.js +47 -250
  80. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index79.js +239 -101
  81. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index8.js +58 -5
  82. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index80.js +107 -202
  83. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index81.js +209 -3
  84. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index82.js +4 -8
  85. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index83.js +6 -113
  86. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index84.js +115 -1
  87. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index85.js +0 -24
  88. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index86.js +25 -0
  89. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index9.js +5 -4
  90. package/dist/libs/tesouro-embedded-components-react/shared/data-access/dist/lib/rest/zod.gen.js +1784 -1769
  91. package/dist/libs/tesouro-embedded-components-react/shared/feature/dist/lib/analytics/build-info.js +1 -1
  92. package/dist/libs/tesouro-embedded-components-react/widget-suite/feature/dist/index8.js +1 -1
  93. package/package.json +1 -1
@@ -2,123 +2,222 @@
2
2
  "use client";
3
3
  "use client";
4
4
  "use client";
5
- import { toast as e } from "../../../../../packages/shared-ui-shadcn/dist/index.js";
6
- import "../../../shared/ui/dist/index.js";
7
- import { useUpdatePayableMutation as t } from "../../data-access/dist/index13.js";
8
- import { useCounterpartBankAccountsQuery as n, useCreateCounterpartBankAccountMutation as r } from "../../../shared/counterpart-management/data-access/dist/index5.js";
9
- import { useUpdatePayableCounterpartBankAccountMutation as i } from "../../data-access/dist/index14.js";
5
+ import { hasAnyScope as e } from "../../../shared/data-access/dist/lib/hasAnyScope.js";
6
+ import { Scope as t } from "../../../shared/data-access/dist/lib/scopes.js";
7
+ import "../../../shared/data-access/dist/index.js";
8
+ import { useWidgetConfig as n } from "../../../shared/feature/dist/lib/WidgetProvider/hooks.js";
9
+ import "../../../shared/feature/dist/index.js";
10
+ import { useCounterpartsQuery as r } from "../../../shared/counterpart-management/data-access/dist/index3.js";
11
+ import { useCreateCounterpartBankAccountMutation as ee, useUpdateCounterpartBankAccountMutation as te } from "../../../shared/counterpart-management/data-access/dist/index5.js";
12
+ import { usePayableSuggestionsQuery as i } from "../../data-access/dist/index18.js";
10
13
  import "../../data-access/dist/index.js";
11
- import { counterpartFormBankAccountToCreatePayload as a, counterpartFormBankAccountToUpdatePayload as o, getAchInstructions as s, isAchCompatibleBankAccount as c, resolveCounterpartBankAccountWrite as l, validateAchFormValues as u } from "../../../shared/counterpart-management/feature/dist/lib/helpers.js";
14
+ import { maskAccountNumber as a } from "./index23.js";
15
+ import { counterpartFormBankAccountToCreatePayload as ne, counterpartFormBankAccountToUpdatePayload as re, getAchInstructions as ie, getCounterpartEmail as o, getCounterpartName as s, getPayableAchInstructions as c, hasAchFormValues as l, resolveCounterpartBankAccountWrite as ae, validateAchFormValues as oe } from "../../../shared/counterpart-management/feature/dist/lib/helpers.js";
16
+ import { useCounterpartDetails as se } from "../../../shared/counterpart-management/feature/dist/lib/useCounterpartDetails.js";
12
17
  import "../../../shared/counterpart-management/feature/dist/index.js";
13
- import { useCallback as d, useEffect as f, useRef as p, useState as m } from "react";
18
+ import { VENDOR_SECTION_PROPS_LABELS_EN as ce } from "./index46.js";
19
+ import { buildVendorPrefill as le } from "./index48.js";
20
+ import { VendorInlineForm as ue } from "./index49.js";
21
+ import { useCallback as u, useEffect as d, useMemo as f, useRef as p, useState as m } from "react";
22
+ import { jsx as de } from "react/jsx-runtime";
14
23
  //#region ../../libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index50.js
15
- var h = {
24
+ var fe = 10, h = 300, g = {
16
25
  accountHolderName: "",
17
26
  routingNumber: "",
18
27
  accountNumber: ""
19
28
  };
20
- function g(e, t) {
21
- return e?.find((e) => e.id === t && c(e)) ?? s(e);
22
- }
23
- function _({ payableId: c, counterpartId: _, currentBankAccountId: v, canReadCounterpartBankAccounts: y = !0, saveErrorMessage: b, linkErrorMessage: x }) {
24
- let [S, C] = m(!1), [w, T] = m(h), [E, D] = m(), O = n(_, { enabled: y }), k = O.data?.data, A = r(), j = i(), M = t(), N = p(void 0), P = p(!1);
25
- f(() => {
26
- N.current = void 0;
27
- }, [_, c]);
28
- let F = d(() => {
29
- if (S) return;
30
- let e = O.isFetching ? void 0 : g(k, v);
31
- T(e ? {
32
- accountHolderName: e.account_holder_name ?? "",
33
- routingNumber: e.routing_number ?? "",
34
- accountNumber: e.account_number ?? ""
35
- } : h), N.current = e?.id ?? N.current, P.current = !O.isFetching, D(void 0), C(!0);
36
- }, [
37
- k,
38
- O.isFetching,
39
- v,
40
- S
41
- ]);
42
- f(() => {
43
- if (!S || P.current || O.isFetching) return;
44
- P.current = !0;
45
- let e = g(k, v);
46
- e && (T((t) => t.accountHolderName === "" && t.routingNumber === "" && t.accountNumber === "" ? {
47
- accountHolderName: e.account_holder_name ?? "",
48
- routingNumber: e.routing_number ?? "",
49
- accountNumber: e.account_number ?? ""
50
- } : t), N.current = e.id);
29
+ function _({ payableId: _, counterpartId: v, payableCounterpartId: y, payableCounterpartBankAccountId: b, isVendorKnown: x = !0, onCounterpartChange: S, requiredError: pe, extractedVendor: C, labels: me }) {
30
+ let w = {
31
+ ...ce,
32
+ ...me
33
+ }, { initResponse: T } = n(), he = e(T?.scopes, [t.CounterpartReadOrg]), [E, D] = m(""), [ge, _e] = m(""), [O, k] = m(), [ve, A] = m(!1), [j, M] = m(g), N = p(j);
34
+ N.current = j;
35
+ let [P, F] = m(!1), I = l(j) || P, [ye, L] = m(), [R, z] = m(), B = p(v), [V, be] = m(!1), H = u(() => {
36
+ A(!1), M(g), L(void 0), z(void 0);
37
+ }, []), U = u((e) => {
38
+ be(!0), S(e);
39
+ }, [S]), W = i(_, { enabled: !!_ && !v && !y }).data?.suggested_counterpart?.id;
40
+ d(() => {
41
+ !V && !v && !y && W && U(W);
51
42
  }, [
52
- S,
53
- O.isFetching,
54
- k,
55
43
  v,
56
- y
57
- ]);
58
- let I = d(() => {
59
- C(!1);
60
- }, []), L = d((e) => {
61
- T((t) => ({
62
- ...t,
63
- ...e
64
- }));
65
- }, []), R = d(async () => {
66
- if (!c || !_) return !1;
67
- let t = u(w);
68
- if (Object.keys(t).length > 0) return D(t), !1;
69
- if (D(void 0), !y || O.isFetching || O.isError) return e.error(b), !1;
70
- let n = N.current;
71
- try {
72
- let e = l(k, n ?? s(k)?.id);
73
- e.kind === "update" ? (await j.mutateAsync({
74
- path: {
75
- counterpart_id: _,
76
- bank_account_id: e.bankAccountId
44
+ y,
45
+ V,
46
+ W,
47
+ U
48
+ ]), d(() => {
49
+ B.current !== v && (B.current = v, H());
50
+ }, [v, H]), d(() => {
51
+ let e = setTimeout(() => {
52
+ _e(E.trim());
53
+ }, h);
54
+ return () => clearTimeout(e);
55
+ }, [E]);
56
+ let G = r({
57
+ sort: "counterpart_name",
58
+ order: "asc",
59
+ limit: fe,
60
+ counterpart_name__icontains: ge || void 0,
61
+ is_vendor: !0,
62
+ enabled: !O && !v && x && he
63
+ }), K = se({ selectedId: v }), q = ee(), J = te(), Y = f(() => {
64
+ let e = K.counterpart;
65
+ if (!e) return;
66
+ if (K.isBankAccountsLoading) return {
67
+ name: s(e),
68
+ email: o(e),
69
+ methodLabel: w.paymentMethodLoading,
70
+ fields: []
71
+ };
72
+ if (K.isBankAccountsError) return {
73
+ name: s(e),
74
+ email: o(e),
75
+ methodLabel: w.paymentMethodUnavailable,
76
+ fields: []
77
+ };
78
+ let t = c(K.bankAccounts);
79
+ return {
80
+ name: s(e),
81
+ email: o(e),
82
+ methodLabel: t ? w.achMethod : w.noMethod,
83
+ fields: t ? [
84
+ {
85
+ label: w.accountHolder,
86
+ value: t.account_holder_name ?? ""
87
+ },
88
+ {
89
+ label: w.routingNumber,
90
+ value: t.routing_number ?? ""
77
91
  },
78
- body: o(w, { includeAchDefaults: e.includeAchDefaults }),
79
- payableId: c,
80
- makeDefault: e.includeAchDefaults || !k?.find((t) => t.id === e.bankAccountId)?.is_default_for_currency
81
- }), n = e.bankAccountId) : n = (await A.mutateAsync({
82
- path: { counterpart_id: _ },
83
- body: a(w, { isDefaultForCurrency: e.isDefaultForCurrency })
84
- }))?.id, N.current = n;
85
- } catch {
86
- return e.error(b), !1;
87
- }
88
- if (n !== v) try {
89
- await M.mutateAsync({
90
- path: { payable_id: c },
91
- body: { counterpart_bank_account_id: n }
92
- });
93
- } catch {
94
- return e.error(x), !1;
95
- }
96
- return C(!1), !0;
92
+ {
93
+ label: w.accountNumber,
94
+ value: t.account_number ?? "",
95
+ maskedValue: t.account_number ? a(t.account_number) : ""
96
+ }
97
+ ] : []
98
+ };
97
99
  }, [
98
- k,
99
- O.isError,
100
- O.isFetching,
101
- y,
102
- _,
103
- A,
100
+ K.bankAccounts,
101
+ K.counterpart,
102
+ K.isBankAccountsError,
103
+ K.isBankAccountsLoading,
104
+ w
105
+ ]), X = f(() => ie(K.bankAccounts), [K.bankAccounts]), Z = f(() => c(K.bankAccounts)?.id, [K.bankAccounts]), Q = u(async () => {
106
+ let e = N.current;
107
+ if (!v) return { ok: !0 };
108
+ if (!l(e)) return b && v === y ? {
109
+ ok: !0,
110
+ counterpartBankAccountId: b
111
+ } : K.isBankAccountsLoading || K.isBankAccountsFetching || K.isBankAccountsError ? { ok: !1 } : {
112
+ ok: !0,
113
+ counterpartBankAccountId: Z
114
+ };
115
+ if (K.isBankAccountsLoading || K.isBankAccountsFetching || K.isBankAccountsError) return { ok: !1 };
116
+ let t = oe(e);
117
+ if (Object.keys(t).length > 0) return L(t), A(!0), { ok: !1 };
118
+ L(void 0);
119
+ let n = ae(K.bankAccounts, R ?? X?.id);
120
+ if (n.kind === "update") return await J.mutateAsync({
121
+ path: {
122
+ counterpart_id: v,
123
+ bank_account_id: n.bankAccountId
124
+ },
125
+ body: re(e, { includeAchDefaults: n.includeAchDefaults })
126
+ }), z(n.bankAccountId), {
127
+ ok: !0,
128
+ counterpartBankAccountId: n.bankAccountId
129
+ };
130
+ let r = await q.mutateAsync({
131
+ path: { counterpart_id: v },
132
+ body: ne(e, { isDefaultForCurrency: n.isDefaultForCurrency })
133
+ });
134
+ return z(r?.id), {
135
+ ok: !0,
136
+ counterpartBankAccountId: r?.id
137
+ };
138
+ }, [
139
+ X,
104
140
  v,
105
- x,
106
- c,
141
+ q,
142
+ K.bankAccounts,
143
+ K.isBankAccountsError,
144
+ K.isBankAccountsFetching,
145
+ K.isBankAccountsLoading,
146
+ R,
147
+ Z,
107
148
  b,
108
- j,
109
- M,
110
- w
111
- ]);
149
+ y,
150
+ J
151
+ ]), xe = f(() => (G.data?.data ?? []).map((e) => ({
152
+ name: s(e),
153
+ email: o(e),
154
+ onSelect: () => U(e.id)
155
+ })), [G.data, U]), Se = f(() => le(C), [C]), $ = u(() => {
156
+ k(void 0), F(!1);
157
+ }, []), Ce = u((e) => {
158
+ k(void 0), F(!1), U(e);
159
+ }, [U]);
160
+ if (O) return {
161
+ mode: "creating",
162
+ newVendorForm: /* @__PURE__ */ de(ue, {
163
+ mode: O,
164
+ counterpart: O === "edit" ? K.counterpart : void 0,
165
+ primaryAddress: O === "edit" ? K.primaryAddress : void 0,
166
+ bankAccounts: O === "edit" ? K.bankAccounts : void 0,
167
+ isBankAccountsLoading: O === "edit" ? K.isBankAccountsLoading : void 0,
168
+ isBankAccountsError: O === "edit" ? K.isBankAccountsError : void 0,
169
+ initialName: O === "create" ? E : void 0,
170
+ initialValues: O === "create" ? Se : void 0,
171
+ onSaved: Ce,
172
+ onCancel: $,
173
+ onDirtyChange: F
174
+ }),
175
+ onClear: $,
176
+ hasUnsavedVendorChanges: I
177
+ };
178
+ if (Y) {
179
+ let e = K.isBankAccountsLoading || K.isBankAccountsFetching || K.isBankAccountsError;
180
+ return {
181
+ mode: "resolved",
182
+ summary: Y,
183
+ onEdit: e ? void 0 : () => k("edit"),
184
+ onClear: () => U(void 0),
185
+ paymentInstructions: e ? void 0 : {
186
+ isOpen: ve,
187
+ values: j,
188
+ errors: ye,
189
+ onOpen: () => {
190
+ A(!0), X && (M({
191
+ accountHolderName: X.account_holder_name ?? "",
192
+ routingNumber: X.routing_number ?? "",
193
+ accountNumber: X.account_number ?? ""
194
+ }), z(X.id));
195
+ },
196
+ onChange: (e) => {
197
+ M((t) => ({
198
+ ...t,
199
+ ...e
200
+ })), L(void 0);
201
+ }
202
+ },
203
+ savePaymentInstructions: Q,
204
+ hasUnsavedVendorChanges: I
205
+ };
206
+ }
207
+ let we = !x || !T || !!v && K.isLoading;
112
208
  return {
113
- isOpen: S,
114
- values: w,
115
- errors: E,
116
- isSaving: A.isPending || j.isPending || M.isPending,
117
- open: F,
118
- close: I,
119
- onChange: L,
120
- save: R
209
+ mode: "selecting",
210
+ error: G.isError ? w.searchFailed : K.isError ? w.vendorDetailsFailed : pe,
211
+ search: {
212
+ query: E,
213
+ onQueryChange: D,
214
+ isLoading: we || G.isFetching,
215
+ onAddVendor: () => k("create"),
216
+ results: xe
217
+ },
218
+ savePaymentInstructions: Q,
219
+ hasUnsavedVendorChanges: I
121
220
  };
122
221
  }
123
222
  //#endregion
124
- export { _ as usePaymentInstructionsForm };
223
+ export { _ as useVendorSectionProps };
@@ -1,16 +1,124 @@
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 "../../../shared/ui/dist/index.js";
7
+ import { useUpdatePayableMutation as t } from "../../data-access/dist/index13.js";
8
+ import { useCounterpartBankAccountsQuery as n, useCreateCounterpartBankAccountMutation as r } from "../../../shared/counterpart-management/data-access/dist/index5.js";
9
+ import { useUpdatePayableCounterpartBankAccountMutation as i } from "../../data-access/dist/index14.js";
10
+ import "../../data-access/dist/index.js";
11
+ import { counterpartFormBankAccountToCreatePayload as a, counterpartFormBankAccountToUpdatePayload as o, getAchInstructions as s, isAchCompatibleBankAccount as c, resolveCounterpartBankAccountWrite as l, validateAchFormValues as u } from "../../../shared/counterpart-management/feature/dist/lib/helpers.js";
12
+ import "../../../shared/counterpart-management/feature/dist/index.js";
13
+ import { useCallback as d, useEffect as f, useRef as p, useState as m } from "react";
1
14
  //#region ../../libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index51.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
- if (typeof e != "string") {
8
- n(/* @__PURE__ */ Error("Failed to read file as a data URL"));
9
- return;
10
- }
11
- t(e.slice(e.indexOf(",") + 1));
12
- }, r.readAsDataURL(e);
13
- });
15
+ var h = {
16
+ accountHolderName: "",
17
+ routingNumber: "",
18
+ accountNumber: ""
19
+ };
20
+ function g(e, t) {
21
+ return e?.find((e) => e.id === t && c(e)) ?? s(e);
22
+ }
23
+ function _({ payableId: c, counterpartId: _, currentBankAccountId: v, canReadCounterpartBankAccounts: y = !0, saveErrorMessage: b, linkErrorMessage: x }) {
24
+ let [S, C] = m(!1), [w, T] = m(h), [E, D] = m(), O = n(_, { enabled: y }), k = O.data?.data, A = r(), j = i(), M = t(), N = p(void 0), P = p(!1);
25
+ f(() => {
26
+ N.current = void 0;
27
+ }, [_, c]);
28
+ let F = d(() => {
29
+ if (S) return;
30
+ let e = O.isFetching ? void 0 : g(k, v);
31
+ T(e ? {
32
+ accountHolderName: e.account_holder_name ?? "",
33
+ routingNumber: e.routing_number ?? "",
34
+ accountNumber: e.account_number ?? ""
35
+ } : h), N.current = e?.id ?? N.current, P.current = !O.isFetching, D(void 0), C(!0);
36
+ }, [
37
+ k,
38
+ O.isFetching,
39
+ v,
40
+ S
41
+ ]);
42
+ f(() => {
43
+ if (!S || P.current || O.isFetching) return;
44
+ P.current = !0;
45
+ let e = g(k, v);
46
+ e && (T((t) => t.accountHolderName === "" && t.routingNumber === "" && t.accountNumber === "" ? {
47
+ accountHolderName: e.account_holder_name ?? "",
48
+ routingNumber: e.routing_number ?? "",
49
+ accountNumber: e.account_number ?? ""
50
+ } : t), N.current = e.id);
51
+ }, [
52
+ S,
53
+ O.isFetching,
54
+ k,
55
+ v,
56
+ y
57
+ ]);
58
+ let I = d(() => {
59
+ C(!1);
60
+ }, []), L = d((e) => {
61
+ T((t) => ({
62
+ ...t,
63
+ ...e
64
+ }));
65
+ }, []), R = d(async () => {
66
+ if (!c || !_) return !1;
67
+ let t = u(w);
68
+ if (Object.keys(t).length > 0) return D(t), !1;
69
+ if (D(void 0), !y || O.isFetching || O.isError) return e.error(b), !1;
70
+ let n = N.current;
71
+ try {
72
+ let e = l(k, n ?? s(k)?.id);
73
+ e.kind === "update" ? (await j.mutateAsync({
74
+ path: {
75
+ counterpart_id: _,
76
+ bank_account_id: e.bankAccountId
77
+ },
78
+ body: o(w, { includeAchDefaults: e.includeAchDefaults }),
79
+ payableId: c,
80
+ makeDefault: e.includeAchDefaults || !k?.find((t) => t.id === e.bankAccountId)?.is_default_for_currency
81
+ }), n = e.bankAccountId) : n = (await A.mutateAsync({
82
+ path: { counterpart_id: _ },
83
+ body: a(w, { isDefaultForCurrency: e.isDefaultForCurrency })
84
+ }))?.id, N.current = n;
85
+ } catch {
86
+ return e.error(b), !1;
87
+ }
88
+ if (n !== v) try {
89
+ await M.mutateAsync({
90
+ path: { payable_id: c },
91
+ body: { counterpart_bank_account_id: n }
92
+ });
93
+ } catch {
94
+ return e.error(x), !1;
95
+ }
96
+ return C(!1), !0;
97
+ }, [
98
+ k,
99
+ O.isError,
100
+ O.isFetching,
101
+ y,
102
+ _,
103
+ A,
104
+ v,
105
+ x,
106
+ c,
107
+ b,
108
+ j,
109
+ M,
110
+ w
111
+ ]);
112
+ return {
113
+ isOpen: S,
114
+ values: w,
115
+ errors: E,
116
+ isSaving: A.isPending || j.isPending || M.isPending,
117
+ open: F,
118
+ close: I,
119
+ onChange: L,
120
+ save: R
121
+ };
14
122
  }
15
123
  //#endregion
16
- export { e as encodeFileToBase64 };
124
+ export { _ as usePaymentInstructionsForm };
@@ -1,51 +1,16 @@
1
- import { parseDecimalAmountToMinorUnits as e } from "../../../shared/util/dist/lib/parseDecimalAmountToMinorUnits.js";
2
- import "../../data-access/dist/index.js";
3
1
  //#region ../../libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index52.js
4
- var t = "USD";
5
- function n(n) {
6
- return e(n, t);
7
- }
8
- function r(e) {
9
- let t = e.trim();
10
- if (!t) return null;
11
- let n = Number(t);
12
- return Number.isFinite(n) && n > 0 ? n : null;
13
- }
14
- function i(e) {
15
- return !!(e.description.trim() || e.glCode.trim() || n(e.price) !== null || n(e.amount) !== null);
16
- }
17
- function a(e) {
18
- return n(e) ?? 0;
19
- }
20
- function o(e) {
21
- let t = Number.parseFloat(e);
22
- return Number.isFinite(t) ? t : 0;
23
- }
24
- function s(e) {
25
- return (e / 100).toFixed(2);
26
- }
27
- function c({ values: e, counterpartId: r, clearCounterpart: i, counterpartBankAccountId: a, editedTotals: o, document: s }) {
28
- let c = { currency: t };
29
- return r ? c.counterpart_id = r : i && (c.counterpart_id = null), r ? c.counterpart_bank_account_id = a ?? null : i && (c.counterpart_bank_account_id = null), e.invoiceNumber && (c.document_id = e.invoiceNumber), e.invoiceDate && (c.issued_at = e.invoiceDate), e.dueDate && (c.due_date = e.dueDate), s && (c.base64_encoded_file = s.base64EncodedFile, c.file_name = s.fileName), o && (c.discount = n(o.discount) ?? 0, c.tax_amount = n(o.tax) ?? 0, o.total !== void 0 && (c.total_amount = n(o.total) ?? 0)), c;
30
- }
31
- function l(e) {
32
- return e.filter(i).map((e) => {
33
- 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);
34
- return {
35
- name: e.description,
36
- quantity: i,
37
- unit_price: a,
38
- tax: 0,
39
- ...t !== null && t !== o ? { subtotal: t } : {},
40
- ...e.glCode ? { ledger_account_id: e.glCode } : {}
41
- };
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
+ if (typeof e != "string") {
8
+ n(/* @__PURE__ */ Error("Failed to read file as a data URL"));
9
+ return;
10
+ }
11
+ t(e.slice(e.indexOf(",") + 1));
12
+ }, r.readAsDataURL(e);
42
13
  });
43
14
  }
44
- function u(e, t) {
45
- return s(Math.round(o(e) * a(t)));
46
- }
47
- function d(e, t, n) {
48
- return s(e.reduce((e, t) => e + a(t.amount), 0) + a(t) - a(n));
49
- }
50
15
  //#endregion
51
- export { d as calculateTotal, u as displayLineAmount, i as isPersistableLineItem, c as mapBillFormToPayload, l as mapLineItemsToPayload, n as parseMoneyToMinorUnits, r as parseQuantity };
16
+ export { e as encodeFileToBase64 };
@@ -1,35 +1,51 @@
1
- import { BILL_CREATE_MESSAGE_LABELS_EN as e } from "./index45.js";
2
- import { isPersistableLineItem as t, parseMoneyToMinorUnits as n, parseQuantity as r } from "./index52.js";
1
+ import { parseDecimalAmountToMinorUnits as e } from "../../../shared/util/dist/lib/parseDecimalAmountToMinorUnits.js";
2
+ import "../../data-access/dist/index.js";
3
3
  //#region ../../libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index53.js
4
- var i = /^(?:\d{1,3}(?:,\d{3})+(?:\.\d+)?|\d+(?:\.\d+)?|\.\d+)$/;
5
- function a(e) {
4
+ var t = "USD";
5
+ function n(n) {
6
+ return e(n, t);
7
+ }
8
+ function r(e) {
6
9
  let t = e.trim();
7
- return !t || n(t) !== null ? !0 : i.test(t) ? Number(t.replaceAll(",", "")) === 0 : !1;
8
- }
9
- function o(t, i = e) {
10
- let a = {};
11
- for (let e of t) {
12
- let t = n(e.price), o = n(e.amount), s = {};
13
- e.price.trim() && t === null && (s.price = i.unreadableMoney), e.amount.trim() && o === null && (s.amount = i.unreadableMoney), r(e.quantity) === null && (e.quantity.trim() || t !== null || o !== null) && (s.quantity = i.unusableQuantity), Object.keys(s).length && (a[e.id] = s);
14
- }
15
- return Object.keys(a).length ? a : void 0;
16
- }
17
- function s(i, a, o, s = e) {
18
- let c = {};
19
- a || (c.vendor = s.requiredField), i.invoiceNumber.trim() || (c.invoiceNumber = s.requiredField), i.invoiceDate.trim() || (c.invoiceDate = s.requiredField), i.dueDate.trim() || (c.dueDate = s.requiredField);
20
- let l = {};
21
- return o.forEach((e, i) => {
22
- if (i > 0 && !t(e)) return;
23
- let a = {};
24
- e.description.trim() || (a.description = s.requiredField), r(e.quantity) === null && (a.quantity = s.requiredField), n(e.price) === null && n(e.amount) === null && (a.price = s.requiredField, a.amount = s.requiredField), Object.keys(a).length && (l[e.id] = a);
25
- }), {
26
- formErrors: Object.keys(c).length ? c : void 0,
27
- lineItemErrors: Object.keys(l).length ? l : void 0
28
- };
29
- }
30
- function c(t, r, i, o = e) {
31
- let s = {};
32
- return a(t) || (s.discount = o.unreadableDiscount), a(r) || (s.tax = o.unreadableTax), i !== void 0 && n(i) === null && (s.total = o.unreadableTotal), Object.keys(s).length ? s : void 0;
10
+ if (!t) return null;
11
+ let n = Number(t);
12
+ return Number.isFinite(n) && n > 0 ? n : null;
13
+ }
14
+ function i(e) {
15
+ return !!(e.description.trim() || e.glCode.trim() || n(e.price) !== null || n(e.amount) !== null);
16
+ }
17
+ function a(e) {
18
+ return n(e) ?? 0;
19
+ }
20
+ function o(e) {
21
+ let t = Number.parseFloat(e);
22
+ return Number.isFinite(t) ? t : 0;
23
+ }
24
+ function s(e) {
25
+ return (e / 100).toFixed(2);
26
+ }
27
+ function c({ values: e, counterpartId: r, clearCounterpart: i, counterpartBankAccountId: a, editedTotals: o, document: s }) {
28
+ let c = { currency: t };
29
+ return r ? c.counterpart_id = r : i && (c.counterpart_id = null), r ? c.counterpart_bank_account_id = a ?? null : i && (c.counterpart_bank_account_id = null), e.invoiceNumber && (c.document_id = e.invoiceNumber), e.invoiceDate && (c.issued_at = e.invoiceDate), e.dueDate && (c.due_date = e.dueDate), s && (c.base64_encoded_file = s.base64EncodedFile, c.file_name = s.fileName), o && (c.discount = n(o.discount) ?? 0, c.tax_amount = n(o.tax) ?? 0, o.total !== void 0 && (c.total_amount = n(o.total) ?? 0)), c;
30
+ }
31
+ function l(e) {
32
+ return e.filter(i).map((e) => {
33
+ 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);
34
+ return {
35
+ name: e.description,
36
+ quantity: i,
37
+ unit_price: a,
38
+ tax: 0,
39
+ ...t !== null && t !== o ? { subtotal: t } : {},
40
+ ...e.glCode ? { ledger_account_id: e.glCode } : {}
41
+ };
42
+ });
43
+ }
44
+ function u(e, t) {
45
+ return s(Math.round(o(e) * a(t)));
46
+ }
47
+ function d(e, t, n) {
48
+ return s(e.reduce((e, t) => e + a(t.amount), 0) + a(t) - a(n));
33
49
  }
34
50
  //#endregion
35
- export { a as isReadableMoneyOrZero, s as validateBillCompleteness, c as validateBillTotals, o as validateLineItems };
51
+ export { d as calculateTotal, u as displayLineAmount, i as isPersistableLineItem, c as mapBillFormToPayload, l as mapLineItemsToPayload, n as parseMoneyToMinorUnits, r as parseQuantity };