@tesouro/embedded-components-react 0.3.22 → 0.3.23

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 (91) hide show
  1. package/dist/index.js +1 -1
  2. package/dist/lib/BillPayWidget.js +1 -1
  3. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index.js +15 -15
  4. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index10.js +31 -32
  5. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index11.js +42 -1
  6. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index12.js +158 -43
  7. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index13.js +33 -4
  8. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index14.js +1 -16
  9. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index15.js +45 -12
  10. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index16.js +4 -64
  11. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index17.js +13 -26
  12. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index18.js +14 -62
  13. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index19.js +56 -123
  14. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index2.js +18 -3
  15. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index20.js +15 -10
  16. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index21.js +61 -40
  17. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index22.js +130 -50
  18. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index23.js +20 -4
  19. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index24.js +38 -69
  20. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index25.js +48 -46
  21. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index26.js +5 -93
  22. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index27.js +71 -34
  23. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index28.js +48 -139
  24. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index29.js +91 -66
  25. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index3.js +22 -5
  26. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index30.js +34 -22
  27. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index31.js +144 -210
  28. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index32.js +63 -209
  29. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index33.js +21 -103
  30. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index34.js +209 -12
  31. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index35.js +211 -44
  32. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index36.js +104 -30
  33. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index37.js +12 -165
  34. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index38.js +47 -35
  35. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index39.js +29 -99
  36. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index4.js +64 -5
  37. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index40.js +166 -12
  38. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index41.js +34 -243
  39. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index42.js +104 -4
  40. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index43.js +12 -27
  41. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index44.js +259 -81
  42. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index45.js +4 -145
  43. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index46.js +33 -3
  44. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index47.js +82 -2
  45. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index48.js +155 -37
  46. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index49.js +2 -0
  47. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index5.js +2 -6
  48. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index50.js +2 -6
  49. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index51.js +43 -9
  50. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index52.js +1 -94
  51. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index53.js +8 -3
  52. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index54.js +7 -5
  53. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index55.js +85 -13
  54. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index56.js +3 -59
  55. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index57.js +9 -3
  56. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index58.js +19 -120
  57. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index59.js +56 -8
  58. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index6.js +3 -32
  59. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index60.js +3 -46
  60. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index61.js +116 -15
  61. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index62.js +8 -28
  62. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index63.js +43 -83
  63. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index64.js +19 -47
  64. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index65.js +27 -249
  65. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index66.js +82 -109
  66. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index67.js +47 -206
  67. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index68.js +253 -4
  68. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index69.js +111 -6
  69. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index7.js +6 -39
  70. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index70.js +197 -102
  71. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index71.js +3 -0
  72. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index72.js +6 -23
  73. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index73.js +114 -0
  74. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index74.js +1 -0
  75. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index75.js +25 -0
  76. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index8.js +5 -24
  77. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index9.js +3 -162
  78. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index.js +9 -6
  79. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index82.js +10 -11
  80. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index83.js +123 -8
  81. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index84.js +2 -170
  82. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index85.js +18 -2
  83. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index86.js +7 -11
  84. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index87.js +163 -82
  85. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index88.js +1 -1
  86. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index89.js +14 -0
  87. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index90.js +89 -0
  88. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index91.js +2 -0
  89. package/dist/libs/tesouro-embedded-components-react/shared/feature/dist/lib/analytics/build-info.js +1 -1
  90. package/dist/libs/tesouro-embedded-components-react/widget-suite/feature/dist/index7.js +1 -1
  91. package/package.json +1 -1
@@ -1,104 +1,34 @@
1
- "use client";
2
- "use client";
3
- "use client";
4
- "use client";
5
- import { calculateTotal as e, displayLineAmount as t, parseMoneyToMinorUnits as n } from "./index35.js";
6
- import { emptyLineItem as r, mapPayableToBillForm as i } from "./index38.js";
7
- import { useCallback as a, useEffect as o, useMemo as s, useState as c } from "react";
1
+ import { BILL_CREATE_MESSAGE_LABELS_EN as e } from "./index31.js";
2
+ import { isPersistableLineItem as t, parseMoneyToMinorUnits as n, parseQuantity as r } from "./index38.js";
8
3
  //#region ../../libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index39.js
9
- function l(e, r, i) {
10
- return n(r) === null ? i : t(e, r);
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;
11
8
  }
