@tesouro/embedded-components-react 0.5.205 → 0.5.207

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/README.md +1 -1
  2. package/dist/index.d.ts +51 -4
  3. package/dist/index.js +1 -1
  4. package/dist/lib/ReceivablesWidget.d.ts +51 -4
  5. package/dist/lib/ReceivablesWidget.js +1 -1
  6. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/data-access/dist/index.js +2 -2
  7. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/data-access/dist/index10.js +84 -2
  8. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/data-access/dist/index2.js +31 -25
  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 +109 -193
  11. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index11.js +154 -37
  12. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index12.js +193 -135
  13. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index13.js +37 -58
  14. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index14.js +140 -86
  15. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index15.js +42 -47
  16. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index16.js +58 -313
  17. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index17.js +91 -65
  18. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index18.js +108 -102
  19. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index19.js +48 -249
  20. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index20.js +365 -0
  21. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index21.js +75 -0
  22. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index22.js +115 -0
  23. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index23.js +285 -0
  24. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index5.js +1 -1
  25. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index8.js +93 -407
  26. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index9.js +430 -86
  27. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index.js +17 -12
  28. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index10.js +92 -16
  29. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index11.js +3 -1
  30. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index12.js +24 -4
  31. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index13.js +0 -10
  32. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index14.js +2 -0
  33. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index15.js +3 -264
  34. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index16.js +16 -70
  35. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index17.js +1 -424
  36. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index18.js +4 -106
  37. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index19.js +12 -93
  38. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index2.js +5 -179
  39. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index20.js +1 -344
  40. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index21.js +264 -0
  41. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index22.js +72 -0
  42. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index23.js +402 -0
  43. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index24.js +106 -0
  44. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index25.js +249 -0
  45. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index26.js +93 -0
  46. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index27.js +344 -0
  47. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index3.js +195 -32
  48. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index4.js +29 -202
  49. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index5.js +183 -137
  50. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index6.js +157 -20
  51. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index7.js +16 -1
  52. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index8.js +25 -3
  53. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index9.js +4 -3
  54. package/dist/libs/tesouro-embedded-components-react/shared/counterpart-management/feature/dist/index.js +11 -11
  55. package/dist/libs/tesouro-embedded-components-react/shared/data-access/dist/index.js +38 -38
  56. package/dist/libs/tesouro-embedded-components-react/shared/data-access/dist/lib/rest/@tanstack/react-query.gen.js +220 -198
  57. package/dist/libs/tesouro-embedded-components-react/shared/data-access/dist/lib/rest/sdk.gen.js +124 -84
  58. package/dist/libs/tesouro-embedded-components-react/shared/feature/dist/lib/analytics/build-info.js +1 -1
  59. package/package.json +1 -1
@@ -1,318 +1,63 @@
1
- "use client";
2
- "use client";
3
- "use client";
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 Ce, useUpdateReceivableMutation as we } from "../../data-access/dist/index6.js";
16
- import "../../data-access/dist/index.js";
17
- import { useReceivableAttachmentUploads as Te } from "./index12.js";
18
- import { useReceivableBankAccount as Ee } from "./index14.js";
19
- import { calculateInvoiceTotals as De } from "./index15.js";
20
- import { getCurrencyOptions as Oe } from "../../../shared/product-catalog/feature/dist/lib/helpers.js";
21
- import { useMeasureUnitsQuery as ke } from "../../../shared/product-catalog/data-access/dist/index9.js";
22
- import { useMeasureUnits as Ae } from "../../../shared/product-catalog/feature/dist/lib/useMeasureUnits.js";
23
- import "../../../shared/product-catalog/feature/dist/index.js";
24
- import { useCallback as c, useEffect as l, useMemo as u, useRef as d, useState as f } 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";
25
4
  //#region ../../libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index16.js
