@tesouro/embedded-components-react 0.5.280 → 0.5.281

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 (52) hide show
  1. package/dist/index.css +8 -0
  2. package/dist/index.d.ts +2 -2
  3. package/dist/lib/BankAccountOnboardingWidget.d.ts +2 -2
  4. package/dist/lib/WidgetSuite.d.ts +2 -2
  5. package/dist/libs/tesouro-embedded-components-react/bank-account-onboarding-widget/feature/dist/lib/BankAccountOnboardingWidget/labels.js +2 -2
  6. package/dist/libs/tesouro-embedded-components-react/bank-account-onboarding-widget/ui/dist/index30.js +1 -1
  7. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/data-access/dist/index18.js +1 -0
  8. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index.js +6 -6
  9. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index13.js +8 -8
  10. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index14.js +7 -28
  11. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index15.js +8 -160
  12. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index16.js +20 -13
  13. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index17.js +148 -27
  14. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index18.js +21 -96
  15. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index19.js +37 -79
  16. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index20.js +98 -3
  17. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index21.js +83 -54
  18. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index22.js +3 -113
  19. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index23.js +54 -184
  20. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index24.js +108 -75
  21. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index25.js +181 -29
  22. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index26.js +74 -83
  23. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index27.js +27 -412
  24. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index28.js +88 -12
  25. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index29.js +413 -77
  26. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index30.js +13 -80
  27. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index31.js +77 -226
  28. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index32.js +78 -41
  29. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index33.js +216 -234
  30. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index34.js +44 -23
  31. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index35.js +233 -611
  32. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index36.js +25 -4
  33. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index37.js +647 -39
  34. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index38.js +4 -243
  35. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index39.js +42 -3
  36. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index40.js +250 -3
  37. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index41.js +2 -66
  38. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index42.js +5 -1
  39. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index43.js +67 -0
  40. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index44.js +1 -0
  41. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/ui/dist/index12.js +11 -11
  42. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/ui/dist/index15.js +47 -47
  43. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/data-access/dist/lib/invalidatePayableQueries/invalidatePayableQueries.js +2 -2
  44. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/data-access/dist/lib/invalidatePayableQueries/reconcileCancelledPaymentQueries.js +19 -19
  45. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/lib/BillPayWidgetNative/BillsTab.js +1 -1
  46. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/pay-bill/data-access/dist/index4.js +15 -15
  47. package/dist/libs/tesouro-embedded-components-react/shared/data-access/dist/lib/rest/zod.gen.js +2 -0
  48. package/dist/libs/tesouro-embedded-components-react/shared/data-access/dist/lib/user/useAllOrganizationUsersQuery.js +1 -0
  49. package/dist/libs/tesouro-embedded-components-react/shared/feature/dist/lib/analytics/build-info.js +1 -1
  50. package/dist/libs/tesouro-embedded-components-react/shared/ui/dist/lib/OnboardingShell/OnboardingShell.js +1 -1
  51. package/dist/libs/tesouro-embedded-components-react/shared/ui/dist/lib/OnboardingShell/labels.js +2 -2
  52. package/package.json +1 -1
@@ -2,631 +2,253 @@
2
2
  "use client";
3
3
  "use client";
4
4
  "use client";
