@tesouro/embedded-components-react 0.5.227 → 0.5.230

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 (90) hide show
  1. package/README.md +22 -21
  2. package/dist/index.d.ts +87 -34
  3. package/dist/index.js +1 -1
  4. package/dist/lib/ReceivablesWidget.d.ts +87 -34
  5. package/dist/lib/ReceivablesWidget.js +1 -1
  6. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/data-access/dist/index.js +5 -5
  7. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/data-access/dist/index10.js +29 -59
  8. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/data-access/dist/index11.js +1 -1
  9. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/data-access/dist/index5.js +32 -33
  10. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/data-access/dist/index6.js +34 -32
  11. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/data-access/dist/index7.js +1 -1
  12. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index.js +1 -1
  13. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index10.js +120 -52
  14. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index11.js +44 -100
  15. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index12.js +93 -442
  16. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index13.js +356 -201
  17. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index14.js +225 -157
  18. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index15.js +152 -21
  19. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index16.js +18 -221
  20. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index17.js +220 -31
  21. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index18.js +125 -124
  22. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index19.js +58 -150
  23. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index20.js +232 -46
  24. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index21.js +303 -122
  25. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index22.js +43 -58
  26. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index23.js +125 -98
  27. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index24.js +140 -106
  28. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index25.js +46 -232
  29. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index26.js +119 -29
  30. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index27.js +81 -613
  31. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index28.js +116 -39
  32. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index29.js +27 -33
  33. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index30.js +634 -72
  34. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index31.js +39 -119
  35. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index32.js +36 -317
  36. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index33.js +82 -0
  37. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index34.js +139 -0
  38. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index35.js +340 -0
  39. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index5.js +1 -1
  40. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index7.js +15 -2
  41. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index8.js +55 -468
  42. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index9.js +443 -97
  43. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index.js +24 -22
  44. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index10.js +32 -2
  45. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index11.js +205 -84
  46. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index12.js +161 -3
  47. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index13.js +12 -20
  48. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index14.js +25 -1
  49. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index15.js +4 -3
  50. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index16.js +95 -3
  51. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index17.js +3 -18
  52. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index18.js +24 -1
  53. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index19.js +42 -4
  54. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index2.js +14 -7
  55. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index20.js +19 -12
  56. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index21.js +73 -1
  57. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index22.js +17 -261
  58. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index23.js +12 -44
  59. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index24.js +28 -68
  60. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index25.js +288 -479
  61. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index26.js +1 -106
  62. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index27.js +48 -0
  63. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index28.js +72 -2
  64. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index29.js +496 -4
  65. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index3.js +121 -27
  66. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index30.js +106 -1
  67. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index32.js +2 -28
  68. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index33.js +4 -236
  69. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index34.js +0 -2
  70. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index35.js +90 -239
  71. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index36.js +24 -89
  72. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index37.js +231 -54
  73. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index38.js +3 -353
  74. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index39.js +249 -0
  75. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index4.js +100 -207
  76. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index40.js +93 -0
  77. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index41.js +59 -0
  78. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index42.js +353 -0
  79. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index5.js +35 -29
  80. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index6.js +2 -216
  81. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index7.js +9 -159
  82. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index8.js +27 -14
  83. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index9.js +216 -23
  84. package/dist/libs/tesouro-embedded-components-react/shared/data-access/dist/index.js +40 -40
  85. package/dist/libs/tesouro-embedded-components-react/shared/data-access/dist/lib/rest/@tanstack/react-query.gen.js +189 -211
  86. package/dist/libs/tesouro-embedded-components-react/shared/data-access/dist/lib/rest/sdk.gen.js +43 -59
  87. package/dist/libs/tesouro-embedded-components-react/shared/feature/dist/lib/analytics/build-info.js +1 -1
  88. package/dist/libs/tesouro-embedded-components-react/shared/product-catalog/feature/dist/index.js +12 -12
  89. package/package.json +1 -1
  90. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index31.js +0 -100
@@ -3,634 +3,102 @@
3
3
  "use client";
4
4
  "use client";
5
5
  import { toast as e } from "../../../../../packages/shared-ui-shadcn/dist/index.js";
6
- import { getStateOptions as t } from "../../../shared/util/dist/lib/usStates.js";
6
+ import { extractApiErrorMessage as t } from "../../../shared/util/dist/lib/apiErrors.js";
7
7
  import "../../../shared/ui/dist/index.js";