26
- function p({ messages: p, counterpartMessageLabels: m, embeddedBankName: je, onCreated: h }) {
27
- let g = Ce(), _ = we(), v = d([]), y = d(""), b = n(), [x, S] = f(!1), [C, w] = f("create"), [T, E] = f(), [D, O] = f(() => s()), [Me, k] = f({}), [A, Ne] = f("none"), j = Ae(), M = ke(), N = M.data?.data, { unitNamesById: P } = j, [Pe, F] = f(), [I, L] = f(!1), R = d(!1), z = u(() => e(), []), Fe = u(() => ({
28
- ...r,
29
- ...m
30
- }), [m]), B = i(D.customerId), Ie = B.data?.data?.[0], V = B.data?.data?.[0]?.id, Le = c((e) => {
31
- O((t) => ({
32
- ...t,
33
- attachments: e(t.attachments)
34
- }));
35
- }, []), H = Te({
36
- attachments: D.attachments,
37
- setAttachments: Le,
38
- receivableId: T
39
- }), { reset: U, discardUploads: W, commitRemovals: G } = H, Re = D.type === "invoice" ? he({
40
- attachments: D.attachments,
41
- pendingUploads: H.pendingUploads,
42
- isCountLimitReached: H.isCountLimitReached,
43
- isRecurring: !1,
44
- messages: p
45
- }) : void 0, ze = c((e) => {
46
- O((t) => ({
47
- ...t,
48
- customerId: e ?? ""
49
- }));
50
- }, []), K = a({
51
- view: A,
52
- setView: Ne,
53
- selectedId: D.customerId || void 0,
54
- setSelectedId: ze,
55
- messages: Fe,
56
- counterpartType: "customer",
57
- counterpart: void 0,
58
- primaryAddress: Ie
59
- }), Be = c((e) => O((t) => ({
60
- ...t,
61
- ...e
62
- })), []), q = Ee({
63
- open: x,
64
- bankAccountId: D.bankAccountId,
65
- embeddedBankName: je,
66
- messages: p,
67
- onSelect: Be
68
- }), J = q.reset, Y = c(() => {
69
- v.current = [], F(void 0), w("create"), E(void 0), O(s()), k({}), L(!1), U();
70
- }, [U]), Ve = c((e = "invoice") => {
71
- J(), v.current = [], F(void 0), w("create"), E(void 0), O({
72
- ...s(),
73
- type: e
74
- }), k({}), U(), L(!1), S(!0);
75
- }, [U, J]), He = c((e) => {
76
- e.type !== "credit_note" && (J(), v.current = e.line_items, y.current = e.currency, F(void 0), w("edit"), E(e.id), O(xe(e, N)), k({}), L(!1), U(), S(!0));
77
- }, [
78
- U,
79
- J,
80
- N
81
- ]);
82
- l(() => {
83
- N?.length && O((e) => {
84
- let t = se(e.lineItems, N);
85
- return t === e.lineItems ? e : {
86
- ...e,
87
- lineItems: t
88
- };
89
- });
90
- }, [N]);
91
- let X = H.isUploading, Ue = c(() => {
92
- X || (W(), S(!1), k({}));
93
- }, [W, X]), We = c((e) => {
94
- let t = e.taxRate === void 0 ? e : {
95
- ...e,
96
- taxRate: le(e.taxRate)
97
- }, { currency: n, type: r } = t;
98
- if (r !== void 0 && r !== "invoice" && W(), n === void 0) {
99
- O((e) => ({
100
- ...e,
101
- ...t
102
- }));
103
- return;
104
- }
105
- R.current = !0, O((e) => e.currency === n ? {
106
- ...e,
107
- ...t
108
- } : {
109
- ...e,
110
- ...t,
111
- lineItems: e.lineItems.map((t) => ({
112
- ...t,
113
- price: re(t.price, e.currency, n)
114
- }))
115
- });
116
- }, [W]), Ge = c(() => {
117
- O((e) => {
118
- let t = ne(e.taxRate);
119
- return t === e.taxRate ? e : {
120
- ...e,
121
- taxRate: t
122
- };
123
- });
124
- }, []), Z = c((e, t) => {
125
- let n = me(e, {
126
- currency: t,
127
- messages: p
128
- });
129
- k((e) => ({
130
- ...e,
131
- lineItems: n,
132
- lineItemsSummary: fe(n)
133
- }));
134
- }, [p]), Q = c((e, { validate: t }) => {
135
- t && (R.current = !0), O((t) => ({
136
- ...t,
137
- lineItems: e(t.lineItems)
138
- }));
139
- }, []);
140
- l(() => {
141
- R.current && (R.current = !1, Z(D.lineItems, D.currency));
142
- }, [
143
- Z,
144
- D.currency,
145
- D.lineItems
146
- ]);
147
- let Ke = c((e, t) => {
148
- let { unit: n, ...r } = t, i = ce(r);
149
- i.name !== void 0 && (i.productId = ""), n !== void 0 && (i.measureUnitId = n, i.measureUnitName = ""), Q((t) => t.map((t) => t.id === e ? {
150
- ...t,
151
- ...i
152
- } : t), { validate: I });
153
- }, [Q, I]), qe = c((e, t) => {
154
- Q((n) => n.map((n) => n.id === e ? {
155
- ...n,
156
- ...oe({
157
- product: t,
158
- currency: D.currency,
159
- unitNamesById: P
160
- })
161
- } : n), { validate: !0 });
162
- }, [
163
- Q,
164
- P,
165
- D.currency
166
- ]), $ = c((e, t) => {
167
- t && Q((n) => t.kind === "remove" ? n.filter((t) => t.id !== e) : n.map((n) => n.id === e ? {
168
- ...n,
169
- ...t.patch
170
- } : n), { validate: !0 });
171
- }, [Q]), Je = c((e, t) => {
172
- let n = D.lineItems.find((t) => t.id === e);
173
- n && $(e, te({
174
- lineItem: n,
175
- field: t,
176
- rowCount: D.lineItems.length,
177
- currency: D.currency
178
- }));
179
- }, [
180
- $,
181
- D.currency,
182
- D.lineItems
183
- ]), Ye = c((e, t) => {
184
- let n = D.lineItems.find((t) => t.id === e);
185
- n && $(e, ue({
186
- lineItem: n,
187
- step: t,
188
- rowCount: D.lineItems.length
189
- }));
190
- }, [$, D.lineItems]), Xe = c(() => {
191
- let e = o(D.currency);
192
- F(e.id), O((t) => ({
193
- ...t,
194
- lineItems: [...t.lineItems, e]
195
- }));
196
- }, [D.currency]), Ze = c((e) => {
197
- Q((t) => t.length <= 1 ? t : t.filter((t) => t.id !== e), { validate: !0 });
198
- }, [Q]), Qe = c(async () => {
199
- if (X) return;
200
- if (M.isLoading) {
201
- k({ form: p.lineItemsLoading });
202
- return;
203
- }
204
- let e = de(D.lineItems), n = e.length === D.lineItems.length ? D : {
205
- ...D,
206
- lineItems: e
207
- };
208
- n !== D && O(n);
209
- let r = Se({
210
- values: n,
211
- billingAddressId: V,
212
- messages: p
213
- });
214
- if (_e(r)) {
215
- k(r), L(!0);
216
- return;
217
- }
218
- k({});
219
- try {
220
- if (C === "edit" && T) {
221
- let e = { receivable_id: T };
222
- await _.mutateAsync({
223
- path: e,
224
- body: be({
225
- values: n,
226
- billingAddressId: V ?? "",
227
- lineItemChanges: ye({
228
- values: n,
229
- originalLineItems: v.current,
230
- originalCurrency: y.current,
231
- unitNamesById: P,
232
- units: N
233
- })
234
- })
235
- }), G(), S(!1), Y();
236
- return;
237
- }
238
- let e = await g.mutateAsync({ body: ve({
239
- values: n,
240
- billingAddressId: V ?? "",
241
- unitNamesById: P
242
- }) });
243
- S(!1), Y(), e?.id && h?.(e.id, e.type);
244
- } catch (e) {
245
- k({ form: t(e) ?? p.genericError });
246
- }
247
- }, [
248
- V,
249
- G,
250
- g,
251
- T,
252
- X,
253
- p,
254
- C,
255
- h,
256
- Y,
257
- N,
258
- P,
259
- M.isLoading,
260
- _,
261
- D
262
- ]), $e = u(() => ({
263
- ...D,
264
- lineItems: D.lineItems.map(pe)
265
- }), [D]), et = u(() => ee(D.lineItems), [D.lineItems]), tt = u(() => De({
266
- lineItems: D.lineItems.filter((e) => !ae(e)),
267
- currency: D.currency,
268
- taxRate: Number(D.taxRate) || void 0
269
- }), [
270
- D.currency,
271
- D.lineItems,
272
- D.taxRate
273
- ]);
5
+ var n = {
6
+ routingNumber: "",
7
+ accountNumber: "",
8
+ accountHolderName: "",
9
+ displayName: ""
10
+ };
11
+ function r(n) {
12
+ let r = new Set(n ?? []);
274
13
  return {
275
- open: x,
276
- setOpen: S,
277
- mode: C,
278
- values: D,
279
- sheetValues: $e,
280
- errors: Me,
281
- setValues: O,
282
- updateValues: We,
283
- commitTaxRate: Ge,
284
- updateLineItem: Ke,
285
- selectProduct: qe,
286
- commitLineItem: Je,
287
- stepLineItem: Ye,
288
- addLineItem: Xe,
289
- removeLineItem: Ze,
290
- attachmentsView: Re,
291
- attachmentsUploading: H.isUploading,
292
- saveDisabled: M.isLoading || H.isUploading,
293
- selectAttachmentFiles: H.selectFiles,
294
- setAttachmentIncludeInEmail: H.setIncludeInEmail,
295
- removeAttachment: H.remove,
296
- autoFocusLineItemId: Pe,
297
- lineItemUnitOptions: j.unitOptions,
298
- lineItemsLoading: M.isLoading,
299
- lineItemControls: et,
300
- totals: tt,
301
- currencySymbol: ie(D.currency),
302
- isSubmitting: g.isPending || _.isPending,
303
- currencyOptions: Oe(D.currency),
304
- paymentTermsOptions: ge(b.data?.data),
305
- openCreate: Ve,
306
- openEdit: He,
307
- close: Ue,
308
- submit: Qe,
309
- units: j,
310
- counterpartView: A,
311
- counterpartForm: K,
312
- stateOptions: z,
313
- openCounterpartCreate: K.openCreate,
314
- bankAccount: q
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
315
60
  };
316
61
  }
317
62
  //#endregion
318
- export { p as useReceivableForm };
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,74 +2,100 @@
2
2
  "use client";
3
3
  "use client";
4
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";
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";
9
+ import "../../../shared/feature/dist/index.js";
10
+ import { useCreateEntityBankAccountMutation as r, usePaymentAccountsQuery as i } from "../../data-access/dist/index3.js";
7
11
  import "../../data-access/dist/index.js";
8
- import { useCallback as i, useEffect as a, useMemo as o, useState as s } from "react";
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 "./index16.js";
13
+ import { useCallback as d, useEffect as f, useMemo as p, useRef as m, useState as h } from "react";
9
14
  //#region ../../libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index17.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]);
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
+ });
30
+ }, [
31
+ T,
32
+ b,
33
+ g,
34
+ C
35
+ ]);
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);
57
+ }
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
+ ]);
44
72
  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
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
91
+ ]),
92
+ reset: P,
93
+ selectAccount: F,
94
+ openAddAccount: I,
95
+ cancelAddAccount: L,
96
+ updateAccountForm: R,
97
+ saveAccount: z
64
98
  };
65
99
  }
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
100
  //#endregion
75
- export { l as useReceivablesTable };
101
+ export { g as useReceivableBankAccount };