12
- function u({ payable: t, lineItems: n } = {}) {
13
- let u = s(() => i({
14
- payable: t ?? {},
15
- lineItems: n ?? []
16
- }), [t, n]), [d, f] = c(u.values), [p, m] = c(u.lineItems), [h, g] = c(u.discount), [_, v] = c(u.tax), [y, b] = c(u.total || void 0), [x, S] = c(), [C, w] = c(), [T, E] = c(!1), [D, O] = c(!1), [k, A] = c(!1);
17
- o(() => {
18
- T || f(u.values);
19
- }, [u]), o(() => {
20
- D || m(u.lineItems);
21
- }, [u]), o(() => {
22
- k || (g(u.discount), v(u.tax), b(u.total || void 0));
23
- }, [u]);
24
- let j = a((e) => {
25
- f((t) => ({
26
- ...t,
27
- ...e
28
- })), E(!0);
29
- }, []), M = a((e) => {
30
- w((t) => {
31
- if (!t?.[e]) return t;
32
- let n = { ...t };
33
- return delete n[e], Object.keys(n).length ? n : void 0;
34
- });
35
- }, []), N = a((e, t) => {
36
- M(e), m((n) => n.map((n) => {
37
- if (n.id !== e) return n;
38
- let r = {
39
- ...n,
40
- ...t
41
- };
42
- return "amount" in t ? r : {
43
- ...r,
44
- amount: l(r.quantity, r.price, r.amount)
45
- };
46
- })), O(!0), b(void 0);
47
- }, [M]), P = a((e, t) => {
48
- M(e), m((n) => n.map((n) => {
49
- if (n.id !== e) return n;
50
- let r = Number.parseFloat(n.quantity), i = String(Math.max(1, (Number.isFinite(r) ? r : 1) + t));
51
- return {
52
- ...n,
53
- quantity: i,
54
- amount: l(i, n.price, n.amount)
55
- };
56
- })), O(!0), b(void 0);
57
- }, [M]), F = a((e) => {
58
- M(e), m((t) => t.length <= 1 ? t : t.filter((t) => t.id !== e)), O(!0), b(void 0);
59
- }, [M]), I = a(() => {
60
- m((e) => [...e, r()]), O(!0), b(void 0);
61
- }, []), L = a((e) => {
62
- g(e), A(!0), b(void 0);
63
- }, []), R = a((e) => {
64
- v(e), A(!0), b(void 0);
65
- }, []), z = a((e) => {
66
- b(e), A(!0);
67
- }, []), B = s(() => p.map((e) => ({
68
- ...e,
69
- onChange: (t) => N(e.id, t),
70
- onQuantityStep: (t) => P(e.id, t),
71
- onRemove: () => F(e.id)
72
- })), [
73
- p,
74
- N,
75
- F,
76
- P
77
- ]), V = s(() => e(p, _, h), [
78
- p,
79
- _,
80
- h
81
- ]);
82
- return {
83
- values: d,
84
- errors: x,
85
- setErrors: S,
86
- lineItemErrors: C,
87
- setLineItemErrors: w,
88
- onChange: j,
89
- lineItems: p,
90
- lineItemRows: B,
91
- discount: h,
92
- onDiscountChange: L,
93
- tax: _,
94
- onTaxChange: R,
95
- total: y ?? V,
96
- totalOverride: y,
97
- onTotalChange: z,
98
- onAddLineItem: I,
99
- isTotalsDirty: k,
100
- isDirty: T || D || k
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
101
28
  };
102
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;
32
+ }
103
33
  //#endregion
104
- export { u as useBillForm };
34
+ export { s as validateBillCompleteness, c as validateBillTotals, o as validateLineItems };
@@ -1,7 +1,66 @@
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 { formatCalendarDate as t } from "../../../shared/util/dist/lib/formatCalendarDate.js";
8
+ import { formatMoneyExact as n } from "../../../shared/util/dist/lib/formatMoneyExact.js";
9
+ import { extractApiErrorMessage as r } from "../../../shared/util/dist/lib/apiErrors.js";
10
+ import { dateToCalendarKey as i, getDefaultPaymentDate as a, isTodayInEastern as o } from "./index3.js";
11
+ import { useMarkPayableAsPaidMutation as s } from "../../data-access/dist/index10.js";
12
+ import "../../data-access/dist/index.js";
13
+ import { mergeMarkAsPaidFlowLabels as c } from "./index2.js";
14
+ import { useEffect as l, useState as u } from "react";
1
15
  //#region ../../libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index4.js
