@tesouro/embedded-components-react 0.5.135 → 0.5.138

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 (21) hide show
  1. package/dist/index.js +1 -1
  2. package/dist/lib/BillPayWidget.js +1 -1
  3. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index.js +2 -2
  4. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index48.js +2 -0
  5. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index55.js +36 -16
  6. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index83.js +26 -129
  7. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index84.js +145 -204
  8. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index85.js +214 -4
  9. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index86.js +4 -7
  10. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index87.js +5 -111
  11. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index88.js +113 -1
  12. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index89.js +0 -26
  13. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index90.js +27 -0
  14. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index36.js +2 -0
  15. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index82.js +93 -79
  16. package/dist/libs/tesouro-embedded-components-react/shared/counterpart-management/data-access/dist/index.js +4 -4
  17. package/dist/libs/tesouro-embedded-components-react/shared/counterpart-management/data-access/dist/index3.js +21 -12
  18. package/dist/libs/tesouro-embedded-components-react/shared/counterpart-management/feature/dist/index.js +17 -17
  19. package/dist/libs/tesouro-embedded-components-react/shared/feature/dist/lib/analytics/build-info.js +1 -1
  20. package/dist/libs/tesouro-embedded-components-react/widget-suite/feature/dist/index8.js +1 -1
  21. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -15,7 +15,7 @@ import { RefreshingRootWidgetProvider as y } from "./libs/tesouro-embedded-compo
15
15
  import { useDisclosuresAcceptanceSurface as b, useOwnWidgetConfig as x, useRefetchWidget as S, useWidgetConfig as C, useWidgetError as w, useWidgetInitStaleForToken as T, useWidgetLoading as E } from "./libs/tesouro-embedded-components-react/shared/feature/dist/lib/WidgetProvider/hooks.js";
16
16
  import { BankAccountsWidget as D } from "./libs/tesouro-embedded-components-react/bank-accounts-widget/feature/dist/index8.js";
17
17
  import { CounterpartsWidget as O } from "./libs/tesouro-embedded-components-react/counterparts-widget/feature/dist/index8.js";
18
- import { BillPayWidget as k } from "./libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index89.js";
18
+ import { BillPayWidget as k } from "./libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index90.js";
19
19
  import { CardDetailsWidget as A } from "./libs/tesouro-embedded-components-react/card-details-widget/feature/dist/index13.js";
20
20
  import { CreditCardsWidget as j } from "./libs/tesouro-embedded-components-react/cards-widget/feature/dist/index10.js";
21
21
  import { DebitCardsWidget as M } from "./libs/tesouro-embedded-components-react/cards-widget/feature/dist/index11.js";
@@ -1,3 +1,3 @@
1
- import { BillPayWidget as e } from "../libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index89.js";
1
+ import { BillPayWidget as e } from "../libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index90.js";
2
2
  import "../libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index.js";
3
3
  export { e as BillPayWidget };
@@ -25,8 +25,8 @@ import "./index70.js";
25
25
  import "./index71.js";
26
26
  import "./index73.js";
27
27
  import "./index76.js";
28
- import "./index83.js";
29
28
  import "./index84.js";
30
29
  import "./index85.js";
31
- import { BillPayWidget as e } from "./index89.js";
30
+ import "./index86.js";
31
+ import { BillPayWidget as e } from "./index90.js";
32
32
  export { e as BillPayWidget };