5
- import { toast as e } from "../../../../../../packages/shared-ui-shadcn/dist/index.js";
6
- import { formatCalendarDate as t } from "../../../../shared/util/dist/lib/formatCalendarDate.js";
7
- import { buildPayableAuditHistory as n, hasUnattributedAuditRows as r } from "../../../../shared/util/dist/lib/auditHistory/buildPayableAuditHistory.js";
8
- import { hasAnyScope as i } from "../../../../shared/data-access/dist/lib/hasAnyScope.js";
9
- import { Scope as a } from "../../../../shared/data-access/dist/lib/scopes.js";
10
- import { useAllLedgerAccountsQuery as ee } from "../../../../shared/data-access/dist/lib/reference-data/useLedgerAccountsQuery.js";
11
- import "../../../../shared/data-access/dist/index.js";
12
- import "../../../../shared/ui/dist/index.js";
13
- import { useWidgetConfig as te } from "../../../../shared/feature/dist/lib/WidgetProvider/hooks.js";
14
- import { useOrganizationUserNames as ne } from "../../../../shared/feature/dist/lib/user/useOrganizationUserNames.js";
15
- import { useLocalCalendarDay as re } from "../../../../shared/feature/dist/lib/calendar/useLocalCalendarDay.js";
16
- import "../../../../shared/feature/dist/index.js";
17
- import { hasUnpaidBalance as ie } from "../../../util/dist/lib/derivePayableStatus.js";
18
- import { formatScheduledDateLabel as ae } from "../../../util/dist/lib/formatScheduledDateLabel.js";
19
- import { isEditablePayableStatus as oe } from "../../../util/dist/lib/isEditablePayableStatus.js";
20
- import { resolveVendor as se } from "../../../util/dist/lib/resolveVendor.js";
21
- import { BillDecisionDialog as o } from "../../../ui/dist/index4.js";
22
- import "../../../ui/dist/index.js";
23
- import { BillCreateScreen as ce } from "../../ui/dist/index31.js";
24
- import { BillDuplicateNotice as le } from "../../ui/dist/index37.js";
25
- import { BillRejectedBanner as ue } from "../../ui/dist/index40.js";
26
- import { DiscardChangesDialog as de } from "../../ui/dist/index43.js";
27
- import { ExtractionNotice as fe } from "../../ui/dist/index46.js";
28
- import { UnsavedBillDialog as pe } from "../../ui/dist/index52.js";
29
- import "../../ui/dist/index.js";
30
- import { BILL_CREATE_MESSAGE_LABELS_EN as me, mergeBillCreateScreenCopy as he } from "./index23.js";
31
- import { usePayableApprovalRequestsQuery as ge } from "../../data-access/dist/index2.js";
32
- import { usePayableHistoryQuery as _e } from "../../data-access/dist/index3.js";
33
- import { useAllPayableLineItemsQuery as ve } from "../../data-access/dist/index4.js";
34
- import { useUpdatePayableMutation as ye } from "../../data-access/dist/index15.js";
35
- import { usePayableQuery as be } from "../../data-access/dist/index21.js";
36
- import "../../data-access/dist/index.js";
37
- import { useBillCreateController as xe } from "./index31.js";
38
- import { useBillForm as Se } from "./index33.js";
39
- import { buildPaymentHistory as Ce } from "./index2.js";
40
- import { currentApprovalRound as we } from "./index3.js";
41
- import { usePayableDuplicateReview as Te } from "./index6.js";
42
- import { canOverrideApprovalPolicy as Ee, canReadCounterpartBankAccounts as De } from "./index7.js";
43
- import { usePayableApprovalRoundStart as Oe } from "./index11.js";
44
- import { useApprovalPolicyCardView as ke } from "./index12.js";
45
- import { resolveBillRejectionNotice as Ae } from "./index13.js";
46
- import { useCurrentApprovalRequestId as je } from "./index14.js";
47
- import { usePayableDetailActions as Me } from "./index15.js";
48
- import { useScheduledPayment as Ne } from "./index16.js";
49
- import { useDraftDelete as Pe } from "./index17.js";
50
- import { buildBillDetailView as Fe } from "./index19.js";
51
- import { resolveEditorDismissal as Ie } from "./index20.js";
52
- import { SourceDocumentContainer as Le } from "./index24.js";
53
- import { usePayableAchInstructions as Re } from "../../../../shared/counterpart-management/feature/dist/lib/usePayableAchInstructions.js";
54
- import "../../../../shared/counterpart-management/feature/dist/index.js";
55
- import { useVendorSectionProps as ze } from "./index27.js";
56
- import { billCreateTestIds as s } from "./index34.js";
57
- import { cloneElement as Be, isValidElement as Ve, useCallback as c, useEffect as He, useMemo as l, useRef as Ue, useState as u } from "react";
58
- import { Fragment as We, jsx as d, jsxs as Ge } from "react/jsx-runtime";
59
- import { Trash2Icon as Ke } from "lucide-react";
5
+ import { BILL_CREATE_MESSAGE_LABELS_EN as e } from "./index25.js";
6
+ import { calculateTotal as t, displayLineAmount as n, normalizeMoneyOnBlur as r, parseMoneyToMinorUnits as i, parseQuantity as a } from "./index31.js";
7
+ import { validateBillTotals as o } from "./index32.js";
8
+ import { emptyLineItem as s, mapPayableToBillForm as c } from "./index34.js";
9
+ import { useCallback as l, useEffect as u, useMemo as d, useRef as f, useState as p } from "react";
60
10
  //#region ../../libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index35.js
