@tesouro/embedded-components-react 0.5.201 → 0.5.203

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 (61) hide show
  1. package/README.md +20 -6
  2. package/dist/index.css +3 -0
  3. package/dist/index.d.ts +82 -7
  4. package/dist/index.js +8 -7
  5. package/dist/lib/MarketingWidget.d.ts +66 -7
  6. package/dist/lib/MarketingWidget.js +5 -4
  7. package/dist/lib/ReceivablesWidget.d.ts +16 -0
  8. package/dist/lib/ReceivablesWidget.js +1 -1
  9. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/data-access/dist/index.js +6 -6
  10. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/data-access/dist/index2.js +24 -18
  11. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/data-access/dist/index4.js +65 -2
  12. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index.js +1 -1
  13. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index10.js +188 -45
  14. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index11.js +30 -265
  15. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index12.js +144 -64
  16. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index13.js +47 -109
  17. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index14.js +293 -216
  18. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index15.js +75 -0
  19. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index16.js +114 -0
  20. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index17.js +237 -0
  21. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index4.js +14 -1
  22. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index5.js +28 -243
  23. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index6.js +212 -375
  24. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index7.js +64 -62
  25. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index8.js +409 -187
  26. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index9.js +73 -40
  27. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index.js +10 -9
  28. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index10.js +0 -9
  29. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index11.js +4 -1
  30. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index12.js +10 -263
  31. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index13.js +1 -72
  32. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index14.js +241 -398
  33. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index15.js +66 -100
  34. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index16.js +406 -76
  35. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index17.js +92 -330
  36. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index18.js +93 -0
  37. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index19.js +344 -0
  38. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index2.js +6 -1
  39. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index4.js +157 -20
  40. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index5.js +24 -1
  41. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index6.js +1 -3
  42. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index7.js +3 -18
  43. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index8.js +2 -0
  44. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index9.js +18 -4
  45. package/dist/libs/tesouro-embedded-components-react/marketing-widget/feature/dist/index.js +5 -4
  46. package/dist/libs/tesouro-embedded-components-react/marketing-widget/feature/dist/index3.js +1 -0
  47. package/dist/libs/tesouro-embedded-components-react/marketing-widget/feature/dist/index4.js +33 -81
  48. package/dist/libs/tesouro-embedded-components-react/marketing-widget/feature/dist/index5.js +34 -0
  49. package/dist/libs/tesouro-embedded-components-react/marketing-widget/feature/dist/index6.js +20 -0
  50. package/dist/libs/tesouro-embedded-components-react/marketing-widget/feature/dist/index7.js +161 -0
  51. package/dist/libs/tesouro-embedded-components-react/marketing-widget/ui/dist/index.js +3 -3
  52. package/dist/libs/tesouro-embedded-components-react/marketing-widget/ui/dist/index3.js +5 -1
  53. package/dist/libs/tesouro-embedded-components-react/marketing-widget/ui/dist/index8.js +34 -81
  54. package/dist/libs/tesouro-embedded-components-react/marketing-widget/ui/dist/index9.js +92 -0
  55. package/dist/libs/tesouro-embedded-components-react/shared/data-access/dist/index.js +38 -37
  56. package/dist/libs/tesouro-embedded-components-react/shared/data-access/dist/lib/rest/@tanstack/react-query.gen.js +54 -54
  57. package/dist/libs/tesouro-embedded-components-react/shared/data-access/dist/lib/rest/sdk.gen.js +115 -94
  58. package/dist/libs/tesouro-embedded-components-react/shared/data-access/dist/lib/useOrganizationApplicationStatus.js +25 -0
  59. package/dist/libs/tesouro-embedded-components-react/shared/data-access/dist/lib/useOrganizationOnboardingSuppression.js +9 -9
  60. package/dist/libs/tesouro-embedded-components-react/shared/feature/dist/lib/analytics/build-info.js +1 -1
  61. package/package.json +1 -1
@@ -2,74 +2,154 @@
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 { toFileArray as e, validateAttachmentFile as t } from "./index7.js";
6
+ import { useDeleteReceivableAttachmentMutation as n, useUploadReceivableAttachmentMutation as r } from "../../data-access/dist/index4.js";
7
7
  import "../../data-access/dist/index.js";
