@tesouro/embedded-components-react 0.5.279 → 0.5.280

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