@tesouro/embedded-components-react 0.5.24 → 0.5.26

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.
package/dist/index.css CHANGED
@@ -3925,6 +3925,9 @@
3925
3925
  .ttw\:perspective-\[1000px\] {
3926
3926
  perspective: 1000px;
3927
3927
  }
3928
+ .ttw\:slide-in-from-top-1 {
3929
+ --tw-enter-translate-y: calc(1*var(--spacing)*-1);
3930
+ }
3928
3931
  .ttw\:transform-3d {
3929
3932
  transform-style: preserve-3d;
3930
3933
  }
@@ -6,7 +6,8 @@ var e = {
6
6
  duplicateCaption: (e) => `${e} possible ${e === 1 ? "duplicate" : "duplicates"}`,
7
7
  failedCaption: (e) => `${e} failed to upload`,
8
8
  tooManyFilesError: (e) => `You can only upload up to ${e} files at a time`,
9
- remainingCapacityError: (e) => e === 0 ? "Wait for the current uploads to finish before adding more files" : `You can upload ${e} more ${e === 1 ? "file" : "files"} right now`
9
+ remainingCapacityError: (e) => e === 0 ? "Wait for the current uploads to finish before adding more files" : `You can upload ${e} more ${e === 1 ? "file" : "files"} right now`,
10
+ billDeletedError: "This bill was already deleted"
10
11
  };
11
12
  //#endregion
12
13
  export { e as BILL_UPLOAD_QUEUE_LABELS_EN };
@@ -4,109 +4,126 @@
4
4
  "use client";
5
5
  import { toast as e } from "../../../../../packages/shared-ui-shadcn/dist/index.js";
6
6
  import { useEmbedApi as t } from "../../../shared/data-access/dist/lib/EmbedApiContext.js";
7
+ import { organizationHeaders as n } from "../../../shared/data-access/dist/lib/organizationHeaders.js";
8
+ import { getPayablesIdOptions as r } from "../../../shared/data-access/dist/lib/rest/@tanstack/react-query.gen.js";
9
+ import { withAuthEpoch as i } from "../../../shared/data-access/dist/lib/withAuthEpoch.js";
10
+ import { isApiNotFoundError as a } from "../../../shared/data-access/dist/lib/isApiNotFoundError.js";
11
+ import "../../../shared/data-access/dist/index.js";
7
12
  import "../../../shared/ui/dist/index.js";
8
- import { useUploadPayableFromFileMutation as n } from "../../data-access/dist/index13.js";
9
- import { usePayableOcrQueries as r } from "../../data-access/dist/index15.js";
13
+ import { useUploadPayableFromFileMutation as o } from "../../data-access/dist/index13.js";
14
+ import { usePayableOcrQueries as s } from "../../data-access/dist/index15.js";
10
15
  import "../../data-access/dist/index.js";
11
- import { billPayUploadQueueKey as i } from "./index69.js";
12
- import { BILL_UPLOAD_QUEUE_LABELS_EN as a } from "./index70.js";
13
- import { useCallback as o, useEffect as s, useMemo as c, useState as l } from "react";
14
- import { useQuery as u, useQueryClient as d } from "@tanstack/react-query";
16
+ import { billPayUploadQueueKey as c } from "./index69.js";
17
+ import { BILL_UPLOAD_QUEUE_LABELS_EN as l } from "./index70.js";
18
+ import { useCallback as u, useEffect as d, useMemo as f, useState as p } from "react";
19
+ import { useQuery as m, useQueryClient as h } from "@tanstack/react-query";
15
20
  //#region ../../libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index71.js
