@tesouro/embedded-components-react 0.4.4 → 0.4.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +37 -37
- package/dist/index.d.ts +14 -8
- package/dist/lib/CreditCardsWidget.d.ts +4 -2
- package/dist/lib/DebitCardsWidget.d.ts +4 -2
- package/dist/lib/WidgetSuite.d.ts +14 -8
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/data-access/dist/index.js +8 -8
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/data-access/dist/index10.js +50 -29
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/data-access/dist/index11.js +39 -30
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/data-access/dist/index12.js +26 -311
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/data-access/dist/index13.js +326 -12
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/data-access/dist/index14.js +1 -1
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/data-access/dist/index15.js +1 -1
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/data-access/dist/index4.js +13 -27
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/data-access/dist/index5.js +28 -245
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/data-access/dist/index6.js +256 -92
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/data-access/dist/index7.js +86 -73
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/data-access/dist/index8.js +77 -14
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/data-access/dist/index9.js +18 -63
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index.js +4 -4
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index10.js +1 -1
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index14.js +1 -1
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index22.js +1 -1
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index29.js +1 -1
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index3.js +1 -1
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index30.js +1 -1
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index31.js +1 -1
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index32.js +2 -2
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index33.js +1 -1
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index35.js +1 -1
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index37.js +72 -56
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index38.js +77 -48
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index39.js +47 -91
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index40.js +91 -33
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index41.js +33 -167
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index42.js +168 -75
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index43.js +75 -21
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index44.js +23 -210
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index45.js +199 -203
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index46.js +198 -89
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index47.js +105 -13
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index48.js +12 -47
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index49.js +47 -31
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index50.js +27 -198
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index51.js +198 -30
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index52.js +30 -234
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index53.js +240 -18
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index54.js +19 -341
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index55.js +344 -4
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index56.js +4 -33
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index57.js +32 -83
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index58.js +25 -25
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index59.js +1 -1
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index65.js +1 -1
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index7.js +1 -1
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index76.js +1 -1
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index77.js +2 -2
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index9.js +1 -1
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index25.js +2 -0
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index26.js +28 -3
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index56.js +2 -0
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index57.js +152 -131
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index97.js +1 -1
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index98.js +32 -27
- package/dist/libs/tesouro-embedded-components-react/cards-widget/ui/dist/lib/CardsList/CardsList.js +84 -87
- package/dist/libs/tesouro-embedded-components-react/cards-widget/ui/dist/lib/CardsList/labels.js +0 -1
- package/dist/libs/tesouro-embedded-components-react/shared/feature/dist/lib/analytics/build-info.js +1 -1
- package/dist/libs/tesouro-embedded-components-react/widget-suite/feature/dist/index4.js +2 -2
- package/dist/libs/tesouro-embedded-components-react/widget-suite/feature/dist/index9.js +12 -10
- package/package.json +1 -1
|
@@ -1,242 +1,38 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
"use client";
|
|
3
|
-
"use client";
|
|
4
|
-
"use client";
|
|
5
|
-
import { BILL_CREATE_MESSAGE_LABELS_EN as e } from "./index41.js";
|
|
6
|
-
import { calculateTotal as t, displayLineAmount as n, parseMoneyToMinorUnits as r, parseQuantity as i } from "./index48.js";
|
|
7
|
-
import { validateBillTotals as a } from "./index49.js";
|
|
8
|
-
import { emptyLineItem as o, mapPayableToBillForm as s } from "./index51.js";
|
|
9
|
-
import { useCallback as c, useEffect as l, useMemo as u, useRef as ee, useState as d } from "react";
|
|
10
1
|
//#region ../../libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index52.js
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
|
2
|
+
function e() {
|
|
3
|
+
return {
|
|
4
|
+
id: crypto.randomUUID(),
|
|
5
|
+
description: "",
|
|
6
|
+
glCode: "",
|
|
7
|
+
quantity: "1",
|
|
8
|
+
price: "",
|
|
9
|
+
amount: ""
|
|
34
10
|
};
|
|
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;
|
|
45
11
|
}
|
|
46
|
-
function
|
|
47
|
-
return
|
|
12
|
+
function t(e) {
|
|
13
|
+
return typeof e == "number" ? (e / 100).toFixed(2) : "";
|
|
48
14
|
}
|
|
49
|
-
function
|
|
50
|
-
let
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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 : 1) + 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
|
-
]);
|
|
15
|
+
function n({ payable: n, lineItems: r }) {
|
|
16
|
+
let i = {
|
|
17
|
+
invoiceNumber: n.document_id ?? "",
|
|
18
|
+
invoiceDate: n.issued_at ?? "",
|
|
19
|
+
dueDate: n.due_date ?? "",
|
|
20
|
+
poNumber: ""
|
|
21
|
+
}, a = r.map((e) => ({
|
|
22
|
+
id: e.id,
|
|
23
|
+
description: e.name ?? "",
|
|
24
|
+
glCode: e.ledger_account_id ?? "",
|
|
25
|
+
quantity: e.quantity == null ? "" : String(e.quantity),
|
|
26
|
+
price: t(e.unit_price),
|
|
27
|
+
amount: t(e.subtotal)
|
|
28
|
+
})), o = n.amount_due ?? (n.total_amount == null ? void 0 : n.total_amount - (n.discount ?? 0));
|
|
217
29
|
return {
|
|
218
|
-
values:
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
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
|
|
30
|
+
values: i,
|
|
31
|
+
lineItems: a.length ? a : [e()],
|
|
32
|
+
discount: t(n.discount),
|
|
33
|
+
tax: t(n.tax_amount),
|
|
34
|
+
total: o ? t(o) : ""
|
|
239
35
|
};
|
|
240
36
|
}
|
|
241
37
|
//#endregion
|
|
242
|
-
export {
|
|
38
|
+
export { e as emptyLineItem, n as mapPayableToBillForm };
|
|
@@ -1,20 +1,242 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
"use client";
|
|
3
|
+
"use client";
|
|
4
|
+
"use client";
|
|
5
|
+
import { BILL_CREATE_MESSAGE_LABELS_EN as e } from "./index42.js";
|
|
6
|
+
import { calculateTotal as t, displayLineAmount as n, parseMoneyToMinorUnits as r, parseQuantity as i } from "./index49.js";
|
|
7
|
+
import { validateBillTotals as a } from "./index50.js";
|
|
8
|
+
import { emptyLineItem as o, mapPayableToBillForm as s } from "./index52.js";
|
|
9
|
+
import { useCallback as c, useEffect as l, useMemo as u, useRef as ee, useState as d } from "react";
|
|
1
10
|
//#region ../../libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index53.js
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
|
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;
|
|
45
|
+
}
|
|
46
|
+
function v(e, t, i) {
|
|
47
|
+
return r(t) === null ? i : n(e, t);
|
|
48
|
+
}
|
|
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 : 1) + 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
|
+
]);
|
|
217
|
+
return {
|
|
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
|
|
239
|
+
};
|
|
240
|
+
}
|
|
19
241
|
//#endregion
|
|
20
|
-
export {
|
|
242
|
+
export { y as useBillForm };
|