8
- import { COUNTERPART_MESSAGE_LABELS_EN as n } from "../../../shared/counterpart-management/feature/dist/lib/labels.js";
9
- import { useCounterpartAddressesQuery as r } from "../../../shared/counterpart-management/data-access/dist/index7.js";
10
- import { useCounterpartForm as i } from "../../../shared/counterpart-management/feature/dist/lib/useCounterpartForm.js";
11
- import "../../../shared/counterpart-management/feature/dist/index.js";
12
- import "../../ui/dist/index10.js";
13
- import "../../ui/dist/index.js";
14
- import { buildLineItemControls as a, commitLineItemField as o, commitTaxRateInput as s, convertPriceInput as c, createLineItem as l, getCurrencySymbol as ee, lineItemFromProduct as te, reconcileLineItemIds as ne, reconcileMeasureUnits as re, sanitizeLineItemPatch as ie, sanitizeTaxRateInput as ae, stepLineItemQuantity as oe, stripBlankLineItems as se, summarizeLineItemErrors as ce, toSheetLineItem as le, validateLineItems as ue } from "./index6.js";
15
- import { buildReceivableAttachmentsView as de } from "./index7.js";
16
- import { buildCreateRecurrencePayload as fe, buildUpdateRecurrencePayload as pe, clearRecurrenceRecipients as me, countIssuedIterations as he, isRecurring as u, recurrenceToFormFields as ge, validateRecurrence as _e, willRecurrenceIssue as ve } from "./index8.js";
17
- import { convertDiscountInput as ye, decorateDiscountInput as be, discountInputToMinorUnits as xe, sanitizeDiscountInput as Se } from "./index10.js";
18
- import { buildFormTotalsView as Ce, calculateFormTotals as we, validateDiscount as Te, validateInvoiceTotals as Ee } from "./index11.js";
19
- import { createEmptyReceivableFormValues as De, hasReceivableFormErrors as Oe, receivableFormValuesToCreatePayload as ke, receivableFormValuesToLineItemChanges as Ae, receivableFormValuesToUpdatePayload as je, receivableToFormValues as Me, submittedLineItemRows as Ne, validateReceivableForm as Pe } from "./index12.js";
20
- import { getIssueReminderBlocker as Fe, shouldShowRemindersInitially as Ie } from "./index14.js";
21
- import { useCreateReceivableMutation as Le, useIssueReceivableMutation as Re, useUpdateReceivableMutation as ze } from "../../data-access/dist/index7.js";
22
- import { useCreateRecurrenceMutation as Be, useRecurrenceQuery as Ve, useUpdateRecurrenceMutation as He } from "../../data-access/dist/index11.js";
8
+ import { useWidgetConfig as n } from "../../../shared/feature/dist/lib/WidgetProvider/hooks.js";
9
+ import "../../../shared/feature/dist/index.js";
10
+ import { useCreateEntityBankAccountMutation as r, usePaymentAccountsQuery as i } from "../../data-access/dist/index3.js";
23
11
  import "../../data-access/dist/index.js";
24
- import { useReceivableIssuePreflight as Ue } from "./index15.js";
25
- import { UNSUBMITTED_PAYLOAD_VARIANTS as We, apiValidationErrorsToFormErrors as Ge, getApiErrorMessage as Ke, parseApiValidationErrors as qe } from "./index18.js";
26
- import { useReceivableAttachmentUploads as Je } from "./index19.js";
27
- import { useReceivablePaymentTerms as Ye } from "./index20.js";
28
- import { useReceivableRecurrence as Xe } from "./index21.js";
29
- import { useReceivableBankAccount as Ze } from "./index23.js";
30
- import { useReceivableReminders as Qe } from "./index24.js";
31
- import { useReceivablePreview as $e } from "./index26.js";
32
- import { getCurrencyOptions as et } from "../../../shared/product-catalog/feature/dist/lib/helpers.js";
33
- import { useMeasureUnitsQuery as tt } from "../../../shared/product-catalog/data-access/dist/index9.js";
34
- import { useMeasureUnits as nt } from "../../../shared/product-catalog/feature/dist/lib/useMeasureUnits.js";
35
- import "../../../shared/product-catalog/feature/dist/index.js";
12
+ import { EMPTY_BANK_ACCOUNT_FORM_VALUES as a, bankAccountFormToPayload as o, buildBankAccountSectionView as s, buildPaymentAccountOptions as c, getBankAccountPermissions as l, validateBankAccountForm as u } from "./index19.js";
36
13
  import { useCallback as d, useEffect as f, useMemo as p, useRef as m, useState as h } from "react";