2
- var e = {
3
- scheduleDialog: "pay-bill-schedule-dialog",
4
- reviewDialog: "pay-bill-review-dialog"
5
- };
16
+ function d({ payableId: d, amountDueMinorUnits: f, amountToPayMinorUnits: p, currencyCode: m, dueDate: h, hasScheduledPayment: g, testId: _, labels: v }) {
17
+ let y = c(v), b = s(), [x, S] = u(!1), [C, w] = u(void 0), [T, E] = u(""), D = x && !g, O = n(f / 100, { currencyCode: m }), k = n((p ?? f) / 100, { currencyCode: m }), A = C ? t(i(C)) : void 0, j = h ? y.dueDateSuffix(t(h)) : void 0, M = () => {
18
+ S(!1), w(void 0), E("");
19
+ };
20
+ return l(() => {
21
+ g && (S(!1), w(void 0), E(""));
22
+ }, [g]), {
23
+ open: () => {
24
+ w(a()), E(""), S(!0);
25
+ },
26
+ isPending: b.isPending,
27
+ dialogProps: {
28
+ open: D,
29
+ amountDue: O,
30
+ dueDateSuffix: j,
31
+ paymentAmount: k,
32
+ selectedDate: C,
33
+ selectedDateLabel: A,
34
+ isToday: C ? o(C) : !1,
35
+ comment: T,
36
+ isSubmitting: b.isPending,
37
+ onDateChange: w,
38
+ onCommentChange: E,
39
+ onConfirm: () => {
40
+ !d || !C || b.isPending || g || b.mutate({
41
+ path: { payable_id: d },
42
+ body: {
43
+ paid_at: `${i(C)}T12:00:00.000Z`,
44
+ is_external: !0,
45
+ ...T.trim() ? { comment: T.trim() } : {}
46
+ }
47
+ }, {
48
+ onSuccess: () => {
49
+ e.success(y.paidToast), M();
50
+ },
51
+ onError: (t) => {
52
+ e.error(r(t) ?? y.submitError);
53
+ }
54
+ });
55
+ },
56
+ onCancel: () => {
57
+ b.isPending || M();
58
+ },
59
+ testId: _ ? `${_}-mark-as-paid-dialog` : void 0,
60
+ confirmTestId: _ ? `${_}-mark-as-paid-confirm` : void 0,
61
+ labels: y.dialog
62
+ }
63
+ };
64
+ }
6
65
  //#endregion
7
- export { e as payBillFlowTestIds };
66
+ export { d as useMarkAsPaidFlow };
@@ -1,15 +1,169 @@
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 "./index31.js";
11
+ import { encodeFileToBase64 as s } from "./index37.js";
12
+ import { mapBillFormToPayload as c, mapLineItemsToPayload as l } from "./index38.js";
13
+ import { validateBillCompleteness as u, validateBillTotals as d, validateLineItems as f } from "./index39.js";
14
+ import { useCallback as p, useRef as m, useState as h } from "react";
1
15
  //#region ../../libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index40.js
