@tesouro/embedded-components-react 0.5.248 → 0.5.249

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