@tesouro/embedded-components-react 0.5.200 → 0.5.201

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.
@@ -2,74 +2,276 @@
2
2
  "use client";
3
3
  "use client";
4
4
  "use client";
5
- import { buildReceivableRows as e, statusFilterOptions as t, typeForTab as n } from "./index6.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 { 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 ee } from "../../../shared/counterpart-management/feature/dist/lib/useCounterpartForm.js";
11
+ import "../../../shared/counterpart-management/feature/dist/index.js";
12
+ import { buildLineItemControls as te, commitLineItemField as ne, commitTaxRateInput as re, convertPriceInput as a, createLineItem as o, getCurrencySymbol as s, isBlankLineItem as ie, lineItemFromProduct as ae, reconcileMeasureUnits as oe, sanitizeLineItemPatch as se, sanitizeTaxRateInput as ce, stepLineItemQuantity as c, stripBlankLineItems as le, summarizeLineItemErrors as ue, toSheetLineItem as de, validateLineItems as fe } from "./index5.js";
13
+ import { createEmptyReceivableFormValues as l, getPaymentTermOptions as pe, hasReceivableFormErrors as me, receivableFormValuesToCreatePayload as he, receivableFormValuesToLineItemChanges as ge, receivableFormValuesToUpdatePayload as _e, receivableToFormValues as ve, validateReceivableForm as ye } from "./index6.js";
14
+ import { useCreateReceivableMutation as u, useUpdateReceivableMutation as d } from "../../data-access/dist/index6.js";
7
15
  import "../../data-access/dist/index.js";
8
- import { useCallback as i, useEffect as a, useMemo as o, useState as s } from "react";
16
+ import { calculateInvoiceTotals as f } from "./index10.js";
17
+ import { getCurrencyOptions as p } from "../../../shared/product-catalog/feature/dist/lib/helpers.js";
18
+ import { useMeasureUnitsQuery as m } from "../../../shared/product-catalog/data-access/dist/index9.js";
19
+ import { useMeasureUnits as h } from "../../../shared/product-catalog/feature/dist/lib/useMeasureUnits.js";
20
+ import "../../../shared/product-catalog/feature/dist/index.js";
21
+ import { useCallback as g, useEffect as _, useMemo as v, useRef as y, useState as b } from "react";
9
22
  //#region ../../libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index11.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]);