2
- var e = {
3
- dialog: "bill-pay-bill-create-dialog",
4
- vendorSection: "bill-pay-bill-create-vendor",
5
- lineItems: "bill-pay-bill-create-line-items",
6
- documentPanel: "bill-pay-bill-create-document",
7
- duplicateNotice: "bill-pay-bill-create-duplicate-notice",
8
- decisionDialog: "bill-pay-bill-decision-dialog",
9
- decisionConfirm: "bill-pay-bill-decision-confirm",
10
- decisionReason: "bill-pay-bill-decision-reason",
11
- deleteDraftDialog: "bill-pay-bill-delete-draft-dialog",
12
- deleteDraftConfirm: "bill-pay-bill-delete-draft-confirm"
16
+ var g = {
17
+ document_id: "invoiceNumber",
18
+ issued_at: "invoiceDate",
19
+ due_date: "dueDate",
20
+ counterpart_id: "vendor"
13
21
  };
22
+ function _(e) {
23
+ return e.type === "type_error.none.not_allowed" || e.msg === "none is not an allowed value";
24
+ }
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));
30
+ }
31
+ return r.length && (n.form = r.join(" ")), n;
32
+ }
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]
39
+ };
40
+ return n;
41
+ }
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 (e) => {
50
+ let t = !j && M ? {
51
+ base64EncodedFile: await s(M),
52
+ fileName: M.name
53
+ } : void 0, n = c({
54
+ values: _.values,
55
+ counterpartId: b,
56
+ clearCounterpart: x,
57
+ counterpartBankAccountId: e,
58
+ editedTotals: _.isTotalsDirty ? {
59
+ discount: _.discount,
60
+ tax: _.tax,
61
+ total: _.totalOverride
62
+ } : void 0,
63
+ document: t
64
+ }), r = j;
65
+ if (r ? await z.mutateAsync({
66
+ path: { payable_id: r },
67
+ body: n
68
+ }) : (r = (await R.mutateAsync({ body: n }))?.id, r && (A(r), w?.(r), t && N(void 0))), !r) throw Error("Payable was created without an id");
69
+ return await B.mutateAsync({
70
+ path: { payable_id: r },
71
+ body: { data: l(_.lineItems) }
72
+ }), r;
73
+ }, [
74
+ b,
75
+ x,
76
+ R,
77
+ _.discount,
78
+ _.isTotalsDirty,
79
+ _.lineItems,
80
+ _.tax,
81
+ _.totalOverride,
82
+ _.values,
83
+ w,
84
+ j,
85
+ B,
86
+ M,
87
+ z
88
+ ]);
89
+ return {
90
+ saveDraft: p(async () => {
91
+ if (!L.current && U()) {
92
+ L.current = !0, I("draft");
93
+ try {
94
+ let t = await S?.();
95
+ if (t && !t.ok) return;
96
+ let n = await W(t?.counterpartBankAccountId);
97
+ _.setErrors(void 0), C?.(n), T?.(n), e.success(O.draftSaved);
98
+ } catch {
99
+ _.setErrors({ form: O.saveFailed });
100
+ } finally {
101
+ I(void 0), L.current = !1;
102
+ }
103
+ }
104
+ }, [
105
+ _,
106
+ U,
107
+ O.draftSaved,
108
+ O.saveFailed,
109
+ T,
110
+ C,
111
+ S,
112
+ W
113
+ ]),
114
+ finalize: p(async () => {
115
+ if (L.current) return;
116
+ let t = f(_.lineItems, O), n = d(_.discount, _.tax, _.totalOverride, O), { formErrors: r, lineItemErrors: i } = u(_.values, b, _.lineItems, O), a = y(i, t);
117
+ _.setLineItemErrors(a);
118
+ let o = {
119
+ ...r,
120
+ ...n
121
+ };
122
+ if (_.setErrors(Object.keys(o).length ? o : void 0), t && e.error(O.lineItemsNeedAttention), !(a || Object.keys(o).length)) {
123
+ L.current = !0, I("finalize");
124
+ try {
125
+ let t;
126
+ try {
127
+ let e = await S?.();
128
+ if (e && !e.ok) return;
129
+ t = await W(e?.counterpartBankAccountId);
130
+ } catch {
131
+ _.setErrors({ form: O.saveFailed });
132
+ return;
133
+ }
134
+ C?.(t);
135
+ try {
136
+ let n = await V.mutateAsync({ path: { payable_id: t } });
137
+ if (n.validation_errors.length) {
138
+ _.setErrors(v(n.validation_errors, O));
139
+ return;
140
+ }
141
+ await H.mutateAsync({ path: { payable_id: t } }), _.setErrors(void 0), E?.(t), e.success(O.billFinalized);
142
+ } catch {
143
+ _.setErrors({ form: O.finalizeFailed });
144
+ }
145
+ } finally {
146
+ I(void 0), L.current = !1;
147
+ }
148
+ }
149
+ }, [
150
+ b,
151
+ _,
152
+ O,
153
+ E,
154
+ C,
155
+ S,
156
+ W,
157
+ H,
158
+ V
159
+ ]),
160
+ payableId: j,
161
+ isSavingDraft: F === "draft",
162
+ isFinalizing: F === "finalize",
163
+ stagedFile: M,
164
+ stageFile: N,
165
+ clearStagedFile: P
166
+ };
167
+ }
14
168
  //#endregion
