@tesouro/embedded-components-react 0.5.28 → 0.5.31

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 (118) hide show
  1. package/README.md +14 -13
  2. package/dist/index.css +15 -0
  3. package/dist/index.d.ts +9 -0
  4. package/dist/index.js +1 -1
  5. package/dist/lib/BankAccountOnboardingWidget.d.ts +9 -0
  6. package/dist/lib/BillPayWidget.js +1 -1
  7. package/dist/libs/tesouro-embedded-components-react/bank-account-onboarding-widget/feature/dist/index18.js +155 -151
  8. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/data-access/dist/index.js +5 -5
  9. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/data-access/dist/index14.js +2 -44
  10. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index.js +7 -7
  11. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index12.js +1 -1
  12. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index15.js +1 -1
  13. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index25.js +2 -2
  14. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index27.js +2 -2
  15. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index43.js +52 -67
  16. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index46.js +15 -12
  17. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index48.js +57 -62
  18. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index49.js +1 -1
  19. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index51.js +68 -207
  20. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index52.js +278 -175
  21. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index53.js +13 -126
  22. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index54.js +47 -12
  23. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index55.js +53 -47
  24. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index56.js +204 -49
  25. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index57.js +32 -202
  26. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index58.js +234 -32
  27. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index59.js +21 -240
  28. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index60.js +532 -19
  29. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index61.js +4 -436
  30. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index62.js +42 -4
  31. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index63.js +230 -35
  32. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index64.js +3 -233
  33. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index65.js +4 -3
  34. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index66.js +44 -2
  35. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index67.js +1 -46
  36. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index68.js +8 -1
  37. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index69.js +11 -6
  38. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index70.js +127 -11
  39. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index71.js +3 -129
  40. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index72.js +127 -3
  41. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index73.js +8 -124
  42. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index74.js +7 -8
  43. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index75.js +46 -8
  44. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index76.js +18 -43
  45. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index77.js +28 -20
  46. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index78.js +82 -27
  47. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index79.js +47 -83
  48. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index80.js +250 -47
  49. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index81.js +122 -241
  50. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index82.js +206 -126
  51. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index83.js +3 -213
  52. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index84.js +8 -4
  53. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index85.js +113 -6
  54. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index86.js +1 -115
  55. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index87.js +24 -0
  56. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index.js +39 -33
  57. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index101.js +10 -11
  58. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index102.js +123 -8
  59. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index103.js +2 -170
  60. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index104.js +18 -2
  61. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index105.js +7 -11
  62. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index106.js +158 -96
  63. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index107.js +1 -1
  64. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index108.js +11 -7
  65. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index109.js +100 -44
  66. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index111.js +10 -0
  67. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index112.js +52 -0
  68. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index113.js +2 -0
  69. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index13.js +1 -1
  70. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index26.js +20 -22
  71. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index27.js +4 -9
  72. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index28.js +103 -146
  73. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index30.js +3 -2
  74. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index31.js +93 -88
  75. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index46.js +15 -16
  76. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index48.js +1 -0
  77. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index50.js +43 -29
  78. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index65.js +55 -51
  79. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index66.js +9 -2
  80. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index67.js +33 -1
  81. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index68.js +2 -8
  82. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index69.js +2 -39
  83. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index70.js +0 -1
  84. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index71.js +6 -2
  85. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index72.js +34 -31
  86. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index74.js +2 -37
  87. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index75.js +34 -10
  88. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index76.js +2 -201
  89. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index77.js +39 -3
  90. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index78.js +3 -8
  91. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index79.js +187 -350
  92. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index80.js +3 -10
  93. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index81.js +13 -5
  94. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index82.js +356 -85
  95. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index83.js +10 -0
  96. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index84.js +9 -2
  97. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index85.js +87 -119
  98. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index87.js +2 -94
  99. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index88.js +125 -2
  100. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index89.js +25 -4
  101. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index90.js +90 -26
  102. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index92.js +3 -3
  103. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index93.js +26 -30
  104. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index95.js +4 -9
  105. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index96.js +30 -102
  106. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index98.js +9 -14
  107. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index99.js +85 -104
  108. package/dist/libs/tesouro-embedded-components-react/shared/counterpart-management/data-access/dist/index.js +5 -5
  109. package/dist/libs/tesouro-embedded-components-react/shared/counterpart-management/feature/dist/index.js +17 -17
  110. package/dist/libs/tesouro-embedded-components-react/shared/counterpart-management/feature/dist/lib/useCounterpartDetails.js +4 -0
  111. package/dist/libs/tesouro-embedded-components-react/shared/counterpart-management/feature/dist/lib/useCounterpartForm.js +92 -87
  112. package/dist/libs/tesouro-embedded-components-react/shared/feature/dist/lib/analytics/build-info.js +1 -1
  113. package/dist/libs/tesouro-embedded-components-react/shared/ui/dist/lib/OnboardingShell/OnboardingShell.js +126 -105
  114. package/dist/libs/tesouro-embedded-components-react/shared/ui/dist/lib/OnboardingShell/OnboardingShellOverlayPortal.js +13 -6
  115. package/dist/libs/tesouro-embedded-components-react/widget-suite/feature/dist/index8.js +1 -1
  116. package/package.json +1 -1
  117. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index88.js +0 -25
  118. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index86.js +0 -28