61
- function qe(e) {
62
- let t = [...new Set(e)];
63
- return t.length > 0 ? t : void 0;
11
+ var m = /^[0-9.,-]+$/;
12
+ function h(e) {
13
+ let t = e.trim().replace(/^\$\s*/, "");
14
+ return t ? m.test(t) ? t : null : "";
64
15
  }
65
- function Je({ open: Je, onOpenChange: f, payableId: Ye, initialCounterpartId: Xe, readOnly: p = !1, copy: m, onCollapse: Ze, onEdit: Qe, onOpenBill: h, renderPaymentFlows: $e }) {
66
- let g = l(() => he(m), [m]), _ = m?.messages, et = l(() => ({
67
- ...me,
68
- ..._
69
- }), [_]), tt = Ye ? void 0 : Xe, [nt, rt] = u(tt), [it, at] = u(!!tt), [ot, st] = u(!1), [ct, v] = u(!1), [lt, ut] = u(), y = c((e) => {
70
- ut(() => e);
71
- }, []), [dt, ft] = u(), b = Ye ?? dt, x = be(b, { pollWhileOcrProcessing: !0 }), S = ve(b), { initResponse: C } = te(), pt = !!C, mt = i(C?.scopes, [a.AccountingConfigReadOrg]), w = ee({ enabled: mt }), T = x.data, E = !b || !!T, D = !p && E && !!b && T?.status !== "draft", ht = !p && !!T && !oe(T?.status), O = p || ht, k = Se({
72
- payable: T,
73
- lineItems: S.lineItems,
74
- labels: et
75
- }), A = T?.counterpart_id ?? void 0;
76
- He(() => {
77
- it || A && (rt(A), at(!0));
78
- }, [it, A]);
79
- let gt = c((e) => {
80
- at(!0), rt(e);
81
- }, []), j = Ne({
82
- payableId: b,
83
- scheduledPaymentDate: T?.scheduled_payment_date,
84
- enabled: p || D
85
- }), _t = re(), M = l(() => j.hasScheduledPayment && j.scheduledDate ? ae(j.scheduledDate, g.scheduledRelativeDay, _t) : void 0, [
86
- j.hasScheduledPayment,
87
- j.scheduledDate,
88
- g.scheduledRelativeDay,
89
- _t
90
- ]), N = De(C?.scopes), vt = i(C?.scopes, [a.PayableWriteOrg]), yt = i(C?.scopes, [a.CounterpartWriteOrg]) && vt, P = yt && ie(T?.status) && !j.hasScheduledPayment && !j.isResolving, bt = P && N, xt = P || yt && T?.status === "rejected", St = !p && E && (!b || T?.status === "draft") && !j.hasScheduledPayment && !j.isResolving, F = ze({
91
- payableId: b,
92
- counterpartId: p ? A : nt,
93
- payableCounterpartId: A,
94
- isVendorKnown: p ? !!T : E,
95
- onCounterpartChange: gt,
96
- requiredError: k.errors?.vendor,
97
- payableCounterpartBankAccountId: T?.counterpart_bank_account_id ?? void 0,
98
- extractedVendor: T?.counterpart_raw_data ?? void 0,
99
- readOnly: p,
100
- canEditVendor: !p || bt,
101
- canEditPaymentInstructions: !p || P,
102
- canAddPaymentInstructions: !p || xt,
103
- confirmDiscard: y,
104
- labels: m?.vendorSection
105
- }), I = F.activePayToOperation === "missingInstructions" ? St || xt : F.activePayToOperation === "existingInstructions" ? St || P : F.activePayToOperation === "vendor" && p ? bt : !1, Ct = !!(b && it) && !nt, L = x.refetch, wt = c(async () => {
106
- let { data: e } = await L();
107
- return e?.status ?? void 0;
108
- }, [L]), Tt = ye(), [R, Et] = u(!1), z = Ue(void 0), Dt = c(async () => {
109
- if (z.current) return z.current;
110
- let t = (async () => {
111
- if (I) {
112
- Et(!0);
113
- try {
114
- let t;
115
- try {
116
- t = await F.prepareVendorForSave({ closeOnSuccess: !1 });
117
- } catch {
118
- e.error(g.detail.paymentInstructionsSaveError);
119
- return;
120
- }
121
- if (!t.ok) return;
122
- if (!b) {
123
- F.finalizePayToSave();
124
- return;
125
- }
126
- let n = t.counterpartId && t.counterpartId !== T?.counterpart_id ? t.counterpartId : void 0, r = t.counterpartBankAccountId && t.counterpartBankAccountId !== T?.counterpart_bank_account_id ? t.counterpartBankAccountId : void 0;
127
- if (n || r) {
128
- let t = {
129
- path: { payable_id: b },
130
- body: {
131
- ...n ? { counterpart_id: n } : {},
132
- ...r ? { counterpart_bank_account_id: r } : {}
133
- }
134
- };
135
- try {
136
- await Tt.mutateAsync(t);
137
- } catch {
138
- try {
139
- await Tt.mutateAsync(t);
140
- } catch {
141
- e.error(g.detail.paymentInstructionsLinkError);
142
- return;
143
- }
144
- }
145
- F.finalizePayToSave();
146
- return;
147
- }
148
- F.finalizePayToSave(), await L();
149
- } finally {
150
- Et(!1);
151
- }
16
+ var g = [
17
+ "quantity",
18
+ "price",
19
+ "amount"
20
+ ];
21
+ function _(e) {
22
+ let t = e.trim(), n = /[.,]$/.test(t) ? t.slice(0, -1) : t;
23
+ return t && !n ? null : n;
24
+ }
25
+ function v(e, t, n) {
26
+ if (t === void 0) return;
27
+ let r = _(t);
28
+ if (r !== null) return o(e === "discount" ? r : "", e === "tax" ? r : "", e === "total" ? r : void 0, n)?.[e];
29
+ }
30
+ function y(e, t) {
31
+ let n = {}, r = {
32
+ price: null,
33
+ amount: null
34
+ };
35
+ for (let a of ["price", "amount"]) {
36
+ let o = _(e[a]);
37
+ o !== null && (r[a] = i(o), o && r[a] === null && (n[a] = t.unreadableMoney));
38
+ }
39
+ let o = _(e.quantity);
40
+ if (o !== null) {
41
+ let e = r.price !== null || r.amount !== null;
42
+ a(o) === null && (o || e) && (n.quantity = t.unusableQuantity);
43
+ }
44
+ return n;
45
+ }
46
+ function b(e, t, r) {
47
+ return i(t) === null ? r : n(e, t);
48
+ }
49
+ function x({ payable: n, lineItems: i, labels: a = e } = {}) {
50
+ let o = d(() => c({
51
+ payable: n ?? {},
52
+ lineItems: i ?? []
53
+ }), [n, i]), [m, _] = p(o.values), [x, S] = p(o.lineItems), [C, w] = p(o.discount), [T, E] = p(o.tax), [D, O] = p(o.total || void 0), [ee, k] = p(), A = f(void 0), te = l((e) => {
54
+ k((t) => {
55
+ let n = typeof e == "function" ? e(t) : e;
56
+ return n?.form !== A.current && (A.current = void 0), n;
57
+ });
58
+ }, []), ne = l((e) => {
59
+ A.current = e, k((t) => ({
60
+ ...t,
61
+ form: e
62
+ }));
63
+ }, []), j = l(() => {
64
+ k((e) => {
65
+ if (!e?.form || e.form !== A.current) return e;
66
+ A.current = void 0;
67
+ let t = { ...e };
68
+ return delete t.form, Object.keys(t).length ? t : void 0;
69
+ });
70
+ }, []), [re, M] = p(), [N, P] = p(), [F, I] = p(!1), [L, R] = p(!1), [z, B] = p(!1);
71
+ u(() => {
72
+ F || _(o.values);
73
+ }, [o]), u(() => {
74
+ L || S(o.lineItems);
75
+ }, [o]), u(() => {
76
+ z || (w(o.discount), E(o.tax), O(o.total || void 0));
77
+ }, [o]);
78
+ let ie = l((e) => {
79
+ _((t) => ({
80
+ ...t,
81
+ ...e
82
+ })), I(!0), k((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]), V = l((e, t) => {
89
+ M((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
+ }, []), H = l((e, t) => {
98
+ V(e, v(e, t, a));
99
+ }, [a, V]), U = l(() => {
100
+ O(void 0), H("total", void 0), j();
101
+ }, [H, j]), W = l((e, t = []) => {
102
+ let n = y(e, a);
103
+ P((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
+ }, [a]), G = l((e, t, n) => {
117
+ P((r) => ({
118
+ ...r,
119
+ [e]: {
120
+ ...r?.[e],
121
+ [t]: n
152
122
  }
153
- })();
154
- z.current = t;
155
- try {
156
- await t;
157
- } finally {
158
- z.current = void 0;
159
- }
123
+ }));
124
+ }, []), K = l((e, t, n = []) => {
125
+ let r = x.find((t) => t.id === e);
126
+ if (!r) return;
127
+ let i = t(r);
128
+ S(x.map((t) => t.id === e ? i : t)), W(i, n), R(!0), U();
160
129
  }, [
161
- I,
162
- g.detail.paymentInstructionsLinkError,
163
- g.detail.paymentInstructionsSaveError,
164
- Tt,
165
- T?.counterpart_bank_account_id,
166
- T?.counterpart_id,
167
- b,
168
- L,
169
- F
170
- ]), B = l(() => I ? F.mode === "creating" && Ve(F.newVendorForm) ? {
171
- ...F,
172
- newVendorForm: Be(F.newVendorForm, {
173
- onSave: Dt,
174
- isSaving: R
175
- })
176
- } : F.mode === "resolved" && F.paymentInstructions ? {
177
- ...F,
178
- paymentInstructions: {
179
- ...F.paymentInstructions,
180
- onSave: Dt,
181
- isSaving: R
182
- }
183
- } : F : F, [
184
- I,
185
- R,
186
- Dt,
187
- F
188
- ]);
189
- He(() => {
190
- p && F.isEditingPayTo && !I && F.discardPayToEdits();
191
- }, [
192
- I,
193
- p,
194
- F.discardPayToEdits,
195
- F.isEditingPayTo
196
- ]);
197
- let Ot = l(() => D ? {
198
- ..._,
199
- draftSaved: et.submittedSaved
200
- } : _, [
201
- D,
202
- _,
203
- et.submittedSaved
204
- ]), V = xe({
205
- payableId: Ye,
206
- form: k,
207
- labels: Ot,
208
- counterpartId: nt,
209
- isVendorPending: F.mode === "creating" || F.isPendingVendor,
210
- clearCounterpart: Ct,
211
- prepareVendorForSave: F.prepareVendorForSave,
212
- onPayableCreated: ft,
213
- onSaved: ft,
214
- onDraftSaved: () => f(!1),
215
- onFinalized: () => f(!1),
216
- readSavedStatus: D ? wt : void 0
217
- }), kt = !!(V.isSavingDraft || V.isFinalizing || F.isVendorSavePending), H = p ? b : void 0, U = je({
218
- payableId: H,
219
- status: T?.status
220
- }), At = Ue(null), [jt, Mt] = u(!1), Nt = se(T), W = Re({
221
- counterpartId: p ? A : void 0,
222
- currency: T?.currency,
223
- currentBankAccountId: p ? T?.counterpart_bank_account_id ?? void 0 : void 0,
224
- enabled: N && p
225
- }), G = ke({
226
- payableId: H,
227
- approvalPolicyId: T?.approval_policy_id,
228
- enabled: p,
229
- copy: g.approvalPolicyCopy
230
- }), Pt = Ee({
231
- status: T?.status,
232
- scopes: C?.scopes,
233
- arePendingApproversUnknown: G.isLoading,
234
- hasApprovalPolicy: !!T?.approval_policy_id,
235
- hasWaitingRequest: U.hasWaitingRequest
236
- }), Ft = !!U.id, It = U.isLoading || G.isLoading, Lt = l(() => qe(G.pendingApprovers.flatMap((e) => e.names)), [G.pendingApprovers]), Rt = p || D ? b : void 0, zt = p ? Qe : void 0, K = c((e) => {
237
- let t = () => {
238
- F.discardPayToEdits(), e?.();
239
- };
240
- F.hasUnsavedVendorChanges ? y(t) : t();
241
- }, [y, F]), { actions: Bt, decisionDialog: Vt, isActionPending: Ht } = Me({
242
- payableId: Rt,
243
- status: T?.status,
244
- currentApprovalRequestId: U.id,
245
- arePendingApproversUnknown: G.isLoading,
246
- hasScheduledPayment: j.hasScheduledPayment,
247
- scheduledPaymentIntentId: j.scheduledPaymentIntentId,
248
- isScheduledPaymentUnknown: j.isResolving,
249
- isPayabilityUnknown: W.isLoading,
250
- hasApprovalPolicy: !!T?.approval_policy_id,
251
- hasWaitingRequest: U.hasWaitingRequest,
252
- pendingApprovers: G.pendingApprovers,
253
- labels: g.actions,
254
- isMarkAsPaidPending: jt,
255
- onMarkAsPaidSelect: () => At.current?.openMarkAsPaid(),
256
- onPayBillSelect: () => K(() => At.current?.openPayBill()),
257
- onEditSelect: zt,
258
- onActionSucceeded: (e) => {
259
- if (e === "reopen") {
260
- zt?.();
130
+ U,
131
+ x,
132
+ W
133
+ ]), q = l((e, t) => {
134
+ let n = { ...t };
135
+ for (let r of g) {
136
+ let i = t[r];
137
+ if (i === void 0) continue;
138
+ let o = h(i);
139
+ if (o === null) {
140
+ G(e, r, a.numbersOnly);
261
141
  return;
262
142
  }
263
- D && f(!1);
143
+ n[r] = o;
264
144
  }
265
- }), Ut = Pe({
266
- payableId: b,
267
- status: T?.status,
268
- enabled: !p,
269
- labels: g.deleteDraft,
270
- onDeleted: () => f(!1)
271
- }), Wt = kt || Ht, Gt = T?.ocr_status === "processing", Kt = x.isLoading || S.isResolving || Gt, qt = x.isLoading || S.isResolving || w.isResolving || W.isLoading, Jt = x.isError || S.isError || w.isError, Yt = l(() => [...Ut.menuItems, ...D || p && !qt && !Jt ? Bt.menu.map((e) => ({
272
- id: e.id,
273
- label: e.label,
274
- onSelect: e.onSelect,
275
- disabled: e.disabled,
276
- icon: e.icon,
277
- sectionHeading: e.sectionHeading
278
- })) : []], [
279
- Bt.menu,
280
- Ut.menuItems,
281
- D,
282
- p,
283
- qt,
284
- Jt
285
- ]), q = l(() => (w.data?.data ?? []).map((e) => ({
286
- value: e.id,
287
- label: [e.nominal_code, e.name].filter(Boolean).join(" — ")
288
- })), [w.data]), J;
289
- pt && (mt ? w.isError ? J = g.lineItemsGlCodeUnavailable.loadError : !w.isResolving && q.length === 0 && (J = g.lineItemsGlCodeUnavailable.empty) : J = g.lineItemsGlCodeUnavailable.noAccess);
290
- let Xt = !pt || !!J || w.isResolving, Zt = mt && !w.isResolving && !w.isError, Y = _e(H), Qt = T?.status === "rejected" || !p && D, $t = i(C?.scopes, [a.ApprovalRequestReadOrg]), en = Qt && $t, tn = i(C?.scopes, [a.UserReadOrg]), { userNames: X, isError: nn, isResolving: rn } = ne({ enabled: (p || Qt) && tn }), an = l(() => n(Y.data?.data ?? [], X, g.history), [
291
- Y.data,
292
- X,
293
- g.history
294
- ]), on = tn && nn && r(Y.data?.data ?? [], an, X), sn = Oe({
295
- payableId: b,
296
- enabled: en
297
- }), cn = ge(b, { enabled: en }), ln = l(() => we(cn.data?.data, sn.roundStartedAt), [cn.data, sn.roundStartedAt]), Z = l(() => Ae({
298
- payableStatus: T?.status,
299
- approvalRequests: ln,
300
- userNames: X,
301
- payableUpdatedAt: T?.updated_at,
302
- labels: g.detail
303
- }), [
304
- T?.status,
305
- T?.updated_at,
306
- ln,
307
- X,
308
- g.detail
309
- ]), un = l(() => Ce({
310
- records: j.paymentRecords,
311
- events: Y.data?.data ?? [],
312
- currencyCode: T?.currency,
313
- labels: g.detail
314
- }), [
315
- j.paymentRecords,
316
- Y.data,
317
- T?.currency,
318
- g.detail
319
- ]), dn = l(() => {
320
- if (!p || !T) return;
321
- let e = Fe({
322
- payable: T,
323
- lineItems: S.lineItems,
324
- glCodeOptions: q,
325
- glCodeRosterAvailable: Zt,
326
- history: an,
327
- paymentHistory: un,
328
- approvalPolicy: G.view,
329
- labels: g.detail,
330
- hasScheduledPayment: j.hasScheduledPayment,
331
- rejection: Z,
332
- payableAchInstructions: W.achInstructions,
333
- payableAchInstructionsReadable: N && !W.isError
334
- });
335
- return F.mode === "resolved" && F.summary ? {
336
- ...e,
337
- payTo: F.summary
338
- } : e;
145
+ K(e, (e) => {
146
+ let t = {
147
+ ...e,
148
+ ...n
149
+ };
150
+ return "amount" in n ? t : {
151
+ ...t,
152
+ amount: b(t.quantity, t.price, t.amount)
153
+ };
154
+ }, Object.keys(n));
339
155
  }, [
340
- j.hasScheduledPayment,
341
- G.view,
342
- N,
343
- g.detail,
344
- q,
345
- Zt,
346
- an,
347
- S.lineItems,
348
- T,
349
- W.achInstructions,
350
- W.isError,
351
- un,
352
- p,
353
- Z,
354
- F.mode,
355
- F.summary
356
- ]), fn = T?.source_of_payable_data === "ocr", Q = Nt?.name, pn = p ? Q ? g.viewTitle(Q) : g.readOnlyTitle : Q && (fn || D) ? g.extractedTitle(Q) : g.newTitle, mn = p && T?.created_at ? g.addedOn(t(T.created_at.slice(0, 10))) : void 0, hn = c(() => {
357
- if (p && F.isEditingPayTo) {
358
- K(() => f(!1));
359
- return;
360
- }
361
- let e = k.isDirty || F.hasUnsavedVendorChanges || !!V.stagedFile || V.isFileDeletionPending;
362
- switch (Ie({
363
- isUnsavedPromptOpen: ct,
364
- isLocked: O,
365
- isDirty: e
366
- })) {
367
- case "dismiss-prompt":
368
- v(!1);
369
- return;
370
- case "prompt":
371
- v(!0);
372
- return;
373
- default: f(!1);
374
- }
375
- }, [
376
- V.isFileDeletionPending,
377
- V.stagedFile,
378
- k.isDirty,
379
- O,
380
- ct,
381
156
  K,
382
- f,
383
- p,
384
- F.hasUnsavedVendorChanges,
385
- F.isEditingPayTo
386
- ]), gn = c((e, t) => {
387
- if (!h) return;
388
- let n = () => h(e, t);
389
- if (p && F.isEditingPayTo) {
390
- K(n);
157
+ a,
158
+ G
159
+ ]), J = l((e, t) => {
160
+ S((n) => n.map((n) => n.id === e ? {
161
+ ...n,
162
+ [t]: r(n[t])
163
+ } : n));
164
+ }, []), Y = l((e, t) => {
165
+ K(e, (e) => {
166
+ let n = Number.parseFloat(e.quantity), r = String(Math.max(1, (Number.isFinite(n) ? n : 0) + t));
167
+ return {
168
+ ...e,
169
+ quantity: r,
170
+ amount: b(r, e.price, e.amount)
171
+ };
172
+ });
173
+ }, [K]), X = l((e) => {
174
+ P((t) => {
175
+ if (!t?.[e]) return t;
176
+ let n = { ...t };
177
+ return delete n[e], Object.keys(n).length ? n : void 0;
178
+ });
179
+ }, []), Z = l((e) => {
180
+ X(e), S((t) => t.length <= 1 ? t : t.filter((t) => t.id !== e)), R(!0), U();
181
+ }, [X, U]), ae = l(() => {
182
+ S((e) => [...e, s()]), R(!0), U();
183
+ }, [U]), Q = l((e, t, n) => {
184
+ let r = h(t);
185
+ if (r === null) {
186
+ V(e, a.numbersOnly);
391
187
  return;
392
188
  }
393
- let r = k.isDirty || F.hasUnsavedVendorChanges || !!V.stagedFile || V.isFileDeletionPending;
394
- !O && r ? y(n) : n();
189
+ n(r), B(!0), U(), H(e, r);
395
190
  }, [
396
- y,
397
- V.isFileDeletionPending,
398
- V.stagedFile,
399
- k.isDirty,
400
- O,
401
- K,
402
- h,
403
- p,
404
- F.hasUnsavedVendorChanges,
405
- F.isEditingPayTo
406
- ]), _n = c(() => {
407
- if (F.isEditingPayTo) {
408
- K(Ze);
191
+ U,
192
+ a,
193
+ H,
194
+ V
195
+ ]), oe = l((e) => Q("discount", e, w), [Q]), se = l((e) => Q("tax", e, E), [Q]), $ = l(() => w((e) => r(e)), []), ce = l(() => E((e) => r(e)), []), le = l((e) => {
196
+ let t = h(e);
197
+ if (t === null) {
198
+ V("total", a.numbersOnly);
409
199
  return;
410
200
  }
411
- Ze?.();
412
- }, [
413
- K,
414
- Ze,
415
- F.isEditingPayTo
416
- ]), vn = c(() => {
417
- v(!1), f(!1);
418
- }, [f]), yn = Kt || F.mode === "creating", bn = c(async () => {
419
- if (yn) return;
420
- let e = await V.saveDraft();
421
- v(!1), e && f(!1);
422
- }, [
423
- V,
424
- yn,
425
- f
426
- ]), $ = Te({
427
- payable: T,
428
- onOpenPayable: h ? gn : void 0,
429
- onRemoved: () => f(!1),
430
- canManage: vt
431
- }), xn = c((e) => {
432
- if (!(Wt || $.isBusy)) return e ? f(!0) : hn();
201
+ O(t), B(!0), H("total", t), j();
433
202
  }, [
434
- $.isBusy,
435
- Wt,
436
- hn,
437
- f
438
- ]), Sn = $.isPossibleDuplicate, Cn = !p && fn && !ot, wn = !p && !!Z, Tn = wn || Sn || Cn ? /* @__PURE__ */ Ge(We, { children: [
439
- wn && Z ? /* @__PURE__ */ d(ue, {
440
- ...Z,
441
- labels: g.rejectedBanner
442
- }) : null,
443
- Sn ? /* @__PURE__ */ d(le, {
444
- onNotADuplicate: $.onNotADuplicate,
445
- onRemoveBill: $.onRemoveBill,
446
- isActionDisabled: $.isBusy,
447
- rows: $.rows,
448
- collapsedRowCount: $.collapsedRowCount,
449
- showMoreLabel: $.showMoreLabel,
450
- labels: $.removeBillLabel ? { removeBillButton: $.removeBillLabel } : void 0,
451
- testId: s.duplicateNotice
452
- }) : null,
453
- Cn ? /* @__PURE__ */ d(fe, {
454
- onDismiss: () => st(!0),
455
- labels: m?.extractionNotice
456
- }) : null
457
- ] }) : void 0;
458
- return /* @__PURE__ */ Ge(We, { children: [
459
- /* @__PURE__ */ d(ce, {
460
- open: Je,
461
- onOpenChange: xn,
462
- title: pn,
463
- subtitle: mn,
464
- notice: Tn,
465
- vendor: {
466
- ...B,
467
- testId: s.vendorSection
468
- },
469
- values: k.values,
470
- errors: k.errors,
471
- onChange: k.onChange,
472
- lineItems: {
473
- items: k.lineItemRows,
474
- glCodeOptions: q,
475
- glCodeDisabled: Xt,
476
- glCodeUnavailableMessage: J,
477
- discount: k.discount,
478
- onDiscountChange: k.onDiscountChange,
479
- onDiscountBlur: k.onDiscountBlur,
480
- tax: k.tax,
481
- onTaxChange: k.onTaxChange,
482
- onTaxBlur: k.onTaxBlur,
483
- total: k.total,
484
- onTotalChange: k.onTotalChange,
485
- onTotalBlur: k.onTotalBlur,
486
- onAddLineItem: k.onAddLineItem,
487
- errors: k.lineItemErrors,
488
- totalsErrors: k.totalsErrors,
489
- testId: s.lineItems
490
- },
491
- documentPanel: /* @__PURE__ */ d(Le, {
492
- payableId: b,
493
- readOnly: O,
494
- isDocumentPending: !!b && !T?.file && (x.isLoading || T?.ocr_status === "processing"),
495
- file: T?.file ? {
496
- id: T.file.id,
497
- name: T.file.name,
498
- url: T.file.url,
499
- mimetype: T.file.mimetype
500
- } : void 0,
501
- staging: {
502
- stagedFile: V.stagedFile,
503
- onFileStaged: V.stageFile,
504
- onClearStagedFile: V.clearStagedFile,
505
- isSaving: kt
506
- },
507
- deletion: {
508
- isPending: V.isFileDeletionPending,
509
- onRequest: V.requestFileDeletion,
510
- onDetachNow: V.detachFileNow,
511
- isDeleting: V.isDeletingFile,
512
- hasFailed: V.hasFileDeletionFailed
513
- },
514
- labels: m?.sourceDocument
515
- }),
516
- menuItems: Yt,
517
- readOnly: O,
518
- detail: p ? {
519
- view: dn,
520
- actions: Bt,
521
- scheduledSummary: M ? g.scheduledSummary(M.label) : void 0,
522
- scheduledSummaryDate: M?.absoluteLabel,
523
- scheduledStatusLabel: M ? g.scheduledStatusBadge(M.label) : void 0,
524
- showApprovalOverrideNotice: !It && Pt,
525
- awaitingApprovalNotice: !It && !Ft && !Pt && T?.status === "approve_in_progress" && T?.approval_policy_id ? Lt ? g.awaitingApprovalNotice(Lt) : g.awaitingApprovalUnknownNotice : void 0,
526
- payTo: {
527
- onEdit: B.mode === "resolved" ? B.onEdit : void 0,
528
- paymentInstructions: B.paymentInstructions,
529
- detailsWarning: B.detailsWarning,
530
- editForm: B.mode === "creating" ? B.newVendorForm : void 0
531
- },
532
- hideMissingPaymentInstructions: T?.status === "paid" || T?.status === "canceled",
533
- isLoading: qt,
534
- isError: Jt,
535
- paymentHistoryError: j.isError || Y.isError,
536
- paymentHistoryLoading: j.isResolving || Y.isLoading,
537
- historyError: Y.isError,
538
- historyLoading: Y.isLoading || rn,
539
- historyNamesError: on
540
- } : void 0,
541
- isLineItemsLoading: Kt,
542
- isSaving: Wt || R,
543
- isSavingDraft: V.isSavingDraft,
544
- isSubmitting: V.isFinalizing,
545
- onCancel: hn,
546
- onCollapse: p ? _n : void 0,
547
- onSaveDraft: V.saveDraft,
548
- onFinalize: V.finalize,
549
- scrollToErrorToken: V.scrollToErrorToken,
550
- showSubmit: !O && E,
551
- testId: s.dialog,
552
- labels: m?.screen
553
- }),
554
- /* @__PURE__ */ d(pe, {
555
- open: ct,
556
- onSaveDraft: bn,
557
- onDiscard: vn,
558
- onCancel: () => v(!1),
559
- isSaving: V.isSavingDraft,
560
- isSaveDraftDisabled: yn,
561
- labels: g.unsavedChanges,
562
- testId: s.unsavedDialog,
563
- saveDraftTestId: s.unsavedSaveDraft,
564
- discardTestId: s.unsavedDiscard,
565
- closeTestId: s.unsavedClose
566
- }),
567
- /* @__PURE__ */ d(de, {
568
- open: !!lt,
569
- onDiscard: () => {
570
- let e = lt;
571
- ut(void 0), e?.();
572
- },
573
- onKeepEditing: () => ut(void 0),
574
- labels: g.discardChanges,
575
- testId: s.discardDialog,
576
- discardTestId: s.discardConfirm
577
- }),
578
- /* @__PURE__ */ d(o, {
579
- ...Vt,
580
- labels: { cancelButton: g.actions.decisionDialog.cancelButton },
581
- testId: s.decisionDialog,
582
- confirmTestId: s.decisionConfirm,
583
- reasonTestId: s.decisionReason
584
- }),
585
- /* @__PURE__ */ d(o, {
586
- ...Ut.dialog,
587
- labels: { cancelButton: g.actions.decisionDialog.cancelButton },
588
- testId: s.deleteDraftDialog,
589
- confirmTestId: s.deleteDraftConfirm
590
- }),
591
- /* @__PURE__ */ d(o, {
592
- open: $.removeConfirmation.open,
593
- copy: $.removeConfirmation.copy,
594
- onConfirm: $.removeConfirmation.onConfirm,
595
- onCancel: $.removeConfirmation.onCancel,
596
- isPending: $.removeConfirmation.isPending,
597
- confirmIcon: /* @__PURE__ */ d(Ke, {}),
598
- labels: { cancelButton: $.removeConfirmation.cancelButtonLabel },
599
- testId: s.duplicateRemoveDialog,
600
- confirmTestId: s.duplicateRemoveConfirm
601
- }),
602
- /* @__PURE__ */ d(o, {
603
- open: $.cancelRowConfirmation.open,
604
- copy: $.cancelRowConfirmation.copy,
605
- onConfirm: $.cancelRowConfirmation.onConfirm,
606
- onCancel: $.cancelRowConfirmation.onCancel,
607
- isPending: $.cancelRowConfirmation.isPending,
608
- labels: { cancelButton: $.cancelRowConfirmation.cancelButtonLabel },
609
- testId: s.duplicateCancelRowDialog,
610
- confirmTestId: s.duplicateCancelRowConfirm
611
- }),
612
- /* @__PURE__ */ d(o, {
613
- open: $.keepRowConfirmation.open,
614
- copy: $.keepRowConfirmation.copy,
615
- onConfirm: $.keepRowConfirmation.onConfirm,
616
- onCancel: $.keepRowConfirmation.onCancel,
617
- isPending: $.keepRowConfirmation.isPending,
618
- labels: { cancelButton: $.keepRowConfirmation.cancelButtonLabel }
619
- }),
620
- $e?.({
621
- ref: At,
622
- payable: T,
623
- payableId: H,
624
- isPayBillEnabled: p,
625
- hasScheduledPayment: j.hasScheduledPayment,
626
- onMissingAchInstructions: yt ? F.openPaymentInstructions : void 0,
627
- onMarkAsPaidPendingChange: Mt
628
- })
629
- ] });
203
+ j,
204
+ a,
205
+ H,
206
+ V
207
+ ]), ue = l(() => {
208
+ O((e) => e === void 0 ? e : r(e));
209
+ }, []), de = d(() => x.map((e) => ({
210
+ ...e,
211
+ onChange: (t) => q(e.id, t),
212
+ onBlur: (t) => J(e.id, t),
213
+ onQuantityStep: (t) => Y(e.id, t),
214
+ onRemove: () => Z(e.id)
215
+ })), [
216
+ J,
217
+ x,
218
+ q,
219
+ Z,
220
+ Y
221
+ ]), fe = d(() => t(x, T, C), [
222
+ x,
223
+ T,
224
+ C
225
+ ]);
226
+ return {
227
+ values: m,
228
+ errors: ee,
229
+ setErrors: te,
230
+ setSaveFailureMessage: ne,
231
+ lineItemErrors: N,
232
+ setLineItemErrors: P,
233
+ totalsErrors: re,
234
+ setTotalsErrors: M,
235
+ onChange: ie,
236
+ lineItems: x,
237
+ lineItemRows: de,
238
+ discount: C,
239
+ onDiscountChange: oe,
240
+ onDiscountBlur: $,
241
+ tax: T,
242
+ onTaxChange: se,
243
+ onTaxBlur: ce,
244
+ total: D ?? fe,
245
+ totalOverride: D,
246
+ onTotalChange: le,
247
+ onTotalBlur: ue,
248
+ onAddLineItem: ae,
249
+ isTotalsDirty: z,
250
+ isDirty: F || L || z
251
+ };
630
252
  }
631
253
  //#endregion
632
- export { Je as BillCreateDialog, Je as default };
254
+ export { x as useBillForm };