15
- export { e as billCreateTestIds };
169
+ export { v as mapValidationErrorsToForm, b as useBillCreateController };
@@ -1,247 +1,38 @@
1
- "use client";
2
- "use client";
3
- "use client";
4
- "use client";
5
- import { hasAnyScope as e } from "../../../shared/data-access/dist/lib/hasAnyScope.js";
6
- import { Scope as t } from "../../../shared/data-access/dist/lib/scopes.js";
7
- import { useAllLedgerAccountsQuery as ee } from "../../../shared/data-access/dist/lib/reference-data/useLedgerAccountsQuery.js";
8
- import { useAllOrganizationUsersQuery as te } from "../../../shared/data-access/dist/lib/user/useAllOrganizationUsersQuery.js";
9
- import "../../../shared/data-access/dist/index.js";
10
- import { formatCalendarDate as ne } from "../../../shared/util/dist/lib/formatCalendarDate.js";
11
- import { useWidgetConfig as re } from "../../../shared/feature/dist/lib/WidgetProvider/hooks.js";
12
- import "../../../shared/feature/dist/index.js";
13
- import { resolveVendor as ie } from "./index3.js";
14
- import { BillCreateScreen as ae } from "../../ui/dist/index41.js";
15
- import { BillDecisionDialog as n } from "../../ui/dist/index47.js";
16
- import { BillDuplicateNotice as oe } from "../../ui/dist/index57.js";
17
- import { ExtractionNotice as se } from "../../ui/dist/index74.js";
18
- import "../../ui/dist/index.js";
19
- import { usePayableHistoryQuery as ce } from "../../data-access/dist/index6.js";
20
- import { useAllPayableLineItemsQuery as le } from "../../data-access/dist/index7.js";
21
- import { usePayableQuery as ue } from "../../data-access/dist/index13.js";
22
- import "../../data-access/dist/index.js";
23
- import { PayBillFlow as de } from "./index10.js";
24
- import "./index11.js";
25
- import { mergeBillCreateScreenCopy as fe } from "./index28.js";
26
- import { useBillCreateController as pe } from "./index37.js";
27
- import { useBillForm as me } from "./index39.js";
28
- import { useApprovalPolicyCardView as he } from "./index16.js";
29
- import { useCurrentApprovalRequestId as ge } from "./index17.js";
30
- import { usePayableDetailActions as _e } from "./index19.js";
31
- import { useScheduledPayment as r } from "./index20.js";
32
- import { useDraftDelete as ve } from "./index21.js";
33
- import { buildBillDetailView as ye } from "./index24.js";
34
- import { buildBillHistory as be } from "./index25.js";
35
- import { SourceDocumentContainer as xe } from "./index29.js";
36
- import { useVendorSectionProps as Se } from "./index32.js";
37
- import { usePaymentInstructionsForm as Ce } from "./index33.js";
38
- import { billCreateTestIds as i } from "./index40.js";
39
- import { useCallback as a, useEffect as we, useMemo as o, useRef as Te, useState as s } from "react";
40
- import { Fragment as c, jsx as l, jsxs as u } from "react/jsx-runtime";
41
1
  //#region ../../libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index41.js