@@ -1,210 +1,40 @@
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 { extractApiErrorMessage as t } from "../../../shared/util/dist/lib/apiErrors.js";
8
- import { useReplacePayableLineItemsMutation as n } from "../../data-access/dist/index10.js";
9
- import { useCreatePayableMutation as r, useDeletePayableFileMutation as i, useSubmitPayableForApprovalMutation as a, useUpdatePayableMutation as o, useValidatePayableMutation as s } from "../../data-access/dist/index13.js";
10
- import "../../data-access/dist/index.js";
11
- import { BILL_CREATE_MESSAGE_LABELS_EN as c } from "./index48.js";
12
- import { encodeFileToBase64 as l } from "./index54.js";
13
- import { mapBillFormToPayload as u, mapLineItemsToPayload as d } from "./index55.js";
14
- import { validateBillCompleteness as f, validateBillTotalIsPayable as p, validateBillTotals as m, validateLineItems as h, validateStoredAmountDue as ee } from "./index56.js";
15
- import { useCallback as g, useRef as _, useState as v } from "react";
1
+ import { resolveLineItemAmountMinorUnits as e } from "./index40.js";
2
+ import { resolveLineItemQuantity as t } from "./index41.js";
16
3
  //#region ../../libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index57.js
17
- var y = {
18
- document_id: "invoiceNumber",
19
- issued_at: "invoiceDate",
20
- due_date: "dueDate",
21
- counterpart_id: "vendor"
22
- }, b = { tax_amount: "tax" };
23
- function x(e) {
24
- return e.type === "type_error.none.not_allowed" || e.msg === "none is not an allowed value";
25
- }
26
- function S(e) {
27
- return !!t(e)?.includes("line_items_enabled");
28
- }
29
- function C(e, t = c) {
30
- let n = {}, r = {}, i = [];
31
- for (let a of e) {
32
- let e = a.loc[0] ?? t.unknownValidationField, o = y[e], s = b[e], c = x(a) ? t.requiredField : a.msg;
33
- o ? n[o] = c : s ? r[s] = c : i.push(t.unmappedValidationError(e, c));
34
- }
35
- return i.length && (n.form = i.join(" ")), {
36
- formErrors: n,
37
- totalsErrors: Object.keys(r).length ? r : void 0
4
+ function n() {
5
+ return {
6
+ id: crypto.randomUUID(),
7
+ description: "",
8
+ glCode: "",
9
+ quantity: "1",
10
+ price: "",
11
+ amount: ""
38
12
  };
39
13
  }
40
- function te(e, t) {
41
- if (!e && !t) return;
42
- let n = {}, r = /* @__PURE__ */ new Set([...Object.keys(e ?? {}), ...Object.keys(t ?? {})]);
43
- for (let i of r) n[i] = {
44
- ...e?.[i],
45
- ...t?.[i]
46
- };
47
- return n;
14
+ function r(e) {
15
+ return typeof e == "number" ? (e / 100).toFixed(2) : "";
48
16
  }
49
- function w({ payableId: t, form: y, counterpartId: b, clearCounterpart: x, prepareVendorForSave: w, onSaved: T, onPayableCreated: E, readSavedStatus: D, onDraftSaved: O, onFinalized: k, labels: A }) {
50
- let j = {
51
- ...c,
52
- ...A
53
- }, [M, N] = v(), P = t ?? M, [F, I] = v(), L = g(() => I(void 0), []), [R, z] = v(!1), B = g(() => z(!0), []), [V, H] = v(), U = _(!1), [ne, re] = v(0), W = g(() => re((e) => e + 1), []), G = r(), K = i(), q = o(), J = n(), Y = s(), X = a(), Z = g(() => y.isTotalsDirty ? m(y.discount, y.tax, y.totalOverride, j) : void 0, [y, j]), Q = g(() => {
54
- let t = h(y.lineItems, j), n = Z();
55
- return y.setLineItemErrors(t), y.setTotalsErrors(n), !t && !n || (y.setErrors(void 0), t && e.error(j.lineItemsNeedAttention), W(), !1);
56
- }, [
57
- y,
58
- j,
59
- W,
60
- Z
61
- ]), $ = g(async (e) => {
62
- let t = !P && F ? {
63
- base64EncodedFile: await l(F),
64
- fileName: F.name
65
- } : void 0, n = u({
66
- values: y.values,
67
- counterpartId: b,
68
- clearCounterpart: x,
69
- counterpartBankAccountId: e,
70
- editedTotals: y.isTotalsDirty ? {
71
- discount: y.discount,
72
- tax: y.tax,
73
- total: y.totalOverride
74
- } : void 0,
75
- document: t
76
- }), r = P;
77
- if (r ? await q.mutateAsync({
78
- path: { payable_id: r },
79
- body: n
80
- }) : (r = (await G.mutateAsync({ body: n }))?.id, r && (N(r), E?.(r), t && I(void 0))), !r) throw Error("Payable was created without an id");
81
- if (R) {
82
- try {
83
- await K.mutateAsync({ path: { payable_id: r } });
84
- } catch {}
85
- z(!1);
86
- }
87
- return await J.mutateAsync({
88
- path: { payable_id: r },
89
- body: { data: d(y.lineItems) }
90
- }), r;
91
- }, [
92
- b,
93
- x,
94
- G,
95
- K,
96
- R,
97
- y.discount,
98
- y.isTotalsDirty,
99
- y.lineItems,
100
- y.tax,
101
- y.totalOverride,
102
- y.values,
103
- E,
104
- P,
105
- J,
106
- F,
107
- q
108
- ]), ie = g(async () => {
109
- P && (await K.mutateAsync({ path: { payable_id: P } }), z(!1));
110
- }, [K, P]);
17
+ function i({ payable: i, lineItems: a }) {
18
+ let o = {
19
+ invoiceNumber: i.document_id ?? "",
20
+ invoiceDate: i.issued_at ?? "",
21
+ dueDate: i.due_date ?? "",
22
+ poNumber: ""
23
+ }, s = a.map((n) => ({
24
+ id: n.id,
25
+ description: n.name ?? "",
26
+ glCode: n.ledger_account_id ?? "",
27
+ quantity: String(t(n)),
28
+ price: r(n.unit_price),
29
+ amount: r(e(n))
30
+ })), c = i.amount_due ?? (i.total_amount == null ? void 0 : i.total_amount - (i.discount ?? 0));
111
31
  return {
112
- saveDraft: g(async () => {
113
- if (!U.current && Q()) {
114
- U.current = !0, H("draft");
115
- try {
116
- let t = await w?.();
117
- if (t && !t.ok) return;
118
- let n = await $(t?.counterpartBankAccountId);
119
- y.setErrors(void 0), T?.(n), O?.(n);
120
- let r = await D?.();
121
- return e.success(r === "draft" ? j.submittedDemoted : j.draftSaved), n;
122
- } catch (e) {
123
- y.setSaveFailureMessage(S(e) ? j.discountTaxBlockedByLineItems : j.saveFailed), W();
124
- return;
125
- } finally {
126
- H(void 0), U.current = !1;
127
- }
128
- }
129
- }, [
130
- y,
131
- Q,
132
- j.discountTaxBlockedByLineItems,
133
- j.draftSaved,
134
- j.saveFailed,
135
- j.submittedDemoted,
136
- O,
137
- T,
138
- D,
139
- w,
140
- $,
141
- W
142
- ]),
143
- finalize: g(async () => {
144
- if (U.current) return;
145
- let t = h(y.lineItems, j), n = Z(), r = p(y.total, j), i = y.isTotalsDirty ? ee(y.totalOverride, y.discount, j) : void 0, a = n || r || i ? {
146
- ...i,
147
- ...r,
148
- ...n
149
- } : void 0, { formErrors: o, lineItemErrors: s } = f(y.values, b, y.lineItems, j), c = te(s, t);
150
- y.setLineItemErrors(c), y.setTotalsErrors(a);
151
- let l = o ?? {};
152
- if (y.setErrors(Object.keys(l).length ? l : void 0), t && e.error(j.lineItemsNeedAttention), c || a || Object.keys(l).length) {
153
- W();
154
- return;
155
- }
156
- U.current = !0, H("finalize");
157
- try {
158
- let t;
159
- try {
160
- let e = await w?.();
161
- if (e && !e.ok) return;
162
- t = await $(e?.counterpartBankAccountId);
163
- } catch (e) {
164
- y.setSaveFailureMessage(S(e) ? j.discountTaxBlockedByLineItems : j.saveFailed), W();
165
- return;
166
- }
167
- T?.(t);
168
- try {
169
- let n = await Y.mutateAsync({ path: { payable_id: t } });
170
- if (n.validation_errors.length) {
171
- let e = C(n.validation_errors, j);
172
- y.setErrors(e.formErrors), y.setTotalsErrors(e.totalsErrors), W();
173
- return;
174
- }
175
- await X.mutateAsync({ path: { payable_id: t } }), y.setErrors(void 0), k?.(t), e.success(j.billFinalized);
176
- } catch {
177
- y.setSaveFailureMessage(j.finalizeFailed), W();
178
- }
179
- } finally {
180
- H(void 0), U.current = !1;
181
- }
182
- }, [
183
- b,
184
- y,
185
- j,
186
- k,
187
- T,
188
- w,
189
- $,
190
- W,
191
- X,
192
- Z,
193
- Y
194
- ]),
195
- payableId: P,
196
- isSavingDraft: V === "draft",
197
- isFinalizing: V === "finalize",
198
- stagedFile: F,
199
- stageFile: I,
200
- clearStagedFile: L,
201
- scrollToErrorToken: ne,
202
- isFileDeletionPending: R,
203
- requestFileDeletion: B,
204
- detachFileNow: ie,
205
- isDeletingFile: K.isPending,
206
- hasFileDeletionFailed: K.isError
32
+ values: o,
33
+ lineItems: s.length ? s : [n()],
34
+ discount: r(i.discount),
35
+ tax: r(i.tax_amount),
36
+ total: c ? r(c) : ""
207
37
  };
208
38
  }
209
39
  //#endregion
210
- export { C as mapValidationErrorsToForm, w as useBillCreateController };
40
+ export { n as emptyLineItem, i as mapPayableToBillForm };
@@ -1,40 +1,242 @@
1
- import { resolveLineItemAmountMinorUnits as e } from "./index40.js";
2
- import { resolveLineItemQuantity as t } from "./index41.js";
1
+ "use client";
2
+ "use client";
3
+ "use client";
4
+ "use client";
5
+ import { BILL_CREATE_MESSAGE_LABELS_EN as e } from "./index48.js";
6
+ import { calculateTotal as t, displayLineAmount as n, parseMoneyToMinorUnits as r, parseQuantity as i } from "./index54.js";
7
+ import { validateBillTotals as a } from "./index55.js";
8
+ import { emptyLineItem as o, mapPayableToBillForm as s } from "./index57.js";
9
+ import { useCallback as c, useEffect as l, useMemo as u, useRef as ee, useState as d } from "react";
3
10
  //#region ../../libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index58.js
4
- function n() {
5
- return {
6
- id: crypto.randomUUID(),
7
- description: "",
8
- glCode: "",
9
- quantity: "1",
10
- price: "",
11
- amount: ""
11
+ var f = /^[0-9.,-]+$/;
12
+ function p(e) {
13
+ let t = e.trim().replace(/^\$\s*/, "");
14
+ return t ? f.test(t) ? t : null : "";
15
+ }
16
+ var m = [
17
+ "quantity",
18
+ "price",
19
+ "amount"
20
+ ];
21
+ function h(e) {
22
+ let t = e.trim(), n = /[.,]$/.test(t) ? t.slice(0, -1) : t;
23
+ return t && !n ? null : n;
24
+ }
25
+ function g(e, t, n) {
26
+ if (t === void 0) return;
27
+ let r = h(t);
28
+ if (r !== null) return a(e === "discount" ? r : "", e === "tax" ? r : "", e === "total" ? r : void 0, n)?.[e];
29
+ }
30
+ function _(e, t) {
31
+ let n = {}, a = {
32
+ price: null,
33
+ amount: null
12
34
  };
35
+ for (let i of ["price", "amount"]) {
36
+ let o = h(e[i]);
37
+ o !== null && (a[i] = r(o), o && a[i] === null && (n[i] = t.unreadableMoney));
38
+ }
39
+ let o = h(e.quantity);
40
+ if (o !== null) {
41
+ let e = a.price !== null || a.amount !== null;
42
+ i(o) === null && (o || e) && (n.quantity = t.unusableQuantity);
43
+ }
44
+ return n;
13
45
  }
14
- function r(e) {
15
- return typeof e == "number" ? (e / 100).toFixed(2) : "";
46
+ function v(e, t, i) {
47
+ return r(t) === null ? i : n(e, t);
16
48
  }
17
- function i({ payable: i, lineItems: a }) {
18
- let o = {
19
- invoiceNumber: i.document_id ?? "",
20
- invoiceDate: i.issued_at ?? "",
21
- dueDate: i.due_date ?? "",
22
- poNumber: ""
23
- }, s = a.map((n) => ({
24
- id: n.id,
25
- description: n.name ?? "",
26
- glCode: n.ledger_account_id ?? "",
27
- quantity: String(t(n)),
28
- price: r(n.unit_price),
29
- amount: r(e(n))
30
- })), c = i.amount_due ?? (i.total_amount == null ? void 0 : i.total_amount - (i.discount ?? 0));
49
+ function y({ payable: n, lineItems: r, labels: i = e } = {}) {
50
+ let a = u(() => s({
51
+ payable: n ?? {},
52
+ lineItems: r ?? []
53
+ }), [n, r]), [f, h] = d(a.values), [y, b] = d(a.lineItems), [x, S] = d(a.discount), [C, w] = d(a.tax), [T, E] = d(a.total || void 0), [te, D] = d(), O = ee(void 0), k = c((e) => {
54
+ D((t) => {
55
+ let n = typeof e == "function" ? e(t) : e;
56
+ return n?.form !== O.current && (O.current = void 0), n;
57
+ });
58
+ }, []), A = c((e) => {
59
+ O.current = e, D((t) => ({
60
+ ...t,
61
+ form: e
62
+ }));
63
+ }, []), j = c(() => {
64
+ D((e) => {
65
+ if (!e?.form || e.form !== O.current) return e;
66
+ O.current = void 0;
67
+ let { form: t, ...n } = e;
68
+ return Object.keys(n).length ? n : void 0;
69
+ });
70
+ }, []), [M, N] = d(), [P, F] = d(), [I, L] = d(!1), [R, z] = d(!1), [B, V] = d(!1);
71
+ l(() => {
72
+ I || h(a.values);
73
+ }, [a]), l(() => {
74
+ R || b(a.lineItems);
75
+ }, [a]), l(() => {
76
+ B || (S(a.discount), w(a.tax), E(a.total || void 0));
77
+ }, [a]);
78
+ let H = c((e) => {
79
+ h((t) => ({
80
+ ...t,
81
+ ...e
82
+ })), L(!0), D((t) => {
83
+ if (!t) return t;
84
+ let n = { ...t };
85
+ for (let t of Object.keys(e)) delete n[t];
86
+ return Object.keys(n).length ? n : void 0;
87
+ }), j();
88
+ }, [j]), U = c((e, t) => {
89
+ N((n) => {
90
+ if (!n?.[e] && !t) return n;
91
+ let r = {
92
+ ...n,
93
+ [e]: t
94
+ };
95
+ return t || delete r[e], Object.keys(r).length ? r : void 0;
96
+ });
97
+ }, []), W = c((e, t) => {
98
+ U(e, g(e, t, i));
99
+ }, [i, U]), G = c(() => {
100
+ E(void 0), W("total", void 0), j();
101
+ }, [W, j]), K = c((e, t = []) => {
102
+ let n = _(e, i);
103
+ F((r) => {
104
+ let i = r?.[e.id], a = { ...i };
105
+ for (let e of [
106
+ "price",
107
+ "amount",
108
+ "quantity"
109
+ ]) n[e] ? a[e] = n[e] : delete a[e];
110
+ t.includes("description") && delete a.description;
111
+ let o = Object.keys(a).length > 0;
112
+ if (!i && !o) return r;
113
+ let s = { ...r };
114
+ return o ? s[e.id] = a : delete s[e.id], Object.keys(s).length ? s : void 0;
115
+ });
116
+ }, [i]), q = c((e, t, n) => {
117
+ F((r) => ({
118
+ ...r,
119
+ [e]: {
120
+ ...r?.[e],
121
+ [t]: n
122
+ }
123
+ }));
124
+ }, []), J = c((e, t, n = []) => {
125
+ let r = y.find((t) => t.id === e);
126
+ if (!r) return;
127
+ let i = t(r);
128
+ b(y.map((t) => t.id === e ? i : t)), K(i, n), z(!0), G();
129
+ }, [
130
+ G,
131
+ y,
132
+ K
133
+ ]), Y = c((e, t) => {
134
+ let n = { ...t };
135
+ for (let r of m) {
136
+ let a = t[r];
137
+ if (a === void 0) continue;
138
+ let o = p(a);
139
+ if (o === null) {
140
+ q(e, r, i.numbersOnly);
141
+ return;
142
+ }
143
+ n[r] = o;
144
+ }
145
+ J(e, (e) => {
146
+ let t = {
147
+ ...e,
148
+ ...n
149
+ };
150
+ return "amount" in n ? t : {
151
+ ...t,
152
+ amount: v(t.quantity, t.price, t.amount)
153
+ };
154
+ }, Object.keys(n));
155
+ }, [
156
+ J,
157
+ i,
158
+ q
159
+ ]), X = c((e, t) => {
160
+ J(e, (e) => {
161
+ let n = Number.parseFloat(e.quantity), r = String(Math.max(1, (Number.isFinite(n) ? n : 0) + t));
162
+ return {
163
+ ...e,
164
+ quantity: r,
165
+ amount: v(r, e.price, e.amount)
166
+ };
167
+ });
168
+ }, [J]), Z = c((e) => {
169
+ F((t) => {
170
+ if (!t?.[e]) return t;
171
+ let n = { ...t };
172
+ return delete n[e], Object.keys(n).length ? n : void 0;
173
+ });
174
+ }, []), Q = c((e) => {
175
+ Z(e), b((t) => t.length <= 1 ? t : t.filter((t) => t.id !== e)), z(!0), G();
176
+ }, [Z, G]), ne = c(() => {
177
+ b((e) => [...e, o()]), z(!0), G();
178
+ }, [G]), $ = c((e, t, n) => {
179
+ let r = p(t);
180
+ if (r === null) {
181
+ U(e, i.numbersOnly);
182
+ return;
183
+ }
184
+ n(r), V(!0), G(), W(e, r);
185
+ }, [
186
+ G,
187
+ i,
188
+ W,
189
+ U
190
+ ]), re = c((e) => $("discount", e, S), [$]), ie = c((e) => $("tax", e, w), [$]), ae = c((e) => {
191
+ let t = p(e);
192
+ if (t === null) {
193
+ U("total", i.numbersOnly);
194
+ return;
195
+ }
196
+ E(t), V(!0), W("total", t), j();
197
+ }, [
198
+ j,
199
+ i,
200
+ W,
201
+ U
202
+ ]), oe = u(() => y.map((e) => ({
203
+ ...e,
204
+ onChange: (t) => Y(e.id, t),
205
+ onQuantityStep: (t) => X(e.id, t),
206
+ onRemove: () => Q(e.id)
207
+ })), [
208
+ y,
209
+ Y,
210
+ Q,
211
+ X
212
+ ]), se = u(() => t(y, C, x), [
213
+ y,
214
+ C,
215
+ x
216
+ ]);
31
217
  return {
32
- values: o,
33
- lineItems: s.length ? s : [n()],
34
- discount: r(i.discount),
35
- tax: r(i.tax_amount),
36
- total: c ? r(c) : ""
218
+ values: f,
219
+ errors: te,
220
+ setErrors: k,
221
+ setSaveFailureMessage: A,
222
+ lineItemErrors: P,
223
+ setLineItemErrors: F,
224
+ totalsErrors: M,
225
+ setTotalsErrors: N,
226
+ onChange: H,
227
+ lineItems: y,
228
+ lineItemRows: oe,
229
+ discount: x,
230
+ onDiscountChange: re,
231
+ tax: C,
232
+ onTaxChange: ie,
233
+ total: T ?? se,
234
+ totalOverride: T,
235
+ onTotalChange: ae,
236
+ onAddLineItem: ne,
237
+ isTotalsDirty: B,
238
+ isDirty: I || R || B
37
239
  };
38
240
  }
39
241
  //#endregion
40
- export { n as emptyLineItem, i as mapPayableToBillForm };
242
+ export { y as useBillForm };