8
- import { useCallback as i, useEffect as a, useMemo as o, useState as s } from "react";
8
+ import { useCallback as i, useEffect as a, useRef as o, useState as s } from "react";
9
9
  //#region ../../libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index12.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");
10
+ function c({ attachments: c, setAttachments: l, receivableId: u }) {
11
+ let { mutateAsync: d } = r(), { mutate: f } = n(), [p, m] = s([]), [h, g] = s(!1), _ = o(0), v = o(/* @__PURE__ */ new Set()), y = o(/* @__PURE__ */ new Set()), b = o(/* @__PURE__ */ new Set()), x = o(0), S = o(!1), C = o({
12
+ deleteFile: f,
13
+ receivableId: u
14
+ });
13
15
  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]);
16
+ C.current = {
17
+ deleteFile: f,
18
+ receivableId: u
19
+ };
20
+ }, [f, u]), a(() => {
21
+ S.current = !1;
22
+ let e = y.current;
23
+ return () => {
24
+ S.current = !0;
25
+ let { deleteFile: t, receivableId: n } = C.current;
26
+ for (let r of e) t({
27
+ path: { file_id: r },
28
+ receivableId: n
29
+ });
30
+ e.clear();
31
+ };
32
+ }, []);
33
+ let w = i(async (e, t) => {
34
+ let n = x.current, r = () => S.current || x.current !== n;
35
+ try {
36
+ let n = await d({
37
+ file: t,
38
+ receivableId: u
39
+ });
40
+ if (r() || v.current.delete(e)) {
41
+ f({
42
+ path: { file_id: n.id },
43
+ receivableId: u
44
+ });
45
+ return;
46
+ }
47
+ y.current.add(n.id), m((t) => t.filter((t) => t.id !== e)), l((e) => [...e, {
48
+ id: n.id,
49
+ includeInEmail: !0,
50
+ name: n.name,
51
+ size: n.size
52
+ }]);
53
+ } catch {
54
+ let t = v.current.delete(e);
55
+ if (r() || t) return;
56
+ m((t) => t.map((t) => t.id === e ? {
57
+ ...t,
58
+ status: "upload_failed"
59
+ } : t));
60
+ }
61
+ }, [
62
+ f,
63
+ u,
64
+ l,
65
+ d
66
+ ]), T = i((n) => {
67
+ let r = e(n);
68
+ if (r.length === 0) return;
69
+ let i = p.filter((e) => e.status === "uploading").length, a = 10 - c.length - i, o = [], s = !1;
70
+ for (let e of r) {
71
+ _.current += 1;
72
+ let n = `pending-attachment-${_.current}`, r = t(e);
73
+ if (r) {
74
+ o.push({
75
+ id: n,
76
+ name: e.name,
77
+ status: r
78
+ });
79
+ continue;
80
+ }
81
+ if (a <= 0) {
82
+ s = !0;
83
+ continue;
84
+ }
85
+ --a, o.push({
86
+ id: n,
87
+ name: e.name,
88
+ status: "uploading"
89
+ }), w(n, e);
90
+ }
91
+ o.length > 0 && m((e) => [...e, ...o]), g(s);
92
+ }, [
93
+ c.length,
94
+ p,
95
+ w
96
+ ]), E = i((e, t) => {
97
+ l((n) => n.map((n) => n.id === e ? {
98
+ ...n,
99
+ includeInEmail: t
100
+ } : n));
101
+ }, [l]), D = i((e) => {
102
+ g(!1);
103
+ let t = p.find((t) => t.id === e);
104
+ if (t) {
105
+ t.status === "uploading" && v.current.add(e), m((t) => t.filter((t) => t.id !== e));
106
+ return;
107
+ }
108
+ if (l((t) => t.filter((t) => t.id !== e)), !y.current.delete(e)) {
109
+ b.current.add(e);
110
+ return;
111
+ }
112
+ f({
113
+ path: { file_id: e },
114
+ receivableId: u
115
+ });
116
+ }, [
117
+ f,
118
+ p,
119
+ u,
120
+ l
121
+ ]), O = i(() => {
122
+ x.current += 1, v.current.clear(), y.current.clear(), b.current.clear(), m([]), g(!1);
123
+ }, []), k = i(() => {
124
+ let e = new Set(y.current);
125
+ for (let t of e) f({
126
+ path: { file_id: t },
127
+ receivableId: u
128
+ });
129
+ l((t) => t.filter(({ id: t }) => !e.has(t))), O();
130
+ }, [
131
+ f,
132
+ u,
133
+ O,
134
+ l
135
+ ]), A = i(() => {
136
+ for (let e of b.current) f({
137
+ path: { file_id: e },
138
+ receivableId: u
139
+ });
140
+ b.current.clear();
141
+ }, [f, u]);
44
142
  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
