@tesouro/embedded-components-react 0.5.211 → 0.5.213

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 (33) hide show
  1. package/dist/index.d.ts +16 -0
  2. package/dist/index.js +1 -1
  3. package/dist/lib/ReceivablesWidget.d.ts +16 -0
  4. package/dist/lib/ReceivablesWidget.js +1 -1
  5. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index.js +1 -1
  6. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index10.js +113 -109
  7. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index11.js +416 -132
  8. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index12.js +113 -211
  9. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index13.js +154 -37
  10. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index14.js +193 -135
  11. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index15.js +32 -37
  12. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index16.js +150 -58
  13. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index17.js +35 -89
  14. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index18.js +58 -116
  15. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index19.js +96 -47
  16. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index20.js +103 -347
  17. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index21.js +364 -64
  18. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index22.js +66 -106
  19. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index23.js +105 -275
  20. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index24.js +288 -0
  21. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index6.js +76 -61
  22. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index9.js +48 -422
  23. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index.js +5 -5
  24. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index22.js +38 -62
  25. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index23.js +61 -391
  26. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index24.js +457 -89
  27. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index25.js +91 -234
  28. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index26.js +234 -78
  29. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index27.js +80 -331
  30. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index28.js +344 -0
  31. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index3.js +10 -0
  32. package/dist/libs/tesouro-embedded-components-react/shared/feature/dist/lib/analytics/build-info.js +1 -1
  33. package/package.json +1 -1
@@ -2,74 +2,374 @@
2
2
  "use client";
3
3
  "use client";
4
4
  "use client";
