@tesouro/embedded-components-react 0.5.8 → 0.5.9

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.
@@ -25,7 +25,8 @@ var p = {
25
25
  lineItemsNeedAttention: "Check the highlighted line items before saving.",
26
26
  unreadableDiscount: "Enter a valid discount amount.",
27
27
  unreadableTax: "Enter a valid tax amount.",
28
- unreadableTotal: "Enter a valid total amount."
28
+ unreadableTotal: "Enter a valid total amount.",
29
+ totalNotGreaterThanZero: "Total amount must be greater than $0."
29
30
  }, m = {
30
31
  achMethod: "via ACH bank transfer",
31
32
  noMethod: "No payment method on file",
@@ -27,9 +27,31 @@ function s(i, a, o, s = e) {
27
27
  lineItemErrors: Object.keys(l).length ? l : void 0
28
28
  };
29
29
  }
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;
30
+ function c(e) {
31
+ let t = e.trim();
32
+ if (!t) return !0;
33
+ let n = t.startsWith("-") ? t.slice(1) : t;
34
+ return i.test(n) ? Number(t.replaceAll(",", "")) <= 0 : !1;
35
+ }
36
+ function l(e, t) {
37
+ if (n(e) === null) return c(e) ? t.totalNotGreaterThanZero : t.unreadableTotal;
38
+ }
39
+ function u(t, n = e) {
40
+ let r = l(t, n);
41
+ return r ? { total: r } : void 0;
42
+ }
43
+ function d(t, r, i = e) {
44
+ if (t === void 0) return;
45
+ let a = n(t);
46
+ if (a !== null) return a - (n(r) ?? 0) > 0 ? void 0 : { total: i.totalNotGreaterThanZero };
47
+ }
48
+ function f(t, n, r, i = e) {
49
+ let o = {};
50
+ if (a(t) || (o.discount = i.unreadableDiscount), a(n) || (o.tax = i.unreadableTax), r !== void 0) {
51
+ let e = l(r, i);
52
+ e && (o.total = e);
53
+ }
54
+ return Object.keys(o).length ? o : void 0;
33
55
  }
34
56
  //#endregion
35
- export { a as isReadableMoneyOrZero, s as validateBillCompleteness, c as validateBillTotals, o as validateLineItems };
57
+ export { a as isReadableMoneyOrZero, s as validateBillCompleteness, u as validateBillTotalIsPayable, f as validateBillTotals, o as validateLineItems, d as validateStoredAmountDue };
@@ -9,27 +9,27 @@ import { useReplacePayableLineItemsMutation as n } from "../../data-access/dist/
9
9
  import { useCreatePayableMutation as r, useDeletePayableFileMutation as i, useSubmitPayableForApprovalMutation as a, useUpdatePayableMutation as o, useValidatePayableMutation as s } from "../../data-access/dist/index13.js";
10
10
  import "../../data-access/dist/index.js";
11
11
  import { BILL_CREATE_MESSAGE_LABELS_EN as c } from "./index47.js";
12
- import { encodeFileToBase64 as ee } from "./index53.js";
13
- import { mapBillFormToPayload as l, mapLineItemsToPayload as u } from "./index54.js";
14
- import { validateBillCompleteness as d, validateBillTotals as f, validateLineItems as p } from "./index55.js";
15
- import { useCallback as m, useRef as h, useState as g } from "react";
12
+ import { encodeFileToBase64 as l } from "./index53.js";
13
+ import { mapBillFormToPayload as u, mapLineItemsToPayload as d } from "./index54.js";
14
+ import { validateBillCompleteness as f, validateBillTotalIsPayable as p, validateBillTotals as m, validateLineItems as h, validateStoredAmountDue as ee } from "./index55.js";
15
+ import { useCallback as g, useRef as _, useState as v } from "react";
16
16
  //#region ../../libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index56.js
