@tesouro/embedded-components-react 0.3.11 → 0.3.13

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 (81) hide show
  1. package/dist/index.d.ts +12 -0
  2. package/dist/index.js +1 -1
  3. package/dist/lib/BillPayWidget.js +1 -1
  4. package/dist/lib/CardsWidget.d.ts +12 -0
  5. package/dist/lib/CreateCardWidget.d.ts +12 -0
  6. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index.js +8 -8
  7. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index14.js +13 -14
  8. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index15.js +7 -46
  9. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index16.js +54 -16
  10. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index17.js +24 -52
  11. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index18.js +61 -113
  12. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index19.js +123 -13
  13. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index20.js +11 -31
  14. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index21.js +40 -50
  15. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index22.js +51 -5
  16. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index23.js +5 -72
  17. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index24.js +71 -48
  18. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index25.js +48 -79
  19. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index26.js +91 -33
  20. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index27.js +33 -137
  21. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index28.js +138 -67
  22. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index29.js +63 -200
  23. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index30.js +194 -184
  24. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index31.js +180 -50
  25. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index32.js +64 -12
  26. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index33.js +12 -46
  27. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index34.js +46 -30
  28. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index35.js +26 -158
  29. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index36.js +159 -31
  30. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index37.js +32 -98
  31. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index38.js +102 -13
  32. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index39.js +13 -241
  33. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index40.js +244 -4
  34. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index41.js +4 -29
  35. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index42.js +28 -81
  36. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index43.js +77 -130
  37. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index44.js +145 -3
  38. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index45.js +3 -4
  39. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index46.js +2 -43
  40. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index47.js +45 -1
  41. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index48.js +1 -8
  42. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index49.js +6 -9
  43. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index50.js +9 -92
  44. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index51.js +94 -3
  45. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index52.js +3 -9
  46. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index53.js +7 -20
  47. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index54.js +14 -51
  48. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index55.js +59 -3
  49. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index56.js +3 -110
  50. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index57.js +107 -8
  51. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index58.js +8 -40
  52. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index59.js +38 -15
  53. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index60.js +18 -98
  54. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index61.js +92 -173
  55. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index62.js +180 -4
  56. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index63.js +5 -8
  57. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index64.js +6 -112
  58. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index65.js +114 -1
  59. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index66.js +0 -24
  60. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index67.js +25 -0
  61. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index16.js +56 -18
  62. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index46.js +4 -1
  63. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index47.js +75 -46
  64. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index52.js +3 -2
  65. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index53.js +120 -115
  66. package/dist/libs/tesouro-embedded-components-react/cards-widget/feature/dist/index5.js +1 -2
  67. package/dist/libs/tesouro-embedded-components-react/create-card-widget/data-access/dist/index.js +3 -2
  68. package/dist/libs/tesouro-embedded-components-react/create-card-widget/data-access/dist/index5.js +19 -12
  69. package/dist/libs/tesouro-embedded-components-react/create-card-widget/data-access/dist/index6.js +22 -0
  70. package/dist/libs/tesouro-embedded-components-react/create-card-widget/feature/dist/index4.js +4 -1
  71. package/dist/libs/tesouro-embedded-components-react/create-card-widget/feature/dist/index5.js +0 -1
  72. package/dist/libs/tesouro-embedded-components-react/create-card-widget/feature/dist/index6.js +22 -37
  73. package/dist/libs/tesouro-embedded-components-react/create-card-widget/feature/dist/index7.js +167 -110
  74. package/dist/libs/tesouro-embedded-components-react/shared/data-access/dist/index.js +18 -18
  75. package/dist/libs/tesouro-embedded-components-react/shared/data-access/dist/lib/rest/@tanstack/react-query.gen.js +111 -104
  76. package/dist/libs/tesouro-embedded-components-react/shared/data-access/dist/lib/rest/sdk.gen.js +144 -128
  77. package/dist/libs/tesouro-embedded-components-react/shared/data-access/dist/lib/user/useAllOrganizationUsersQuery.js +20 -18
  78. package/dist/libs/tesouro-embedded-components-react/shared/feature/dist/lib/analytics/build-info.js +1 -1
  79. package/dist/libs/tesouro-embedded-components-react/widget-suite/feature/dist/index7.js +1 -1
  80. package/dist/packages/shared-ui-shadcn/dist/index.js +1998 -1935
  81. package/package.json +1 -1
