@tesouro/embedded-components-react 0.5.204 → 0.5.205

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 (44) hide show
  1. package/README.md +15 -14
  2. package/dist/index.d.ts +38 -0
  3. package/dist/index.js +1 -1
  4. package/dist/lib/ReceivablesWidget.d.ts +38 -0
  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/index13.js +53 -42
  11. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index14.js +81 -283
  12. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index15.js +47 -70
  13. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index16.js +303 -99
  14. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index17.js +68 -230
  15. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index18.js +115 -0
  16. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index19.js +253 -0
  17. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index5.js +1 -1
  18. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index8.js +34 -19
  19. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index9.js +14 -0
  20. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index.js +10 -9
  21. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index10.js +18 -1
  22. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index11.js +0 -3
  23. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index12.js +0 -7
  24. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index13.js +10 -0
  25. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index14.js +1 -264
  26. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index15.js +259 -67
  27. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index16.js +61 -412
  28. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index17.js +407 -89
  29. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index18.js +73 -60
  30. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index19.js +80 -331
  31. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index2.js +20 -0
  32. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index20.js +344 -0
  33. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index4.js +183 -137
  34. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index5.js +157 -20
  35. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index6.js +24 -1
  36. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index7.js +1 -3
  37. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index8.js +1 -1
  38. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index9.js +3 -18
  39. package/dist/libs/tesouro-embedded-components-react/shared/data-access/dist/index.js +38 -38
  40. package/dist/libs/tesouro-embedded-components-react/shared/data-access/dist/lib/rest/@tanstack/react-query.gen.js +213 -202
  41. package/dist/libs/tesouro-embedded-components-react/shared/data-access/dist/lib/rest/sdk.gen.js +136 -116
  42. package/dist/libs/tesouro-embedded-components-react/shared/feature/dist/lib/analytics/build-info.js +1 -1
  43. package/dist/packages/shared-ui-shadcn/dist/index.js +1763 -1749
  44. package/package.json +1 -1
@@ -2,113 +2,317 @@
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 { 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";
13
23
  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";
24
+ import { useCallback as c, useEffect as l, useMemo as u, useRef as d, useState as f } from "react";
17
25
  //#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
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
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));
35
77
  }, [
36
- T,
37
- _,
38
- w
78
+ U,
79
+ J,
80
+ N
39
81
  ]);
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));
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;
62
104
  }
63
- }), L = f((e) => {
64
- l() || (O(e.id), A(!0), x?.(e.id, e.type));
65
- }, [x]);
66
- 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
95
- ]),
96
- handleDetailsActionClick: f((e, t) => {
97
- if (e === "edit") {
98
- N.receivable && (P.openEdit(N.receivable), A(!1));
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();
99
236
  return;
100
237
  }
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
- ])
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
+ ]);
274
+ 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
111
315
  };
112
316
  }
113
317
  //#endregion
114
- export { g as useReceivablesWidget };
318
+ export { p as useReceivableForm };