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