5
- import { buildReceivableRows as e, statusFilterOptions as t, typeForTab as n } from "./index9.js";
6
- import { useReceivablesQuery as r } from "../../data-access/dist/index9.js";
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 { COUNTERPART_MESSAGE_LABELS_EN as n } from "../../../shared/counterpart-management/feature/dist/lib/labels.js";
8
+ import { useCounterpartAddressesQuery as r } from "../../../shared/counterpart-management/data-access/dist/index7.js";
9
+ import { useCounterpartForm as i } from "../../../shared/counterpart-management/feature/dist/lib/useCounterpartForm.js";
10
+ import "../../../shared/counterpart-management/feature/dist/index.js";
11
+ import "../../ui/dist/index9.js";
12
+ import "../../ui/dist/index.js";
13
+ import { buildLineItemControls as ee, commitLineItemField as te, commitTaxRateInput as ne, convertPriceInput as re, createLineItem as ie, getCurrencySymbol 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";
14
+ import { buildReceivableAttachmentsView as he } from "./index7.js";
15
+ import { convertDiscountInput as ge, decorateDiscountInput as _e, discountInputToMinorUnits as ve, sanitizeDiscountInput as ye } from "./index9.js";
16
+ import { buildFormTotalsView as be, calculateFormTotals as xe, validateDiscount as Se, validateInvoiceTotals as Ce } from "./index10.js";
17
+ import { createEmptyReceivableFormValues as a, hasReceivableFormErrors as we, receivableFormValuesToCreatePayload as Te, receivableFormValuesToLineItemChanges as Ee, receivableFormValuesToUpdatePayload as De, receivableToFormValues as Oe, validateReceivableForm as ke } from "./index11.js";
18
+ import { shouldShowRemindersInitially as Ae } from "./index13.js";
19
+ import { useCreateReceivableMutation as je, useUpdateReceivableMutation as Me } from "../../data-access/dist/index6.js";
7
20
  import "../../data-access/dist/index.js";
8
- import { useCallback as i, useEffect as a, useMemo as o, useState as s } from "react";
21
+ import { useReceivableAttachmentUploads as Ne } from "./index16.js";
22
+ import { useReceivablePaymentTerms as Pe } from "./index17.js";
23
+ import { useReceivableBankAccount as Fe } from "./index19.js";
24
+ import { useReceivableReminders as Ie } from "./index20.js";
25
+ import { getCurrencyOptions as Le } from "../../../shared/product-catalog/feature/dist/lib/helpers.js";
26
+ import { useMeasureUnitsQuery as Re } from "../../../shared/product-catalog/data-access/dist/index9.js";
27
+ import { useMeasureUnits as ze } from "../../../shared/product-catalog/feature/dist/lib/useMeasureUnits.js";
28
+ import "../../../shared/product-catalog/feature/dist/index.js";
29
+ import { useCallback as o, useEffect as Be, useMemo as s, useRef as c, useState as l } from "react";
9
30
  //#region ../../libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index21.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();
31
+ function u({ messages: u, counterpartMessageLabels: d, embeddedBankName: Ve, onCreated: He }) {
32
+ let f = je(), p = Me(), m = c([]), h = c(""), [g, _] = l(!1), [v, y] = l("create"), [b, x] = l(), [S, C] = l(() => a()), [Ue, w] = l({}), [We, Ge] = l("none"), T = ze(), E = Re(), D = E.data?.data, { unitNamesById: O } = T, [Ke, k] = l(), [A, j] = l(!1), M = c(!1), N = c(!1), P = c(!1), F = c({
33
+ lines: !1,
34
+ discount: !1
35
+ }), [I, L] = l(!1), qe = s(() => e(), []), Je = s(() => ({
36
+ ...n,
37
+ ...d
38
+ }), [d]), Ye = r(S.customerId), Xe = Ye.data?.data?.[0], R = Ye.data?.data?.[0]?.id, Ze = o((e) => {
39
+ C((t) => ({
40
+ ...t,
41
+ attachments: e(t.attachments)
42
+ }));
43
+ }, []), z = Ne({
44
+ attachments: S.attachments,
45
+ setAttachments: Ze,
46
+ receivableId: b
47
+ }), { reset: B, discardUploads: V, commitRemovals: Qe } = z, $e = S.type === "invoice" ? he({
48
+ attachments: S.attachments,
49
+ pendingUploads: z.pendingUploads,
50
+ isCountLimitReached: z.isCountLimitReached,
51
+ isRecurring: !1,
52
+ messages: u
53
+ }) : void 0, et = o((e) => {
54
+ C((t) => ({
55
+ ...t,
56
+ customerId: e ?? ""
57
+ }));
58
+ }, []), H = i({
59
+ view: We,
60
+ setView: Ge,
61
+ selectedId: S.customerId || void 0,
62
+ setSelectedId: et,
63
+ messages: Je,
64
+ counterpartType: "customer",
65
+ counterpart: void 0,
66
+ primaryAddress: Xe
67
+ }), tt = o((e) => C((t) => {
68
+ let n = e({
69
+ paymentTermsId: t.paymentTermsId,
70
+ paymentTermsCustomDate: t.paymentTermsCustomDate
71
+ });
72
+ return {
73
+ ...t,
74
+ ...n,
75
+ ...n.paymentTermsId === "receipt_due" ? { paymentReminderId: "" } : {}
76
+ };
77
+ }), []), U = Pe({
78
+ paymentTermsId: S.paymentTermsId,
79
+ paymentTermsCustomDate: S.paymentTermsCustomDate,
80
+ messages: u,
81
+ onChange: tt
82
+ }), W = U.reset, nt = o((e) => C((t) => ({
83
+ ...t,
84
+ ...e
85
+ })), []), G = Fe({
86
+ open: g,
87
+ bankAccountId: S.bankAccountId,
88
+ embeddedBankName: Ve,
89
+ messages: u,
90
+ onSelect: nt
91
+ }), K = G.reset, rt = o((e) => C((t) => ({
92
+ ...t,
93
+ ...e
94
+ })), []), q = f.isPending || p.isPending, it = Ie({
95
+ open: g,
96
+ isInvoice: S.type === "invoice",
97
+ disabled: q,
98
+ paymentTermsId: S.paymentTermsId,
99
+ paymentTermsCustomDate: S.paymentTermsCustomDate,
100
+ paymentReminderId: S.paymentReminderId,
101
+ overdueReminderId: S.overdueReminderId,
102
+ messages: u,
103
+ onSelect: rt
104
+ }), J = it.reset, Y = o(() => {
105
+ m.current = [], k(void 0), y("create"), x(void 0), C(a()), w({}), j(!1), L(!1), F.current = {
106
+ lines: !1,
107
+ discount: !1
108
+ }, B();
109
+ }, [B]), at = o((e = "invoice") => {
110
+ W(), K();
111
+ let t = {
112
+ ...a(),
113
+ type: e
114
+ };
115
+ J(Ae(t)), m.current = [], k(void 0), y("create"), x(void 0), C(t), w({}), B(), j(!1), L(!1), F.current = {
116
+ lines: !1,
117
+ discount: !1
118
+ }, _(!0);
119
+ }, [
120
+ B,
121
+ W,
122
+ K,
123
+ J
124
+ ]), ot = o((e) => {
125
+ if (e.type === "credit_note") return;
126
+ W(), K();
127
+ let t = Oe(e, D);
128
+ J(Ae(t)), m.current = e.line_items, h.current = e.currency, k(void 0), y("edit"), x(e.id), C(t), w({}), j(!1), L(!1), F.current = {
129
+ lines: !1,
130
+ discount: !1
131
+ }, B(), _(!0);
132
+ }, [
133
+ B,
134
+ W,
135
+ K,
136
+ J,
137
+ D
138
+ ]);
139
+ Be(() => {
140
+ D?.length && C((e) => {
141
+ let t = se(e.lineItems, D);
142
+ return t === e.lineItems ? e : {
143
+ ...e,
144
+ lineItems: t
145
+ };
146
+ });
43
147
  }, [D]);
148
+ let X = z.isUploading, st = o(() => {
149
+ X || (V(), _(!1), w({}));
150
+ }, [V, X]), ct = o((e) => {
151
+ let t = { ...e };
152
+ t.taxRate !== void 0 && (t.taxRate = le(t.taxRate), P.current = !0), t.type !== void 0 && t.type !== "invoice" && V(), t.discount !== void 0 && A && (N.current = !0), t.discountType !== void 0 && (N.current = !0), t.currency !== void 0 && (M.current = !0), C((e) => {
153
+ let n = {
154
+ ...e,
155
+ ...t
156
+ };
157
+ return t.discount !== void 0 && (n.discount = ye(t.discount, n.discountType, n.currency)), n.currency !== e.currency && (n.lineItems = e.lineItems.map((t) => ({
158
+ ...t,
159
+ price: re(t.price, e.currency, n.currency)
160
+ }))), (n.currency !== e.currency || n.discountType !== e.discountType) && (n.discount = ge({
161
+ value: n.discount,
162
+ type: n.discountType,
163
+ currency: n.currency
164
+ })), n;
165
+ });
166
+ }, [V, A]), lt = o(() => L(!0), []), ut = o(() => {
167
+ L(!1), N.current = !0, C((e) => ({
168
+ ...e,
169
+ discount: ge({
170
+ value: e.discount,
171
+ type: e.discountType,
172
+ currency: e.currency
173
+ })
174
+ }));
175
+ }, []), dt = o(() => {
176
+ P.current = !0, C((e) => {
177
+ let t = ne(e.taxRate);
178
+ return t === e.taxRate ? e : {
179
+ ...e,
180
+ taxRate: t
181
+ };
182
+ });
183
+ }, []), Z = o((e, { validate: t }) => {
184
+ t && (M.current = !0), C((t) => ({
185
+ ...t,
186
+ lineItems: e(t.lineItems)
187
+ }));
188
+ }, []);
189
+ Be(() => {
190
+ let e = M.current, t = N.current;
191
+ if (!e && !t && !P.current) return;
192
+ M.current = !1, N.current = !1, P.current = !1, e && (F.current.lines = !0), t && (F.current.discount = !0);
193
+ let n = e ? me(S.lineItems, {
194
+ currency: S.currency,
195
+ messages: u
196
+ }) : void 0;
197
+ w((t) => {
198
+ let r = { ...t };
199
+ return F.current.lines && (r.lineItems = e ? n : t.lineItems, r.lineItemsSummary = fe(r.lineItems, Ce(S, u))), F.current.discount && (r.discount = Se(S, u)), r;
200
+ });
201
+ }, [u, S]);
202
+ let ft = o((e, t) => {
203
+ let { unit: n, ...r } = t, i = ce(r);
204
+ i.name !== void 0 && (i.productId = ""), n !== void 0 && (i.measureUnitId = n, i.measureUnitName = ""), i.taxable !== void 0 && (P.current = !0), Z((t) => t.map((t) => t.id === e ? {
205
+ ...t,
206
+ ...i
207
+ } : t), { validate: A });
208
+ }, [Z, A]), pt = o((e, t) => {
209
+ Z((n) => n.map((n) => n.id === e ? {
210
+ ...n,
211
+ ...oe({
212
+ product: t,
213
+ currency: S.currency,
214
+ unitNamesById: O
215
+ })
216
+ } : n), { validate: !0 });
217
+ }, [
218
+ Z,
219
+ O,
220
+ S.currency
221
+ ]), Q = o((e, t) => {
222
+ t && Z((n) => t.kind === "remove" ? n.filter((t) => t.id !== e) : n.map((n) => n.id === e ? {
223
+ ...n,
224
+ ...t.patch
225
+ } : n), { validate: !0 });
226
+ }, [Z]), mt = o((e, t) => {
227
+ let n = S.lineItems.find((t) => t.id === e);
228
+ n && Q(e, te({
229
+ lineItem: n,
230
+ field: t,
231
+ rowCount: S.lineItems.length,
232
+ currency: S.currency
233
+ }));
234
+ }, [
235
+ Q,
236
+ S.currency,
237
+ S.lineItems
238
+ ]), ht = o((e, t) => {
239
+ let n = S.lineItems.find((t) => t.id === e);
240
+ n && Q(e, ue({
241
+ lineItem: n,
242
+ step: t,
243
+ rowCount: S.lineItems.length
244
+ }));
245
+ }, [Q, S.lineItems]), gt = o(() => {
246
+ let e = ie(S.currency);
247
+ k(e.id), C((t) => ({
248
+ ...t,
249
+ lineItems: [...t.lineItems, e]
250
+ }));
251
+ }, [S.currency]), _t = o((e) => {
252
+ Z((t) => t.length <= 1 ? t : t.filter((t) => t.id !== e), { validate: !0 });
253
+ }, [Z]), vt = o(async () => {
254
+ if (X) return;
255
+ if (E.isLoading) {
256
+ w({ form: u.lineItemsLoading });
257
+ return;
258
+ }
259
+ let e = de(S.lineItems), n = e.length === S.lineItems.length ? S : {
260
+ ...S,
261
+ lineItems: e
262
+ };
263
+ n !== S && C(n);
264
+ let r = ke({
265
+ values: n,
266
+ billingAddressId: R,
267
+ messages: u
268
+ });
269
+ if (we(r)) {
270
+ w(r), j(!0), F.current = {
271
+ lines: !0,
272
+ discount: !0
273
+ };
274
+ return;
275
+ }
276
+ w({});
277
+ try {
278
+ if (v === "edit" && b) {
279
+ let e = { receivable_id: b };
280
+ await p.mutateAsync({
281
+ path: e,
282
+ body: De({
283
+ values: n,
284
+ billingAddressId: R ?? "",
285
+ lineItemChanges: Ee({
286
+ values: n,
287
+ originalLineItems: m.current,
288
+ originalCurrency: h.current,
289
+ unitNamesById: O,
290
+ units: D
291
+ })
292
+ })
293
+ }), Qe(), _(!1), Y();
294
+ return;
295
+ }
296
+ let e = await f.mutateAsync({ body: Te({
297
+ values: n,
298
+ billingAddressId: R ?? "",
299
+ unitNamesById: O
300
+ }) });
301
+ _(!1), Y(), e?.id && He?.(e.id, e.type);
302
+ } catch (e) {
303
+ w({ form: t(e) ?? u.genericError });
304
+ }
305
+ }, [
306
+ R,
307
+ Qe,
308
+ f,
309
+ b,
310
+ X,
311
+ u,
312
+ v,
313
+ He,
314
+ Y,
315
+ D,
316
+ O,
317
+ E.isLoading,
318
+ p,
319
+ S
320
+ ]), yt = s(() => ({
321
+ ...S,
322
+ discount: I ? S.discount : _e(ve(S.discount, S.discountType, S.currency), S.discountType, S.currency),
323
+ lineItems: S.lineItems.map(pe)
324
+ }), [I, S]), bt = s(() => ee(S.lineItems), [S.lineItems]), $ = s(() => xe(S), [S]), xt = s(() => be($, S.currency), [$, S.currency]);
44
325
  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
326
+ open: g,
327
+ setOpen: _,
328
+ mode: v,
329
+ values: S,
330
+ sheetValues: yt,
331
+ errors: Ue,
332
+ setValues: C,
333
+ updateValues: ct,
334
+ commitTaxRate: dt,
335
+ focusDiscount: lt,
336
+ commitDiscount: ut,
337
+ updateLineItem: ft,
338
+ selectProduct: pt,
339
+ commitLineItem: mt,
340
+ stepLineItem: ht,
341
+ addLineItem: gt,
342
+ removeLineItem: _t,
343
+ attachmentsView: $e,
344
+ attachmentsUploading: z.isUploading,
345
+ saveDisabled: E.isLoading || z.isUploading,
346
+ selectAttachmentFiles: z.selectFiles,
347
+ setAttachmentIncludeInEmail: z.setIncludeInEmail,
348
+ removeAttachment: z.remove,
349
+ autoFocusLineItemId: Ke,
350
+ lineItemUnitOptions: T.unitOptions,
351
+ lineItemsLoading: E.isLoading,
352
+ lineItemControls: bt,
353
+ totals: $,
354
+ totalsView: xt,
355
+ currencySymbol: ae(S.currency),
356
+ isSubmitting: q,
357
+ currencyOptions: Le(S.currency),
358
+ paymentTerms: U,
359
+ showBillingSection: S.type === "invoice" || v === "edit",
360
+ showDueDateField: S.type === "quote",
361
+ openCreate: at,
362
+ openEdit: ot,
363
+ close: st,
364
+ submit: vt,
365
+ units: T,
366
+ counterpartView: We,
367
+ counterpartForm: H,
368
+ stateOptions: qe,
369
+ openCounterpartCreate: H.openCreate,
370
+ bankAccount: G,
371
+ reminders: it
64
372
  };
65
373
  }
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
374
  //#endregion
