@tesouro/embedded-components-react 0.5.204 → 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 (56) hide show
  1. package/README.md +15 -14
  2. package/dist/index.d.ts +49 -4
  3. package/dist/index.js +1 -1
  4. package/dist/lib/ReceivablesWidget.d.ts +49 -4
  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/index10.js +88 -193
  11. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index11.js +184 -31
  12. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index12.js +32 -145
  13. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index13.js +150 -47
  14. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index14.js +37 -293
  15. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index15.js +58 -70
  16. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index16.js +86 -99
  17. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index17.js +48 -233
  18. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index18.js +336 -0
  19. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index19.js +75 -0
  20. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index20.js +115 -0
  21. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index21.js +270 -0
  22. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index5.js +1 -1
  23. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index8.js +95 -394
  24. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index9.js +422 -72
  25. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index.js +15 -10
  26. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index10.js +94 -1
  27. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index11.js +3 -4
  28. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index12.js +24 -11
  29. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index13.js +1 -1
  30. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index14.js +3 -264
  31. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index15.js +3 -72
  32. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index16.js +16 -421
  33. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index17.js +1 -106
  34. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index18.js +4 -93
  35. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index19.js +11 -343
  36. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index2.js +5 -159
  37. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index20.js +1 -0
  38. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index21.js +264 -0
  39. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index22.js +72 -0
  40. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index23.js +401 -0
  41. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index24.js +106 -0
  42. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index25.js +93 -0
  43. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index26.js +344 -0
  44. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index3.js +182 -32
  45. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index4.js +27 -154
  46. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index5.js +203 -20
  47. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index6.js +161 -1
  48. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index7.js +16 -3
  49. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index8.js +25 -3
  50. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index9.js +3 -17
  51. package/dist/libs/tesouro-embedded-components-react/shared/data-access/dist/index.js +38 -38
  52. package/dist/libs/tesouro-embedded-components-react/shared/data-access/dist/lib/rest/@tanstack/react-query.gen.js +213 -202
  53. package/dist/libs/tesouro-embedded-components-react/shared/data-access/dist/lib/rest/sdk.gen.js +136 -116
  54. package/dist/libs/tesouro-embedded-components-react/shared/feature/dist/lib/analytics/build-info.js +1 -1
  55. package/dist/packages/shared-ui-shadcn/dist/index.js +1763 -1749
  56. package/package.json +1 -1
@@ -2,154 +2,41 @@
2
2
  "use client";
3
3
  "use client";
4
4
  "use client";
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";
5
+ import { buildReceivableDetailsView as e } from "./index9.js";
6
+ import { useReceivableHistoryQuery as t, useReceivableMailsQuery as n, useReceivablePdfLinkQuery as r, useReceivableQuery as i } from "../../data-access/dist/index9.js";
7
7
  import "../../data-access/dist/index.js";
8
- import { useCallback as i, useEffect as a, useRef as o, useState as s } from "react";
8
+ import { useMemo as a } from "react";
9
9
  //#region ../../libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index12.js
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
- });
15
- a(() => {
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]);
10
+ function o({ selectedReceivableId: o, enabled: s = !0, messages: c }) {
11
+ let l = i(o, { enabled: s }), u = t(o, {
12
+ enabled: s,
13
+ limit: 25,
14
+ sort: "timestamp",
15
+ order: "desc"
16
+ }), d = n(o, {
17
+ enabled: s,
18
+ limit: 10,
19
+ sort: "created_at",
20
+ order: "desc"
21
+ }), f = r(o, { enabled: s && !!l.data }), p = a(() => e({
22
+ receivable: l.data,
23
+ history: u.data?.data ?? [],
24
+ mails: d.data?.data ?? [],
25
+ pdfUrl: f.data?.file_url || f.data?.original_file_url || void 0,
26
+ messages: c
27
+ }), [
28
+ l.data,
29
+ u.data?.data,
30
+ d.data?.data,
31
+ c,
32
+ f.data
33
+ ]);
142
34
  return {
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
35
+ receivable: l.data,
36
+ detailsView: p,
37
+ isLoading: l.isLoading || u.isLoading || d.isLoading || f.isLoading,
38
+ isError: l.isError
152
39
  };
153
40
  }
154
41
  //#endregion
155
- export { c as useReceivableAttachmentUploads };
42
+ export { o as useReceivableDetails };
@@ -1,52 +1,155 @@
1
- import { parseQuantity as e, priceInputToMinorUnits as t } from "./index6.js";
1
+ "use client";
2
+ "use client";
3
+ "use client";
4
+ "use client";
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
+ import "../../data-access/dist/index.js";
8
+ import { useCallback as i, useEffect as a, useRef as o, useState as s } from "react";
2
9
  //#region ../../libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index13.js
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
- }
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
+ });
15
+ a(() => {
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]);
10
142
  return {
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
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
49
152
  };
50
153
  }
51
154
  //#endregion
52
- export { a as allocateDiscount, o as calculateInvoiceTotals, r as calculateItemsSubtotals, i as resolveDiscountAmount };
155
+ export { c as useReceivableAttachmentUploads };