@tesouro/embedded-components-react 0.5.224 → 0.5.226

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 (41) hide show
  1. package/README.md +335 -413
  2. package/dist/index.d.ts +23 -2
  3. package/dist/index.js +1 -1
  4. package/dist/lib/ReceivablesWidget.d.ts +23 -2
  5. package/dist/lib/ReceivablesWidget.js +1 -1
  6. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/data-access/dist/index.js +4 -4
  7. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/data-access/dist/index10.js +45 -31
  8. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index.js +1 -1
  9. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index12.js +51 -32
  10. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index13.js +20 -1
  11. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index15.js +17 -202
  12. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index16.js +220 -31
  13. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index17.js +32 -145
  14. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index18.js +126 -44
  15. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index19.js +145 -117
  16. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index20.js +46 -58
  17. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index21.js +113 -87
  18. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index22.js +58 -116
  19. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index23.js +98 -225
  20. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index24.js +111 -27
  21. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index25.js +225 -462
  22. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index26.js +34 -41
  23. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index27.js +627 -34
  24. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index28.js +39 -77
  25. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index29.js +34 -112
  26. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index30.js +75 -310
  27. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index31.js +124 -0
  28. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index32.js +324 -0
  29. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index6.js +20 -15
  30. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index8.js +56 -53
  31. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index9.js +33 -29
  32. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index25.js +184 -162
  33. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index4.js +1 -3
  34. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index6.js +78 -69
  35. package/dist/libs/tesouro-embedded-components-react/shared/counterpart-management/feature/dist/lib/CounterpartSelector.js +7 -6
  36. package/dist/libs/tesouro-embedded-components-react/shared/counterpart-management/ui/dist/index15.js +20 -19
  37. package/dist/libs/tesouro-embedded-components-react/shared/data-access/dist/index.js +39 -39
  38. package/dist/libs/tesouro-embedded-components-react/shared/data-access/dist/lib/rest/@tanstack/react-query.gen.js +210 -199
  39. package/dist/libs/tesouro-embedded-components-react/shared/data-access/dist/lib/rest/sdk.gen.js +60 -52
  40. package/dist/libs/tesouro-embedded-components-react/shared/feature/dist/lib/analytics/build-info.js +1 -1
  41. package/package.json +1 -1
@@ -1,231 +1,104 @@
1
- import { minorExponentForCurrency as e } from "../../../shared/util/dist/lib/amountOutputToMajorUnits.js";
2
- import "../../ui/dist/index10.js";
3
- import "../../ui/dist/index.js";
4
- import { isBlankLineItem as t, parseQuantity as n, priceInputToMinorUnits as r } from "./index6.js";
5
- import { formatTermDate as i, termDueDate as a } from "./index9.js";
6
- import { formatMoney as o } from "./index12.js";
7
- import { differenceInCalendarDays as s, isValid as c, parseISO as l } from "date-fns";
1
+ "use client";
2
+ "use client";
3
+ "use client";
4
+ "use client";
5
+ import { toast as e } from "../../../../../packages/shared-ui-shadcn/dist/index.js";
6
+ import { extractApiErrorMessage as t } from "../../../shared/util/dist/lib/apiErrors.js";
7
+ import "../../../shared/ui/dist/index.js";
8
+ import { useWidgetConfig as n } from "../../../shared/feature/dist/lib/WidgetProvider/hooks.js";
9
+ import "../../../shared/feature/dist/index.js";
10
+ import { useCreateEntityBankAccountMutation as r, usePaymentAccountsQuery as i } from "../../data-access/dist/index3.js";
11
+ import "../../data-access/dist/index.js";
12
+ import { EMPTY_BANK_ACCOUNT_FORM_VALUES as a, bankAccountFormToPayload as o, buildBankAccountSectionView as s, buildPaymentAccountOptions as c, getBankAccountPermissions as l, validateBankAccountForm as u } from "./index22.js";
13
+ import { useCallback as d, useEffect as f, useMemo as p, useRef as m, useState as h } from "react";
8
14
  //#region ../../libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index23.js
