@tesouro/embedded-components-react 0.4.5 → 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/feature/dist/index.js +4 -4
- 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 -19
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index54.js +19 -342
- 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 +24 -24
- 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/index77.js +2 -2
- 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/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,206 +1,35 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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 "./index41.js";
|
|
12
|
-
import { encodeFileToBase64 as ee } from "./index47.js";
|
|
13
|
-
import { mapBillFormToPayload as l, mapLineItemsToPayload as u } from "./index48.js";
|
|
14
|
-
import { validateBillCompleteness as d, validateBillTotals as f, validateLineItems as p } from "./index49.js";
|
|
15
|
-
import { useCallback as m, useRef as h, useState as g } from "react";
|
|
1
|
+
import { BILL_CREATE_MESSAGE_LABELS_EN as e } from "./index42.js";
|
|
2
|
+
import { isPersistableLineItem as t, parseMoneyToMinorUnits as n, parseQuantity as r } from "./index49.js";
|
|
16
3
|
//#region ../../libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index50.js
|
|
17
|
-
var
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
counterpart_id: "vendor"
|
|
22
|
-
}, v = { tax_amount: "tax" };
|
|
23
|
-
function y(e) {
|
|
24
|
-
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;
|
|
25
8
|
}
|
|
26
|
-
function
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
for (let a of e) {
|
|
32
|
-
let e = a.loc[0] ?? t.unknownValidationField, o = _[e], s = v[e], c = y(a) ? t.requiredField : a.msg;
|
|
33
|
-
o ? n[o] = c : s ? r[s] = c : i.push(t.unmappedValidationError(e, c));
|
|
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), r(e.quantity) === null && (e.quantity.trim() || t !== null || o !== null) && (s.quantity = i.unusableQuantity), Object.keys(s).length && (a[e.id] = s);
|
|
34
14
|
}
|
|
35
|
-
return
|
|
36
|
-
formErrors: n,
|
|
37
|
-
totalsErrors: Object.keys(r).length ? r : void 0
|
|
38
|
-
};
|
|
15
|
+
return Object.keys(a).length ? a : void 0;
|
|
39
16
|
}
|
|
40
|
-
function
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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
|
|
46
28
|
};
|
|
47
|
-
return n;
|
|
48
29
|
}
|
|
49
|
-
function
|
|
50
|
-
let
|
|
51
|
-
|
|
52
|
-
...k
|
|
53
|
-
}, [j, M] = g(), N = t ?? j, [P, F] = g(), I = m(() => F(void 0), []), [L, R] = g(!1), z = m(() => R(!0), []), [B, V] = g(), H = h(!1), [U, te] = g(0), W = m(() => te((e) => e + 1), []), G = r(), K = i(), q = o(), J = n(), Y = s(), X = a(), Z = m(() => _.isTotalsDirty ? f(_.discount, _.tax, _.totalOverride, A) : void 0, [_, A]), Q = m(() => {
|
|
54
|
-
let t = p(_.lineItems, A), n = Z();
|
|
55
|
-
return _.setLineItemErrors(t), _.setTotalsErrors(n), !t && !n || (_.setErrors(void 0), t && e.error(A.lineItemsNeedAttention), W(), !1);
|
|
56
|
-
}, [
|
|
57
|
-
_,
|
|
58
|
-
A,
|
|
59
|
-
W,
|
|
60
|
-
Z
|
|
61
|
-
]), $ = m(async (e) => {
|
|
62
|
-
let t = !N && P ? {
|
|
63
|
-
base64EncodedFile: await ee(P),
|
|
64
|
-
fileName: P.name
|
|
65
|
-
} : void 0, n = l({
|
|
66
|
-
values: _.values,
|
|
67
|
-
counterpartId: v,
|
|
68
|
-
clearCounterpart: y,
|
|
69
|
-
counterpartBankAccountId: e,
|
|
70
|
-
editedTotals: _.isTotalsDirty ? {
|
|
71
|
-
discount: _.discount,
|
|
72
|
-
tax: _.tax,
|
|
73
|
-
total: _.totalOverride
|
|
74
|
-
} : void 0,
|
|
75
|
-
document: t
|
|
76
|
-
}), r = N;
|
|
77
|
-
if (r ? await q.mutateAsync({
|
|
78
|
-
path: { payable_id: r },
|
|
79
|
-
body: n
|
|
80
|
-
}) : (r = (await G.mutateAsync({ body: n }))?.id, r && (M(r), T?.(r), t && F(void 0))), !r) throw Error("Payable was created without an id");
|
|
81
|
-
if (L) {
|
|
82
|
-
try {
|
|
83
|
-
await K.mutateAsync({ path: { payable_id: r } });
|
|
84
|
-
} catch {}
|
|
85
|
-
R(!1);
|
|
86
|
-
}
|
|
87
|
-
return await J.mutateAsync({
|
|
88
|
-
path: { payable_id: r },
|
|
89
|
-
body: { data: u(_.lineItems) }
|
|
90
|
-
}), r;
|
|
91
|
-
}, [
|
|
92
|
-
v,
|
|
93
|
-
y,
|
|
94
|
-
G,
|
|
95
|
-
K,
|
|
96
|
-
L,
|
|
97
|
-
_.discount,
|
|
98
|
-
_.isTotalsDirty,
|
|
99
|
-
_.lineItems,
|
|
100
|
-
_.tax,
|
|
101
|
-
_.totalOverride,
|
|
102
|
-
_.values,
|
|
103
|
-
T,
|
|
104
|
-
N,
|
|
105
|
-
J,
|
|
106
|
-
P,
|
|
107
|
-
q
|
|
108
|
-
]), ne = m(async () => {
|
|
109
|
-
N && (await K.mutateAsync({ path: { payable_id: N } }), R(!1));
|
|
110
|
-
}, [K, N]);
|
|
111
|
-
return {
|
|
112
|
-
saveDraft: m(async () => {
|
|
113
|
-
if (!H.current && Q()) {
|
|
114
|
-
H.current = !0, V("draft");
|
|
115
|
-
try {
|
|
116
|
-
let t = await C?.();
|
|
117
|
-
if (t && !t.ok) return;
|
|
118
|
-
let n = await $(t?.counterpartBankAccountId);
|
|
119
|
-
_.setErrors(void 0), w?.(n), D?.(n);
|
|
120
|
-
let r = await E?.();
|
|
121
|
-
return e.success(r === "draft" ? A.submittedDemoted : A.draftSaved), n;
|
|
122
|
-
} catch (e) {
|
|
123
|
-
_.setSaveFailureMessage(b(e) ? A.discountTaxBlockedByLineItems : A.saveFailed), W();
|
|
124
|
-
return;
|
|
125
|
-
} finally {
|
|
126
|
-
V(void 0), H.current = !1;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
}, [
|
|
130
|
-
_,
|
|
131
|
-
Q,
|
|
132
|
-
A.discountTaxBlockedByLineItems,
|
|
133
|
-
A.draftSaved,
|
|
134
|
-
A.saveFailed,
|
|
135
|
-
A.submittedDemoted,
|
|
136
|
-
D,
|
|
137
|
-
w,
|
|
138
|
-
E,
|
|
139
|
-
C,
|
|
140
|
-
$,
|
|
141
|
-
W
|
|
142
|
-
]),
|
|
143
|
-
finalize: m(async () => {
|
|
144
|
-
if (H.current) return;
|
|
145
|
-
let t = p(_.lineItems, A), n = Z(), { formErrors: r, lineItemErrors: i } = d(_.values, v, _.lineItems, A), a = S(i, t);
|
|
146
|
-
_.setLineItemErrors(a), _.setTotalsErrors(n);
|
|
147
|
-
let o = r ?? {};
|
|
148
|
-
if (_.setErrors(Object.keys(o).length ? o : void 0), t && e.error(A.lineItemsNeedAttention), a || n || Object.keys(o).length) {
|
|
149
|
-
W();
|
|
150
|
-
return;
|
|
151
|
-
}
|
|
152
|
-
H.current = !0, V("finalize");
|
|
153
|
-
try {
|
|
154
|
-
let t;
|
|
155
|
-
try {
|
|
156
|
-
let e = await C?.();
|
|
157
|
-
if (e && !e.ok) return;
|
|
158
|
-
t = await $(e?.counterpartBankAccountId);
|
|
159
|
-
} catch (e) {
|
|
160
|
-
_.setSaveFailureMessage(b(e) ? A.discountTaxBlockedByLineItems : A.saveFailed), W();
|
|
161
|
-
return;
|
|
162
|
-
}
|
|
163
|
-
w?.(t);
|
|
164
|
-
try {
|
|
165
|
-
let n = await Y.mutateAsync({ path: { payable_id: t } });
|
|
166
|
-
if (n.validation_errors.length) {
|
|
167
|
-
let e = x(n.validation_errors, A);
|
|
168
|
-
_.setErrors(e.formErrors), _.setTotalsErrors(e.totalsErrors), W();
|
|
169
|
-
return;
|
|
170
|
-
}
|
|
171
|
-
await X.mutateAsync({ path: { payable_id: t } }), _.setErrors(void 0), O?.(t), e.success(A.billFinalized);
|
|
172
|
-
} catch {
|
|
173
|
-
_.setSaveFailureMessage(A.finalizeFailed), W();
|
|
174
|
-
}
|
|
175
|
-
} finally {
|
|
176
|
-
V(void 0), H.current = !1;
|
|
177
|
-
}
|
|
178
|
-
}, [
|
|
179
|
-
v,
|
|
180
|
-
_,
|
|
181
|
-
A,
|
|
182
|
-
O,
|
|
183
|
-
w,
|
|
184
|
-
C,
|
|
185
|
-
$,
|
|
186
|
-
W,
|
|
187
|
-
X,
|
|
188
|
-
Z,
|
|
189
|
-
Y
|
|
190
|
-
]),
|
|
191
|
-
payableId: N,
|
|
192
|
-
isSavingDraft: B === "draft",
|
|
193
|
-
isFinalizing: B === "finalize",
|
|
194
|
-
stagedFile: P,
|
|
195
|
-
stageFile: F,
|
|
196
|
-
clearStagedFile: I,
|
|
197
|
-
scrollToErrorToken: U,
|
|
198
|
-
isFileDeletionPending: L,
|
|
199
|
-
requestFileDeletion: z,
|
|
200
|
-
detachFileNow: ne,
|
|
201
|
-
isDeletingFile: K.isPending,
|
|
202
|
-
hasFileDeletionFailed: K.isError
|
|
203
|
-
};
|
|
30
|
+
function c(t, r, i, o = e) {
|
|
31
|
+
let s = {};
|
|
32
|
+
return a(t) || (s.discount = o.unreadableDiscount), a(r) || (s.tax = o.unreadableTax), i !== void 0 && n(i) === null && (s.total = o.unreadableTotal), Object.keys(s).length ? s : void 0;
|
|
204
33
|
}
|
|
205
34
|
//#endregion
|
|
206
|
-
export {
|
|
35
|
+
export { a as isReadableMoneyOrZero, s as validateBillCompleteness, c as validateBillTotals, o as validateLineItems };
|
|
@@ -1,38 +1,206 @@
|
|
|
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 "./index42.js";
|
|
12
|
+
import { encodeFileToBase64 as ee } from "./index48.js";
|
|
13
|
+
import { mapBillFormToPayload as l, mapLineItemsToPayload as u } from "./index49.js";
|
|
14
|
+
import { validateBillCompleteness as d, validateBillTotals as f, validateLineItems as p } from "./index50.js";
|
|
15
|
+
import { useCallback as m, useRef as h, useState as g } from "react";
|
|
1
16
|
//#region ../../libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index51.js
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
17
|
+
var _ = {
|
|
18
|
+
document_id: "invoiceNumber",
|
|
19
|
+
issued_at: "invoiceDate",
|
|
20
|
+
due_date: "dueDate",
|
|
21
|
+
counterpart_id: "vendor"
|
|
22
|
+
}, v = { tax_amount: "tax" };
|
|
23
|
+
function y(e) {
|
|
24
|
+
return e.type === "type_error.none.not_allowed" || e.msg === "none is not an allowed value";
|
|
25
|
+
}
|
|
26
|
+
function b(e) {
|
|
27
|
+
return !!t(e)?.includes("line_items_enabled");
|
|
28
|
+
}
|
|
29
|
+
function x(e, t = c) {
|
|
30
|
+
let n = {}, r = {}, i = [];
|
|
31
|
+
for (let a of e) {
|
|
32
|
+
let e = a.loc[0] ?? t.unknownValidationField, o = _[e], s = v[e], c = y(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
|
|
10
38
|
};
|
|
11
39
|
}
|
|
12
|
-
function
|
|
13
|
-
|
|
40
|
+
function S(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
48
|
}
|
|
15
|
-
function
|
|
16
|
-
let
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
49
|
+
function C({ payableId: t, form: _, counterpartId: v, clearCounterpart: y, prepareVendorForSave: C, onSaved: w, onPayableCreated: T, readSavedStatus: E, onDraftSaved: D, onFinalized: O, labels: k }) {
|
|
50
|
+
let A = {
|
|
51
|
+
...c,
|
|
52
|
+
...k
|
|
53
|
+
}, [j, M] = g(), N = t ?? j, [P, F] = g(), I = m(() => F(void 0), []), [L, R] = g(!1), z = m(() => R(!0), []), [B, V] = g(), H = h(!1), [U, te] = g(0), W = m(() => te((e) => e + 1), []), G = r(), K = i(), q = o(), J = n(), Y = s(), X = a(), Z = m(() => _.isTotalsDirty ? f(_.discount, _.tax, _.totalOverride, A) : void 0, [_, A]), Q = m(() => {
|
|
54
|
+
let t = p(_.lineItems, A), n = Z();
|
|
55
|
+
return _.setLineItemErrors(t), _.setTotalsErrors(n), !t && !n || (_.setErrors(void 0), t && e.error(A.lineItemsNeedAttention), W(), !1);
|
|
56
|
+
}, [
|
|
57
|
+
_,
|
|
58
|
+
A,
|
|
59
|
+
W,
|
|
60
|
+
Z
|
|
61
|
+
]), $ = m(async (e) => {
|
|
62
|
+
let t = !N && P ? {
|
|
63
|
+
base64EncodedFile: await ee(P),
|
|
64
|
+
fileName: P.name
|
|
65
|
+
} : void 0, n = l({
|
|
66
|
+
values: _.values,
|
|
67
|
+
counterpartId: v,
|
|
68
|
+
clearCounterpart: y,
|
|
69
|
+
counterpartBankAccountId: e,
|
|
70
|
+
editedTotals: _.isTotalsDirty ? {
|
|
71
|
+
discount: _.discount,
|
|
72
|
+
tax: _.tax,
|
|
73
|
+
total: _.totalOverride
|
|
74
|
+
} : void 0,
|
|
75
|
+
document: t
|
|
76
|
+
}), r = N;
|
|
77
|
+
if (r ? await q.mutateAsync({
|
|
78
|
+
path: { payable_id: r },
|
|
79
|
+
body: n
|
|
80
|
+
}) : (r = (await G.mutateAsync({ body: n }))?.id, r && (M(r), T?.(r), t && F(void 0))), !r) throw Error("Payable was created without an id");
|
|
81
|
+
if (L) {
|
|
82
|
+
try {
|
|
83
|
+
await K.mutateAsync({ path: { payable_id: r } });
|
|
84
|
+
} catch {}
|
|
85
|
+
R(!1);
|
|
86
|
+
}
|
|
87
|
+
return await J.mutateAsync({
|
|
88
|
+
path: { payable_id: r },
|
|
89
|
+
body: { data: u(_.lineItems) }
|
|
90
|
+
}), r;
|
|
91
|
+
}, [
|
|
92
|
+
v,
|
|
93
|
+
y,
|
|
94
|
+
G,
|
|
95
|
+
K,
|
|
96
|
+
L,
|
|
97
|
+
_.discount,
|
|
98
|
+
_.isTotalsDirty,
|
|
99
|
+
_.lineItems,
|
|
100
|
+
_.tax,
|
|
101
|
+
_.totalOverride,
|
|
102
|
+
_.values,
|
|
103
|
+
T,
|
|
104
|
+
N,
|
|
105
|
+
J,
|
|
106
|
+
P,
|
|
107
|
+
q
|
|
108
|
+
]), ne = m(async () => {
|
|
109
|
+
N && (await K.mutateAsync({ path: { payable_id: N } }), R(!1));
|
|
110
|
+
}, [K, N]);
|
|
29
111
|
return {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
112
|
+
saveDraft: m(async () => {
|
|
113
|
+
if (!H.current && Q()) {
|
|
114
|
+
H.current = !0, V("draft");
|
|
115
|
+
try {
|
|
116
|
+
let t = await C?.();
|
|
117
|
+
if (t && !t.ok) return;
|
|
118
|
+
let n = await $(t?.counterpartBankAccountId);
|
|
119
|
+
_.setErrors(void 0), w?.(n), D?.(n);
|
|
120
|
+
let r = await E?.();
|
|
121
|
+
return e.success(r === "draft" ? A.submittedDemoted : A.draftSaved), n;
|
|
122
|
+
} catch (e) {
|
|
123
|
+
_.setSaveFailureMessage(b(e) ? A.discountTaxBlockedByLineItems : A.saveFailed), W();
|
|
124
|
+
return;
|
|
125
|
+
} finally {
|
|
126
|
+
V(void 0), H.current = !1;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}, [
|
|
130
|
+
_,
|
|
131
|
+
Q,
|
|
132
|
+
A.discountTaxBlockedByLineItems,
|
|
133
|
+
A.draftSaved,
|
|
134
|
+
A.saveFailed,
|
|
135
|
+
A.submittedDemoted,
|
|
136
|
+
D,
|
|
137
|
+
w,
|
|
138
|
+
E,
|
|
139
|
+
C,
|
|
140
|
+
$,
|
|
141
|
+
W
|
|
142
|
+
]),
|
|
143
|
+
finalize: m(async () => {
|
|
144
|
+
if (H.current) return;
|
|
145
|
+
let t = p(_.lineItems, A), n = Z(), { formErrors: r, lineItemErrors: i } = d(_.values, v, _.lineItems, A), a = S(i, t);
|
|
146
|
+
_.setLineItemErrors(a), _.setTotalsErrors(n);
|
|
147
|
+
let o = r ?? {};
|
|
148
|
+
if (_.setErrors(Object.keys(o).length ? o : void 0), t && e.error(A.lineItemsNeedAttention), a || n || Object.keys(o).length) {
|
|
149
|
+
W();
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
H.current = !0, V("finalize");
|
|
153
|
+
try {
|
|
154
|
+
let t;
|
|
155
|
+
try {
|
|
156
|
+
let e = await C?.();
|
|
157
|
+
if (e && !e.ok) return;
|
|
158
|
+
t = await $(e?.counterpartBankAccountId);
|
|
159
|
+
} catch (e) {
|
|
160
|
+
_.setSaveFailureMessage(b(e) ? A.discountTaxBlockedByLineItems : A.saveFailed), W();
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
w?.(t);
|
|
164
|
+
try {
|
|
165
|
+
let n = await Y.mutateAsync({ path: { payable_id: t } });
|
|
166
|
+
if (n.validation_errors.length) {
|
|
167
|
+
let e = x(n.validation_errors, A);
|
|
168
|
+
_.setErrors(e.formErrors), _.setTotalsErrors(e.totalsErrors), W();
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
await X.mutateAsync({ path: { payable_id: t } }), _.setErrors(void 0), O?.(t), e.success(A.billFinalized);
|
|
172
|
+
} catch {
|
|
173
|
+
_.setSaveFailureMessage(A.finalizeFailed), W();
|
|
174
|
+
}
|
|
175
|
+
} finally {
|
|
176
|
+
V(void 0), H.current = !1;
|
|
177
|
+
}
|
|
178
|
+
}, [
|
|
179
|
+
v,
|
|
180
|
+
_,
|
|
181
|
+
A,
|
|
182
|
+
O,
|
|
183
|
+
w,
|
|
184
|
+
C,
|
|
185
|
+
$,
|
|
186
|
+
W,
|
|
187
|
+
X,
|
|
188
|
+
Z,
|
|
189
|
+
Y
|
|
190
|
+
]),
|
|
191
|
+
payableId: N,
|
|
192
|
+
isSavingDraft: B === "draft",
|
|
193
|
+
isFinalizing: B === "finalize",
|
|
194
|
+
stagedFile: P,
|
|
195
|
+
stageFile: F,
|
|
196
|
+
clearStagedFile: I,
|
|
197
|
+
scrollToErrorToken: U,
|
|
198
|
+
isFileDeletionPending: L,
|
|
199
|
+
requestFileDeletion: z,
|
|
200
|
+
detachFileNow: ne,
|
|
201
|
+
isDeletingFile: K.isPending,
|
|
202
|
+
hasFileDeletionFailed: K.isError
|
|
35
203
|
};
|
|
36
204
|
}
|
|
37
205
|
//#endregion
|
|
38
|
-
export {
|
|
206
|
+
export { x as mapValidationErrorsToForm, C as useBillCreateController };
|