143
+ pendingUploads: p,
144
+ isUploading: p.some((e) => e.status === "uploading"),
145
+ isCountLimitReached: h,
146
+ selectFiles: T,
147
+ setIncludeInEmail: E,
148
+ remove: D,
149
+ reset: O,
150
+ discardUploads: k,
151
+ commitRemovals: A
64
152
  };
65
153
  }
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
154
  //#endregion
75
- export { l as useReceivablesTable };
155
+ export { c as useReceivableAttachmentUploads };
@@ -1,114 +1,52 @@
1
- "use client";
2
- "use client";
3
- "use client";
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 "./index11.js";
15
- import { useReceivablesTable as d } from "./index12.js";
16
- import { useCallback as f, useEffect as p, useMemo as m, useState as h } from "react";
1
+ import { parseQuantity as e, priceInputToMinorUnits as t } from "./index6.js";
17
2
  //#region ../../libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index13.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]);
3
+ var n = 1e4;
4
+ function r({ lineItems: n, currency: r, taxRate: i }) {
5
+ let a = i ? i / 100 : 0, o = 0, s = 0;
6
+ for (let i of n) {
7
+ let n = Math.round(t(i.price, r) * e(i.quantity));
8
+ i.taxable ? o += n : s += n;
9
+ }
66
10
  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
- ])
11
+ taxableItemsSubtotal: o,
12
+ nonTaxableItemsSubtotal: s,
13
+ subtotal: o + s,
14
+ rate: a
15
+ };
16
+ }
17
+ function i({ discount: e, subtotal: t }) {
18
+ if (!e) return 0;
19
+ let r = e.value ?? (e.type === "amount" ? e.amount : Math.round(t * e.amount / n));
20
+ return Math.min(Math.max(r, 0), t);
21
+ }
22
+ function a({ taxableItemsSubtotal: e, nonTaxableItemsSubtotal: t, discountAmount: n }) {
23
+ let r = e + t, i = r > 0 ? Math.round(e / r * n) : 0;
24
+ return {
25
+ taxableSubtotal: e - i,
26
+ nonTaxableSubtotal: t - (n - i)
27
+ };
28
+ }
29
+ function o({ lineItems: e, currency: t, taxRate: n, discount: o }) {
30
+ let s = r({
31
+ lineItems: e,
32
+ currency: t,
33
+ taxRate: n
34
+ }), c = i({
35
+ discount: o,
36
+ subtotal: s.subtotal
37
+ }), { taxableSubtotal: l, nonTaxableSubtotal: u } = a({
38
+ ...s,
39
+ discountAmount: c
40
+ }), d = s.rate ? Math.round(l * s.rate) : 0, f = s.subtotal - c;
41
+ return {
42
+ ...s,
43
+ discountAmount: c,
44
+ discountedSubtotal: f,
45
+ taxableSubtotal: l,
46
+ nonTaxableSubtotal: u,
47
+ totalTaxes: d,
48
+ total: f + d
111
49
  };
112
50
  }
113
51
  //#endregion
114
- export { g as useReceivablesWidget };
52
+ export { a as allocateDiscount, o as calculateInvoiceTotals, r as calculateItemsSubtotals, i as resolveDiscountAmount };