@@ -2,67 +2,197 @@
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 "../../../shared/ui/dist/index.js";
7
- import { useUpdatePayableMutation as t } from "../../data-access/dist/index10.js";
5
+ import { maskAccountNumber as e } from "./index5.js";
6
+ import { usePayableSuggestionsQuery as t } from "../../data-access/dist/index14.js";
8
7
  import "../../data-access/dist/index.js";
9
- import { counterpartFormBankAccountToCreatePayload as n, validateAchFormValues as r } from "../../../shared/counterpart-management/feature/dist/lib/helpers.js";
10
- import { useCreateCounterpartBankAccountMutation as i } from "../../../shared/counterpart-management/data-access/dist/index5.js";
8
+ import { VENDOR_SECTION_PROPS_LABELS_EN as n } from "./index28.js";
9
+ import { counterpartFormBankAccountToCreatePayload as ee, counterpartFormBankAccountToUpdatePayload as r, getAchInstructions as i, getCounterpartEmail as a, getCounterpartName as o, getPayableAchInstructions as s, hasAchFormValues as c, resolveCounterpartBankAccountWrite as te, validateAchFormValues as ne } from "../../../shared/counterpart-management/feature/dist/lib/helpers.js";
10
+ import { useCounterpartsQuery as re } from "../../../shared/counterpart-management/data-access/dist/index3.js";
11
+ import { useCreateCounterpartBankAccountMutation as ie, useUpdateCounterpartBankAccountMutation as l } from "../../../shared/counterpart-management/data-access/dist/index5.js";
12
+ import { useCounterpartDetails as ae } from "../../../shared/counterpart-management/feature/dist/lib/useCounterpartDetails.js";
11
13
  import "../../../shared/counterpart-management/feature/dist/index.js";
12
- import { useCallback as a, useRef as o, useState as s } from "react";
14
+ import { VendorInlineForm as oe } from "./index30.js";
15
+ import { useCallback as u, useEffect as d, useMemo as f, useRef as p, useState as m } from "react";
16
+ import { jsx as h } from "react/jsx-runtime";
13
17
  //#region ../../libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index31.js