16
- function f({ onOpenBill: f, labels: p } = {}) {
17
- let m = {
18
- ...a,
19
- ...p
20
- }, h = p?.tooManyFilesError ?? a.tooManyFilesError, g = p?.remainingCapacityError ?? a.remainingCapacityError, { organizationId: _ } = t(), v = d(), y = c(() => i(_), [_]), b = n(), [x, S] = l(!1), { data: C = [] } = u({
21
- queryKey: y,
22
- queryFn: () => v.getQueryData(y) ?? [],
21
+ function g({ onOpenBill: g, labels: _ } = {}) {
22
+ let v = {
23
+ ...l,
24
+ ..._
25
+ }, y = _?.tooManyFilesError ?? l.tooManyFilesError, b = _?.remainingCapacityError ?? l.remainingCapacityError, { client: x, organizationId: S, authEpoch: C } = t(), w = h(), T = f(() => c(S), [S]), E = o(), [D, O] = p(!1), { data: k = [] } = m({
26
+ queryKey: T,
27
+ queryFn: () => w.getQueryData(T) ?? [],
23
28
  staleTime: Infinity,
24
29
  gcTime: Infinity,
25
30
  initialData: []
26
- }), w = o((e, t) => {
27
- v.setQueryData(y, (n) => (n ?? []).map((n) => n.localId === e ? {
31
+ }), A = u((e, t) => {
32
+ w.setQueryData(T, (n) => (n ?? []).map((n) => n.localId === e ? {
28
33
  ...n,
29
34
  ...t
30
35
  } : n));
31
- }, [v, y]), T = o((e) => {
32
- v.setQueryData(y, (t) => (t ?? []).filter((t) => t.localId !== e));
33
- }, [v, y]), E = o((t) => {
34
- let n = (v.getQueryData(y) ?? []).filter((e) => e.status === "uploading").length;
36
+ }, [w, T]), j = u((e) => {
37
+ w.setQueryData(T, (t) => (t ?? []).filter((t) => t.localId !== e));
38
+ }, [w, T]), M = u((t) => {
39
+ let n = (w.getQueryData(T) ?? []).filter((e) => e.status === "uploading").length;
35
40
  if (t.length + n > 10) {
36
- e.error(n > 0 ? g(10 - n) : h(10));
41
+ e.error(n > 0 ? b(10 - n) : y(10));
37
42
  return;
38
43
  }
39
- S(!1);
44
+ O(!1);
40
45
  for (let e of t) {
41
46
  let t = crypto.randomUUID();
42
- v.setQueryData(y, (n) => [...n ?? [], {
47
+ w.setQueryData(T, (n) => [...n ?? [], {
43
48
  localId: t,
44
49
  fileName: e.name,
45
50
  status: "uploading"
46
- }]), b.mutateAsync({ file: e }).then((e) => w(t, { payableId: e?.id })).catch(() => w(t, { status: "failed" }));
51
+ }]), E.mutateAsync({ file: e }).then((e) => A(t, { payableId: e?.id })).catch(() => A(t, { status: "failed" }));
47
52
  }
48
53
  }, [
54
+ A,
49
55
  w,
50
- v,
56
+ T,
57
+ b,
51
58
  y,
52
- g,
53
- h,
54
- b
55
- ]), D = r({ payableIds: C.filter((e) => e.status === "uploading" && e.payableId).map((e) => e.payableId) });
56
- s(() => {
59
+ E
60
+ ]), N = s({ payableIds: k.filter((e) => e.status === "uploading" && e.payableId).map((e) => e.payableId) });
61
+ d(() => {
57
62
  let e = /* @__PURE__ */ new Set();
58
- for (let t of D) if (t.suspectedDuplicateOf.length !== 0) {
63
+ for (let t of N) if (t.suspectedDuplicateOf.length !== 0) {
59
64
  e.add(t.payableId);
60
65
  for (let n of t.suspectedDuplicateOf) e.add(n);
61
66
  }
62
- for (let { payableId: t, ocrStatus: n, isError: r } of D) {
63
- let i = C.find((e) => e.payableId === t && e.status === "uploading");
64
- i && (n === "success" ? w(i.localId, { status: e.has(t) ? "duplicate" : "ready" }) : (r || n === "error" || n === "canceled") && w(i.localId, { status: "failed" }));
67
+ for (let { payableId: t, ocrStatus: n, isError: r } of N) {
68
+ let i = k.find((e) => e.payableId === t && e.status === "uploading");
69
+ i && (n === "success" ? A(i.localId, { status: e.has(t) ? "duplicate" : "ready" }) : (r || n === "error" || n === "canceled") && A(i.localId, { status: "failed" }));
65
70
  }
66
- for (let t of C) t.status === "ready" && t.payableId && e.has(t.payableId) && w(t.localId, { status: "duplicate" });
71
+ for (let t of k) t.status === "ready" && t.payableId && e.has(t.payableId) && A(t.localId, { status: "duplicate" });
67
72
  }, [
68
- C,
69
- D,
70
- w
73
+ k,
74
+ N,
75
+ A
71
76
  ]);
72
- let O = C.filter((e) => e.status === "uploading"), k = C.filter((e) => e.status === "ready"), A = C.filter((e) => e.status === "duplicate"), j = C.filter((e) => e.status === "failed"), M = (e) => ({
73
- id: e.localId,
74
- fileName: e.fileName,
75
- status: e.status,
76
- onOpen: (e.status === "ready" || e.status === "duplicate") && e.payableId && f ? () => {
77
- f(e.payableId), T(e.localId);
77
+ let P = k.filter((e) => e.status === "uploading"), F = k.filter((e) => e.status === "ready"), I = k.filter((e) => e.status === "duplicate"), L = k.filter((e) => e.status === "failed"), R = (t) => ({
78
+ id: t.localId,
79
+ fileName: t.fileName,
80
+ status: t.status,
81
+ onOpen: (t.status === "ready" || t.status === "duplicate") && t.payableId && g ? () => {
82
+ let o = t.payableId;
83
+ w.fetchQuery({
84
+ ...i(r({
85
+ client: x,
86
+ headers: n(S),
87
+ path: { payable_id: o }
88
+ }), C),
89
+ retry: !1
90
+ }).catch((e) => {
91
+ if (a(e)) return "deleted";
92
+ }).then((n) => {
93
+ n === "deleted" ? e.error(v.billDeletedError) : g(o), j(t.localId);
94
+ });
78
95
  } : void 0
79
- }), N = O.length ? [{
96
+ }), z = P.length ? [{
80
97
  id: "in-progress",
81
- items: C.map(M)
98
+ items: k.map(R)
82
99
  }] : [
83
- ...k.length ? [{
100
+ ...F.length ? [{
84
101
  id: "ready",
85
- caption: m.readyCaption(k.length),
86
- items: k.map(M)
102
+ caption: v.readyCaption(F.length),
103
+ items: F.map(R)
87
104
  }] : [],
88
- ...A.length ? [{
105
+ ...I.length ? [{
89
106
  id: "duplicate",
90
- caption: m.duplicateCaption(A.length),
91
- items: A.map(M)
107
+ caption: v.duplicateCaption(I.length),
108
+ items: I.map(R)
92
109
  }] : [],
93
- ...j.length ? [{
110
+ ...L.length ? [{
94
111
  id: "failed",
95
- caption: m.failedCaption(j.length),
96
- items: j.map(M)
112
+ caption: v.failedCaption(L.length),
113
+ items: L.map(R)
97
114
  }] : []
98
- ], P = k.length + A.length, F = O.length ? m.uploadingSummary(C.length) : P ? m.completeSummary(P) : m.failedCaption(j.length), I = o(() => {
99
- v.setQueryData(y, []);
100
- }, [v, y]);
115
+ ], B = F.length + I.length, V = P.length ? v.uploadingSummary(k.length) : B ? v.completeSummary(B) : v.failedCaption(L.length), H = u(() => {
116
+ w.setQueryData(T, []);
117
+ }, [w, T]);
101
118
  return {
102
- enqueue: E,
103
- sections: N,
104
- summaryLabel: F,
105
- collapsed: x,
106
- onToggleCollapsed: o(() => S((e) => !e), []),
107
- onClose: I,
108
- isVisible: C.length > 0
119
+ enqueue: M,
120
+ sections: z,
121
+ summaryLabel: V,
122
+ collapsed: D,
123
+ onToggleCollapsed: u(() => O((e) => !e), []),
124
+ onClose: H,
125
+ isVisible: k.length > 0
109
126
  };
110
127
  }
111
128
  //#endregion
112
- export { f as useBillUploadQueue };
129
+ export { g as useBillUploadQueue };
@@ -2,117 +2,133 @@
2
2
  "use client";
3
3
  "use client";
4
4
  "use client";
5
- import { formatCalendarDate as e } from "../../../shared/util/dist/lib/formatCalendarDate.js";
6
- import { formatMoneyExact as t } from "../../../shared/util/dist/lib/formatMoneyExact.js";
7
- import { hasSuspectedPayableDuplicate as n } from "../../data-access/dist/index7.js";
5
+ import { useEmbedApi as e } from "../../../shared/data-access/dist/lib/EmbedApiContext.js";
6
+ import { formatCalendarDate as t } from "../../../shared/util/dist/lib/formatCalendarDate.js";
7
+ import { formatMoneyExact as n } from "../../../shared/util/dist/lib/formatMoneyExact.js";
8
+ import { hasSuspectedPayableDuplicate as ee } from "../../data-access/dist/index7.js";
8
9
  import { usePayablesQuery as r, usePayablesTotalCountQuery as i } from "../../data-access/dist/index17.js";
9
10
  import "../../data-access/dist/index.js";
10
- import { derivePayableStatus as a } from "./index7.js";
11
- import { resolveVendorName as o } from "./index8.js";
12
- import { isEditablePayableStatus as s } from "./index19.js";
13
- import { BillQueue as c, DEFAULT_BILL_QUEUE as l, billQueueColumns as u, billQueueHasScheduledPayment as d, billQueueOffersAddPanel as f, billQueueStatuses as p, billSortColumnId as m, billSortField as h } from "./index73.js";
14
- import { useBillsFilters as g } from "./index81.js";
15
- import { useCallback as _, useEffect as v, useMemo as y, useState as b } from "react";
11
+ import { derivePayableStatus as te } from "./index7.js";
12
+ import { resolveVendorName as a } from "./index8.js";
13
+ import { isEditablePayableStatus as ne } from "./index19.js";
14
+ import { BillQueue as o, DEFAULT_BILL_QUEUE as s, billQueueColumns as c, billQueueHasScheduledPayment as l, billQueueOffersAddPanel as u, billQueueStatuses as d, billSortColumnId as f, billSortField as p } from "./index73.js";
15
+ import { useBillsFilters as m } from "./index81.js";
16
+ import { useCallback as h, useEffect as g, useMemo as _, useState as v } from "react";
16
17
  //#region ../../libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index82.js
17
- var x = 10, S = [{
18
+ var y = 10, b = [{
18
19
  id: "addedOnLabel",
19
20
  desc: !0
20
21
  }];
21
- function C({ enabled: C = !0, canReadVendors: w = !0, isVendorFilterPaused: T = !1, filterLabels: E, onOpenBill: D, duplicateRowNote: O, attachmentLabel: k }) {
22
- let [A, j] = b(l), [M, N] = b(S), [P, F] = b(x), [I, L] = b(), [R, z] = b(""), [B, V] = b(""), H = _(() => L(void 0), []);
23
- v(() => {
22
+ function x({ enabled: x = !0, canReadVendors: S = !0, isVendorFilterPaused: C = !1, filterLabels: w, onOpenBill: T, duplicateRowNote: E, attachmentLabel: D }) {
23
+ let [O, k] = v(s), [A, j] = v(b), [M, N] = v(y), [P, F] = v(), [I, L] = v(""), [R, z] = v(""), B = h(() => F(void 0), []);
24
+ g(() => {
24
25
  let e = setTimeout(() => {
25
- V(R), H();
26
+ z(I), B();
26
27
  }, 300);
27
28
  return () => clearTimeout(e);
28
- }, [R, H]);
29
- let U = g({
30
- offersStatusFilter: A === c.All,
31
- offersVendorFilter: w,
32
- isVendorFilterPaused: T,
33
- labels: E,
34
- onFiltersChange: H
35
- }), W = M[0], G = h(W?.id), K = r({
36
- ...U.query,
37
- limit: P,
38
- pagination_token: I,
39
- status__in: p(A) ?? U.query.status__in,
40
- has_scheduled_payment: d(A),
41
- counterpart_name__icontains: B || void 0,
42
- sort: G,
43
- order: G ? W?.desc ? "desc" : "asc" : void 0,
44
- enabled: C
45
- }), q = K.data?.data.length === 0, J = i({ enabled: C && q }), Y = !q || (J.data?.count ?? 1) > 0, X = y(() => (K.data?.data ?? []).map((r) => {
46
- let i = a({
47
- apiStatus: r.status,
48
- dueDate: r.due_date,
49
- scheduledPaymentDate: r.scheduled_payment_date
50
- }), l = r.amount_due ?? r.total_amount, u = r.status === "partially_paid" || r.status === "paid", d = (e) => e == null ? "" : t(e / 100, { currencyCode: r.currency ?? "USD" });
29
+ }, [I, B]);
30
+ let V = m({
31
+ offersStatusFilter: O === o.All,
32
+ offersVendorFilter: S,
33
+ isVendorFilterPaused: C,
34
+ labels: w,
35
+ onFiltersChange: B
36
+ }), H = A[0], U = p(H?.id), W = U ? H?.desc ? "desc" : "asc" : void 0, G = _(() => ({
37
+ ...V.query,
38
+ limit: M,
39
+ pagination_token: P,
40
+ status__in: d(O) ?? V.query.status__in,
41
+ has_scheduled_payment: l(O),
42
+ counterpart_name__icontains: R || void 0,
43
+ sort: U,
44
+ order: W
45
+ }), [
46
+ V.query,
47
+ M,
48
+ P,
49
+ O,
50
+ R,
51
+ U,
52
+ W
53
+ ]), { organizationId: K } = e(), q = JSON.stringify([K, G]), J = r({
54
+ ...G,
55
+ enabled: x
56
+ }), [Y, X] = v(q);
57
+ g(() => {
58
+ J.isFetching || X(q);
59
+ }, [J.isFetching, q]);
60
+ let Z = J.data?.data.length === 0, Q = i({ enabled: x && Z }), re = !Z || (Q.data?.count ?? 1) > 0, ie = _(() => (J.data?.data ?? []).map((e) => {
61
+ let r = te({
62
+ apiStatus: e.status,
63
+ dueDate: e.due_date,
64
+ scheduledPaymentDate: e.scheduled_payment_date
65
+ }), i = e.amount_due ?? e.total_amount, s = e.status === "partially_paid" || e.status === "paid", c = (t) => t == null ? "" : n(t / 100, { currencyCode: e.currency ?? "USD" });
51
66
  return {
52
- vendorLabel: o(r),
53
- issueDateLabel: e(r.issued_at),
54
- dueDateLabel: e(r.due_date),
55
- dueDateTone: i.isOverdue ? "danger" : "default",
56
- scheduledDateLabel: e(r.scheduled_payment_date),
57
- scheduledDateIsGap: A === c.Scheduled,
58
- paidDateLabel: e(r.paid_at?.slice(0, 10)),
59
- amountDueLabel: d(l),
60
- amountPaidLabel: u ? d(r.amount_paid) : "",
61
- amountPaidIsGap: A === c.Paid,
62
- amountScheduledLabel: d(r.amount_to_pay ?? l),
63
- totalAmountLabel: d(r.total_amount),
64
- attachment: r.file_id ? { label: k } : void 0,
65
- status: i.status,
66
- statusTone: i.tone,
67
- addedOnLabel: e(r.created_at?.slice(0, 10)),
68
- ...n(r) ? {
67
+ rowKey: e.id,
68
+ vendorLabel: a(e),
69
+ issueDateLabel: t(e.issued_at),
70
+ dueDateLabel: t(e.due_date),
71
+ dueDateTone: r.isOverdue ? "danger" : "default",
72
+ scheduledDateLabel: t(e.scheduled_payment_date),
73
+ scheduledDateIsGap: O === o.Scheduled,
74
+ paidDateLabel: t(e.paid_at?.slice(0, 10)),
75
+ amountDueLabel: c(i),
76
+ amountPaidLabel: s ? c(e.amount_paid) : "",
77
+ amountPaidIsGap: O === o.Paid,
78
+ amountScheduledLabel: c(e.amount_to_pay ?? i),
79
+ totalAmountLabel: c(e.total_amount),
80
+ attachment: e.file_id ? { label: D } : void 0,
81
+ status: r.status,
82
+ statusTone: r.tone,
83
+ addedOnLabel: t(e.created_at?.slice(0, 10)),
84
+ ...ee(e) ? {
69
85
  rowTone: "warning",
70
- rowNote: O
86
+ rowNote: E
71
87
  } : {},
72
- onOpen: () => D(r.id, s(r.status))
88
+ onOpen: () => T(e.id, ne(e.status))
73
89
  };
74
90
  }), [
75
- K.data?.data,
76
- O,
77
- k,
91
+ J.data?.data,
92
+ E,
78
93
  D,
79
- A
80
- ]), Z = _((e) => {
94
+ T,
95
+ O
96
+ ]), ae = h((e) => {
81
97
  let t = e;
82
- j(t), N((e) => {
98
+ k(t), j((e) => {
83
99
  let n = e[0]?.id;
84
- return n ? u(t).some((e) => m(e) === n) ? e : S : e;
85
- }), H();
86
- }, [H]), Q = _((e) => {
87
- N((t) => typeof e == "function" ? e(t) : e), H();
88
- }, [H]), $ = _((e) => {
89
- F(e), H();
90
- }, [H]), ee = _(() => L(K.data?.next_pagination_token ?? void 0), [K.data?.next_pagination_token]), te = _(() => L(K.data?.prev_pagination_token ?? void 0), [K.data?.prev_pagination_token]), ne = _(() => {
91
- K.refetch();
92
- }, [K.refetch]);
100
+ return n ? c(t).some((e) => f(e) === n) ? e : b : e;
101
+ }), B();
102
+ }, [B]), oe = h((e) => {
103
+ j((t) => typeof e == "function" ? e(t) : e), B();
104
+ }, [B]), $ = h((e) => {
105
+ N(e), B();
106
+ }, [B]), se = h(() => F(J.data?.next_pagination_token ?? void 0), [J.data?.next_pagination_token]), ce = h(() => F(J.data?.prev_pagination_token ?? void 0), [J.data?.prev_pagination_token]), le = h(() => {
107
+ J.refetch();
108
+ }, [J.refetch]);
93
109
  return {
94
- rows: X,
95
- isLoading: K.isFetching || q && J.isLoading,
96
- isError: K.isError,
97
- onRetry: ne,
98
- selectedFilterTabId: A,
99
- onFilterTabChange: Z,
100
- searchValue: R,
101
- onSearchChange: z,
102
- hasAnyBills: Y,
103
- isSearchActive: B.length > 0 || U.isFilterActive,
104
- filterBarProps: U.filterBarProps,
105
- visibleColumns: u(A),
106
- showAddPanelWhenEmpty: f(A),
107
- sorting: M,
108
- onSortingChange: Q,
109
- pageSize: P,
110
+ rows: ie,
111
+ isLoading: J.isLoading || q !== Y || Z && Q.isLoading,
112
+ isError: J.isError,
113
+ onRetry: le,
114
+ selectedFilterTabId: O,
115
+ onFilterTabChange: ae,
116
+ searchValue: I,
117
+ onSearchChange: L,
118
+ hasAnyBills: re,
119
+ isSearchActive: R.length > 0 || V.isFilterActive,
120
+ filterBarProps: V.filterBarProps,
121
+ visibleColumns: c(O),
122
+ showAddPanelWhenEmpty: u(O),
123
+ sorting: A,
124
+ onSortingChange: oe,
125
+ pageSize: M,
110
126
  onPageSizeChange: $,
111
- hasNextPage: !!K.data?.next_pagination_token,
112
- hasPrevPage: !!K.data?.prev_pagination_token,
113
- onNextPage: ee,
114
- onPrevPage: te
127
+ hasNextPage: !!J.data?.next_pagination_token,
128
+ hasPrevPage: !!J.data?.prev_pagination_token,
129
+ onNextPage: se,
130
+ onPrevPage: ce
115
131
  };
116
132
  }
117
133
  //#endregion
118
- export { C as useBillsTable };
134
+ export { x as useBillsTable };
@@ -328,6 +328,8 @@ function x({ rows: x, isLoading: S, isError: C, sorting: ve, onSortingChange: ye
328
328
  }) : /* @__PURE__ */ g(r, {
329
329
  columns: we,
330
330
  data: x,
331
+ getRowId: (e) => e.rowKey,
332
+ animatesNewRows: !0,
331
333
  isLoading: S,
332
334
  sorting: ve,
333
335
  onSortingChange: ye,