@@ -33,6 +33,8 @@ var y = {
33
33
  unreadableTotal: "Enter a valid total amount.",
34
34
  totalNotGreaterThanZero: "Total amount must be greater than $0.",
35
35
  poNumberTooLong: "PO number must be 255 characters or fewer.",
36
+ implausibleInvoiceDate: "Enter an invoice date within the last 10 years, no more than 30 days from today.",
37
+ implausibleDueDate: "Enter a due date within the last 10 years and next 5 years.",
36
38
  dueBeforeInvoiceDate: "Due date must be on or after the invoice date."
37
39
  }, b = {
38
40
  paymentInstructionsValue: (e) => `Account ending in ${e}`,
@@ -1,16 +1,36 @@
1
1
  import { BILL_CREATE_MESSAGE_LABELS_EN as e } from "./index48.js";
2
2
  import { isPersistableLineItem as t, parseMoneyToMinorUnits as n, parseQuantity as r } from "./index54.js";
3
3
  //#region ../../libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index55.js
4
- var i = /^(?:\d{1,3}(?:,\d{3})+(?:\.\d+)?|\d+(?:\.\d+)?|\.\d+)$/, a = 255;
5
- function o(t, n = e) {
4
+ var i = /^(?:\d{1,3}(?:,\d{3})+(?:\.\d+)?|\d+(?:\.\d+)?|\.\d+)$/, a = 255, o = 10, s = 5, c = 30, l = 864e5;
5
+ function u() {
6
+ let e = /* @__PURE__ */ new Date();
7
+ return Date.UTC(e.getFullYear(), e.getMonth(), e.getDate());
8
+ }
9
+ function d() {
10
+ let e = new Date(u());
11
+ return e.setUTCFullYear(e.getUTCFullYear() - o), e;
12
+ }
13
+ function f(e) {
14
+ let t = new Date(e);
15
+ if (Number.isNaN(t.getTime())) return !1;
16
+ let n = new Date(u() + c * l);
17
+ return t < d() || t > n;
18
+ }
19
+ function p(e) {
20
+ let t = new Date(e);
21
+ if (Number.isNaN(t.getTime())) return !1;
22
+ let n = new Date(u());
23
+ return n.setUTCFullYear(n.getUTCFullYear() + s), t < d() || t > n;
24
+ }
25
+ function m(t, n = e) {
6
26
  let r = {};
7
27
  return t.poNumber.length > a && (r.poNumber = n.poNumberTooLong), Object.keys(r).length ? r : void 0;
8
28
  }
9
- function s(e) {
29
+ function h(e) {
10
30
  let t = e.trim();
11
31
  return !t || n(t) !== null ? !0 : i.test(t) ? Number(t.replaceAll(",", "")) === 0 : !1;
12
32
  }
13
- function c(t, i = e) {
33
+ function g(t, i = e) {
14
34
  let a = {};
15
35
  for (let e of t) {
16
36
  let t = n(e.price), o = n(e.amount), s = {};
@@ -18,11 +38,11 @@ function c(t, i = e) {
18
38
  }
19
39
  return Object.keys(a).length ? a : void 0;
20
40
  }
21
- function l(i, a, o, s = e) {
41
+ function _(i, a, o, s = e) {
22
42
  let c = {};
23
43
  a || (c.vendor = s.requiredField), i.invoiceNumber.trim() || (c.invoiceNumber = s.requiredField);
24
44
  let l = i.invoiceDate.trim(), u = i.dueDate.trim();
25
- l || (c.invoiceDate = s.requiredField), u ? l && u < l && (c.dueDate = s.dueBeforeInvoiceDate) : c.dueDate = s.requiredField;
45
+ l ? f(l) && (c.invoiceDate = s.implausibleInvoiceDate) : c.invoiceDate = s.requiredField, u ? p(u) ? c.dueDate = s.implausibleDueDate : l && u < l && (c.dueDate = s.dueBeforeInvoiceDate) : c.dueDate = s.requiredField;
26
46
  let d = {};
27
47
  return o.forEach((e, i) => {
28
48
  if (i > 0 && !t(e)) return;
@@ -33,31 +53,31 @@ function l(i, a, o, s = e) {
33
53
  lineItemErrors: Object.keys(d).length ? d : void 0
34
54
  };
35
55
  }
36
- function u(e) {
56
+ function v(e) {
37
57
  let t = e.trim();
38
58
  if (!t) return !0;
39
59
  let n = t.startsWith("-") ? t.slice(1) : t;
40
60
  return i.test(n) ? Number(t.replaceAll(",", "")) <= 0 : !1;
41
61
  }
42
- function d(e, t) {
43
- if (n(e) === null) return u(e) ? t.totalNotGreaterThanZero : t.unreadableTotal;
62
+ function y(e, t) {
63
+ if (n(e) === null) return v(e) ? t.totalNotGreaterThanZero : t.unreadableTotal;
44
64
  }
45
- function f(t, n = e) {
46
- let r = d(t, n);
65
+ function b(t, n = e) {
66
+ let r = y(t, n);
47
67
  return r ? { total: r } : void 0;
48
68
  }
49
- function p(t, r = e) {
69
+ function x(t, r = e) {
50
70
  if (t === void 0) return;
51
71
  let i = n(t);
52
72
  if (i !== null) return i > 0 ? void 0 : { total: r.totalNotGreaterThanZero };
53
73
  }
54
- function m(t, n, r, i = e) {
74
+ function S(t, n, r, i = e) {
55
75
  let a = {};
56
- if (s(t) || (a.discount = i.unreadableDiscount), s(n) || (a.tax = i.unreadableTax), r !== void 0) {
57
- let e = d(r, i);
76
+ if (h(t) || (a.discount = i.unreadableDiscount), h(n) || (a.tax = i.unreadableTax), r !== void 0) {
77
+ let e = y(r, i);
58
78
  e && (a.total = e);
59
79
  }
60
80
  return Object.keys(a).length ? a : void 0;
61
81
  }
62
82
  //#endregion
63
- export { s as isReadableMoneyOrZero, l as validateBillCompleteness, f as validateBillTotalIsPayable, m as validateBillTotals, o as validateBillValues, c as validateLineItems, p as validateStoredAmountDue };
83
+ export { h as isReadableMoneyOrZero, _ as validateBillCompleteness, b as validateBillTotalIsPayable, S as validateBillTotals, m as validateBillValues, g as validateLineItems, x as validateStoredAmountDue };
@@ -2,137 +2,34 @@
2
2
  "use client";
3
3
  "use client";
4
4
  "use client";
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 r } from "../../data-access/dist/index7.js";
9
- import { usePayablesQuery as i, usePayablesTotalCountQuery as a } from "../../data-access/dist/index17.js";
10
- import "../../data-access/dist/index.js";
11
- import { derivePayableStatus as o } from "./index7.js";
12
- import { resolveVendorName as ee } from "./index8.js";
13
- import { isEditablePayableStatus as s } from "./index19.js";
14
- import { BillQueue as c, DEFAULT_BILL_QUEUE as l, billQueueColumns as u, billQueueHasScheduledPayment as te, billQueueOffersAddPanel as d, billQueueStatuses as f, billSortColumnId as ne, billSortField as p } from "./index73.js";
15
- import { useBillsFilters as m } from "./index82.js";
16
- import { useCallback as h, useEffect as g, useMemo as _, useState as v } from "react";
5
+ import { useCounterpartsByIdsQuery as e } from "../../../shared/counterpart-management/data-access/dist/index3.js";
6
+ import { resolveVendorName as t } from "./index8.js";
7
+ import { getCounterpartName as n } from "../../../shared/counterpart-management/feature/dist/lib/helpers.js";
8
+ import "../../../shared/counterpart-management/feature/dist/index.js";
9
+ import { useMemo as r } from "react";
17
10
  //#region ../../libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index83.js
18
- var y = 10, b = [{
19
- id: "addedOnLabel",
20
- desc: !0
21
- }];
22
- function x({ enabled: x = !0, canReadVendors: S = !0, isVendorFilterPaused: C = !1, filterLabels: re, onOpenBill: w, duplicateRowNote: T, attachmentLabel: E }) {
23
- let [D, ie] = v(l), [O, k] = v(b), [A, j] = v(y), [M, N] = v(), [P, F] = v(""), [I, L] = v(""), R = h(() => N(void 0), []);
24
- g(() => {
25
- let e = setTimeout(() => {
26
- L(P), R();
27
- }, 300);
28
- return () => clearTimeout(e);
29
- }, [P, R]);
30
- let z = m({
31
- offersStatusFilter: D === c.All,
32
- offersVendorFilter: S,
33
- isVendorFilterPaused: C,
34
- labels: re,
35
- onFiltersChange: R
36
- }), { filterByVendor: B } = z, V = O[0], H = p(V?.id), U = H ? V?.desc ? "desc" : "asc" : void 0, W = _(() => ({
37
- ...z.query,
38
- limit: A,
39
- pagination_token: M,
40
- status__in: f(D) ?? z.query.status__in,
41
- has_scheduled_payment: te(D),
42
- counterpart_name__icontains: I || void 0,
43
- sort: H,
44
- order: U
45
- }), [
46
- z.query,
47
- A,
48
- M,
49
- D,
50
- I,
51
- H,
52
- U
53
- ]), { organizationId: G } = e(), K = JSON.stringify([G, W]), q = i({
54
- ...W,
55
- enabled: x,
56
- pollWhileOcrProcessing: !0
57
- }), [J, ae] = v(K);
58
- g(() => {
59
- q.isFetching || ae(K);
60
- }, [q.isFetching, K]);
61
- let Y = q.data?.data.length, X = Y === 0, Z = a({ enabled: x && X }), oe = !X || (Z.data?.count ?? 1) > 0, Q = _(() => (q.data?.data ?? []).filter((e) => e.ocr_status !== "processing").map((e) => {
62
- let i = o({
63
- apiStatus: e.status,
64
- dueDate: e.due_date,
65
- scheduledPaymentDate: e.scheduled_payment_date
66
- }), a = e.amount_due ?? e.total_amount, l = e.status === "partially_paid" || e.status === "paid", u = (t) => t == null ? "" : n(t / 100, { currencyCode: e.currency ?? "USD" });
67
- return {
68
- rowKey: e.id,
69
- vendorLabel: ee(e),
70
- issueDateLabel: t(e.issued_at),
71
- dueDateLabel: t(e.due_date),
72
- dueDateTone: i.isOverdue ? "danger" : "default",
73
- scheduledDateLabel: t(e.scheduled_payment_date),
74
- scheduledDateIsGap: D === c.Scheduled,
75
- paidDateLabel: t(e.paid_at?.slice(0, 10)),
76
- amountDueLabel: u(a),
77
- amountPaidLabel: l ? u(e.amount_paid) : "",
78
- amountPaidIsGap: D === c.Paid,
79
- amountScheduledLabel: u(e.amount_to_pay ?? a),
80
- totalAmountLabel: u(e.total_amount),
81
- attachment: e.file_id ? { label: E } : void 0,
82
- status: i.status,
83
- statusTone: i.tone,
84
- addedOnLabel: t(e.created_at?.slice(0, 10)),
85
- ...r(e) ? {
86
- rowTone: "warning",
87
- rowNote: T
88
- } : {},
89
- onOpen: () => w(e.id, s(e.status))
90
- };
91
- }), [
92
- q.data?.data,
93
- T,
94
- E,
95
- w,
96
- D
97
- ]), $ = h((e) => {
98
- let t = e;
99
- ie(t), k((e) => {
100
- let n = e[0]?.id;
101
- return n ? u(t).some((e) => ne(e) === n) ? e : b : e;
102
- }), R();
103
- }, [R]), se = h((e) => {
104
- $(c.All), F(""), B(e);
105
- }, [B, $]), ce = h((e) => {
106
- k((t) => typeof e == "function" ? e(t) : e), R();
107
- }, [R]), le = h((e) => {
108
- j(e), R();
109
- }, [R]), ue = h(() => N(q.data?.next_pagination_token ?? void 0), [q.data?.next_pagination_token]), de = h(() => N(q.data?.prev_pagination_token ?? void 0), [q.data?.prev_pagination_token]), fe = h(() => {
110
- q.refetch();
111
- }, [q.refetch]);
11
+ var i = {
12
+ Resolving: "resolving",
13
+ Unavailable: "unavailable",
14
+ Settled: "settled"
15
+ }, a = /* @__PURE__ */ new Map();
16
+ function o({ payables: i, enabled: o, canReadVendors: c = !0, isPaused: l = !1 } = {}) {
17
+ let u = r(() => (i ?? []).filter((e) => !t(e)).map((e) => e.counterpart_id).filter((e) => !!e), [i]), d = e({
18
+ counterpartIds: u,
19
+ enabled: o !== !1 && c && !l
20
+ }), f = !c && !l;
112
21
  return {
113
- rows: Q,
114
- isLoading: q.isLoading || K !== J || X && Z.isLoading || (Y ?? 0) > 0 && Q.length === 0,
115
- isError: q.isError,
116
- onRetry: fe,
117
- selectedFilterTabId: D,
118
- onFilterTabChange: $,
119
- showVendorBills: se,
120
- searchValue: P,
121
- onSearchChange: F,
122
- hasAnyBills: oe,
123
- isSearchActive: I.length > 0 || z.isFilterActive,
124
- filterBarProps: z.filterBarProps,
125
- visibleColumns: u(D),
126
- showAddPanelWhenEmpty: d(D),
127
- sorting: O,
128
- onSortingChange: ce,
129
- pageSize: A,
130
- onPageSizeChange: le,
131
- hasNextPage: !!q.data?.next_pagination_token,
132
- hasPrevPage: !!q.data?.prev_pagination_token,
133
- onNextPage: ue,
134
- onPrevPage: de
22
+ vendorNames: r(() => f ? a : new Map((d.data?.data ?? []).map((e) => [e.id, n(e)]).filter((e) => !!e[1])), [d.data?.data, f]),
23
+ lookup: s({
24
+ hasUnresolvedIds: u.length > 0,
25
+ isScopeWithdrawn: f,
26
+ isFetching: d.isFetching,
27
+ isError: d.isError
28
+ })
135
29
  };
136
30
  }
31
+ function s({ hasUnresolvedIds: e, isScopeWithdrawn: t, isFetching: n, isError: r }) {
32
+ return e ? t ? i.Unavailable : n ? i.Resolving : r ? i.Unavailable : i.Settled : i.Settled;
33
+ }
137
34
  //#endregion
138
- export { x as useBillsTable };
35
+ export { i as BillVendorLookup, o as useBillVendorNames };
@@ -2,213 +2,154 @@
2
2
  "use client";
3
3
  "use client";
4
4
  "use client";
5
- import { toast as e } from "../../../../../packages/shared-ui-shadcn/dist/index.js";
6
- import { hasAnyScope as t } from "../../../shared/data-access/dist/lib/hasAnyScope.js";
7
- import { Scope as n } from "../../../shared/data-access/dist/lib/scopes.js";
8
- import "../../../shared/data-access/dist/index.js";
9
- import "../../../shared/ui/dist/index.js";
10
- import { useWidgetConfig as ee, useWidgetInitStaleForToken as te } from "../../../shared/feature/dist/lib/WidgetProvider/hooks.js";
11
- import "../../../shared/feature/dist/index.js";
12
- import { useDuplicateBillsCount as ne } from "./index10.js";
13
- import { AddBillDialog as r } from "../../ui/dist/index10.js";
14
- import { BillsScreen as re } from "../../ui/dist/index82.js";
15
- import "../../ui/dist/index.js";
16
- import { DuplicateBillsContainer as ie } from "./index12.js";
17
- import "./index14.js";
18
- import { BillCreateDialog as i } from "./index60.js";
19
- import "./index61.js";
20
- import { BillDetailsContainer as ae } from "./index63.js";
21
- import "./index64.js";
22
- import "./index70.js";
23
- import "./index71.js";
24
- import { BILL_QUEUE_ORDER as a } from "./index73.js";
25
- import { BILLS_TAB_LABELS_EN as o } from "./index76.js";
26
- import { useBillsTable as s } from "./index83.js";
27
- import { formatBillQueueBadge as c } from "./index72.js";
28
- import { copyTextToClipboard as l } from "./index74.js";
29
- import { resolveDuplicateWarning as u } from "./index75.js";
30
- import { billsTabTestIds as d, billsTableCellTestIds as f } from "./index77.js";
31
- import { useBillQueueCounts as oe } from "./index78.js";
32
- import { useCallback as p, useEffect as m, useMemo as h, useState as g } from "react";
33
- import { jsx as _, jsxs as se } from "react/jsx-runtime";
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 r } from "../../data-access/dist/index7.js";
9
+ import { usePayablesQuery as i, usePayablesTotalCountQuery as a } from "../../data-access/dist/index17.js";
10
+ import "../../data-access/dist/index.js";
11
+ import { derivePayableStatus as o } from "./index7.js";
12
+ import { resolveVendorName as ee } from "./index8.js";
13
+ import { isEditablePayableStatus as te } from "./index19.js";
14
+ import { BillQueue as s, DEFAULT_BILL_QUEUE as c, billQueueColumns as l, billQueueHasScheduledPayment as u, billQueueOffersAddPanel as d, billQueueStatuses as f, billSortColumnId as ne, billSortField as re } from "./index73.js";
15
+ import { useBillsFilters as ie } from "./index82.js";
16
+ import { BillVendorLookup as p, useBillVendorNames as ae } from "./index83.js";
17
+ import { useCallback as m, useEffect as h, useMemo as g, useState as _ } from "react";
34
18
  //#region ../../libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index84.js
35
- var v = "bills@business-banking.app";
36
- function y({ labels: y, onEnqueueFiles: b, openPayableId: x, onOpenPayableHandled: S, vendorIntent: C, onVendorIntentHandled: w, poweredByBankName: T, onSettingsClick: E }) {
37
- let D = h(() => ({
38
- ...o,
39
- ...y,
40
- queues: {
41
- ...o.queues,
42
- ...y?.queues
43
- },
44
- filters: {
45
- ...o.filters,
46
- ...y?.filters,
47
- presets: {
48
- ...o.filters.presets,
49
- ...y?.filters?.presets
50
- },
51
- statuses: {
52
- ...o.filters.statuses,
53
- ...y?.filters?.statuses
54
- },
55
- dateFieldNames: {
56
- ...o.filters.dateFieldNames,
57
- ...y?.filters?.dateFieldNames
58
- }
59
- },
60
- filterBar: {
61
- ...o.filterBar,
62
- ...y?.filterBar
63
- },
64
- queueEmptyStates: a.reduce((e, t) => ({
65
- ...e,
66
- [t]: {
67
- ...o.queueEmptyStates[t],
68
- ...y?.queueEmptyStates?.[t]
69
- }
70
- }), {})
71
- }), [y]), [ce, O] = g(!1), [le, k] = g(), [A, j] = g(), [M, N] = g(!1), [P, F] = g(), [I, L] = g(!1), [R, z] = g(!1), [B, V] = g(!1), { initResponse: H } = ee(), U = te(), ue = t(H?.scopes, [n.PayableReadOrg]), de = t(H?.scopes, [n.PayableWriteOrg]), W = !H || ue, G = !H || de, fe = p((e, t) => {
72
- if (t && G) {
73
- k(e), j(void 0), N(!0);
74
- return;
75
- }
76
- F(e), z(!0);
77
- }, [G]), pe = t(H?.scopes, [n.CounterpartReadOrg]), K = s({
78
- enabled: W,
79
- canReadVendors: pe,
80
- isVendorFilterPaused: U,
81
- filterLabels: D.filters,
82
- onOpenBill: fe,
83
- duplicateRowNote: D.duplicateRowNote,
84
- attachmentLabel: D.attachmentIndicator
85
- }), q = ne({ enabled: W }), me = u(q, D), J = oe({ enabled: W }), he = h(() => a.map((e) => ({
86
- id: e,
87
- label: D.queues[e],
88
- badge: c(J[e])
89
- })), [D.queues, J]), ge = (e) => {
90
- V(!1), F(e), z(!0);
91
- }, _e = () => {
92
- L(!1), z(!0);
93
- }, ve = () => {
94
- z(!1), L(!0);
95
- }, Y = () => {
96
- L(!1), z(!1), k(P), j(void 0), N(!0);
97
- }, ye = h(() => ({
98
- createButton: D.createButton,
99
- settingsButton: D.settingsButton,
100
- addBill: { heading: D.nonEmptyHeading }
101
- }), [
102
- D.createButton,
103
- D.settingsButton,
104
- D.nonEmptyHeading
105
- ]), be = h(() => ({
106
- ...K.filterBarProps,
107
- labels: D.filterBar
108
- }), [K.filterBarProps, D.filterBar]), X = p((e) => {
109
- O(!1), k(void 0), j(e), N(!0);
110
- }, []), Z = (e) => {
111
- O(!1), b?.(e);
112
- }, Q = async () => {
113
- await l(v) ? e.success(D.emailCopiedToast) : e.error(D.emailCopyFailedToast);
114
- };
115
- m(() => {
116
- x && (k(x), j(void 0), N(!0), S?.());
117
- }, [S, x]);
118
- let { showVendorBills: $ } = K;
119
- return m(() => {
120
- C && (C.action === "createBill" ? G && X(C.vendorId) : $({
121
- id: C.vendorId,
122
- name: C.vendorName
123
- }), w?.());
19
+ var oe = 10, v = [{
20
+ id: "addedOnLabel",
21
+ desc: !0
22
+ }];
23
+ function y({ enabled: p = !0, canReadVendors: y = !0, isVendorFilterPaused: b = !1, filterLabels: x, onOpenBill: S, duplicateRowNote: C, attachmentLabel: w }) {
24
+ let [T, E] = _(c), [D, O] = _(v), [k, A] = _(oe), [j, M] = _(), [N, P] = _(""), [F, ce] = _(""), I = m(() => M(void 0), []);
25
+ h(() => {
26
+ if (N === F) return;
27
+ let e = setTimeout(() => {
28
+ ce(N), I();
29
+ }, 300);
30
+ return () => clearTimeout(e);
124
31
  }, [
125
- G,
32
+ N,
33
+ F,
34
+ I
35
+ ]);
36
+ let L = ie({
37
+ offersStatusFilter: T === s.All,
38
+ offersVendorFilter: y,
39
+ isVendorFilterPaused: b,
40
+ labels: x,
41
+ onFiltersChange: I
42
+ }), { filterByVendor: R } = L, z = D[0], B = re(z?.id), V = B ? z?.desc ? "desc" : "asc" : void 0, H = g(() => ({
43
+ ...L.query,
44
+ limit: k,
45
+ pagination_token: j,
46
+ status__in: f(T) ?? L.query.status__in,
47
+ has_scheduled_payment: u(T),
48
+ counterpart_name__icontains: F || void 0,
49
+ sort: B,
50
+ order: V
51
+ }), [
52
+ L.query,
53
+ k,
54
+ j,
55
+ T,
56
+ F,
57
+ B,
58
+ V
59
+ ]), { organizationId: U } = e(), W = JSON.stringify([U, H]), G = i({
60
+ ...H,
61
+ enabled: p,
62
+ pollWhileOcrProcessing: !0
63
+ }), [le, ue] = _(W);
64
+ h(() => {
65
+ G.isFetching || ue(W);
66
+ }, [G.isFetching, W]);
67
+ let K = G.data?.data.length, q = K === 0, J = a({ enabled: p && q }), Y = !q || (J.data?.count ?? 1) > 0, { vendorNames: X, lookup: Z } = ae({
68
+ payables: G.data?.data,
69
+ enabled: p,
70
+ canReadVendors: y,
71
+ isPaused: b
72
+ }), Q = g(() => (G.data?.data ?? []).filter((e) => e.ocr_status !== "processing").map((e) => {
73
+ let i = o({
74
+ apiStatus: e.status,
75
+ dueDate: e.due_date,
76
+ scheduledPaymentDate: e.scheduled_payment_date
77
+ }), a = e.amount_due ?? e.total_amount, c = e.status === "partially_paid" || e.status === "paid", l = (t) => t == null ? "" : n(t / 100, { currencyCode: e.currency ?? "USD" }), u = ee(e) || (e.counterpart_id ? X.get(e.counterpart_id) ?? "" : "");
78
+ return {
79
+ rowKey: e.id,
80
+ vendorLabel: u,
81
+ vendorLookup: u || !e.counterpart_id ? void 0 : se(Z),
82
+ issueDateLabel: t(e.issued_at),
83
+ dueDateLabel: t(e.due_date),
84
+ dueDateTone: i.isOverdue ? "danger" : "default",
85
+ scheduledDateLabel: t(e.scheduled_payment_date),
86
+ scheduledDateIsGap: T === s.Scheduled,
87
+ paidDateLabel: t(e.paid_at?.slice(0, 10)),
88
+ amountDueLabel: l(a),
89
+ amountPaidLabel: c ? l(e.amount_paid) : "",
90
+ amountPaidIsGap: T === s.Paid,
91
+ amountScheduledLabel: l(e.amount_to_pay ?? a),
92
+ totalAmountLabel: l(e.total_amount),
93
+ attachment: e.file_id ? { label: w } : void 0,
94
+ status: i.status,
95
+ statusTone: i.tone,
96
+ addedOnLabel: t(e.created_at?.slice(0, 10)),
97
+ ...r(e) ? {
98
+ rowTone: "warning",
99
+ rowNote: C
100
+ } : {},
101
+ onOpen: () => S(e.id, te(e.status))
102
+ };
103
+ }), [
104
+ G.data?.data,
105
+ C,
126
106
  w,
107
+ S,
108
+ T,
127
109
  X,
128
- $,
129
- C
130
- ]), /* @__PURE__ */ se("div", {
131
- "data-testid": d.root,
132
- children: [
133
- /* @__PURE__ */ _(re, {
134
- rows: K.rows,
135
- isLoading: K.isLoading || !H,
136
- isError: K.isError,
137
- onRetry: K.onRetry,
138
- sorting: K.sorting,
139
- onSortingChange: K.onSortingChange,
140
- pageSize: K.pageSize,
141
- onPageSizeChange: K.onPageSizeChange,
142
- hasNextPage: K.hasNextPage,
143
- hasPrevPage: K.hasPrevPage,
144
- onNextPage: K.onNextPage,
145
- onPrevPage: K.onPrevPage,
146
- filterTabs: he,
147
- selectedFilterTabId: K.selectedFilterTabId,
148
- onFilterTabChange: K.onFilterTabChange,
149
- searchValue: K.searchValue,
150
- onSearchChange: K.onSearchChange,
151
- filters: be,
152
- visibleColumns: K.visibleColumns,
153
- cellTestIds: f,
154
- isSearchActive: K.isSearchActive,
155
- showAddPanelWhenEmpty: K.showAddPanelWhenEmpty,
156
- emptyState: D.queueEmptyStates[K.selectedFilterTabId],
157
- onCreateClick: G ? () => O(!0) : void 0,
158
- onSettingsClick: E,
159
- onEnterManually: G ? () => X() : void 0,
160
- onFilesSelected: G ? Z : void 0,
161
- maxFiles: 10,
162
- emailAddress: v,
163
- onCopyEmail: Q,
164
- duplicateWarning: me,
165
- onReviewDuplicates: q.isError ? void 0 : () => V(!0),
166
- labels: ye
167
- }),
168
- B ? /* @__PURE__ */ _(ie, {
169
- open: B,
170
- onOpenChange: V,
171
- enabled: W,
172
- canManageDuplicates: G,
173
- onOpenBill: ge
174
- }) : null,
175
- G ? /* @__PURE__ */ _(r, {
176
- open: ce,
177
- onOpenChange: O,
178
- onFilesSelected: Z,
179
- maxFiles: 10,
180
- onEnterManually: () => X(),
181
- emailAddress: v,
182
- onCopyEmail: Q,
183
- labels: { heading: K.hasAnyBills ? D.nonEmptyHeading : D.emptyHeading }
184
- }) : null,
185
- M ? /* @__PURE__ */ _(i, {
186
- open: M,
187
- onOpenChange: N,
188
- payableId: le,
189
- initialCounterpartId: A
190
- }) : null,
191
- I ? /* @__PURE__ */ _(ae, {
192
- open: I,
193
- onOpenChange: L,
194
- payableId: P,
195
- onClose: () => L(!1),
196
- onExpand: _e,
197
- onEdit: Y,
198
- testId: d.detailsSheet,
199
- poweredByBankName: T
200
- }) : null,
201
- R ? /* @__PURE__ */ _(i, {
202
- open: R,
203
- onOpenChange: z,
204
- payableId: P,
205
- readOnly: !0,
206
- onCollapse: ve,
207
- onEdit: Y,
208
- poweredByBankName: T
209
- }) : null
210
- ]
211
- });
110
+ Z
111
+ ]), $ = m((e) => {
112
+ let t = e;
113
+ E(t), O((e) => {
114
+ let n = e[0]?.id;
115
+ return n ? l(t).some((e) => ne(e) === n) ? e : v : e;
116
+ }), I();
117
+ }, [I]), de = m((e) => {
118
+ $(s.All), P(""), R(e);
119
+ }, [R, $]), fe = m((e) => {
120
+ O((t) => typeof e == "function" ? e(t) : e), I();
121
+ }, [I]), pe = m((e) => {
122
+ A(e), I();
123
+ }, [I]), me = m(() => M(G.data?.next_pagination_token ?? void 0), [G.data?.next_pagination_token]), he = m(() => M(G.data?.prev_pagination_token ?? void 0), [G.data?.prev_pagination_token]), ge = m(() => {
124
+ G.refetch();
125
+ }, [G.refetch]);
126
+ return {
127
+ rows: Q,
128
+ isLoading: G.isLoading || W !== le || q && J.isLoading || (K ?? 0) > 0 && Q.length === 0,
129
+ isError: G.isError,
130
+ onRetry: ge,
131
+ selectedFilterTabId: T,
132
+ onFilterTabChange: $,
133
+ showVendorBills: de,
134
+ searchValue: N,
135
+ onSearchChange: P,
136
+ hasAnyBills: Y,
137
+ isSearchActive: F.length > 0 || L.isFilterActive,
138
+ filterBarProps: L.filterBarProps,
139
+ visibleColumns: l(T),
140
+ showAddPanelWhenEmpty: d(T),
141
+ sorting: D,
142
+ onSortingChange: fe,
143
+ pageSize: k,
144
+ onPageSizeChange: pe,
145
+ hasNextPage: !!G.data?.next_pagination_token,
146
+ hasPrevPage: !!G.data?.prev_pagination_token,
147
+ onNextPage: me,
148
+ onPrevPage: he
149
+ };
150
+ }
151
+ function se(e) {
152
+ return e === p.Settled ? void 0 : e;
212
153
  }
213
154
  //#endregion
214
- export { y as BillsTab, y as default };
155
+ export { y as useBillsTable };