14
- var c = {
18
+ var se = 10, ce = 300, g = {
15
19
  accountHolderName: "",
16
20
  routingNumber: "",
17
21
  accountNumber: ""
18
22
  };
19
- function l({ payableId: l, counterpartId: u, saveErrorMessage: d }) {
20
- let [f, p] = s(!1), [m, h] = s(c), [g, _] = s(), v = i(), y = t(), b = o(void 0), x = a(() => {
21
- h(c), _(void 0), b.current = void 0, p(!0);
22
- }, []), S = a(() => {
23
- p(!1);
24
- }, []), C = a((e) => {
25
- h((t) => ({
26
- ...t,
27
- ...e
28
- }));
29
- }, []), w = a(async () => {
30
- if (!l || !u) return !1;
31
- let t = r(m);
32
- if (Object.keys(t).length > 0) return _(t), !1;
33
- try {
34
- if (!b.current) {
35
- let e = await v.mutateAsync({
36
- path: { counterpart_id: u },
37
- body: n(m)
38
- });
39
- b.current = e.id;
40
- }
41
- return await y.mutateAsync({
42
- path: { payable_id: l },
43
- body: { counterpart_bank_account_id: b.current }
44
- }), b.current = void 0, p(!1), !0;
45
- } catch {
46
- return e.error(d), !1;
47
- }
23
+ function _({ payableId: _, counterpartId: v, payableCounterpartId: y, onCounterpartChange: b, requiredError: x, labels: S }) {
24
+ let C = {
25
+ ...n,
26
+ ...S
27
+ }, [w, T] = m(""), [E, D] = m(""), [O, k] = m(), [le, A] = m(!1), [j, M] = m(g), N = p(j);
28
+ N.current = j;
29
+ let [ue, P] = m(!1), F = c(j) || ue, [I, L] = m(), [R, z] = m(), B = p(v), [V, H] = m(!1), U = u(() => {
30
+ A(!1), M(g), L(void 0), z(void 0);
31
+ }, []), W = u((e) => {
32
+ H(!0), b(e);
33
+ }, [b]), G = t(_, { enabled: !!_ && !v && !y }).data?.suggested_counterpart?.id;
34
+ d(() => {
35
+ !V && !v && !y && G && W(G);
48
36
  }, [
49
- u,
50
37
  v,
51
- l,
52
- d,
53
38
  y,
54
- m
55
- ]);
39
+ V,
40
+ G,
41
+ W
42
+ ]), d(() => {
43
+ B.current !== v && (B.current = v, U());
44
+ }, [v, U]), d(() => {
45
+ let e = setTimeout(() => {
46
+ D(w.trim());
47
+ }, ce);
48
+ return () => clearTimeout(e);
49
+ }, [w]);
50
+ let K = re({
51
+ sort: "counterpart_name",
52
+ order: "asc",
53
+ limit: se,
54
+ counterpart_name__icontains: E || void 0,
55
+ is_vendor: !0,
56
+ enabled: !!E
57
+ }), q = ae({ selectedId: v }), J = ie(), Y = l(), X = f(() => {
58
+ let t = q.counterpart;
59
+ if (!t) return;
60
+ if (q.isBankAccountsLoading) return {
61
+ name: o(t),
62
+ email: a(t),
63
+ methodLabel: C.paymentMethodLoading,
64
+ fields: []
65
+ };
66
+ if (q.isBankAccountsError) return {
67
+ name: o(t),
68
+ email: a(t),
69
+ methodLabel: C.paymentMethodUnavailable,
70
+ fields: []
71
+ };
72
+ let n = s(q.bankAccounts);
73
+ return {
74
+ name: o(t),
75
+ email: a(t),
76
+ methodLabel: n ? C.achMethod : C.noMethod,
77
+ fields: n ? [
78
+ {
79
+ label: C.accountHolder,
80
+ value: n.account_holder_name ?? ""
81
+ },
82
+ {
83
+ label: C.routingNumber,
84
+ value: n.routing_number ?? ""
85
+ },
86
+ {
87
+ label: C.accountNumber,
88
+ value: n.account_number ?? "",
89
+ maskedValue: n.account_number ? e(n.account_number) : ""
90
+ }
91
+ ] : []
92
+ };
93
+ }, [
94
+ q.bankAccounts,
95
+ q.counterpart,
96
+ q.isBankAccountsError,
97
+ q.isBankAccountsLoading,
98
+ C
99
+ ]), Z = f(() => i(q.bankAccounts), [q.bankAccounts]), Q = u(async () => {
100
+ let e = N.current;
101
+ if (!v || !c(e)) return !0;
102
+ if (q.isBankAccountsLoading || q.isBankAccountsError) return !1;
103
+ let t = ne(e);
104
+ if (Object.keys(t).length > 0) return L(t), A(!0), !1;
105
+ L(void 0);
106
+ let n = te(q.bankAccounts, R ?? Z?.id);
107
+ if (n.kind === "update") return await Y.mutateAsync({
108
+ path: {
109
+ counterpart_id: v,
110
+ bank_account_id: n.bankAccountId
111
+ },
112
+ body: r(e, { includeAchDefaults: n.includeAchDefaults })
113
+ }), z(n.bankAccountId), !0;
114
+ let i = await J.mutateAsync({
115
+ path: { counterpart_id: v },
116
+ body: ee(e)
117
+ });
118
+ return z(i?.id), !0;
119
+ }, [
120
+ Z,
121
+ v,
122
+ J,
123
+ q.bankAccounts,
124
+ q.isBankAccountsError,
125
+ q.isBankAccountsLoading,
126
+ R,
127
+ Y
128
+ ]), de = f(() => (K.data?.data ?? []).map((e) => ({
129
+ name: o(e),
130
+ email: a(e),
131
+ onSelect: () => W(e.id)
132
+ })), [K.data, W]), $ = u(() => {
133
+ k(void 0), P(!1);
134
+ }, []), fe = u((e) => {
135
+ k(void 0), P(!1), W(e);
136
+ }, [W]);
137
+ if (O) return {
138
+ mode: "creating",
139
+ newVendorForm: /* @__PURE__ */ h(oe, {
140
+ mode: O,
141
+ counterpart: O === "edit" ? q.counterpart : void 0,
142
+ primaryAddress: O === "edit" ? q.primaryAddress : void 0,
143
+ bankAccounts: O === "edit" ? q.bankAccounts : void 0,
144
+ isBankAccountsLoading: O === "edit" ? q.isBankAccountsLoading : void 0,
145
+ isBankAccountsError: O === "edit" ? q.isBankAccountsError : void 0,
146
+ initialName: O === "create" ? w : void 0,
147
+ onSaved: fe,
148
+ onCancel: $,
149
+ onDirtyChange: P
150
+ }),
151
+ onClear: $,
152
+ hasUnsavedVendorChanges: F
153
+ };
154
+ if (X) {
155
+ let e = q.isBankAccountsLoading || q.isBankAccountsError;
156
+ return {
157
+ mode: "resolved",
158
+ summary: X,
159
+ onEdit: e ? void 0 : () => k("edit"),
160
+ onClear: () => W(void 0),
161
+ paymentInstructions: e ? void 0 : {
162
+ isOpen: le,
163
+ values: j,
164
+ errors: I,
165
+ onOpen: () => {
166
+ A(!0), Z && (M({
167
+ accountHolderName: Z.account_holder_name ?? "",
168
+ routingNumber: Z.routing_number ?? "",
169
+ accountNumber: Z.account_number ?? ""
170
+ }), z(Z.id));
171
+ },
172
+ onChange: (e) => {
173
+ M((t) => ({
174
+ ...t,
175
+ ...e
176
+ })), L(void 0);
177
+ }
178
+ },
179
+ savePaymentInstructions: Q,
180
+ hasUnsavedVendorChanges: F
181
+ };
182
+ }
56
183
  return {
57
- isOpen: f,
58
- values: m,
59
- errors: g,
60
- isSaving: v.isPending || y.isPending,
61
- open: x,
62
- close: S,
63
- onChange: C,
64
- save: w
184
+ mode: "selecting",
185
+ error: K.isError ? C.searchFailed : q.isError ? C.vendorDetailsFailed : x,
186
+ search: {
187
+ query: w,
188
+ onQueryChange: T,
189
+ isLoading: K.isLoading,
190
+ onAddVendor: () => k("create"),
191
+ results: de
192
+ },
193
+ savePaymentInstructions: Q,
194
+ hasUnsavedVendorChanges: F
65
195
  };
66
196
  }
67
197
  //#endregion
68
- export { l as usePaymentInstructionsForm };
198
+ export { _ as useVendorSectionProps };
@@ -1,16 +1,68 @@
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 "../../../shared/ui/dist/index.js";
7
+ import { useUpdatePayableMutation as t } from "../../data-access/dist/index10.js";
8
+ import "../../data-access/dist/index.js";
9
+ import { counterpartFormBankAccountToCreatePayload as n, validateAchFormValues as r } from "../../../shared/counterpart-management/feature/dist/lib/helpers.js";
10
+ import { useCreateCounterpartBankAccountMutation as i } from "../../../shared/counterpart-management/data-access/dist/index5.js";
11
+ import "../../../shared/counterpart-management/feature/dist/index.js";
12
+ import { useCallback as a, useRef as o, useState as s } from "react";
1
13
  //#region ../../libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index32.js
2
- function e(e) {
3
- return new Promise((t, n) => {
4
- let r = new FileReader();
5
- r.onerror = () => n(r.error ?? /* @__PURE__ */ Error("Failed to read file")), r.onload = () => {
6
- let e = r.result;
7
- if (typeof e != "string") {
8
- n(/* @__PURE__ */ Error("Failed to read file as a data URL"));
9
- return;
14
+ var c = {
15
+ accountHolderName: "",
16
+ routingNumber: "",
17
+ accountNumber: ""
18
+ };
19
+ function l({ payableId: l, counterpartId: u, saveErrorMessage: d }) {
20
+ let [f, p] = s(!1), [m, h] = s(c), [g, _] = s(), v = i(), y = t(), b = o(void 0), x = a(() => {
21
+ h(c), _(void 0), b.current = void 0, p(!0);
22
+ }, []), S = a(() => {
23
+ p(!1);
24
+ }, []), C = a((e) => {
25
+ h((t) => ({
26
+ ...t,
27
+ ...e
28
+ }));
29
+ }, []), w = a(async () => {
30
+ if (!l || !u) return !1;
31
+ let t = r(m);
32
+ if (Object.keys(t).length > 0) return _(t), !1;
33
+ try {
34
+ if (!b.current) {
35
+ let e = await v.mutateAsync({
36
+ path: { counterpart_id: u },
37
+ body: n(m)
38
+ });
39
+ b.current = e.id;
10
40
  }
11
- t(e.slice(e.indexOf(",") + 1));
12
- }, r.readAsDataURL(e);
13
- });
41
+ return await y.mutateAsync({
42
+ path: { payable_id: l },
43
+ body: { counterpart_bank_account_id: b.current }
44
+ }), b.current = void 0, p(!1), !0;
45
+ } catch {
46
+ return e.error(d), !1;
47
+ }
48
+ }, [
49
+ u,
50
+ v,
51
+ l,
52
+ d,
53
+ y,
54
+ m
55
+ ]);
56
+ return {
57
+ isOpen: f,
58
+ values: m,
59
+ errors: g,
60
+ isSaving: v.isPending || y.isPending,
61
+ open: x,
62
+ close: S,
63
+ onChange: C,
64
+ save: w
65
+ };
14
66
  }
15
67
  //#endregion
16
- export { e as encodeFileToBase64 };
68
+ export { l as usePaymentInstructionsForm };
@@ -1,50 +1,16 @@
1
- import { parseDecimalAmountToMinorUnits as e } from "../../../shared/util/dist/lib/parseDecimalAmountToMinorUnits.js";
2
- import "../../data-access/dist/index.js";
3
1
  //#region ../../libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index33.js
4
- var t = "USD";
5
- function n(n) {
6
- return e(n, t);
7
- }
8
- function r(e) {
9
- let t = e.trim();
10
- if (!t) return null;
11
- let n = Number(t);
12
- return Number.isFinite(n) && n > 0 ? n : null;
13
- }
14
- function i(e) {
15
- return !!(e.description.trim() || e.glCode.trim() || n(e.price) !== null || n(e.amount) !== null);
16
- }
17
- function a(e) {
18
- return n(e) ?? 0;
19
- }
20
- function o(e) {
21
- let t = Number.parseFloat(e);
22
- return Number.isFinite(t) ? t : 0;
23
- }
24
- function s(e) {
25
- return (e / 100).toFixed(2);
26
- }
27
- function c({ values: e, counterpartId: r, clearCounterpart: i, editedTotals: a, document: o }) {
28
- let s = { currency: t };
29
- return r ? s.counterpart_id = r : i && (s.counterpart_id = null), e.invoiceNumber && (s.document_id = e.invoiceNumber), e.invoiceDate && (s.issued_at = e.invoiceDate), e.dueDate && (s.due_date = e.dueDate), o && (s.base64_encoded_file = o.base64EncodedFile, s.file_name = o.fileName), a && (s.discount = n(a.discount) ?? 0, s.tax_amount = n(a.tax) ?? 0, a.total !== void 0 && (s.total_amount = n(a.total) ?? 0)), s;
30
- }
31
- function l(e) {
32
- return e.filter(i).map((e) => {
33
- let t = n(e.amount), i = r(e.quantity) ?? 1, a = n(e.price) ?? (t === null ? 0 : Math.round(t / i)), o = Math.round(i * a);
34
- return {
35
- name: e.description,
36
- quantity: i,
37
- unit_price: a,
38
- ...t !== null && t !== o ? { subtotal: t } : {},
39
- ...e.glCode ? { ledger_account_id: e.glCode } : {}
40
- };
2
+ function e(e) {
3
+ return new Promise((t, n) => {
4
+ let r = new FileReader();
5
+ r.onerror = () => n(r.error ?? /* @__PURE__ */ Error("Failed to read file")), r.onload = () => {
6
+ let e = r.result;
7
+ if (typeof e != "string") {
8
+ n(/* @__PURE__ */ Error("Failed to read file as a data URL"));
9
+ return;
10
+ }
11
+ t(e.slice(e.indexOf(",") + 1));
12
+ }, r.readAsDataURL(e);
41
13
  });
42
14
  }
43
- function u(e, t) {
44
- return s(Math.round(o(e) * a(t)));
45
- }
46
- function d(e, t, n) {
47
- return s(e.reduce((e, t) => e + a(t.amount), 0) + a(t) - a(n));
48
- }
49
15
  //#endregion
50
- export { d as calculateTotal, u as displayLineAmount, i as isPersistableLineItem, c as mapBillFormToPayload, l as mapLineItemsToPayload, n as parseMoneyToMinorUnits, r as parseQuantity };
16
+ export { e as encodeFileToBase64 };
@@ -1,34 +1,50 @@
1
- import { BILL_CREATE_MESSAGE_LABELS_EN as e } from "./index27.js";
2
- import { isPersistableLineItem as t, parseMoneyToMinorUnits as n, parseQuantity as r } from "./index33.js";
1
+ import { parseDecimalAmountToMinorUnits as e } from "../../../shared/util/dist/lib/parseDecimalAmountToMinorUnits.js";
2
+ import "../../data-access/dist/index.js";
3
3
  //#region ../../libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index34.js
4
- var i = /^(?:\d{1,3}(?:,\d{3})+(?:\.\d+)?|\d+(?:\.\d+)?|\.\d+)$/;
5
- function a(e) {
4
+ var t = "USD";
5
+ function n(n) {
6
+ return e(n, t);
7
+ }
8
+ function r(e) {
6
9
  let t = e.trim();
7
- return !t || n(t) !== null ? !0 : i.test(t) ? Number(t.replaceAll(",", "")) === 0 : !1;
8
- }
9
- function o(t, i = e) {
10
- let a = {};
11
- for (let e of t) {
12
- let t = n(e.price), o = n(e.amount), s = {};
13
- e.price.trim() && t === null && (s.price = i.unreadableMoney), e.amount.trim() && o === null && (s.amount = i.unreadableMoney), (t !== null || o !== null) && r(e.quantity) === null && (s.quantity = i.unusableQuantity), Object.keys(s).length && (a[e.id] = s);
14
- }
15
- return Object.keys(a).length ? a : void 0;
16
- }
17
- function s(i, a, o, s = e) {
18
- let c = {};
19
- a || (c.vendor = s.requiredField), i.invoiceNumber.trim() || (c.invoiceNumber = s.requiredField), i.invoiceDate.trim() || (c.invoiceDate = s.requiredField), i.dueDate.trim() || (c.dueDate = s.requiredField);
20
- let l = {};
21
- return o.forEach((e, i) => {
22
- if (i > 0 && !t(e)) return;
23
- let a = {};
24
- e.description.trim() || (a.description = s.requiredField), r(e.quantity) === null && (a.quantity = s.requiredField), n(e.price) === null && n(e.amount) === null && (a.price = s.requiredField, a.amount = s.requiredField), Object.keys(a).length && (l[e.id] = a);
25
- }), {
26
- formErrors: Object.keys(c).length ? c : void 0,
27
- lineItemErrors: Object.keys(l).length ? l : void 0
28
- };
29
- }
30
- function c(t, r, i, o = e) {
31
- return !a(t) || !a(r) || i !== void 0 && n(i) === null ? { form: o.totalsNeedAttention } : void 0;
10
+ if (!t) return null;
11
+ let n = Number(t);
12
+ return Number.isFinite(n) && n > 0 ? n : null;
13
+ }
14
+ function i(e) {
15
+ return !!(e.description.trim() || e.glCode.trim() || n(e.price) !== null || n(e.amount) !== null);
16
+ }
17
+ function a(e) {
18
+ return n(e) ?? 0;
19
+ }
20
+ function o(e) {
21
+ let t = Number.parseFloat(e);
22
+ return Number.isFinite(t) ? t : 0;
23
+ }
24
+ function s(e) {
25
+ return (e / 100).toFixed(2);
26
+ }
27
+ function c({ values: e, counterpartId: r, clearCounterpart: i, editedTotals: a, document: o }) {
28
+ let s = { currency: t };
29
+ return r ? s.counterpart_id = r : i && (s.counterpart_id = null), e.invoiceNumber && (s.document_id = e.invoiceNumber), e.invoiceDate && (s.issued_at = e.invoiceDate), e.dueDate && (s.due_date = e.dueDate), o && (s.base64_encoded_file = o.base64EncodedFile, s.file_name = o.fileName), a && (s.discount = n(a.discount) ?? 0, s.tax_amount = n(a.tax) ?? 0, a.total !== void 0 && (s.total_amount = n(a.total) ?? 0)), s;
30
+ }
31
+ function l(e) {
32
+ return e.filter(i).map((e) => {
33
+ let t = n(e.amount), i = r(e.quantity) ?? 1, a = n(e.price) ?? (t === null ? 0 : Math.round(t / i)), o = Math.round(i * a);
34
+ return {
35
+ name: e.description,
36
+ quantity: i,
37
+ unit_price: a,
38
+ ...t !== null && t !== o ? { subtotal: t } : {},
39
+ ...e.glCode ? { ledger_account_id: e.glCode } : {}
40
+ };
41
+ });
42
+ }
43
+ function u(e, t) {
44
+ return s(Math.round(o(e) * a(t)));
45
+ }
46
+ function d(e, t, n) {
47
+ return s(e.reduce((e, t) => e + a(t.amount), 0) + a(t) - a(n));
32
48
  }
33
49
  //#endregion
34
- export { s as validateBillCompleteness, c as validateBillTotals, o as validateLineItems };
50
+ export { d as calculateTotal, u as displayLineAmount, i as isPersistableLineItem, c as mapBillFormToPayload, l as mapLineItemsToPayload, n as parseMoneyToMinorUnits, r as parseQuantity };
@@ -1,166 +1,34 @@
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 "../../../shared/ui/dist/index.js";
7
- import { useReplacePayableLineItemsMutation as t } from "../../data-access/dist/index7.js";
8
- import { useCreatePayableMutation as n, useSubmitPayableForApprovalMutation as r, useUpdatePayableMutation as i, useValidatePayableMutation as a } from "../../data-access/dist/index10.js";
9
- import "../../data-access/dist/index.js";
10
- import { BILL_CREATE_MESSAGE_LABELS_EN as o } from "./index27.js";
11
- import { encodeFileToBase64 as s } from "./index32.js";
12
- import { mapBillFormToPayload as c, mapLineItemsToPayload as l } from "./index33.js";
13
- import { validateBillCompleteness as u, validateBillTotals as d, validateLineItems as f } from "./index34.js";
14
- import { useCallback as p, useRef as m, useState as h } from "react";
1
+ import { BILL_CREATE_MESSAGE_LABELS_EN as e } from "./index28.js";
2
+ import { isPersistableLineItem as t, parseMoneyToMinorUnits as n, parseQuantity as r } from "./index34.js";
15
3
  //#region ../../libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index35.js
16
- var g = {
17
- document_id: "invoiceNumber",
18
- issued_at: "invoiceDate",
19
- due_date: "dueDate",
20
- counterpart_id: "vendor"
21
- };
22
- function _(e) {
23
- return e.type === "type_error.none.not_allowed" || e.msg === "none is not an allowed value";
4
+ var i = /^(?:\d{1,3}(?:,\d{3})+(?:\.\d+)?|\d+(?:\.\d+)?|\.\d+)$/;
5
+ function a(e) {
6
+ let t = e.trim();
7
+ return !t || n(t) !== null ? !0 : i.test(t) ? Number(t.replaceAll(",", "")) === 0 : !1;
24
8
  }
25
- function v(e, t = o) {
26
- let n = {}, r = [];
27
- for (let i of e) {
28
- let e = i.loc[0] ?? t.unknownValidationField, a = g[e], o = _(i) ? t.requiredField : i.msg;
29
- a ? n[a] = o : r.push(t.unmappedValidationError(e, o));
9
+ function o(t, i = e) {
10
+ let a = {};
11
+ for (let e of t) {
12
+ let t = n(e.price), o = n(e.amount), s = {};
13
+ e.price.trim() && t === null && (s.price = i.unreadableMoney), e.amount.trim() && o === null && (s.amount = i.unreadableMoney), (t !== null || o !== null) && r(e.quantity) === null && (s.quantity = i.unusableQuantity), Object.keys(s).length && (a[e.id] = s);
30
14
  }
31
- return r.length && (n.form = r.join(" ")), n;
15
+ return Object.keys(a).length ? a : void 0;
32
16
  }
33
- function y(e, t) {
34
- if (!e && !t) return;
35
- let n = {}, r = /* @__PURE__ */ new Set([...Object.keys(e ?? {}), ...Object.keys(t ?? {})]);
36
- for (let i of r) n[i] = {
37
- ...e?.[i],
38
- ...t?.[i]
17
+ function s(i, a, o, s = e) {
18
+ let c = {};
19
+ a || (c.vendor = s.requiredField), i.invoiceNumber.trim() || (c.invoiceNumber = s.requiredField), i.invoiceDate.trim() || (c.invoiceDate = s.requiredField), i.dueDate.trim() || (c.dueDate = s.requiredField);
20
+ let l = {};
21
+ return o.forEach((e, i) => {
22
+ if (i > 0 && !t(e)) return;
23
+ let a = {};
24
+ e.description.trim() || (a.description = s.requiredField), r(e.quantity) === null && (a.quantity = s.requiredField), n(e.price) === null && n(e.amount) === null && (a.price = s.requiredField, a.amount = s.requiredField), Object.keys(a).length && (l[e.id] = a);
25
+ }), {
26
+ formErrors: Object.keys(c).length ? c : void 0,
27
+ lineItemErrors: Object.keys(l).length ? l : void 0
39
28
  };
40
- return n;
41
29
  }
42
- function b({ payableId: g, form: _, counterpartId: b, clearCounterpart: x, prepareVendorForSave: S, onSaved: C, onPayableCreated: w, onDraftSaved: T, onFinalized: E, labels: D }) {
43
- let O = {
44
- ...o,
45
- ...D
46
- }, [k, A] = h(), j = g ?? k, [M, N] = h(), P = p(() => N(void 0), []), [F, I] = h(), L = m(!1), R = n(), z = i(), B = t(), V = a(), H = r(), U = p(() => {
47
- let t = f(_.lineItems, O), n = d(_.discount, _.tax, _.totalOverride, O);
48
- return _.setLineItemErrors(t), !t && !n || (t ? (_.setErrors(void 0), e.error(O.lineItemsNeedAttention)) : _.setErrors(n), !1);
49
- }, [_, O]), W = p(async () => {
50
- let e = !j && M ? {
51
- base64EncodedFile: await s(M),
52
- fileName: M.name
53
- } : void 0, t = c({
54
- values: _.values,
55
- counterpartId: b,
56
- clearCounterpart: x,
57
- editedTotals: _.isTotalsDirty ? {
58
- discount: _.discount,
59
- tax: _.tax,
60
- total: _.totalOverride
61
- } : void 0,
62
- document: e
63
- }), n = j;
64
- if (n ? await z.mutateAsync({
65
- path: { payable_id: n },
66
- body: t
67
- }) : (n = (await R.mutateAsync({ body: t }))?.id, n && (A(n), w?.(n), e && N(void 0))), !n) throw Error("Payable was created without an id");
68
- return await B.mutateAsync({
69
- path: { payable_id: n },
70
- body: { data: l(_.lineItems) }
71
- }), n;
72
- }, [
73
- b,
74
- x,
75
- R,
76
- _.discount,
77
- _.isTotalsDirty,
78
- _.lineItems,
79
- _.tax,
80
- _.totalOverride,
81
- _.values,
82
- w,
83
- j,
84
- B,
85
- M,
86
- z
87
- ]);
88
- return {
89
- saveDraft: p(async () => {
90
- if (!L.current && U()) {
91
- L.current = !0, I("draft");
92
- try {
93
- if (await S?.() === !1) return;
94
- let t = await W();
95
- _.setErrors(void 0), C?.(t), T?.(t), e.success(O.draftSaved);
96
- } catch {
97
- _.setErrors({ form: O.saveFailed });
98
- } finally {
99
- I(void 0), L.current = !1;
100
- }
101
- }
102
- }, [
103
- _,
104
- U,
105
- O.draftSaved,
106
- O.saveFailed,
107
- T,
108
- C,
109
- S,
110
- W
111
- ]),
112
- finalize: p(async () => {
113
- if (L.current) return;
114
- let t = f(_.lineItems, O), n = d(_.discount, _.tax, _.totalOverride, O), { formErrors: r, lineItemErrors: i } = u(_.values, b, _.lineItems, O), a = y(i, t);
115
- _.setLineItemErrors(a);
116
- let o = {
117
- ...r,
118
- ...n
119
- };
120
- if (_.setErrors(Object.keys(o).length ? o : void 0), t && e.error(O.lineItemsNeedAttention), !(a || Object.keys(o).length)) {
121
- L.current = !0, I("finalize");
122
- try {
123
- let t;
124
- try {
125
- if (await S?.() === !1) return;
126
- t = await W();
127
- } catch {
128
- _.setErrors({ form: O.saveFailed });
129
- return;
130
- }
131
- C?.(t);
132
- try {
133
- let n = await V.mutateAsync({ path: { payable_id: t } });
134
- if (n.validation_errors.length) {
135
- _.setErrors(v(n.validation_errors, O));
136
- return;
137
- }
138
- await H.mutateAsync({ path: { payable_id: t } }), _.setErrors(void 0), E?.(t), e.success(O.billFinalized);
139
- } catch {
140
- _.setErrors({ form: O.finalizeFailed });
141
- }
142
- } finally {
143
- I(void 0), L.current = !1;
144
- }
145
- }
146
- }, [
147
- b,
148
- _,
149
- O,
150
- E,
151
- C,
152
- S,
153
- W,
154
- H,
155
- V
156
- ]),
157
- payableId: j,
158
- isSavingDraft: F === "draft",
159
- isFinalizing: F === "finalize",
160
- stagedFile: M,
161
- stageFile: N,
162
- clearStagedFile: P
163
- };
30
+ function c(t, r, i, o = e) {
31
+ return !a(t) || !a(r) || i !== void 0 && n(i) === null ? { form: o.totalsNeedAttention } : void 0;
164
32
  }
165
33
  //#endregion
166
- export { v as mapValidationErrorsToForm, b as useBillCreateController };
34
+ export { s as validateBillCompleteness, c as validateBillTotals, o as validateLineItems };