17
- var _ = {
17
+ var y = {
18
18
  document_id: "invoiceNumber",
19
19
  issued_at: "invoiceDate",
20
20
  due_date: "dueDate",
21
21
  counterpart_id: "vendor"
22
- }, v = { tax_amount: "tax" };
23
- function y(e) {
22
+ }, b = { tax_amount: "tax" };
23
+ function x(e) {
24
24
  return e.type === "type_error.none.not_allowed" || e.msg === "none is not an allowed value";
25
25
  }
26
- function b(e) {
26
+ function S(e) {
27
27
  return !!t(e)?.includes("line_items_enabled");
28
28
  }
29
- function x(e, t = c) {
29
+ function C(e, t = c) {
30
30
  let n = {}, r = {}, i = [];
31
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;
32
+ let e = a.loc[0] ?? t.unknownValidationField, o = y[e], s = b[e], c = x(a) ? t.requiredField : a.msg;
33
33
  o ? n[o] = c : s ? r[s] = c : i.push(t.unmappedValidationError(e, c));
34
34
  }
35
35
  return i.length && (n.form = i.join(" ")), {
@@ -37,7 +37,7 @@ function x(e, t = c) {
37
37
  totalsErrors: Object.keys(r).length ? r : void 0
38
38
  };
39
39
  }
40
- function S(e, t) {
40
+ function te(e, t) {
41
41
  if (!e && !t) return;
42
42
  let n = {}, r = /* @__PURE__ */ new Set([...Object.keys(e ?? {}), ...Object.keys(t ?? {})]);
43
43
  for (let i of r) n[i] = {
@@ -46,161 +46,165 @@ function S(e, t) {
46
46
  };
47
47
  return n;
48
48
  }
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 = {
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
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);
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
56
  }, [
57
- _,
58
- A,
57
+ y,
58
+ j,
59
59
  W,
60
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,
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
69
  counterpartBankAccountId: e,
70
- editedTotals: _.isTotalsDirty ? {
71
- discount: _.discount,
72
- tax: _.tax,
73
- total: _.totalOverride
70
+ editedTotals: y.isTotalsDirty ? {
71
+ discount: y.discount,
72
+ tax: y.tax,
73
+ total: y.totalOverride
74
74
  } : void 0,
75
75
  document: t
76
- }), r = N;
76
+ }), r = P;
77
77
  if (r ? await q.mutateAsync({
78
78
  path: { payable_id: r },
79
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) {
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
82
  try {
83
83
  await K.mutateAsync({ path: { payable_id: r } });
84
84
  } catch {}
85
- R(!1);
85
+ z(!1);
86
86
  }
87
87
  return await J.mutateAsync({
88
88
  path: { payable_id: r },
89
- body: { data: u(_.lineItems) }
89
+ body: { data: d(y.lineItems) }
90
90
  }), r;
91
91
  }, [
92
- v,
93
- y,
92
+ b,
93
+ x,
94
94
  G,
95
95
  K,
96
- L,
97
- _.discount,
98
- _.isTotalsDirty,
99
- _.lineItems,
100
- _.tax,
101
- _.totalOverride,
102
- _.values,
103
- T,
104
- N,
105
- J,
96
+ R,
97
+ y.discount,
98
+ y.isTotalsDirty,
99
+ y.lineItems,
100
+ y.tax,
101
+ y.totalOverride,
102
+ y.values,
103
+ E,
106
104
  P,
105
+ J,
106
+ F,
107
107
  q
108
- ]), ne = m(async () => {
109
- N && (await K.mutateAsync({ path: { payable_id: N } }), R(!1));
110
- }, [K, N]);
108
+ ]), ie = g(async () => {
109
+ P && (await K.mutateAsync({ path: { payable_id: P } }), z(!1));
110
+ }, [K, P]);
111
111
  return {
112
- saveDraft: m(async () => {
113
- if (!H.current && Q()) {
114
- H.current = !0, V("draft");
112
+ saveDraft: g(async () => {
113
+ if (!U.current && Q()) {
114
+ U.current = !0, H("draft");
115
115
  try {
116
- let t = await C?.();
116
+ let t = await w?.();
117
117
  if (t && !t.ok) return;
118
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;
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
122
  } catch (e) {
123
- _.setSaveFailureMessage(b(e) ? A.discountTaxBlockedByLineItems : A.saveFailed), W();
123
+ y.setSaveFailureMessage(S(e) ? j.discountTaxBlockedByLineItems : j.saveFailed), W();
124
124
  return;
125
125
  } finally {
126
- V(void 0), H.current = !1;
126
+ H(void 0), U.current = !1;
127
127
  }
128
128
  }
129
129
  }, [
130
- _,
130
+ y,
131
131
  Q,
132
- A.discountTaxBlockedByLineItems,
133
- A.draftSaved,
134
- A.saveFailed,
135
- A.submittedDemoted,
132
+ j.discountTaxBlockedByLineItems,
133
+ j.draftSaved,
134
+ j.saveFailed,
135
+ j.submittedDemoted,
136
+ O,
137
+ T,
136
138
  D,
137
139
  w,
138
- E,
139
- C,
140
140
  $,
141
141
  W
142
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) {
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) {
149
153
  W();
150
154
  return;
151
155
  }
152
- H.current = !0, V("finalize");
156
+ U.current = !0, H("finalize");
153
157
  try {
154
158
  let t;
155
159
  try {
156
- let e = await C?.();
160
+ let e = await w?.();
157
161
  if (e && !e.ok) return;
158
162
  t = await $(e?.counterpartBankAccountId);
159
163
  } catch (e) {
160
- _.setSaveFailureMessage(b(e) ? A.discountTaxBlockedByLineItems : A.saveFailed), W();
164
+ y.setSaveFailureMessage(S(e) ? j.discountTaxBlockedByLineItems : j.saveFailed), W();
161
165
  return;
162
166
  }
163
- w?.(t);
167
+ T?.(t);
164
168
  try {
165
169
  let n = await Y.mutateAsync({ path: { payable_id: t } });
166
170
  if (n.validation_errors.length) {
167
- let e = x(n.validation_errors, A);
168
- _.setErrors(e.formErrors), _.setTotalsErrors(e.totalsErrors), W();
171
+ let e = C(n.validation_errors, j);
172
+ y.setErrors(e.formErrors), y.setTotalsErrors(e.totalsErrors), W();
169
173
  return;
170
174
  }
171
- await X.mutateAsync({ path: { payable_id: t } }), _.setErrors(void 0), O?.(t), e.success(A.billFinalized);
175
+ await X.mutateAsync({ path: { payable_id: t } }), y.setErrors(void 0), k?.(t), e.success(j.billFinalized);
172
176
  } catch {
173
- _.setSaveFailureMessage(A.finalizeFailed), W();
177
+ y.setSaveFailureMessage(j.finalizeFailed), W();
174
178
  }
175
179
  } finally {
176
- V(void 0), H.current = !1;
180
+ H(void 0), U.current = !1;
177
181
  }
178
182
  }, [
179
- v,
180
- _,
181
- A,
182
- O,
183
+ b,
184
+ y,
185
+ j,
186
+ k,
187
+ T,
183
188
  w,
184
- C,
185
189
  $,
186
190
  W,
187
191
  X,
188
192
  Z,
189
193
  Y
190
194
  ]),
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,
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,
201
205
  isDeletingFile: K.isPending,
202
206
  hasFileDeletionFailed: K.isError
203
207
  };
204
208
  }
205
209
  //#endregion
206
- export { x as mapValidationErrorsToForm, C as useBillCreateController };
210
+ export { C as mapValidationErrorsToForm, w as useBillCreateController };
@@ -255,7 +255,7 @@ function E({ items: E, glCodeOptions: D, glCodeDisabled: O, glCodeUnavailableMes
255
255
  htmlFor: `${U}-discount`,
256
256
  children: H.discount
257
257
  }), /* @__PURE__ */ b("div", {
258
- className: "ttw:flex ttw:flex-col ttw:gap-1.5",
258
+ className: "ttw:flex ttw:flex-col ttw:items-end ttw:gap-1.5",
259
259
  children: [/* @__PURE__ */ b(n, {
260
260
  className: "ttw:w-36",
261
261
  children: [/* @__PURE__ */ y(r, {
@@ -282,7 +282,7 @@ function E({ items: E, glCodeOptions: D, glCodeDisabled: O, glCodeUnavailableMes
282
282
  htmlFor: `${U}-tax`,
283
283
  children: H.tax
284
284
  }), /* @__PURE__ */ b("div", {
285
- className: "ttw:flex ttw:flex-col ttw:gap-1.5",
285
+ className: "ttw:flex ttw:flex-col ttw:items-end ttw:gap-1.5",
286
286
  children: [/* @__PURE__ */ b(n, {
287
287
  className: "ttw:w-36",
288
288
  children: [/* @__PURE__ */ y(r, {
@@ -310,7 +310,7 @@ function E({ items: E, glCodeOptions: D, glCodeDisabled: O, glCodeUnavailableMes
310
310
  className: "ttw:font-semibold",
311
311
  children: H.totalAmount
312
312
  }), /* @__PURE__ */ b("div", {
313
- className: "ttw:flex ttw:flex-col ttw:gap-1.5",
313
+ className: "ttw:flex ttw:flex-col ttw:items-end ttw:gap-1.5",
314
314
  children: [/* @__PURE__ */ b(n, {
315
315
  className: "ttw:w-36",
316
316
  children: [/* @__PURE__ */ y(r, {
@@ -1,5 +1,5 @@
1
1
  //#region ../../libs/tesouro-embedded-components-react/shared/feature/dist/lib/analytics/build-info.js
2
- var e = "@tesouro/embedded-components-react", t = "0.5.8", n = "0b24256254d405d931c130ac6dac3c9f49a6e9e5", r = Object.freeze({
2
+ var e = "@tesouro/embedded-components-react", t = "0.5.9", n = "fa29013241e781286ad74752703fc9b45fd401b2", r = Object.freeze({
3
3
  library_name: e,
4
4
  library_version: t,
5
5
  library_sha: n
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tesouro/embedded-components-react",
3
- "version": "0.5.8",
3
+ "version": "0.5.9",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "packageDepSync": {