42
- function Ee(e) {
43
- return !!(e?.bank_account?.account_holder_name && e.bank_account.routing_number && e.bank_account.account_number);
2
+ function e() {
3
+ return {
4
+ id: crypto.randomUUID(),
5
+ description: "",
6
+ glCode: "",
7
+ quantity: "1",
8
+ price: "",
9
+ amount: ""
10
+ };
44
11
  }
45
- function d({ open: d, onOpenChange: f, payableId: p, readOnly: m = !1, copy: h, poweredByBankName: De, isPossibleDuplicate: Oe }) {
46
- let g = o(() => fe(h), [h]), [_, v] = s(), [y, b] = s(!1), [ke, x] = s(!1), [Ae, S] = s(!1), [C, w] = s(), T = p ?? C, E = ue(T, { pollWhileOcrProcessing: !0 }), D = le(T), O = ee(), k = E.data, A = me({
47
- payable: k,
48
- lineItems: D.lineItems
49
- }), j = k?.counterpart_id;
50
- we(() => {
51
- y || j && (v(j), b(!0));
52
- }, [y, j]);
53
- let je = a((e) => {
54
- b(!0), v(e);
55
- }, []), M = Se({
56
- payableId: m ? void 0 : T,
57
- counterpartId: m ? void 0 : _,
58
- payableCounterpartId: j,
59
- onCounterpartChange: je,
60
- requiredError: A.errors?.vendor,
61
- payableCounterpartBankAccountId: k?.counterpart_bank_account_id ?? void 0,
62
- extractedVendor: k?.counterpart_raw_data ?? void 0
63
- }), N = pe({
64
- payableId: p,
65
- form: A,
66
- counterpartId: _,
67
- clearCounterpart: !!(T && y) && !_,
68
- prepareVendorForSave: M.savePaymentInstructions,
69
- onPayableCreated: w,
70
- onSaved: w,
71
- onDraftSaved: () => f(!1),
72
- onFinalized: () => f(!1)
73
- }), P = !!(N.isSavingDraft || N.isFinalizing), F = m ? T : void 0, I = ge({
74
- payableId: F,
75
- status: k?.status
76
- }), L = Te(null), R = r({
77
- payableId: T,
78
- scheduledPaymentDate: k?.scheduled_payment_date,
79
- enabled: m
80
- }), z = ie(k), B = Ce({
81
- payableId: F,
82
- counterpartId: m ? j : void 0,
83
- saveErrorMessage: g.detail.paymentInstructionsSaveError,
84
- linkErrorMessage: g.detail.paymentInstructionsLinkError
85
- }), { initResponse: V } = re(), H = e(V?.scopes, [t.CounterpartWriteOrg]) && e(V?.scopes, [t.PayableWriteOrg]), U = he({
86
- payableId: F,
87
- approvalPolicyId: k?.approval_policy_id,
88
- enabled: m,
89
- copy: g.approvalPolicyCopy
90
- }), { actions: Me, decisionDialog: Ne } = _e({
91
- payableId: F,
92
- status: k?.status,
93
- currentApprovalRequestId: I.id,
94
- isPolicyApprover: I.isPolicyApprover,
95
- hasWaitingRequest: I.hasWaitingRequest,
96
- hasScheduledPayment: R.hasScheduledPayment,
97
- scheduledPaymentRecordId: R.scheduledPaymentRecordId,
98
- isScheduledPaymentUnknown: R.isResolving,
99
- pendingApprovers: U.pendingApprovers,
100
- labels: g.actions,
101
- onPayBillSelect: () => Ee(z) || !H ? L.current?.open() : B.open()
102
- }), W = ve({
103
- payableId: T,
104
- status: k?.status,
105
- enabled: !m,
106
- labels: g.deleteDraft,
107
- onDeleted: () => f(!1)
108
- }), G = o(() => (O.data?.data ?? []).map((e) => ({
109
- value: e.id,
110
- label: [e.nominal_code, e.name].filter(Boolean).join(" — ")
111
- })), [O.data]), K = ce(F), Pe = e(V?.scopes, [t.UserReadOrg]), q = te({ enabled: m && Pe }), J = o(() => be(K.data?.data ?? [], q.data?.data ?? [], g.history), [
112
- K.data,
113
- q.data,
114
- g.history
115
- ]), Fe = o(() => m && k ? ye({
116
- payable: k,
117
- lineItems: D.lineItems,
118
- glCodeOptions: G,
119
- history: J,
120
- approvalPolicy: U.view,
121
- labels: g.detail,
122
- hasScheduledPayment: R.hasScheduledPayment
123
- }) : void 0, [
124
- R.hasScheduledPayment,
125
- U.view,
126
- g.detail,
127
- G,
128
- J,
129
- D.lineItems,
130
- k,
131
- m
132
- ]), Y = k?.source_of_payable_data === "ocr", X = z?.name, Ie = m ? X ? g.viewTitle(X) : g.readOnlyTitle : Y && X ? g.extractedTitle(X) : g.newTitle, Le = m && k?.created_at ? g.addedOn(ne(k.created_at.slice(0, 10))) : void 0, Z = a(() => {
133
- let e = A.isDirty || M.hasUnsavedVendorChanges || !!N.stagedFile;
134
- !m && e && !window.confirm(g.discardConfirm) || f(!1);
135
- }, [
136
- N.stagedFile,
137
- g.discardConfirm,
138
- A.isDirty,
139
- f,
140
- m,
141
- M.hasUnsavedVendorChanges
142
- ]), Re = a((e) => {
143
- if (!P) return e ? f(!0) : Z();
144
- }, [
145
- Z,
146
- P,
147
- f
148
- ]), Q = !!Oe && !Ae, $ = !m && Y && !ke, ze = Q || $ ? /* @__PURE__ */ u(c, { children: [Q ? /* @__PURE__ */ l(oe, {
149
- onNotADuplicate: m ? void 0 : () => S(!0),
150
- onRemoveBill: m ? void 0 : () => S(!0),
151
- testId: i.duplicateNotice
152
- }) : null, $ ? /* @__PURE__ */ l(se, { onDismiss: () => x(!0) }) : null] }) : void 0;
153
- return /* @__PURE__ */ u(c, { children: [
154
- /* @__PURE__ */ l(ae, {
155
- open: d,
156
- onOpenChange: Re,
157
- title: Ie,
158
- subtitle: Le,
159
- notice: ze,
160
- vendor: {
161
- ...M,
162
- testId: i.vendorSection
163
- },
164
- values: A.values,
165
- errors: A.errors,
166
- onChange: A.onChange,
167
- lineItems: {
168
- items: A.lineItemRows,
169
- glCodeOptions: G,
170
- discount: A.discount,
171
- onDiscountChange: A.onDiscountChange,
172
- tax: A.tax,
173
- onTaxChange: A.onTaxChange,
174
- total: A.total,
175
- onTotalChange: A.onTotalChange,
176
- onAddLineItem: A.onAddLineItem,
177
- errors: A.lineItemErrors,
178
- testId: i.lineItems
179
- },
180
- documentPanel: /* @__PURE__ */ l(xe, {
181
- payableId: T,
182
- readOnly: m,
183
- isDocumentPending: !!T && !k?.file && (E.isLoading || k?.ocr_status === "processing"),
184
- file: k?.file ? {
185
- id: k.file.id,
186
- name: k.file.name,
187
- url: k.file.url,
188
- mimetype: k.file.mimetype
189
- } : void 0,
190
- staging: {
191
- stagedFile: N.stagedFile,
192
- onFileStaged: N.stageFile,
193
- onClearStagedFile: N.clearStagedFile,
194
- isSaving: P
195
- }
196
- }),
197
- menuItems: W.menuItems,
198
- readOnly: m,
199
- detail: m ? {
200
- view: Fe,
201
- actions: Me,
202
- scheduledSummary: R.hasScheduledPayment && R.scheduledDateLabel ? g.scheduledSummary(R.scheduledDateLabel) : void 0,
203
- paymentInstructionsForm: j && H ? {
204
- isOpen: B.isOpen,
205
- values: B.values,
206
- errors: B.errors,
207
- isSaving: B.isSaving,
208
- onOpen: B.open,
209
- onCancel: B.close,
210
- onChange: B.onChange,
211
- onSave: B.save
212
- } : void 0,
213
- isLoading: E.isLoading || D.isResolving || O.isResolving,
214
- isError: E.isError || D.isError || O.isError
215
- } : void 0,
216
- isLineItemsLoading: D.isResolving,
217
- isSaving: P,
218
- isSavingDraft: N.isSavingDraft,
219
- isFinalizing: N.isFinalizing,
220
- onCancel: Z,
221
- onSaveDraft: N.saveDraft,
222
- onFinalize: N.finalize,
223
- testId: i.dialog
224
- }),
225
- /* @__PURE__ */ l(n, {
226
- ...Ne,
227
- labels: { cancelButton: g.actions.decisionDialog.cancelButton },
228
- testId: i.decisionDialog,
229
- confirmTestId: i.decisionConfirm,
230
- reasonTestId: i.decisionReason
231
- }),
232
- /* @__PURE__ */ l(n, {
233
- ...W.dialog,
234
- labels: { cancelButton: g.actions.decisionDialog.cancelButton },
235
- testId: i.deleteDraftDialog,
236
- confirmTestId: i.deleteDraftConfirm
237
- }),
238
- m && k ? /* @__PURE__ */ l(de, {
239
- ref: L,
240
- payable: k,
241
- poweredByBankName: De,
242
- labels: g.payBill
243
- }) : null
244
- ] });
12
+ function t(e) {
13
+ return typeof e == "number" ? (e / 100).toFixed(2) : "";
14
+ }
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
+ }));
29
+ return {
30
+ values: i,
31
+ lineItems: a.length ? a : [e()],
32
+ discount: t(n.discount),
33
+ tax: t(n.tax_amount),
34
+ total: t(n.total_amount)
35
+ };
245
36
  }
246
37
  //#endregion
247
- export { d as BillCreateDialog, d as default };
38
+ export { e as emptyLineItem, n as mapPayableToBillForm };