@tesouro/embedded-components-react 0.5.204 → 0.5.206

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 (56) hide show
  1. package/README.md +15 -14
  2. package/dist/index.d.ts +49 -4
  3. package/dist/index.js +1 -1
  4. package/dist/lib/ReceivablesWidget.d.ts +49 -4
  5. package/dist/lib/ReceivablesWidget.js +1 -1
  6. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/data-access/dist/index.js +7 -7
  7. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/data-access/dist/index2.js +26 -23
  8. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/data-access/dist/index3.js +79 -2
  9. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index.js +1 -1
  10. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index10.js +88 -193
  11. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index11.js +184 -31
  12. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index12.js +32 -145
  13. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index13.js +150 -47
  14. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index14.js +37 -293
  15. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index15.js +58 -70
  16. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index16.js +86 -99
  17. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index17.js +48 -233
  18. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index18.js +336 -0
  19. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index19.js +75 -0
  20. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index20.js +115 -0
  21. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index21.js +270 -0
  22. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index5.js +1 -1
  23. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index8.js +95 -394
  24. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index9.js +422 -72
  25. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index.js +15 -10
  26. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index10.js +94 -1
  27. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index11.js +3 -4
  28. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index12.js +24 -11
  29. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index13.js +1 -1
  30. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index14.js +3 -264
  31. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index15.js +3 -72
  32. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index16.js +16 -421
  33. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index17.js +1 -106
  34. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index18.js +4 -93
  35. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index19.js +11 -343
  36. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index2.js +5 -159
  37. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index20.js +1 -0
  38. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index21.js +264 -0
  39. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index22.js +72 -0
  40. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index23.js +401 -0
  41. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index24.js +106 -0
  42. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index25.js +93 -0
  43. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index26.js +344 -0
  44. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index3.js +182 -32
  45. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index4.js +27 -154
  46. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index5.js +203 -20
  47. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index6.js +161 -1
  48. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index7.js +16 -3
  49. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index8.js +25 -3
  50. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index9.js +3 -17
  51. package/dist/libs/tesouro-embedded-components-react/shared/data-access/dist/index.js +38 -38
  52. package/dist/libs/tesouro-embedded-components-react/shared/data-access/dist/lib/rest/@tanstack/react-query.gen.js +213 -202
  53. package/dist/libs/tesouro-embedded-components-react/shared/data-access/dist/lib/rest/sdk.gen.js +136 -116
  54. package/dist/libs/tesouro-embedded-components-react/shared/feature/dist/lib/analytics/build-info.js +1 -1
  55. package/dist/packages/shared-ui-shadcn/dist/index.js +1763 -1749
  56. package/package.json +1 -1
@@ -2,302 +2,46 @@
2
2
  "use client";
3
3
  "use client";
4
4
  "use client";
5
- import { getStateOptions as e } from "../../../shared/util/dist/lib/usStates.js";
6
- import { extractApiErrorMessage as t } from "../../../shared/util/dist/lib/apiErrors.js";
7
- import { usePaymentTermsQuery as n } from "../../../shared/data-access/dist/lib/reference-data/usePaymentTermsQuery.js";
8
- import { COUNTERPART_MESSAGE_LABELS_EN as r } from "../../../shared/counterpart-management/feature/dist/lib/labels.js";
9
- import { useCounterpartAddressesQuery as i } from "../../../shared/counterpart-management/data-access/dist/index7.js";
10
- import { useCounterpartForm as a } from "../../../shared/counterpart-management/feature/dist/lib/useCounterpartForm.js";
11
- import "../../../shared/counterpart-management/feature/dist/index.js";
12
- import { buildLineItemControls as ee, commitLineItemField as te, commitTaxRateInput as ne, convertPriceInput as re, createLineItem as o, getCurrencySymbol as ie, isBlankLineItem as ae, lineItemFromProduct as oe, reconcileMeasureUnits as se, sanitizeLineItemPatch as ce, sanitizeTaxRateInput as le, stepLineItemQuantity as ue, stripBlankLineItems as de, summarizeLineItemErrors as fe, toSheetLineItem as pe, validateLineItems as me } from "./index6.js";
13
- import { buildReceivableAttachmentsView as he } from "./index7.js";
14
- import { createEmptyReceivableFormValues as s, getPaymentTermOptions as ge, hasReceivableFormErrors as _e, receivableFormValuesToCreatePayload as ve, receivableFormValuesToLineItemChanges as ye, receivableFormValuesToUpdatePayload as be, receivableToFormValues as xe, validateReceivableForm as Se } from "./index8.js";
15
- import { useCreateReceivableMutation as c, useUpdateReceivableMutation as Ce } from "../../data-access/dist/index6.js";
5
+ import { usePaymentTermsQuery as e } from "../../../shared/data-access/dist/lib/reference-data/usePaymentTermsQuery.js";
6
+ import { buildCustomDateCalendar as t, buildPaymentTermsView as n, closeCustomDatePickerFields as r, selectPaymentTermsFields as i, toCustomDateValue as a } from "./index8.js";
16
7
  import "../../data-access/dist/index.js";