75
- export { l as useReceivablesTable };
375
+ export { u as useReceivableForm };
@@ -2,114 +2,74 @@
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";
6
- 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 "./index9.js";
9
- import { RECEIVABLE_MESSAGE_LABELS_EN as o } from "./index10.js";
10
- import { useReceivableActions as s } from "./index12.js";
11
- import { useReceivableDetails as c } from "./index13.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 "./index20.js";
15
- import { useReceivablesTable as d } from "./index21.js";
16
- import { useCallback as f, useEffect as p, useMemo as m, useState as h } from "react";
5
+ import { buildReceivableRows as e, statusFilterOptions as t, typeForTab as n } from "./index11.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";
17
9
  //#region ../../libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index22.js
18
- function g({ counterpartMessageLabels: g, defaultTab: _, embeddedBankName: v, enabledTabs: y, messageLabels: b, onReceivableCreated: x, onReceivableOpened: S }) {
19
- let C = e();
20
- p(() => {
21
- C(t.Mounted);
22
- }, [C]);
23
- let w = m(() => ({
24
- ...o,
25
- ...b
26
- }), [b]), T = m(() => n(y), [y]), [E, D] = h(() => r({
27
- defaultTab: _,
28
- enabledTabs: T
29
- })), [O, k] = h(), [A, j] = h(!1);
30
- p(() => {
31
- T.includes(E) || D(r({
32
- defaultTab: _,
33
- enabledTabs: T
34
- }));
35
- }, [
36
- E,
37
- _,
38
- T
39
- ]);
40
- let M = f((e, t) => {
41
- D(i(t)), k(e), j(!0), x?.(e, t);
42
- }, [x]), N = d({
43
- activeTab: E,
44
- messages: w
45
- }), P = c({
46
- selectedReceivableId: O,
47
- enabled: A,
48
- messages: w
49
- }), F = u({
50
- messages: w,
51
- counterpartMessageLabels: g,
52
- embeddedBankName: v,
53
- onCreated: M
54
- }), I = f(() => {
55
- let e = a(E);
56
- F.openCreate(e === "quote" ? "quote" : "invoice");
57
- }, [E, F.openCreate]), L = s({
58
- selectedReceivable: P.receivable,
59
- messages: w,
60
- onCreated: M,
61
- onDeleted: (e) => {
62
- e === O && (k(void 0), j(!1));
63
- }
64
- }), R = f((e) => {
65
- l() || (k(e.id), j(!0), S?.(e.id, e.type));
66
- }, [S]);
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]);
67
44
  return {
68
- activeTab: E,
69
- enabledTabs: T,
70
- setActiveTab: D,
71
- table: N,
72
- details: P,
73
- detailsOpen: A,
74
- closeDetails: f(() => {
75
- j(!1), k(void 0);
76
- }, []),
77
- form: F,
78
- openCreate: I,
79
- actions: L,
80
- handleRowClick: R,
81
- handleActionClick: f((e, t) => {
82
- let n = N.getReceivableById(t.id);
83
- if (e === "edit") {
84
- if (n) {
85
- F.openEdit(n);
86
- return;
87
- }
88
- k(t.id), j(!0);
89
- return;
90
- }
91
- k(t.id), L.openAction(e, t, n ?? null);
92
- }, [
93
- L,
94
- F.openEdit,
95
- N.getReceivableById
96
- ]),
97
- handleDetailsActionClick: f((e, t) => {
98
- if (e === "edit") {
99
- P.receivable && (F.openEdit(P.receivable), j(!1));
100
- return;
101
- }
102
- L.openAction(e, {
103
- id: t.id,
104
- title: t.title,
105
- type: t.type
106
- }, P.receivable ?? null);
107
- }, [
108
- L,
109
- P.receivable,
110
- F.openEdit
111
- ])
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
112
64
  };
113
65
  }
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
+ };
114
74
  //#endregion
115
- export { g as useReceivablesWidget };
75
+ export { l as useReceivablesTable };