9
- var u = "US", d = 100;
10
- function f(e) {
11
- try {
12
- return new Intl.DisplayNames(void 0, { type: "region" }).of(e) ?? e;
13
- } catch {
14
- return e;
15
- }
16
- }
17
- function p({ address: e, issuerCountry: t, formatCountry: n = f }) {
18
- if (!e) return [];
19
- let r = [e.city, e.state].filter(Boolean).join(", "), i = e.country === u && t === u;
20
- return [
21
- [e.line1, e.line2].filter(Boolean).join(" "),
22
- [r, e.postal_code].filter(Boolean).join(" "),
23
- e.country && !i ? n(e.country) : ""
24
- ].filter(Boolean);
25
- }
26
- var m = { kind: "pending" }, h = (e) => ({
27
- kind: "text",
28
- lines: e
29
- });
30
- function g(e, t) {
31
- return e.previewNetDays.replace("{days}", String(t));
32
- }
33
- function _(e, t) {
34
- let n = e.previewEarlyPaymentDays.replace("{days}", String(t.number_of_days));
35
- return t.discount ? `${n}, ${e.previewEarlyPaymentDiscount.replace("{rate}", String(t.discount / d))}` : n;
36
- }
37
- function v({ paymentTermsId: e, paymentTermsCustomDate: t, paymentTerms: n, issueDate: r, messages: o }) {
38
- let c = {
39
- dueDate: m,
40
- paymentTerms: m
41
- };
42
- if (e === "custom") {
43
- if (!t) return c;
44
- let e = l(t), n = Math.max(0, s(e, r));
45
- return {
46
- dueDate: h([i(e)]),
47
- paymentTerms: h([g(o, n)])
48
- };
49
- }
50
- if (e === "receipt_due") return {
51
- dueDate: h([i(r)]),
52
- paymentTerms: h([o.previewDueOnReceipt])
53
- };
54
- let u = n?.find((t) => t.id === e);
55
- if (!u) return c;
56
- let d = a(u, r), f = [
57
- u.term_1 && _(o, u.term_1),
58
- u.term_2 && _(o, u.term_2),
59
- u.term_final && g(o, u.term_final.number_of_days)
60
- ].filter((e) => !!e);
61
- return {
62
- dueDate: d ? h([i(d)]) : m,
63
- paymentTerms: f.length > 0 ? h(f) : m
64
- };
65
- }
66
- function y(e, t) {
67
- return t ? e.previewTaxId.replace("{taxId}", t) : void 0;
68
- }
69
- function b(e) {
70
- return e.length > 0 ? e : void 0;
71
- }
72
- function x(e, t) {
73
- return e ? {
74
- name: e.type === "organization" ? e.organization.legal_name : void 0,
75
- addressLines: b(p({
76
- address: e.address,
77
- issuerCountry: e.address?.country
78
- })),
79
- taxIdLine: y(t, e.tax_id),
80
- email: e.email ?? void 0,
81
- phone: e.phone ?? void 0
82
- } : {};
83
- }
84
- function S(e) {
85
- let t = "organization" in e ? e.organization : e.individual;
86
- return {
87
- name: "organization" in e ? e.organization.legal_name : [e.individual.first_name, e.individual.last_name].filter(Boolean).join(" "),
88
- email: t.email,
89
- phone: t.phone
90
- };
91
- }
92
- function C({ counterpart: e, billingAddress: t, issuerCountry: n, messages: r }) {
93
- if (!e) return { kind: "pending" };
94
- let { name: i, email: a, phone: o } = S(e);
95
- return i ? {
96
- kind: "party",
97
- name: i,
98
- addressLines: b(p({
99
- address: t,
100
- issuerCountry: n
101
- })),
102
- taxIdLine: y(r, e.tax_id),
103
- email: a || void 0,
104
- phone: o || void 0
105
- } : { kind: "pending" };
106
- }
107
- function w({ lineItems: e, currency: i, unitNamesById: a, messages: s }) {
108
- return e.filter((e) => !t(e)).map((e) => {
109
- let t = r(e.price, i), c = n(e.quantity), l = a[e.measureUnitId] || e.measureUnitName;
110
- return {
111
- id: e.id,
112
- name: e.name,
113
- quantity: String(c),
114
- price: o({
115
- amount: t,
116
- currency: i,
117
- fallback: ""
118
- }),
119
- ...l ? { unit: l } : {},
120
- taxable: e.taxable ? s.previewTaxableYes : s.previewTaxableNo,
121
- amount: o({
122
- amount: Math.round(t * c),
123
- currency: i,
124
- fallback: ""
125
- })
126
- };
127
- });
128
- }
129
- function T(t, n) {
130
- return new Intl.NumberFormat(void 0, {
131
- style: "currency",
132
- currency: n,
133
- currencySign: "accounting"
134
- }).format(-t / 10 ** e(n));
135
- }
136
- function E({ totals: e, currency: t, taxRate: n, messages: r }) {
137
- let i = (e) => o({
138
- amount: e,
139
- currency: t,
140
- fallback: ""
141
- }), a = e.discountAmount > 0, s = e.taxableItemsSubtotal > 0, c = e.nonTaxableItemsSubtotal > 0, l = [{
142
- id: "subtotal",
143
- label: r.previewSubtotal,
144
- value: i(e.subtotal)
145
- }];
146
- return a && l.push({
147
- id: "discount",
148
- label: r.previewDiscount,
149
- value: T(e.discountAmount, t)
150
- }), c && (s || a) && l.push({
151
- id: "nonTaxableSubtotal",
152
- label: r.previewNonTaxableSubtotal,
153
- value: i(e.nonTaxableSubtotal),
154
- muted: !0
155
- }), s && (c || a) && l.push({
156
- id: "taxableSubtotal",
157
- label: r.previewTaxableSubtotal,
158
- value: i(e.taxableSubtotal),
159
- muted: !0
160
- }), l.push({
161
- id: "tax",
162
- label: n ? r.previewTaxWithRate.replace("{rate}", n) : r.previewTax,
163
- value: i(e.totalTaxes)
164
- }), {
165
- rows: l,
166
- total: {
167
- label: r.previewTotal,
168
- value: i(e.total)
15
+ function g({ open: g, bankAccountId: _, embeddedBankName: v, messages: y, onSelect: b }) {
16
+ let { initResponse: x } = n(), S = p(() => l(x?.scopes), [x?.scopes]), { paymentAccounts: C, isLoading: w, isIncomplete: T } = i({
17
+ enabled: g,
18
+ canReadEmbedded: S.canReadEmbedded,
19
+ canReadExternal: S.canReadExternal
20
+ }), E = r(), [D, O] = h(!1), [k, A] = h(a), [j, M] = h({}), N = m(!1), P = d(() => {
21
+ N.current = !1, O(!1), A(a), M({});
22
+ }, []);
23
+ f(() => {
24
+ if (!g || T || N.current || C.length !== 1) return;
25
+ let [e] = C;
26
+ N.current = !0, b({
27
+ bankAccountId: e.id,
28
+ bankAccountType: e.type
29
+ });
30
+ }, [
31
+ T,
32
+ b,
33
+ g,
34
+ C
35
+ ]);
36
+ let F = d((e) => {
37
+ let t = C.find((t) => t.id === e);
38
+ t && b({
39
+ bankAccountId: t.id,
40
+ bankAccountType: t.type
41
+ });
42
+ }, [b, C]), I = d(() => O(!0), []), L = d(() => {
43
+ O(!1), A(a), M({});
44
+ }, []), R = d((e) => A((t) => ({
45
+ ...t,
46
+ ...e
47
+ })), []), z = d(async () => {
48
+ let n = u(k, y);
49
+ if (M(n), !(Object.keys(n).length > 0)) try {
50
+ let t = await E.mutateAsync({ body: o(k) });
51
+ O(!1), A(a), b({
52
+ bankAccountId: t.id,
53
+ bankAccountType: "BANK_DETAILS"
54
+ }), e.success(y.bankAccountCreated.replace("{name}", t.display_name ?? ""));
55
+ } catch (n) {
56
+ e.error(t(n) ?? y.bankAccountCreateFailed);
169
57
  }
170
- };
171
- }
172
- function D({ bankDetails: e, canReceivePayments: t, messages: n }) {
173
- let r = e ? [
174
- [n.previewAccountHolderName, e.accountHolderName],
175
- [n.previewRoutingNumber, e.routingNumber],
176
- [n.previewAccountNumber, e.accountNumber]
177
- ].filter((e) => !!e[1]).map(([e, t]) => e.replace("{value}", t)) : [];
178
- if (t || r.length !== 0) return {
179
- showPayOnline: t,
180
- bankLines: r
181
- };
182
- }
183
- function O({ values: e, totals: t, entity: n, counterpart: r, billingAddress: a, paymentTerms: o, unitNamesById: s, bankDetails: u, canReceivePayments: d = !1, messages: f, today: p = /* @__PURE__ */ new Date() }) {
184
- let h = w({
185
- lineItems: e.lineItems,
186
- currency: e.currency,
187
- unitNamesById: s,
188
- messages: f
189
- }), g = n?.logo?.url, _ = l(e.issueDate), y = c(_) ? _ : p;
58
+ }, [
59
+ E,
60
+ k,
61
+ y,
62
+ b
63
+ ]), B = p(() => c({
64
+ accounts: C,
65
+ embeddedBankName: v,
66
+ messages: y
67
+ }), [
68
+ v,
69
+ y,
70
+ C
71
+ ]);
190
72
  return {
191
- issuer: x(n, f),
192
- logo: g ? {
193
- kind: "image",
194
- src: g
195
- } : { kind: "placeholder" },
196
- billTo: C({
197
- counterpart: r,
198
- billingAddress: a,
199
- issuerCountry: n?.address?.country,
200
- messages: f
201
- }),
202
- invoiceNumber: m,
203
- issueDate: i(y),
204
- ...v({
205
- paymentTermsId: e.paymentTermsId,
206
- paymentTermsCustomDate: e.paymentTermsCustomDate,
207
- paymentTerms: o,
208
- issueDate: y,
209
- messages: f
210
- }),
211
- openingNote: e.openingNote || void 0,
212
- lineItems: h.length > 0 ? {
213
- kind: "rows",
214
- rows: h
215
- } : { kind: "empty" },
216
- totals: h.length > 0 ? E({
217
- totals: t,
218
- currency: e.currency,
219
- taxRate: e.taxRate,
220
- messages: f
221
- }) : void 0,
222
- closingNote: e.closingNote || void 0,
223
- payment: D({
224
- bankDetails: u,
225
- canReceivePayments: d,
226
- messages: f
227
- })
73
+ view: p(() => s({
74
+ options: B,
75
+ isLoading: w,
76
+ selectedId: _,
77
+ isAddingAccount: D,
78
+ canAddAccount: S.canAddAccount,
79
+ formValues: k,
80
+ formErrors: j,
81
+ isSaving: E.isPending
82
+ }), [
83
+ _,
84
+ E.isPending,
85
+ j,
86
+ k,
87
+ D,
88
+ w,
89
+ B,
90
+ S.canAddAccount
91
+ ]),
92
+ isLoading: w,
93
+ hasAccounts: C.length > 0,
94
+ canAddAccount: S.canAddAccount,
95
+ reset: P,
96
+ selectAccount: F,
97
+ openAddAccount: I,
98
+ cancelAddAccount: L,
99
+ updateAccountForm: R,
100
+ saveAccount: z
228
101
  };
229
102
  }
230
103
  //#endregion
231
- export { p as buildPreviewAddressLines, v as buildPreviewPaymentTerms, O as buildReceivablePreviewView, f as formatCountryName };
104
+ export { g as useReceivableBankAccount };
@@ -2,36 +2,120 @@
2
2
  "use client";
3
3
  "use client";
4
4
  "use client";
5
- import { useMyEntityQuery as e } from "../../../shared/data-access/dist/lib/useMyEntityQuery.js";
6
- import { usePaymentTermsQuery as t } from "../../../shared/data-access/dist/lib/reference-data/usePaymentTermsQuery.js";
7
- import "../../../shared/data-access/dist/index.js";
8
- import { useCounterpartQuery as n } from "../../../shared/counterpart-management/data-access/dist/index3.js";
9
- import "../../../shared/counterpart-management/feature/dist/index.js";
5
+ import { toast as e } from "../../../../../packages/shared-ui-shadcn/dist/index.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 "../../../shared/ui/dist/index.js";
9
+ import { useWidgetConfig as r } from "../../../shared/feature/dist/lib/WidgetProvider/hooks.js";
10
+ import "../../../shared/feature/dist/index.js";
11
+ import { areOverdueTermsValid as i, buildOverdueReminderPayload as a, buildPaymentReminderPayload as o, buildRemindersView as s, canCreateReminders as c, getImpliedDueDate as l, isBeforeDueDaysValid as u, sanitizeReminderDays as d } from "./index14.js";
12
+ import { useCreateOverdueReminderMutation as f, useCreatePaymentReminderMutation as p, useOverdueRemindersQuery as m, usePaymentRemindersQuery as h } from "../../data-access/dist/index11.js";
10
13
  import "../../data-access/dist/index.js";
11
- import { buildReceivablePreviewView as r } from "./index23.js";
12
- import { useMemo as i } from "react";
14
+ import { useCallback as g, useMemo as _, useState as v } from "react";
13
15
  //#region ../../libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index24.js
14
- function a({ values: a, totals: o, billingAddress: s, unitNamesById: c, messages: l, enabled: u = !0 }) {
15
- let d = e({ enabled: u }), f = n(u && a.customerId || void 0), p = t({ enabled: u }), m = d.data, h = f.data, g = p.data?.data;
16
- return i(() => r({
17
- values: a,
18
- totals: o,
19
- entity: m,
20
- counterpart: h,
21
- billingAddress: s,
22
- paymentTerms: g,
23
- unitNamesById: c,
24
- messages: l
16
+ var y = [""];
17
+ function b({ open: b, isInvoice: x, disabled: S, paymentTermsId: C, paymentTermsCustomDate: w, paymentReminderId: T, overdueReminderId: E, messages: D, onSelect: O }) {
18
+ let { initResponse: k } = r(), A = n().data?.data, j = _(() => c(k?.scopes), [k?.scopes]), [M, N] = v(!1), [P, F] = v(""), [I, L] = v(y), R = b && x && M, z = h({ enabled: R }), B = m({ enabled: R }), V = p(), H = f(), U = g((e) => {
19
+ N(e), F(""), L(y);
20
+ }, []), W = g((e) => {
21
+ e || (O({
22
+ paymentReminderId: "",
23
+ overdueReminderId: ""
24
+ }), F(""), L(y)), N(e);
25
+ }, [O]), G = g((e) => O({ paymentReminderId: e }), [O]), K = g((e) => O({ overdueReminderId: e }), [O]), q = g((e) => F(d(e)), []), J = g((e, t) => {
26
+ let n = d(t);
27
+ L((t) => t.map((t, r) => r === e ? n : t));
28
+ }, []), Y = g(() => {
29
+ L((e) => e.length < 3 ? [...e, ""] : e);
30
+ }, []), X = g(() => L(y), []), Z = g(() => l({
31
+ paymentTermsId: C,
32
+ paymentTermsCustomDate: w,
33
+ paymentTerms: A,
34
+ today: /* @__PURE__ */ new Date()
25
35
  }), [
26
- s,
27
- h,
28
- m,
29
- l,
30
- g,
31
- o,
32
- c,
33
- a
36
+ A,
37
+ w,
38
+ C
39
+ ]), Q = g(async () => {
40
+ if (u(P)) try {
41
+ let t = await V.mutateAsync({ body: o({
42
+ daysBefore: Number(P),
43
+ dueDate: Z(),
44
+ messages: D
45
+ }) });
46
+ F(""), O({ paymentReminderId: t.id }), e.success(D.reminderAdded);
47
+ } catch (n) {
48
+ e.error(t(n) ?? D.genericError);
49
+ }
50
+ }, [
51
+ P,
52
+ V,
53
+ Z,
54
+ D,
55
+ O
56
+ ]), $ = g(async () => {
57
+ if (i(I)) try {
58
+ let t = await H.mutateAsync({ body: a({
59
+ terms: I,
60
+ dueDate: Z(),
61
+ messages: D
62
+ }) });
63
+ L(y), O({ overdueReminderId: t.id }), e.success(D.reminderAdded);
64
+ } catch (n) {
65
+ e.error(t(n) ?? D.genericError);
66
+ }
67
+ }, [
68
+ H,
69
+ Z,
70
+ D,
71
+ O,
72
+ I
34
73
  ]);
74
+ return {
75
+ view: _(() => x ? s({
76
+ showReminders: M,
77
+ paymentTermsId: C,
78
+ paymentTermsCustomDate: w,
79
+ paymentReminderId: T,
80
+ overdueReminderId: E,
81
+ paymentReminders: z.data?.data,
82
+ overdueReminders: B.data?.data,
83
+ canCreate: j,
84
+ disabled: S,
85
+ beforeDueInput: P,
86
+ overdueTerms: I,
87
+ isCreatingPaymentReminder: V.isPending,
88
+ isCreatingOverdueReminder: H.isPending,
89
+ today: /* @__PURE__ */ new Date(),
90
+ messages: D
91
+ }) : void 0, [
92
+ P,
93
+ j,
94
+ H.isPending,
95
+ V.isPending,
96
+ S,
97
+ x,
98
+ D,
99
+ E,
100
+ B.data?.data,
101
+ I,
102
+ T,
103
+ z.data?.data,
104
+ w,
105
+ C,
106
+ M
107
+ ]),
108
+ reset: U,
109
+ toggle: W,
110
+ selectPaymentReminder: G,
111
+ selectOverdueReminder: K,
112
+ changeBeforeDueInput: q,
113
+ saveBeforeDue: Q,
114
+ changeOverdueTerm: J,
115
+ addOverdueTerm: Y,
116
+ clearOverdueTerms: X,
117
+ saveOverdue: $
118
+ };
35
119
  }
36
120
  //#endregion
37
- export { a as useReceivablePreview };
121
+ export { b as useReceivableReminders };