17
- import { useReceivableAttachmentUploads as we } from "./index12.js";
18
- import { calculateInvoiceTotals as Te } from "./index13.js";
19
- import { getCurrencyOptions as Ee } from "../../../shared/product-catalog/feature/dist/lib/helpers.js";
20
- import { useMeasureUnitsQuery as De } from "../../../shared/product-catalog/data-access/dist/index9.js";
21
- import { useMeasureUnits as l } from "../../../shared/product-catalog/feature/dist/lib/useMeasureUnits.js";
22
- import "../../../shared/product-catalog/feature/dist/index.js";
23
- import { useCallback as u, useEffect as d, useMemo as f, useRef as p, useState as m } from "react";
8
+ import { useCallback as o, useMemo as s, useState as c } from "react";
24
9
  //#region ../../libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index14.js
25
- function h({ messages: h, counterpartMessageLabels: g, onCreated: _ }) {
26
- let v = c(), y = Ce(), b = p([]), x = p(""), S = n(), [C, w] = m(!1), [T, E] = m("create"), [D, O] = m(), [k, A] = m(() => s()), [Oe, j] = m({}), [M, ke] = m("none"), N = l(), P = De(), F = P.data?.data, { unitNamesById: I } = N, [Ae, L] = m(), [R, z] = m(!1), B = p(!1), V = f(() => e(), []), je = f(() => ({
27
- ...r,
28
- ...g
29
- }), [g]), H = i(k.customerId), Me = H.data?.data?.[0], U = H.data?.data?.[0]?.id, Ne = u((e) => {
30
- A((t) => ({
31
- ...t,
32
- attachments: e(t.attachments)
33
- }));
34
- }, []), W = we({
35
- attachments: k.attachments,
36
- setAttachments: Ne,
37
- receivableId: D
38
- }), { reset: G, discardUploads: K, commitRemovals: q } = W, Pe = k.type === "invoice" ? he({
39
- attachments: k.attachments,
40
- pendingUploads: W.pendingUploads,
41
- isCountLimitReached: W.isCountLimitReached,
42
- isRecurring: !1,
43
- messages: h
44
- }) : void 0, Fe = u((e) => {
45
- A((t) => ({
46
- ...t,
47
- customerId: e ?? ""
48
- }));
49
- }, []), J = a({
50
- view: M,
51
- setView: ke,
52
- selectedId: k.customerId || void 0,
53
- setSelectedId: Fe,
54
- messages: je,
55
- counterpartType: "customer",
56
- counterpart: void 0,
57
- primaryAddress: Me
58
- }), Y = u(() => {
59
- b.current = [], L(void 0), E("create"), O(void 0), A(s()), j({}), z(!1), G();
60
- }, [G]), Ie = u((e = "invoice") => {
61
- b.current = [], L(void 0), E("create"), O(void 0), A({
62
- ...s(),
63
- type: e
64
- }), j({}), G(), z(!1), w(!0);
65
- }, [G]), Le = u((e) => {
66
- e.type !== "credit_note" && (b.current = e.line_items, x.current = e.currency, L(void 0), E("edit"), O(e.id), A(xe(e, F)), j({}), z(!1), G(), w(!0));
67
- }, [G, F]);
68
- d(() => {
69
- F?.length && A((e) => {
70
- let t = se(e.lineItems, F);
71
- return t === e.lineItems ? e : {
72
- ...e,
73
- lineItems: t
74
- };
75
- });
76
- }, [F]);
77
- let X = W.isUploading, Re = u(() => {
78
- X || (K(), w(!1), j({}));
79
- }, [K, X]), ze = u((e) => {
80
- let t = e.taxRate === void 0 ? e : {
81
- ...e,
82
- taxRate: le(e.taxRate)
83
- }, { currency: n, type: r } = t;
84
- if (r !== void 0 && r !== "invoice" && K(), n === void 0) {
85
- A((e) => ({
86
- ...e,
87
- ...t
88
- }));
89
- return;
90
- }
91
- B.current = !0, A((e) => e.currency === n ? {
92
- ...e,
93
- ...t
94
- } : {
95
- ...e,
96
- ...t,
97
- lineItems: e.lineItems.map((t) => ({
98
- ...t,
99
- price: re(t.price, e.currency, n)
100
- }))
101
- });
102
- }, [K]), Be = u(() => {
103
- A((e) => {
104
- let t = ne(e.taxRate);
105
- return t === e.taxRate ? e : {
106
- ...e,
107
- taxRate: t
108
- };
109
- });
110
- }, []), Z = u((e, t) => {
111
- let n = me(e, {
112
- currency: t,
113
- messages: h
114
- });
115
- j((e) => ({
116
- ...e,
117
- lineItems: n,
118
- lineItemsSummary: fe(n)
119
- }));
120
- }, [h]), Q = u((e, { validate: t }) => {
121
- t && (B.current = !0), A((t) => ({
122
- ...t,
123
- lineItems: e(t.lineItems)
124
- }));
125
- }, []);
126
- d(() => {
127
- B.current && (B.current = !1, Z(k.lineItems, k.currency));
128
- }, [
129
- Z,
130
- k.currency,
131
- k.lineItems
132
- ]);
133
- let Ve = u((e, t) => {
134
- let { unit: n, ...r } = t, i = ce(r);
135
- i.name !== void 0 && (i.productId = ""), n !== void 0 && (i.measureUnitId = n, i.measureUnitName = ""), Q((t) => t.map((t) => t.id === e ? {
136
- ...t,
137
- ...i
138
- } : t), { validate: R });
139
- }, [Q, R]), He = u((e, t) => {
140
- Q((n) => n.map((n) => n.id === e ? {
141
- ...n,
142
- ...oe({
143
- product: t,
144
- currency: k.currency,
145
- unitNamesById: I
146
- })
147
- } : n), { validate: !0 });
148
- }, [
149
- Q,
150
- I,
151
- k.currency
152
- ]), $ = u((e, t) => {
153
- t && Q((n) => t.kind === "remove" ? n.filter((t) => t.id !== e) : n.map((n) => n.id === e ? {
154
- ...n,
155
- ...t.patch
156
- } : n), { validate: !0 });
157
- }, [Q]), Ue = u((e, t) => {
158
- let n = k.lineItems.find((t) => t.id === e);
159
- n && $(e, te({
160
- lineItem: n,
161
- field: t,
162
- rowCount: k.lineItems.length,
163
- currency: k.currency
164
- }));
165
- }, [
166
- $,
167
- k.currency,
168
- k.lineItems
169
- ]), We = u((e, t) => {
170
- let n = k.lineItems.find((t) => t.id === e);
171
- n && $(e, ue({
172
- lineItem: n,
173
- step: t,
174
- rowCount: k.lineItems.length
175
- }));
176
- }, [$, k.lineItems]), Ge = u(() => {
177
- let e = o(k.currency);
178
- L(e.id), A((t) => ({
179
- ...t,
180
- lineItems: [...t.lineItems, e]
181
- }));
182
- }, [k.currency]), Ke = u((e) => {
183
- Q((t) => t.length <= 1 ? t : t.filter((t) => t.id !== e), { validate: !0 });
184
- }, [Q]), qe = u(async () => {
185
- if (X) return;
186
- if (P.isLoading) {
187
- j({ form: h.lineItemsLoading });
188
- return;
189
- }
190
- let e = de(k.lineItems), n = e.length === k.lineItems.length ? k : {
191
- ...k,
192
- lineItems: e
193
- };
194
- n !== k && A(n);
195
- let r = Se({
196
- values: n,
197
- billingAddressId: U,
198
- messages: h
199
- });
200
- if (_e(r)) {
201
- j(r), z(!0);
202
- return;
203
- }
204
- j({});
205
- try {
206
- if (T === "edit" && D) {
207
- let e = { receivable_id: D };
208
- await y.mutateAsync({
209
- path: e,
210
- body: be({
211
- values: n,
212
- billingAddressId: U ?? "",
213
- lineItemChanges: ye({
214
- values: n,
215
- originalLineItems: b.current,
216
- originalCurrency: x.current,
217
- unitNamesById: I,
218
- units: F
219
- })
220
- })
221
- }), q(), w(!1), Y();
222
- return;
223
- }
224
- let e = await v.mutateAsync({ body: ve({
225
- values: n,
226
- billingAddressId: U ?? "",
227
- unitNamesById: I
228
- }) });
229
- w(!1), Y(), e?.id && _?.(e.id, e.type);
230
- } catch (e) {
231
- j({ form: t(e) ?? h.genericError });
232
- }
233
- }, [
234
- U,
235
- q,
236
- v,
237
- D,
238
- X,
239
- h,
240
- T,
241
- _,
242
- Y,
243
- F,
244
- I,
245
- P.isLoading,
246
- y,
247
- k
248
- ]), Je = f(() => ({
249
- ...k,
250
- lineItems: k.lineItems.map(pe)
251
- }), [k]), Ye = f(() => ee(k.lineItems), [k.lineItems]), Xe = f(() => Te({
252
- lineItems: k.lineItems.filter((e) => !ae(e)),
253
- currency: k.currency,
254
- taxRate: Number(k.taxRate) || void 0
255
- }), [
256
- k.currency,
257
- k.lineItems,
258
- k.taxRate
259
- ]);
10
+ function l({ paymentTermsId: l, paymentTermsCustomDate: u, messages: d, onChange: f }) {
11
+ let p = e(), [m, h] = c(!1);
260
12
  return {
261
- open: C,
262
- setOpen: w,
263
- mode: T,
264
- values: k,
265
- sheetValues: Je,
266
- errors: Oe,
267
- setValues: A,
268
- updateValues: ze,
269
- commitTaxRate: Be,
270
- updateLineItem: Ve,
271
- selectProduct: He,
272
- commitLineItem: Ue,
273
- stepLineItem: We,
274
- addLineItem: Ge,
275
- removeLineItem: Ke,
276
- attachmentsView: Pe,
277
- attachmentsUploading: W.isUploading,
278
- saveDisabled: P.isLoading || W.isUploading,
279
- selectAttachmentFiles: W.selectFiles,
280
- setAttachmentIncludeInEmail: W.setIncludeInEmail,
281
- removeAttachment: W.remove,
282
- autoFocusLineItemId: Ae,
283
- lineItemUnitOptions: N.unitOptions,
284
- lineItemsLoading: P.isLoading,
285
- lineItemControls: Ye,
286
- totals: Xe,
287
- currencySymbol: ie(k.currency),
288
- isSubmitting: v.isPending || y.isPending,
289
- currencyOptions: Ee(k.currency),
290
- paymentTermsOptions: ge(S.data?.data),
291
- openCreate: Ie,
292
- openEdit: Le,
293
- close: Re,
294
- submit: qe,
295
- units: N,
296
- counterpartView: M,
297
- counterpartForm: J,
298
- stateOptions: V,
299
- openCounterpartCreate: J.openCreate
13
+ view: s(() => n({
14
+ terms: p.data?.data,
15
+ isLoading: p.isLoading,
16
+ fields: {
17
+ paymentTermsId: l,
18
+ paymentTermsCustomDate: u
19
+ },
20
+ customDatePickerOpen: m,
21
+ messages: d
22
+ }), [
23
+ m,
24
+ d,
25
+ u,
26
+ l,
27
+ p.data?.data,
28
+ p.isLoading
29
+ ]),
30
+ calendar: s(() => t(u), [u]),
31
+ select: o((e) => {
32
+ f((t) => i(t, e)), h(!1);
33
+ }, [f]),
34
+ changeCustomDatePickerOpen: o((e) => {
35
+ h(e), e || f(r);
36
+ }, [f]),
37
+ selectCustomDate: o((e) => {
38
+ f((t) => r({
39
+ ...t,
40
+ paymentTermsCustomDate: a(e)
41
+ })), h(!1);
42
+ }, [f]),
43
+ reset: o(() => h(!1), [])
300
44
  };
301
45
  }
302
46
  //#endregion
303
- export { h as useReceivableForm };
47
+ export { l as useReceivablePaymentTerms };
@@ -1,75 +1,63 @@
1
- "use client";
2
- "use client";
3
- "use client";
4
- "use client";
5
- import { buildReceivableRows as e, statusFilterOptions as t, typeForTab as n } from "./index8.js";
6
- import { useReceivablesQuery as r } from "../../data-access/dist/index9.js";
7
- import "../../data-access/dist/index.js";
8
- import { useCallback as i, useEffect as a, useMemo as o, useState as s } from "react";
1
+ import { hasAnyScope as e } from "../../../shared/data-access/dist/lib/hasAnyScope.js";
2
+ import { Scope as t } from "../../../shared/data-access/dist/lib/scopes.js";
3
+ import "../../../shared/data-access/dist/index.js";
9
4
  //#region ../../libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index15.js
10
- var c = [];
11
- function l({ activeTab: l, messages: d }) {
12
- let [f, p] = s([]), [m, h] = s(10), [g, _] = s(), [v, y] = s(""), [b, x] = s(""), [S, C] = s("all");
13
- a(() => {
14
- _(void 0), C("all");
15
- }, [l]), a(() => {
16
- let e = setTimeout(() => {
17
- x(v), _(void 0);
18
- }, 300);
19
- return () => clearTimeout(e);
20
- }, [v]);
21
- let w = f[0]?.id, T = w ? u[w] : void 0, E = f[0] ? f[0].desc ? "desc" : "asc" : void 0, D = r({
22
- type: n(l),
23
- limit: m,
24
- pagination_token: g,
25
- search_text: b || void 0,
26
- status: S === "all" ? void 0 : S,
27
- ...T ? {
28
- sort: T,
29
- order: E
30
- } : {}
31
- }), O = D.data?.data ?? c, k = o(() => new Map(O.map((e) => [e.id, e])), [O]), A = i((e) => k.get(e), [k]), j = o(() => e({
32
- receivables: O,
33
- messages: d
34
- }), [d, O]), M = !!b || S !== "all", N = i((e) => {
35
- let t = typeof e == "function" ? e(f) : e;
36
- p(t), _(void 0);
37
- }, [f]), P = i((e) => {
38
- h(e), _(void 0);
39
- }, []), F = i((e) => {
40
- C(e), _(void 0);
41
- }, []), I = i(() => _(D.data?.next_pagination_token ?? void 0), [D.data?.next_pagination_token]), L = i(() => _(D.data?.prev_pagination_token ?? void 0), [D.data?.prev_pagination_token]), R = i(() => {
42
- D.refetch();
43
- }, [D]);
5
+ var n = {
6
+ routingNumber: "",
7
+ accountNumber: "",
8
+ accountHolderName: "",
9
+ displayName: ""
10
+ };
11
+ function r(n) {
12
+ let r = new Set(n ?? []);
44
13
  return {
45
- rows: j,
46
- isLoading: D.isLoading,
47
- isError: D.isError,
48
- sorting: f,
49
- onSortingChange: N,
50
- pageSize: m,
51
- onPageSizeChange: P,
52
- hasNextPage: !!D.data?.next_pagination_token,
53
- hasPrevPage: !!D.data?.prev_pagination_token,
54
- onNextPage: I,
55
- onPrevPage: L,
56
- searchValue: v,
57
- onSearchChange: y,
58
- statusFilter: S,
59
- statusOptions: t(),
60
- onStatusFilterChange: F,
61
- isFiltering: M,
62
- onRetry: R,
63
- getReceivableById: A
14
+ canReadEmbedded: e(r, [t.BankAccountReadOrg]),
15
+ canReadExternal: e(r, [t.ExternalBankAccountReadOrg]),
16
+ canAddAccount: e(r, [t.BankAccountWriteOrg])
17
+ };
18
+ }
19
+ function i(e, t) {
20
+ return [e.displayName || t.bankAccountFallbackName, e.accountNumberLast4].filter(Boolean).join(" - ");
21
+ }
22
+ function a(e, t, n) {
23
+ switch (e) {
24
+ case "INTERNAL": return t ? n.bankAccountPoweredBy.replace("{embeddedBankName}", t) : void 0;
25
+ case "EXTERNAL": return n.bankAccountLinked;
26
+ default: return;
27
+ }
28
+ }
29
+ function o({ accounts: e, embeddedBankName: t, messages: n }) {
30
+ return e.map((e) => ({
31
+ value: e.id,
32
+ label: i(e, n),
33
+ sourceLabel: a(e.type, t, n)
34
+ })).sort((e, t) => e.label.localeCompare(t.label));
35
+ }
36
+ function s({ options: e, isLoading: t, selectedId: n, isAddingAccount: r, canAddAccount: i, formValues: a, formErrors: o, isSaving: s }) {
37
+ return t ? { kind: "loading" } : e.length > 0 && !r ? {
38
+ kind: "picker",
39
+ options: e,
40
+ selected: e.find((e) => e.value === n),
41
+ canAddAccount: i
42
+ } : i ? {
43
+ kind: "form",
44
+ values: a,
45
+ errors: o,
46
+ canCancel: e.length > 0,
47
+ isSaving: s
48
+ } : { kind: "restricted" };
49
+ }
50
+ function c(e, t) {
51
+ let n = {}, r = e.accountHolderName.trim(), i = e.accountNumber.trim(), a = e.routingNumber.trim();
52
+ return r ? r.length > 255 && (n.accountHolderName = t.bankAccountHolderNameTooLong) : n.accountHolderName = t.bankAccountHolderNameRequired, i ? /^\d+$/.test(i) ? i.length < 4 ? n.accountNumber = t.bankAccountNumberTooShort : i.length > 17 && (n.accountNumber = t.bankAccountNumberTooLong) : n.accountNumber = t.bankAccountNumberDigitsOnly : n.accountNumber = t.bankAccountNumberRequired, a ? /^\d{9}$/.test(a) || (n.routingNumber = t.bankAccountRoutingNumberInvalid) : n.routingNumber = t.bankAccountRoutingNumberRequired, e.displayName.length > 200 && (n.displayName = t.bankAccountNicknameTooLong), n;
53
+ }
54
+ function l(e) {
55
+ return {
56
+ display_name: e.displayName || void 0,
57
+ account_holder_name: e.accountHolderName.trim() || void 0,
58
+ account_number: e.accountNumber.trim() || void 0,
59
+ routing_number: e.routingNumber.trim() || void 0
64
60
  };
65
61
  }
66
- var u = {
67
- documentLabel: "document_id",
68
- customerLabel: "counterpart_name",
69
- status: "status",
70
- issueDateLabel: "issue_date",
71
- dueDateLabel: "due_date",
72
- totalLabel: "total_amount"
73
- };
74
62
  //#endregion
75
- export { l as useReceivablesTable };
63
+ export { n as EMPTY_BANK_ACCOUNT_FORM_VALUES, l as bankAccountFormToPayload, s as buildBankAccountSectionView, o as buildPaymentAccountOptions, r as getBankAccountPermissions, i as getPaymentAccountLineLabel, a as getPaymentAccountSourceLabel, c as validateBankAccountForm };
@@ -2,113 +2,100 @@
2
2
  "use client";
3
3
  "use client";
4
4
  "use client";
5
- import { useAnalyticsTrack as e } from "../../../shared/feature/dist/lib/analytics/hooks.js";
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";
7
+ import "../../../shared/ui/dist/index.js";
8
+ import { useWidgetConfig as n } from "../../../shared/feature/dist/lib/WidgetProvider/hooks.js";
6
9
  import "../../../shared/feature/dist/index.js";
7
- import { ReceivablesWidgetAnalyticsEvent as t } from "./index2.js";
8
- import { coerceEnabledTabs as n, resolveInitialTab as r, tabForType as i, typeForTab as a } from "./index8.js";
9
- import { RECEIVABLE_MESSAGE_LABELS_EN as o } from "./index9.js";
10
- import { useReceivableActions as s } from "./index10.js";
11
- import { useReceivableDetails as c } from "./index11.js";
12
- import { hasSelectedText as l } from "../../../shared/product-catalog/feature/dist/lib/helpers.js";
13
- import "../../../shared/product-catalog/feature/dist/index.js";
14
- import { useReceivableForm as u } from "./index14.js";
15
- import { useReceivablesTable as d } from "./index15.js";
16
- import { useCallback as f, useEffect as p, useMemo as m, useState as h } from "react";
10
+ import { useCreateEntityBankAccountMutation as r, usePaymentAccountsQuery as i } from "../../data-access/dist/index3.js";
11
+ import "../../data-access/dist/index.js";
12
+ import { EMPTY_BANK_ACCOUNT_FORM_VALUES as a, bankAccountFormToPayload as o, buildBankAccountSectionView as s, buildPaymentAccountOptions as c, getBankAccountPermissions as l, validateBankAccountForm as u } from "./index15.js";
13
+ import { useCallback as d, useEffect as f, useMemo as p, useRef as m, useState as h } from "react";
17
14
  //#region ../../libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index16.js
18
- function g({ counterpartMessageLabels: g, defaultTab: _, enabledTabs: v, messageLabels: y, onReceivableCreated: b, onReceivableOpened: x }) {
19
- let S = e();
20
- p(() => {
21
- S(t.Mounted);
22
- }, [S]);
23
- let C = m(() => ({
24
- ...o,
25
- ...y
26
- }), [y]), w = m(() => n(v), [v]), [T, E] = h(() => r({
27
- defaultTab: _,
28
- enabledTabs: w
29
- })), [D, O] = h(), [k, A] = h(!1);
30
- p(() => {
31
- w.includes(T) || E(r({
32
- defaultTab: _,
33
- enabledTabs: w
34
- }));
15
+ function g({ open: g, bankAccountId: _, embeddedBankName: v, messages: y, onSelect: b }) {
16
+ let { initResponse: x } = n(), S = p(() => l(x?.scopes), [x?.scopes]), { paymentAccounts: C, isLoading: w, isIncomplete: T } = i({
17
+ enabled: g,
18
+ canReadEmbedded: S.canReadEmbedded,
19
+ canReadExternal: S.canReadExternal
20
+ }), E = r(), [D, O] = h(!1), [k, A] = h(a), [j, M] = h({}), N = m(!1), P = d(() => {
21
+ N.current = !1, O(!1), A(a), M({});
22
+ }, []);
23
+ f(() => {
24
+ if (!g || T || N.current || C.length !== 1) return;
25
+ let [e] = C;
26
+ N.current = !0, b({
27
+ bankAccountId: e.id,
28
+ bankAccountType: e.type
29
+ });
35
30
  }, [
36
31
  T,
37
- _,
38
- w
32
+ b,
33
+ g,
34
+ C
39
35
  ]);
40
- let j = f((e, t) => {
41
- E(i(t)), O(e), A(!0), b?.(e, t);
42
- }, [b]), M = d({
43
- activeTab: T,
44
- messages: C
45
- }), N = c({
46
- selectedReceivableId: D,
47
- enabled: k,
48
- messages: C
49
- }), P = u({
50
- messages: C,
51
- counterpartMessageLabels: g,
52
- onCreated: j
53
- }), F = f(() => {
54
- let e = a(T);
55
- P.openCreate(e === "quote" ? "quote" : "invoice");
56
- }, [T, P.openCreate]), I = s({
57
- selectedReceivable: N.receivable,
58
- messages: C,
59
- onCreated: j,
60
- onDeleted: (e) => {
61
- e === D && (O(void 0), A(!1));
36
+ let F = d((e) => {
37
+ let t = C.find((t) => t.id === e);
38
+ t && b({
39
+ bankAccountId: t.id,
40
+ bankAccountType: t.type
41
+ });
42
+ }, [b, C]), I = d(() => O(!0), []), L = d(() => {
43
+ O(!1), A(a), M({});
44
+ }, []), R = d((e) => A((t) => ({
45
+ ...t,
46
+ ...e
47
+ })), []), z = d(async () => {
48
+ let n = u(k, y);
49
+ if (M(n), !(Object.keys(n).length > 0)) try {
50
+ let t = await E.mutateAsync({ body: o(k) });
51
+ O(!1), A(a), b({
52
+ bankAccountId: t.id,
53
+ bankAccountType: "BANK_DETAILS"
54
+ }), e.success(y.bankAccountCreated.replace("{name}", t.display_name ?? ""));
55
+ } catch (n) {
56
+ e.error(t(n) ?? y.bankAccountCreateFailed);
62
57
  }
63
- }), L = f((e) => {
64
- l() || (O(e.id), A(!0), x?.(e.id, e.type));
65
- }, [x]);
58
+ }, [
59
+ E,
60
+ k,
61
+ y,
62
+ b
63
+ ]), B = p(() => c({
64
+ accounts: C,
65
+ embeddedBankName: v,
66
+ messages: y
67
+ }), [
68
+ v,
69
+ y,
70
+ C
71
+ ]);
66
72
  return {
67
- activeTab: T,
68
- enabledTabs: w,
69
- setActiveTab: E,
70
- table: M,
71
- details: N,
72
- detailsOpen: k,
73
- closeDetails: f(() => {
74
- A(!1), O(void 0);
75
- }, []),
76
- form: P,
77
- openCreate: F,
78
- actions: I,
79
- handleRowClick: L,
80
- handleActionClick: f((e, t) => {
81
- let n = M.getReceivableById(t.id);
82
- if (e === "edit") {
83
- if (n) {
84
- P.openEdit(n);
85
- return;
86
- }
87
- O(t.id), A(!0);
88
- return;
89
- }
90
- O(t.id), I.openAction(e, t, n ?? null);
91
- }, [
92
- I,
93
- P.openEdit,
94
- M.getReceivableById
73
+ view: p(() => s({
74
+ options: B,
75
+ isLoading: w,
76
+ selectedId: _,
77
+ isAddingAccount: D,
78
+ canAddAccount: S.canAddAccount,
79
+ formValues: k,
80
+ formErrors: j,
81
+ isSaving: E.isPending
82
+ }), [
83
+ _,
84
+ E.isPending,
85
+ j,
86
+ k,
87
+ D,
88
+ w,
89
+ B,
90
+ S.canAddAccount
95
91
  ]),
96
- handleDetailsActionClick: f((e, t) => {
97
- if (e === "edit") {
98
- N.receivable && (P.openEdit(N.receivable), A(!1));
99
- return;
100
- }
101
- I.openAction(e, {
102
- id: t.id,
103
- title: t.title,
104
- type: t.type
105
- }, N.receivable ?? null);
106
- }, [
107
- I,
108
- N.receivable,
109
- P.openEdit
110
- ])
92
+ reset: P,
93
+ selectAccount: F,
94
+ openAddAccount: I,
95
+ cancelAddAccount: L,
96
+ updateAccountForm: R,
97
+ saveAccount: z
111
98
  };
112
99
  }
113
100
  //#endregion
114
- export { g as useReceivablesWidget };
101
+ export { g as useReceivableBankAccount };