23
+ function x({ messages: x, counterpartMessageLabels: S, onCreated: C }) {
24
+ let w = u(), T = d(), E = y([]), D = y(""), O = n(), [k, A] = b(!1), [j, M] = b("create"), [N, P] = b(), [F, I] = b(() => l()), [be, L] = b({}), [R, xe] = b("none"), z = h(), B = m(), V = B.data?.data, { unitNamesById: H } = z, [Se, U] = b(), [W, G] = b(!1), K = y(!1), Ce = v(() => e(), []), we = v(() => ({
25
+ ...r,
26
+ ...S
27
+ }), [S]), q = i(F.customerId), Te = q.data?.data?.[0], J = q.data?.data?.[0]?.id, Ee = g((e) => {
28
+ I((t) => ({
29
+ ...t,
30
+ customerId: e ?? ""
31
+ }));
32
+ }, []), Y = ee({
33
+ view: R,
34
+ setView: xe,
35
+ selectedId: F.customerId || void 0,
36
+ setSelectedId: Ee,
37
+ messages: we,
38
+ counterpartType: "customer",
39
+ counterpart: void 0,
40
+ primaryAddress: Te
41
+ }), X = g(() => {
42
+ E.current = [], U(void 0), M("create"), P(void 0), I(l()), L({}), G(!1);
43
+ }, []), De = g((e = "invoice") => {
44
+ E.current = [], U(void 0), M("create"), P(void 0), I({
45
+ ...l(),
46
+ type: e
47
+ }), L({}), G(!1), A(!0);
48
+ }, []), Oe = g((e) => {
49
+ e.type !== "credit_note" && (E.current = e.line_items, D.current = e.currency, U(void 0), M("edit"), P(e.id), I(ve(e, V)), L({}), G(!1), A(!0));
50
+ }, [V]);
51
+ _(() => {
52
+ V?.length && I((e) => {
53
+ let t = oe(e.lineItems, V);
54
+ return t === e.lineItems ? e : {
55
+ ...e,
56
+ lineItems: t
57
+ };
58
+ });
59
+ }, [V]);
60
+ let ke = g(() => {
61
+ A(!1), L({});
62
+ }, []), Ae = g((e) => {
63
+ let t = e.taxRate === void 0 ? e : {
64
+ ...e,
65
+ taxRate: ce(e.taxRate)
66
+ }, { currency: n } = t;
67
+ if (n === void 0) {
68
+ I((e) => ({
69
+ ...e,
70
+ ...t
71
+ }));
72
+ return;
73
+ }
74
+ K.current = !0, I((e) => e.currency === n ? {
75
+ ...e,
76
+ ...t
77
+ } : {
78
+ ...e,
79
+ ...t,
80
+ lineItems: e.lineItems.map((t) => ({
81
+ ...t,
82
+ price: a(t.price, e.currency, n)
83
+ }))
84
+ });
85
+ }, []), je = g(() => {
86
+ I((e) => {
87
+ let t = re(e.taxRate);
88
+ return t === e.taxRate ? e : {
89
+ ...e,
90
+ taxRate: t
91
+ };
92
+ });
93
+ }, []), Z = g((e, t) => {
94
+ let n = fe(e, {
95
+ currency: t,
96
+ messages: x
97
+ });
98
+ L((e) => ({
99
+ ...e,
100
+ lineItems: n,
101
+ lineItemsSummary: ue(n)
102
+ }));
103
+ }, [x]), Q = g((e, { validate: t }) => {
104
+ t && (K.current = !0), I((t) => ({
105
+ ...t,
106
+ lineItems: e(t.lineItems)
107
+ }));
108
+ }, []);
109
+ _(() => {
110
+ K.current && (K.current = !1, Z(F.lineItems, F.currency));
111
+ }, [
112
+ Z,
113
+ F.currency,
114
+ F.lineItems
115
+ ]);
116
+ let Me = g((e, t) => {
117
+ let { unit: n, ...r } = t, i = se(r);
118
+ i.name !== void 0 && (i.productId = ""), n !== void 0 && (i.measureUnitId = n, i.measureUnitName = ""), Q((t) => t.map((t) => t.id === e ? {
119
+ ...t,
120
+ ...i
121
+ } : t), { validate: W });
122
+ }, [Q, W]), Ne = g((e, t) => {
123
+ Q((n) => n.map((n) => n.id === e ? {
124
+ ...n,
125
+ ...ae({
126
+ product: t,
127
+ currency: F.currency,
128
+ unitNamesById: H
129
+ })
130
+ } : n), { validate: !0 });
131
+ }, [
132
+ Q,
133
+ H,
134
+ F.currency
135
+ ]), $ = g((e, t) => {
136
+ t && Q((n) => t.kind === "remove" ? n.filter((t) => t.id !== e) : n.map((n) => n.id === e ? {
137
+ ...n,
138
+ ...t.patch
139
+ } : n), { validate: !0 });
140
+ }, [Q]), Pe = g((e, t) => {
141
+ let n = F.lineItems.find((t) => t.id === e);
142
+ n && $(e, ne({
143
+ lineItem: n,
144
+ field: t,
145
+ rowCount: F.lineItems.length,
146
+ currency: F.currency
147
+ }));
148
+ }, [
149
+ $,
150
+ F.currency,
151
+ F.lineItems
152
+ ]), Fe = g((e, t) => {
153
+ let n = F.lineItems.find((t) => t.id === e);
154
+ n && $(e, c({
155
+ lineItem: n,
156
+ step: t,
157
+ rowCount: F.lineItems.length
158
+ }));
159
+ }, [$, F.lineItems]), Ie = g(() => {
160
+ let e = o(F.currency);
161
+ U(e.id), I((t) => ({
162
+ ...t,
163
+ lineItems: [...t.lineItems, e]
164
+ }));
165
+ }, [F.currency]), Le = g((e) => {
166
+ Q((t) => t.length <= 1 ? t : t.filter((t) => t.id !== e), { validate: !0 });
167
+ }, [Q]), Re = g(async () => {
168
+ if (B.isLoading) {
169
+ L({ form: x.lineItemsLoading });
170
+ return;
171
+ }
172
+ let e = le(F.lineItems), n = e.length === F.lineItems.length ? F : {
173
+ ...F,
174
+ lineItems: e
175
+ };
176
+ n !== F && I(n);
177
+ let r = ye({
178
+ values: n,
179
+ billingAddressId: J,
180
+ messages: x
181
+ });
182
+ if (me(r)) {
183
+ L(r), G(!0);
184
+ return;
185
+ }
186
+ L({});
187
+ try {
188
+ if (j === "edit" && N) {
189
+ let e = { receivable_id: N };
190
+ await T.mutateAsync({
191
+ path: e,
192
+ body: _e({
193
+ values: n,
194
+ billingAddressId: J ?? "",
195
+ lineItemChanges: ge({
196
+ values: n,
197
+ originalLineItems: E.current,
198
+ originalCurrency: D.current,
199
+ unitNamesById: H,
200
+ units: V
201
+ })
202
+ })
203
+ }), A(!1), X();
204
+ return;
205
+ }
206
+ let e = await w.mutateAsync({ body: he({
207
+ values: n,
208
+ billingAddressId: J ?? "",
209
+ unitNamesById: H
210
+ }) });
211
+ A(!1), X(), e?.id && C?.(e.id, e.type);
212
+ } catch (e) {
213
+ L({ form: t(e) ?? x.genericError });
214
+ }
215
+ }, [
216
+ J,
217
+ w,
218
+ N,
219
+ x,
220
+ j,
221
+ C,
222
+ X,
223
+ V,
224
+ H,
225
+ B.isLoading,
226
+ T,
227
+ F
228
+ ]), ze = v(() => ({
229
+ ...F,
230
+ lineItems: F.lineItems.map(de)
231
+ }), [F]), Be = v(() => te(F.lineItems), [F.lineItems]), Ve = v(() => f({
232
+ lineItems: F.lineItems.filter((e) => !ie(e)),
233
+ currency: F.currency,
234
+ taxRate: Number(F.taxRate) || void 0
235
+ }), [
236
+ F.currency,
237
+ F.lineItems,
238
+ F.taxRate
239
+ ]);
44
240
  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
241
+ open: k,
242
+ setOpen: A,
243
+ mode: j,
244
+ values: F,
245
+ sheetValues: ze,
246
+ errors: be,
247
+ setValues: I,
248
+ updateValues: Ae,
249
+ commitTaxRate: je,
250
+ updateLineItem: Me,
251
+ selectProduct: Ne,
252
+ commitLineItem: Pe,
253
+ stepLineItem: Fe,
254
+ addLineItem: Ie,
255
+ removeLineItem: Le,
256
+ autoFocusLineItemId: Se,
257
+ lineItemUnitOptions: z.unitOptions,
258
+ lineItemsLoading: B.isLoading,
259
+ lineItemControls: Be,
260
+ totals: Ve,
261
+ currencySymbol: s(F.currency),
262
+ isSubmitting: w.isPending || T.isPending,
263
+ currencyOptions: p(F.currency),
264
+ paymentTermsOptions: pe(O.data?.data),
265
+ openCreate: De,
266
+ openEdit: Oe,
267
+ close: ke,
268
+ submit: Re,
269
+ units: z,
270
+ counterpartView: R,
271
+ counterpartForm: Y,
272
+ stateOptions: Ce,
273
+ openCounterpartCreate: Y.openCreate
64
274
  };
65
275
  }
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
276
  //#endregion
75
- export { l as useReceivablesTable };
277
+ export { x as useReceivableForm };
@@ -2,113 +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 "./index6.js";
9
- import { RECEIVABLE_MESSAGE_LABELS_EN as o } from "./index7.js";
10
- import { useReceivableActions as s } from "./index8.js";
11
- import { useReceivableDetails as c } from "./index9.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 "./index10.js";
15
- import { useReceivablesTable as d } from "./index11.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 "./index6.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/index12.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
- }));
35
- }, [
36
- T,
37
- _,
38
- w
39
- ]);
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));
62
- }
63
- }), L = f((e) => {
64
- l() || (O(e.id), A(!0), x?.(e.id, e.type));
65
- }, [x]);
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]);
66
44
  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));
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
- ])
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
111
64
  };
112
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
+ };
113
74
  //#endregion
114
- export { g as useReceivablesWidget };
75
+ export { l as useReceivablesTable };