37
14
  //#region ../../libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index27.js
38
- function g({ messages: g, counterpartMessageLabels: rt, embeddedBankName: it, onCreated: at }) {
39
- let ot = Le(), st = ze(), ct = Be(), lt = He(), ut = Re(), _ = m("draft"), dt = m(!1), v = m(!1), y = m(!1), ft = m(null), b = m(void 0), x = m([]), pt = m(""), [S, C] = h(!1), [w, mt] = h("create"), [ht, gt] = h(), [T, _t] = h(), [E, D] = h(() => De()), [vt, O] = h({}), [yt, bt] = h("none"), xt = nt(), k = tt(), A = k.data?.data, { unitNamesById: j } = xt, [St, Ct] = h(), [M, wt] = h(!1), Tt = m(!1), N = m(!1), P = m(!1), F = m({
40
- lines: !1,
41
- discount: !1
42
- }), [Et, I] = h(!1), Dt = p(() => t(), []), Ot = p(() => ({
43
- ...n,
44
- ...rt
45
- }), [rt]), kt = r(E.customerId), At = kt.data?.data?.[0], L = kt.data?.data?.[0]?.id, jt = !!E.customerId && (kt.isLoading || kt.isFetching), R = Ue({
46
- counterpartId: E.customerId,
47
- billingAddressId: L,
48
- billingCountry: At?.country
49
- }), Mt = R.isLoading || jt, Nt = d((e) => {
50
- D((t) => ({
51
- ...t,
52
- attachments: e(t.attachments)
53
- }));
54
- }, []), z = Je({
55
- attachments: E.attachments,
56
- setAttachments: Nt,
57
- receivableId: ht
58
- }), { reset: B, discardUploads: Pt, commitRemovals: Ft } = z, It = E.type === "invoice" ? de({
59
- attachments: E.attachments,
60
- pendingUploads: z.pendingUploads,
61
- isCountLimitReached: z.isCountLimitReached,
62
- isRecurring: u(E),
63
- messages: g
64
- }) : void 0, Lt = d((e) => {
65
- D((t) => {
66
- let n = e ?? "";
67
- return n === t.customerId ? t : me({
68
- ...t,
69
- customerId: n
70
- });
71
- });
72
- }, []), Rt = i({
73
- view: yt,
74
- setView: bt,
75
- selectedId: E.customerId || void 0,
76
- setSelectedId: Lt,
77
- messages: Ot,
78
- counterpartType: "customer",
79
- counterpart: void 0,
80
- primaryAddress: At
81
- }), zt = d((e) => D((t) => {
82
- let n = e({
83
- paymentTermsId: t.paymentTermsId,
84
- paymentTermsCustomDate: t.paymentTermsCustomDate
85
- });
86
- return {
87
- ...t,
88
- ...n,
89
- ...n.paymentTermsId === "receipt_due" ? { paymentReminderId: "" } : {}
90
- };
91
- }), []), Bt = Ye({
92
- paymentTermsId: E.paymentTermsId,
93
- paymentTermsCustomDate: E.paymentTermsCustomDate,
94
- issueDate: E.issueDate,
95
- isRecurring: E.type === "invoice" && u(E),
96
- messages: g,
97
- onChange: zt
98
- }), Vt = Bt.reset, Ht = d((e) => D((t) => ({
99
- ...t,
100
- ...e
101
- })), []), V = Ze({
102
- open: S,
103
- bankAccountId: E.bankAccountId,
104
- embeddedBankName: it,
105
- messages: g,
106
- onSelect: Ht
107
- }), Ut = V.reset, Wt = Ve(T), H = T ? Wt.data : void 0, U = he(H), Gt = U > 0, W = !!T && Wt.isLoading, G = m(void 0);
108
- f(() => {
109
- H && G.current !== H.id && (G.current = H.id, D((e) => ({
110
- ...e,
111
- ...ge(H)
112
- })));
113
- }, [H]);
114
- let Kt = d((e) => D(e), []), qt = d((e) => O((t) => {
115
- if (!e.some((e) => e in t)) return t;
116
- let n = { ...t };
117
- return e.forEach((e) => delete n[e]), n;
118
- }), []), Jt = m([]), Yt = d((e) => {
119
- if (!M) {
120
- qt(e);
121
- return;
122
- }
123
- Jt.current.push(...e);
124
- }, [qt, M]);
125
- f(() => {
126
- let e = Jt.current;
127
- if (!e.length) return;
128
- Jt.current = [];
129
- let t = _e({
130
- fields: E,
131
- issuedCount: U,
132
- messages: g
133
- });
134
- O((n) => {
135
- let r = { ...n };
136
- return e.forEach((e) => {
137
- t[e] ? r[e] = t[e] : delete r[e];
138
- }), r;
139
- });
140
- }, [
141
- U,
142
- g,
143
- E
144
- ]);
145
- let Xt = Xe({
146
- values: E,
147
- errors: vt,
148
- lockSchedule: Gt,
149
- messages: g,
150
- onChange: Kt,
151
- onClearErrors: qt,
152
- onRevalidateErrors: Yt
153
- }), K = Xt.reset, Zt = d((e) => D((t) => ({
154
- ...t,
155
- ...e
156
- })), []), Qt = ot.isPending || st.isPending || ct.isPending || lt.isPending || ut.isPending, $t = Qe({
157
- open: S,
158
- isInvoice: E.type === "invoice",
159
- disabled: Qt,
160
- paymentTermsId: E.paymentTermsId,
161
- paymentTermsCustomDate: E.paymentTermsCustomDate,
162
- paymentReminderId: E.paymentReminderId,
163
- overdueReminderId: E.overdueReminderId,
164
- messages: g,
165
- onSelect: Zt
166
- }), en = $t.reset, tn = d(() => {
167
- x.current = [], Ct(void 0), mt("create"), gt(void 0), _t(void 0), G.current = void 0, b.current = void 0, _.current = "draft", v.current = !1, y.current = !1, D(De()), O({}), wt(!1), I(!1), F.current = {
168
- lines: !1,
169
- discount: !1
170
- }, B(), K();
171
- }, [B, K]), nn = d((e = "invoice") => {
172
- Vt(), Ut(), K();
173
- let t = {
174
- ...De(),
175
- type: e
176
- };
177
- en(Ie(t)), x.current = [], b.current = void 0, _.current = "draft", v.current = !1, y.current = !1, G.current = void 0, Ct(void 0), mt("create"), gt(void 0), _t(void 0), D(t), O({}), B(), wt(!1), I(!1), F.current = {
178
- lines: !1,
179
- discount: !1
180
- }, C(!0);
181
- }, [
182
- B,
183
- Vt,
184
- Ut,
185
- K,
186
- en
187
- ]), rn = d((e, { highlightForIssue: t = !1 } = {}) => {
188
- if (e.type === "credit_note") return;
189
- Vt(), Ut(), K();
190
- let n = Me(e, A);
191
- en(Ie(n)), x.current = e.line_items, pt.current = e.currency, b.current = void 0, _.current = t ? "issue" : "draft", v.current = !1, y.current = t, G.current = void 0, Ct(void 0), mt("edit"), gt(e.id), _t(e.type === "invoice" ? e.recurrence_id ?? void 0 : void 0), D(n), O({}), wt(!1), I(!1), F.current = {
192
- lines: !1,
193
- discount: !1
194
- }, B(), C(!0);
195
- }, [
196
- B,
197
- Vt,
198
- Ut,
199
- K,
200
- en,
201
- A
202
- ]);
203
- f(() => {
204
- A?.length && D((e) => {
205
- let t = re(e.lineItems, A);
206
- return t === e.lineItems ? e : {
207
- ...e,
208
- lineItems: t
209
- };
210
- });
211
- }, [A]);
212
- let an = z.isUploading, on = d(() => {
213
- an || (Pt(), C(!1), O({}));
214
- }, [Pt, an]), sn = d((e) => {
215
- let t = { ...e };
216
- t.taxRate !== void 0 && (t.taxRate = ae(t.taxRate), P.current = !0), t.type !== void 0 && t.type !== "invoice" && Pt(), t.type !== void 0 && (_.current = "draft"), t.discount !== void 0 && M && (N.current = !0), t.discountType !== void 0 && (N.current = !0), t.currency !== void 0 && (Tt.current = !0), D((e) => {
217
- let n = {
218
- ...e,
219
- ...t
220
- };
221
- return t.discount !== void 0 && (n.discount = Se(t.discount, n.discountType, n.currency)), n.currency !== e.currency && (n.lineItems = e.lineItems.map((t) => ({
222
- ...t,
223
- price: c(t.price, e.currency, n.currency)
224
- }))), (n.currency !== e.currency || n.discountType !== e.discountType) && (n.discount = ye({
225
- value: n.discount,
226
- type: n.discountType,
227
- currency: n.currency
228
- })), n;
229
- });
230
- }, [Pt, M]), cn = d(() => I(!0), []), ln = d(() => {
231
- I(!1), N.current = !0, D((e) => ({
232
- ...e,
233
- discount: ye({
234
- value: e.discount,
235
- type: e.discountType,
236
- currency: e.currency
237
- })
238
- }));
239
- }, []), un = d(() => {
240
- P.current = !0, D((e) => {
241
- let t = s(e.taxRate);
242
- return t === e.taxRate ? e : {
243
- ...e,
244
- taxRate: t
245
- };
246
- });
247
- }, []), q = d((e, { validate: t }) => {
248
- t && (Tt.current = !0), D((t) => ({
249
- ...t,
250
- lineItems: e(t.lineItems)
251
- }));
15
+ function g({ open: g, bankAccountId: _, embeddedBankName: v, messages: y, onSelect: b }) {
16
+ let { initResponse: x } = n(), S = p(() => l(x?.scopes), [x?.scopes]), { paymentAccounts: C, isLoading: w, isIncomplete: T } = i({
17
+ enabled: g,
18
+ canReadEmbedded: S.canReadEmbedded,
19
+ canReadExternal: S.canReadExternal
20
+ }), E = r(), [D, O] = h(!1), [k, A] = h(a), [j, M] = h({}), N = m(!1), P = d(() => {
21
+ N.current = !1, O(!1), A(a), M({});
252
22
  }, []);
253
23
  f(() => {
254
- let e = Tt.current, t = N.current;
255
- if (!e && !t && !P.current) return;
256
- Tt.current = !1, N.current = !1, P.current = !1, e && (F.current.lines = !0), t && (F.current.discount = !0);
257
- let n = v.current || U > 0, r = e ? ue(E.lineItems, {
258
- currency: E.currency,
259
- messages: g,
260
- requireComplete: n
261
- }) : void 0;
262
- O((t) => {
263
- let i = { ...t };
264
- return F.current.lines && (i.lineItems = e ? r : t.lineItems, i.lineItemsSummary = ce(i.lineItems, Ee(E, g), n && E.lineItems.length === 0 ? g.lineItemsRequired : void 0)), F.current.discount && (i.discount = Te(E, g)), i;
24
+ if (!g || T || N.current || C.length !== 1) return;
25
+ let [e] = C;
26
+ N.current = !0, b({
27
+ bankAccountId: e.id,
28
+ bankAccountType: e.type
265
29
  });
266
30
  }, [
267
- U,
31
+ T,
32
+ b,
268
33
  g,
269
- E
34
+ C
270
35
  ]);
271
- let dn = d((e, t) => {
272
- let { unit: n, ...r } = t, i = ie(r);
273
- i.name !== void 0 && (i.productId = ""), n !== void 0 && (i.measureUnitId = n, i.measureUnitName = ""), i.taxable !== void 0 && (P.current = !0), q((t) => t.map((t) => t.id === e ? {
274
- ...t,
275
- ...i
276
- } : t), { validate: M });
277
- }, [q, M]), fn = d((e, t) => {
278
- q((n) => n.map((n) => n.id === e ? {
279
- ...n,
280
- ...te({
281
- product: t,
282
- currency: E.currency,
283
- unitNamesById: j
284
- })
285
- } : n), { validate: !0 });
286
- }, [
287
- q,
288
- j,
289
- E.currency
290
- ]), pn = d((e, t) => {
291
- t && q((n) => t.kind === "remove" ? n.filter((t) => t.id !== e) : n.map((n) => n.id === e ? {
292
- ...n,
293
- ...t.patch
294
- } : n), { validate: !0 });
295
- }, [q]), mn = d((e, t) => {
296
- let n = E.lineItems.find((t) => t.id === e);
297
- n && pn(e, o({
298
- lineItem: n,
299
- field: t,
300
- rowCount: E.lineItems.length,
301
- currency: E.currency
302
- }));
303
- }, [
304
- pn,
305
- E.currency,
306
- E.lineItems
307
- ]), hn = d((e, t) => {
308
- let n = E.lineItems.find((t) => t.id === e);
309
- n && pn(e, oe({
310
- lineItem: n,
311
- step: t,
312
- rowCount: E.lineItems.length
313
- }));
314
- }, [pn, E.lineItems]), gn = d(() => {
315
- let e = l(E.currency);
316
- Ct(e.id), D((t) => ({
317
- ...t,
318
- lineItems: [...t.lineItems, e]
319
- }));
320
- }, [E.currency]), _n = d((e) => {
321
- q((t) => t.length <= 1 ? t : t.filter((t) => t.id !== e), { validate: !0 });
322
- }, [q]), J = d((e, t) => e.type === "invoice" && (t === "issue" || ve(e) && U === 0), [U]), vn = d((e, t) => ({
323
- ...Pe({
324
- values: e,
325
- billingAddressId: L,
326
- messages: g,
327
- willIssue: t,
328
- hasStartedRecurrence: U > 0
329
- }),
330
- ...e.type === "invoice" && u(e) ? _e({
331
- fields: e,
332
- issuedCount: U,
333
- messages: g
334
- }) : {}
335
- }), [
336
- L,
337
- U,
338
- g
339
- ]), yn = d(() => {
340
- requestAnimationFrame(() => {
341
- let e = ft.current, t = e?.querySelector("[aria-invalid=\"true\"]");
342
- if (!e || !t) return;
343
- let n = t.getBoundingClientRect().top - e.getBoundingClientRect().top + e.scrollTop;
344
- e.scrollTo({
345
- top: Math.max(0, n - e.clientHeight / 2 + t.offsetHeight / 2),
346
- behavior: "smooth"
347
- });
36
+ let F = d((e) => {
37
+ let t = C.find((t) => t.id === e);
38
+ t && b({
39
+ bankAccountId: t.id,
40
+ bankAccountType: t.type
348
41
  });
349
- }, []), Y = d((e, t) => {
350
- O(e), wt(!0), v.current = t, F.current = {
351
- lines: !0,
352
- discount: !0
353
- }, yn();
354
- }, [yn]), bn = !T || E.frequency !== "once" || Wt.isError;
355
- f(() => {
356
- if (!S || !y.current || jt || W || !bn) return;
357
- y.current = !1;
358
- let e = J(E, "issue");
359
- Y(vn(E, e), e);
360
- }, [
361
- jt,
362
- S,
363
- bn,
364
- W,
365
- Y,
366
- vn,
367
- E,
368
- J
369
- ]);
370
- let xn = m({
371
- values: E,
372
- billingAddressId: L
373
- });
374
- f(() => {
375
- let e = xn.current;
376
- if (xn.current = {
377
- values: E,
378
- billingAddressId: L
379
- }, !M) return;
380
- let t = [
381
- "customerId",
382
- "paymentTermsId",
383
- "bankAccountId",
384
- "openingNote",
385
- "closingNote",
386
- "taxRate"
387
- ].filter((t) => e.values[t] !== E[t] || t === "customerId" && e.billingAddressId !== L || t === "paymentTermsId" && e.values.paymentTermsCustomDate !== E.paymentTermsCustomDate);
388
- if (!t.length) return;
389
- let n = Pe({
390
- values: E,
391
- billingAddressId: L,
392
- messages: g,
393
- willIssue: v.current
394
- });
395
- O((e) => {
396
- let r = { ...e };
397
- return t.forEach((e) => {
398
- n[e] ? r[e] = n[e] : delete r[e];
399
- }), r;
400
- });
401
- }, [
402
- L,
403
- g,
404
- M,
405
- E
406
- ]);
407
- let Sn = d(async (t) => {
408
- if (_.current = t, W) return;
409
- if (an) {
410
- e.error(g.attachmentsUploading);
411
- return;
412
- }
413
- if (k.isLoading) {
414
- e.error(g.lineItemsLoading);
415
- return;
416
- }
417
- let n = se(E.lineItems), r = n.length === E.lineItems.length ? E : {
418
- ...E,
419
- lineItems: n
420
- };
421
- r !== E && D(r);
422
- let i = r.type === "invoice" && u(r), a = J(r, t);
423
- if (a && (Mt || V.isLoading)) {
424
- e.error(g.issueChecksLoading);
425
- return;
426
- }
427
- if (a && !V.canAddAccount && !r.bankAccountId && !V.hasAccounts) {
428
- e.error(g.issueBankAccountUnavailable);
429
- return;
430
- }
431
- let o = vn(r, a);
432
- if (Oe(o)) {
433
- Y(o, a);
434
- return;
435
- }
436
- if (O({}), a && R.isTaxIdMissing) {
437
- e.error(g.issueTaxIdRequired);
438
- return;
439
- }
440
- if (a && (r.paymentReminderId || r.overdueReminderId)) {
441
- let t = Fe(R.counterpart, g);
442
- if (t) {
443
- e.error(t);
444
- return;
445
- }
446
- }
447
- let s = w === "edit" ? ht : b.current, c, l, ee = {};
448
- try {
449
- if (s) {
450
- let e = Ae({
451
- values: r,
452
- originalLineItems: x.current,
453
- originalCurrency: pt.current,
454
- unitNamesById: j,
455
- units: A
456
- });
457
- ee = Ne({
458
- values: r,
459
- originalLineItems: x.current,
460
- changes: e
461
- });
462
- let t = await st.mutateAsync({
463
- path: { receivable_id: s },
464
- body: je({
465
- values: r,
466
- billingAddressId: L ?? "",
467
- lineItemChanges: e
468
- })
469
- });
470
- Ft(), c = s, l = t?.type ?? r.type, i && t && (x.current = t.line_items, pt.current = t.currency, r = {
471
- ...r,
472
- lineItems: ne(r.lineItems, t.line_items)
473
- }, D(r));
474
- } else {
475
- ee = Ne({ values: r });
476
- let e = await ot.mutateAsync({ body: ke({
477
- values: r,
478
- billingAddressId: L ?? "",
479
- unitNamesById: j
480
- }) });
481
- if (!e?.id) {
482
- C(!1), tn();
483
- return;
484
- }
485
- c = e.id, l = e.type, i && (b.current = e.id, x.current = e.line_items, pt.current = e.currency, r = {
486
- ...r,
487
- lineItems: ne(r.lineItems, e.line_items)
488
- }, D(r));
489
- }
490
- } catch (t) {
491
- let n = We[r.type], i = Ke(t, {
492
- irrelevantVariants: n,
493
- messages: g
494
- });
495
- e.error((s ? g.updateFailed : g.createFailed).replace("{errorMessage}", i));
496
- let { errors: o, listError: c } = Ge(qe(t, n), ee), l = ce(o.lineItems, void 0, c);
497
- Y({
498
- ...o,
499
- ...l ? { lineItemsSummary: l } : {}
500
- }, a);
501
- return;
502
- }
503
- if (i) try {
504
- H ? await lt.mutateAsync({
505
- path: { recurrence_id: H.id },
506
- body: pe(r, { lockSchedule: Gt })
507
- }) : await ct.mutateAsync({ body: fe(r, c) });
508
- } catch (t) {
509
- e.error(Ke(t, { messages: g }));
510
- return;
511
- }
512
- else if (a) try {
513
- await ut.mutateAsync({ path: { receivable_id: c } });
514
- } catch {
515
- e.error(g.issueFailedAfterSave);
42
+ }, [b, C]), I = d(() => O(!0), []), L = d(() => {
43
+ O(!1), A(a), M({});
44
+ }, []), R = d((e) => A((t) => ({
45
+ ...t,
46
+ ...e
47
+ })), []), z = d(async () => {
48
+ let n = u(k, y);
49
+ if (M(n), !(Object.keys(n).length > 0)) try {
50
+ let t = await E.mutateAsync({ body: o(k) });
51
+ O(!1), A(a), b({
52
+ bankAccountId: t.id,
53
+ bankAccountType: "BANK_DETAILS"
54
+ }), e.success(y.bankAccountCreated.replace("{name}", t.display_name ?? ""));
55
+ } catch (n) {
56
+ e.error(t(n) ?? y.bankAccountCreateFailed);
516
57
  }
517
- let te = w === "create";
518
- C(!1), tn(), te && at?.(c, l);
519
58
  }, [
520
- V.canAddAccount,
521
- V.hasAccounts,
522
- V.isLoading,
523
- L,
524
- Ft,
525
- ot,
526
- ct,
527
- ht,
528
- H,
529
- an,
530
- Mt,
531
- ut,
532
- Gt,
533
- g,
534
- w,
535
- at,
536
- R.counterpart,
537
- R.isTaxIdMissing,
538
- W,
539
- tn,
540
- Y,
541
- A,
542
- j,
543
- k.isLoading,
544
- st,
545
- lt,
546
- vn,
547
59
  E,
548
- J
549
- ]), X = d(async (e = _.current) => {
550
- if (!dt.current) {
551
- dt.current = !0;
552
- try {
553
- await Sn(e);
554
- } finally {
555
- dt.current = !1;
556
- }
557
- }
558
- }, [Sn]), Cn = p(() => ({
559
- ...E,
560
- discount: Et ? E.discount : be(xe(E.discount, E.discountType, E.currency), E.discountType, E.currency),
561
- lineItems: E.lineItems.map(le)
562
- }), [Et, E]), wn = p(() => a(E.lineItems), [E.lineItems]), Z = p(() => we(E), [E]), Q = E.type === "invoice", Tn = Q && u(E), En = Qt || k.isLoading || z.isUploading || W, Dn = w === "edit" ? g.updateDraftButton : g.saveDraftButton, On = Tn ? H ? g.recurrenceUpdateButton : g.recurrenceActivateButton : Q ? g.issueButton : Dn, $ = Q && !Tn ? "issue" : "draft", kn = d(() => X("draft"), [X]), An = d(() => X($), [$, X]), jn = d(() => X(), [X]), Mn = d(() => {
563
- _.current = "draft";
564
- }, []), Nn = d(() => {
565
- _.current = $;
566
- }, [$]), Pn = p(() => Ce(Z, E.currency), [Z, E.currency]), Fn = $e({
567
- values: E,
568
- totals: Z,
569
- billingAddress: At,
570
- unitNamesById: j,
571
- messages: g,
572
- enabled: S
573
- });
60
+ k,
61
+ y,
62
+ b
63
+ ]), B = p(() => c({
64
+ accounts: C,
65
+ embeddedBankName: v,
66
+ messages: y
67
+ }), [
68
+ v,
69
+ y,
70
+ C
71
+ ]);
574
72
  return {
575
- open: S,
576
- setOpen: C,
577
- mode: w,
578
- values: E,
579
- sheetValues: Cn,
580
- errors: vt,
581
- setValues: D,
582
- updateValues: sn,
583
- commitTaxRate: un,
584
- focusDiscount: cn,
585
- commitDiscount: ln,
586
- updateLineItem: dn,
587
- selectProduct: fn,
588
- commitLineItem: mn,
589
- stepLineItem: hn,
590
- addLineItem: gn,
591
- removeLineItem: _n,
592
- attachmentsView: It,
593
- attachmentsUploading: z.isUploading,
594
- draftButtonLabel: Q && !Tn ? Dn : void 0,
595
- draftDisabled: En,
596
- primaryButtonLabel: On,
597
- primaryDisabled: En || V.isLoading && J(E, $) || Q && (Mt || !Tn && R.isCounterpartLoading),
598
- scrollContainerRef: ft,
599
- selectAttachmentFiles: z.selectFiles,
600
- setAttachmentIncludeInEmail: z.setIncludeInEmail,
601
- removeAttachment: z.remove,
602
- autoFocusLineItemId: St,
603
- lineItemUnitOptions: xt.unitOptions,
604
- lineItemsLoading: k.isLoading,
605
- lineItemControls: wn,
606
- totals: Z,
607
- preview: Fn,
608
- totalsView: Pn,
609
- currencySymbol: ee(E.currency),
610
- isSubmitting: Qt,
611
- currencyOptions: et(E.currency),
612
- paymentTerms: Bt,
613
- showBillingSection: E.type === "invoice" || w === "edit",
614
- recurrence: Xt,
615
- showRecurrenceSection: E.type === "invoice",
616
- recurrenceLoading: W,
617
- showDueDateField: E.type === "quote",
618
- openCreate: nn,
619
- openEdit: rn,
620
- close: on,
621
- submit: jn,
622
- submitDraft: kn,
623
- submitPrimary: An,
624
- selectDraftMode: Mn,
625
- selectPrimaryMode: Nn,
626
- units: xt,
627
- counterpartView: yt,
628
- counterpartForm: Rt,
629
- stateOptions: Dt,
630
- openCounterpartCreate: Rt.openCreate,
631
- bankAccount: V,
632
- reminders: $t
73
+ view: p(() => s({
74
+ options: B,
75
+ isLoading: w,
76
+ selectedId: _,
77
+ isAddingAccount: D,
78
+ canAddAccount: S.canAddAccount,
79
+ formValues: k,
80
+ formErrors: j,
81
+ isSaving: E.isPending
82
+ }), [
83
+ _,
84
+ E.isPending,
85
+ j,
86
+ k,
87
+ D,
88
+ w,
89
+ B,
90
+ S.canAddAccount
91
+ ]),
92
+ isLoading: w,
93
+ hasAccounts: C.length > 0,
94
+ canAddAccount: S.canAddAccount,
95
+ reset: P,
96
+ selectAccount: F,
97
+ openAddAccount: I,
98
+ cancelAddAccount: L,
99
+ updateAccountForm: R,
100
+ saveAccount: z
633
101
  };
634
102
  }
635
103
  //#endregion
636
- export { g as useReceivableForm };
104
+ export { g as useReceivableBankAccount };