@tesouro/embedded-components-react 0.5.214 → 0.5.216

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 (123) hide show
  1. package/dist/index.d.ts +144 -3
  2. package/dist/index.js +14 -13
  3. package/dist/lib/BankAccountOnboardingWidget.d.ts +56 -2
  4. package/dist/lib/BankAccountOnboardingWidget.js +4 -3
  5. package/dist/lib/MarketingWidget.js +1 -1
  6. package/dist/lib/ReceivablesWidget.d.ts +88 -1
  7. package/dist/lib/ReceivablesWidget.js +1 -1
  8. package/dist/lib/WidgetSuite.d.ts +53 -0
  9. package/dist/libs/shared/util-validation/dist/index5.js +7 -0
  10. package/dist/libs/tesouro-embedded-components-react/bank-account-onboarding-widget/feature/dist/index.js +3 -2
  11. package/dist/libs/tesouro-embedded-components-react/bank-account-onboarding-widget/feature/dist/index11.js +72 -72
  12. package/dist/libs/tesouro-embedded-components-react/bank-account-onboarding-widget/feature/dist/index12.js +4 -1
  13. package/dist/libs/tesouro-embedded-components-react/bank-account-onboarding-widget/feature/dist/index13.js +15 -15
  14. package/dist/libs/tesouro-embedded-components-react/bank-account-onboarding-widget/feature/dist/index14.js +60 -60
  15. package/dist/libs/tesouro-embedded-components-react/bank-account-onboarding-widget/feature/dist/index15.js +12 -12
  16. package/dist/libs/tesouro-embedded-components-react/bank-account-onboarding-widget/feature/dist/index16.js +16 -16
  17. package/dist/libs/tesouro-embedded-components-react/bank-account-onboarding-widget/feature/dist/index18.js +11 -11
  18. package/dist/libs/tesouro-embedded-components-react/bank-account-onboarding-widget/feature/dist/index21.js +8 -8
  19. package/dist/libs/tesouro-embedded-components-react/bank-account-onboarding-widget/feature/dist/index22.js +71 -5
  20. package/dist/libs/tesouro-embedded-components-react/bank-account-onboarding-widget/feature/dist/index23.js +95 -33
  21. package/dist/libs/tesouro-embedded-components-react/bank-account-onboarding-widget/feature/dist/index24.js +6 -17
  22. package/dist/libs/tesouro-embedded-components-react/bank-account-onboarding-widget/feature/dist/index25.js +16 -616
  23. package/dist/libs/tesouro-embedded-components-react/bank-account-onboarding-widget/feature/dist/index26.js +669 -0
  24. package/dist/libs/tesouro-embedded-components-react/bank-account-onboarding-widget/ui/dist/index.js +15 -13
  25. package/dist/libs/tesouro-embedded-components-react/bank-account-onboarding-widget/ui/dist/index10.js +52 -37
  26. package/dist/libs/tesouro-embedded-components-react/bank-account-onboarding-widget/ui/dist/index11.js +31 -37
  27. package/dist/libs/tesouro-embedded-components-react/bank-account-onboarding-widget/ui/dist/index12.js +33 -89
  28. package/dist/libs/tesouro-embedded-components-react/bank-account-onboarding-widget/ui/dist/index13.js +39 -12
  29. package/dist/libs/tesouro-embedded-components-react/bank-account-onboarding-widget/ui/dist/index14.js +98 -2
  30. package/dist/libs/tesouro-embedded-components-react/bank-account-onboarding-widget/ui/dist/index15.js +14 -4
  31. package/dist/libs/tesouro-embedded-components-react/bank-account-onboarding-widget/ui/dist/index16.js +2 -185
  32. package/dist/libs/tesouro-embedded-components-react/bank-account-onboarding-widget/ui/dist/index17.js +4 -30
  33. package/dist/libs/tesouro-embedded-components-react/bank-account-onboarding-widget/ui/dist/index18.js +183 -21
  34. package/dist/libs/tesouro-embedded-components-react/bank-account-onboarding-widget/ui/dist/index19.js +26 -66
  35. package/dist/libs/tesouro-embedded-components-react/bank-account-onboarding-widget/ui/dist/index20.js +21 -233
  36. package/dist/libs/tesouro-embedded-components-react/bank-account-onboarding-widget/ui/dist/index21.js +66 -27
  37. package/dist/libs/tesouro-embedded-components-react/bank-account-onboarding-widget/ui/dist/index22.js +233 -26
  38. package/dist/libs/tesouro-embedded-components-react/bank-account-onboarding-widget/ui/dist/index23.js +27 -72
  39. package/dist/libs/tesouro-embedded-components-react/bank-account-onboarding-widget/ui/dist/index24.js +26 -85
  40. package/dist/libs/tesouro-embedded-components-react/bank-account-onboarding-widget/ui/dist/index25.js +74 -8
  41. package/dist/libs/tesouro-embedded-components-react/bank-account-onboarding-widget/ui/dist/index26.js +83 -55
  42. package/dist/libs/tesouro-embedded-components-react/bank-account-onboarding-widget/ui/dist/index27.js +6 -7
  43. package/dist/libs/tesouro-embedded-components-react/bank-account-onboarding-widget/ui/dist/index28.js +37 -42
  44. package/dist/libs/tesouro-embedded-components-react/bank-account-onboarding-widget/ui/dist/index29.js +11 -0
  45. package/dist/libs/tesouro-embedded-components-react/bank-account-onboarding-widget/ui/dist/index30.js +64 -0
  46. package/dist/libs/tesouro-embedded-components-react/bank-account-onboarding-widget/ui/dist/index9.js +7 -33
  47. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/data-access/dist/index.js +7 -7
  48. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/data-access/dist/index10.js +63 -67
  49. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/data-access/dist/index11.js +160 -1
  50. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/data-access/dist/index12.js +6 -0
  51. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/data-access/dist/index2.js +32 -25
  52. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/data-access/dist/index6.js +25 -200
  53. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/data-access/dist/index7.js +175 -1
  54. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/data-access/dist/index8.js +1 -101
  55. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/data-access/dist/index9.js +92 -71
  56. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index.js +1 -1
  57. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index10.js +44 -100
  58. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index11.js +93 -421
  59. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index12.js +442 -112
  60. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index13.js +166 -157
  61. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index14.js +150 -204
  62. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index15.js +202 -31
  63. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index16.js +32 -145
  64. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index17.js +145 -37
  65. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index18.js +44 -58
  66. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index19.js +113 -87
  67. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index20.js +58 -116
  68. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index21.js +83 -357
  69. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index22.js +111 -65
  70. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index23.js +449 -99
  71. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index24.js +68 -281
  72. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index25.js +115 -0
  73. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index26.js +314 -0
  74. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index5.js +1 -1
  75. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index6.js +34 -23
  76. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index8.js +444 -92
  77. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index9.js +113 -52
  78. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index.js +18 -14
  79. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index10.js +2 -92
  80. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index11.js +95 -3
  81. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index12.js +3 -24
  82. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index13.js +24 -1
  83. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index14.js +1 -3
  84. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index15.js +1 -1
  85. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index16.js +3 -18
  86. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index17.js +18 -1
  87. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index18.js +0 -3
  88. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index19.js +0 -8
  89. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index20.js +11 -0
  90. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index21.js +1 -264
  91. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index22.js +258 -42
  92. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index23.js +38 -62
  93. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index24.js +61 -463
  94. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index25.js +457 -89
  95. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index26.js +91 -234
  96. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index27.js +89 -82
  97. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index28.js +22 -338
  98. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index29.js +236 -0
  99. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index3.js +26 -204
  100. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index30.js +3 -0
  101. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index31.js +249 -0
  102. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index32.js +93 -0
  103. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index33.js +344 -0
  104. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index4.js +208 -32
  105. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index5.js +29 -202
  106. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index6.js +183 -137
  107. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index7.js +157 -12
  108. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index8.js +10 -19
  109. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index9.js +23 -2
  110. package/dist/libs/tesouro-embedded-components-react/marketing-widget/feature/dist/index.js +1 -1
  111. package/dist/libs/tesouro-embedded-components-react/marketing-widget/feature/dist/index5.js +16 -19
  112. package/dist/libs/tesouro-embedded-components-react/marketing-widget/feature/dist/index6.js +157 -16
  113. package/dist/libs/tesouro-embedded-components-react/shared/data-access/dist/index.js +40 -40
  114. package/dist/libs/tesouro-embedded-components-react/shared/data-access/dist/lib/onboardingSuppressionReason.js +3 -1
  115. package/dist/libs/tesouro-embedded-components-react/shared/data-access/dist/lib/rest/@tanstack/react-query.gen.js +167 -156
  116. package/dist/libs/tesouro-embedded-components-react/shared/data-access/dist/lib/rest/sdk.gen.js +66 -34
  117. package/dist/libs/tesouro-embedded-components-react/shared/feature/dist/index.js +2 -1
  118. package/dist/libs/tesouro-embedded-components-react/shared/feature/dist/lib/analytics/build-info.js +1 -1
  119. package/dist/libs/tesouro-embedded-components-react/shared/feature/dist/lib/application/bankAccountApplication.js +26 -0
  120. package/dist/libs/tesouro-embedded-components-react/widget-suite/feature/dist/index16.js +1 -1
  121. package/dist/packages/shared-ui-shadcn/dist/index.js +13 -13
  122. package/package.json +1 -1
  123. package/dist/libs/tesouro-embedded-components-react/marketing-widget/feature/dist/index7.js +0 -161
@@ -2,114 +2,464 @@
2
2
  "use client";
3
3
  "use client";
4
4
  "use client";
5
- import { useAnalyticsTrack as e } from "../../../shared/feature/dist/lib/analytics/hooks.js";
6
- import "../../../shared/feature/dist/index.js";
7
- import { ReceivablesWidgetAnalyticsEvent as t } from "./index2.js";
8
- import { coerceEnabledTabs as n, resolveInitialTab as r, tabForType as i, typeForTab as a } from "./index11.js";
9
- import { RECEIVABLE_MESSAGE_LABELS_EN as o } from "./index12.js";
10
- import { useReceivableActions as s } from "./index14.js";
11
- import { useReceivableDetails as c } from "./index15.js";
12
- import { hasSelectedText as l } from "../../../shared/product-catalog/feature/dist/lib/helpers.js";
5
+ import { getStateOptions as e } from "../../../shared/util/dist/lib/usStates.js";
6
+ import { extractApiErrorMessage as t } from "../../../shared/util/dist/lib/apiErrors.js";
7
+ import { COUNTERPART_MESSAGE_LABELS_EN as n } from "../../../shared/counterpart-management/feature/dist/lib/labels.js";
8
+ import { useCounterpartAddressesQuery as r } from "../../../shared/counterpart-management/data-access/dist/index7.js";
9
+ import { useCounterpartForm as i } from "../../../shared/counterpart-management/feature/dist/lib/useCounterpartForm.js";
10
+ import "../../../shared/counterpart-management/feature/dist/index.js";
11
+ import "../../ui/dist/index10.js";
12
+ import "../../ui/dist/index.js";
13
+ import { buildLineItemControls as a, commitLineItemField as ee, commitTaxRateInput as te, convertPriceInput as ne, createLineItem as re, getCurrencySymbol as ie, lineItemFromProduct as ae, reconcileLineItemIds as oe, reconcileMeasureUnits as se, sanitizeLineItemPatch as ce, sanitizeTaxRateInput as le, stepLineItemQuantity as ue, stripBlankLineItems as de, summarizeLineItemErrors as fe, toSheetLineItem as pe, validateLineItems as me } from "./index6.js";
14
+ import { buildReceivableAttachmentsView as he } from "./index7.js";
15
+ import { buildCreateRecurrencePayload as ge, buildUpdateRecurrencePayload as _e, clearRecurrenceRecipients as ve, countIssuedIterations as ye, isRecurring as o, recurrenceToFormFields as be, validateRecurrence as xe } from "./index8.js";
16
+ import { convertDiscountInput as Se, decorateDiscountInput as Ce, discountInputToMinorUnits as we, sanitizeDiscountInput as Te } from "./index10.js";
17
+ import { buildFormTotalsView as Ee, calculateFormTotals as De, validateDiscount as Oe, validateInvoiceTotals as ke } from "./index11.js";
18
+ import { createEmptyReceivableFormValues as Ae, hasReceivableFormErrors as je, receivableFormValuesToCreatePayload as Me, receivableFormValuesToLineItemChanges as Ne, receivableFormValuesToUpdatePayload as Pe, receivableToFormValues as Fe, validateReceivableForm as Ie } from "./index12.js";
19
+ import { shouldShowRemindersInitially as Le } from "./index14.js";
20
+ import { useCreateReceivableMutation as Re, useUpdateReceivableMutation as ze } from "../../data-access/dist/index7.js";
21
+ import { useCreateRecurrenceMutation as Be, useRecurrenceQuery as Ve, useUpdateRecurrenceMutation as He } from "../../data-access/dist/index11.js";
22
+ import "../../data-access/dist/index.js";
23
+ import { useReceivableAttachmentUploads as Ue } from "./index17.js";
24
+ import { useReceivablePaymentTerms as We } from "./index18.js";
25
+ import { useReceivableRecurrence as Ge } from "./index19.js";
26
+ import { useReceivableBankAccount as Ke } from "./index21.js";
27
+ import { useReceivableReminders as qe } from "./index22.js";
28
+ import { getCurrencyOptions as Je } from "../../../shared/product-catalog/feature/dist/lib/helpers.js";
29
+ import { useMeasureUnitsQuery as Ye } from "../../../shared/product-catalog/data-access/dist/index9.js";
30
+ import { useMeasureUnits as Xe } from "../../../shared/product-catalog/feature/dist/lib/useMeasureUnits.js";
13
31
  import "../../../shared/product-catalog/feature/dist/index.js";
14
- import { useReceivableForm as u } from "./index21.js";
15
- import { useReceivablesTable as d } from "./index22.js";
16
- import { useCallback as f, useEffect as p, useMemo as m, useState as h } from "react";
32
+ import { useCallback as s, useEffect as c, useMemo as l, useRef as u, useState as d } from "react";
17
33
  //#region ../../libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index23.js
18
- function g({ counterpartMessageLabels: g, defaultTab: _, embeddedBankName: v, enabledTabs: y, messageLabels: b, onReceivableCreated: x, onReceivableOpened: S }) {
19
- let C = e();
20
- p(() => {
21
- C(t.Mounted);
22
- }, [C]);
23
- let w = m(() => ({
24
- ...o,
25
- ...b
26
- }), [b]), T = m(() => n(y), [y]), [E, D] = h(() => r({
27
- defaultTab: _,
28
- enabledTabs: T
29
- })), [O, k] = h(), [A, j] = h(!1);
30
- p(() => {
31
- T.includes(E) || D(r({
32
- defaultTab: _,
33
- enabledTabs: T
34
+ function f({ messages: f, counterpartMessageLabels: Ze, embeddedBankName: Qe, onCreated: $e }) {
35
+ let p = Re(), m = ze(), et = Be(), tt = He(), h = u(void 0), g = u([]), _ = u(""), [v, y] = d(!1), [b, nt] = d("create"), [rt, it] = d(), [at, x] = d(), [S, C] = d(() => Ae()), [ot, w] = d({}), [st, ct] = d("none"), T = Xe(), E = Ye(), D = E.data?.data, { unitNamesById: O } = T, [lt, k] = d(), [A, j] = d(!1), M = u(!1), N = u(!1), P = u(!1), F = u({
36
+ lines: !1,
37
+ discount: !1
38
+ }), [ut, I] = d(!1), dt = l(() => e(), []), ft = l(() => ({
39
+ ...n,
40
+ ...Ze
41
+ }), [Ze]), pt = r(S.customerId), mt = pt.data?.data?.[0], L = pt.data?.data?.[0]?.id, ht = s((e) => {
42
+ C((t) => ({
43
+ ...t,
44
+ attachments: e(t.attachments)
34
45
  }));
46
+ }, []), R = Ue({
47
+ attachments: S.attachments,
48
+ setAttachments: ht,
49
+ receivableId: rt
50
+ }), { reset: z, discardUploads: B, commitRemovals: gt } = R, _t = S.type === "invoice" ? he({
51
+ attachments: S.attachments,
52
+ pendingUploads: R.pendingUploads,
53
+ isCountLimitReached: R.isCountLimitReached,
54
+ isRecurring: o(S),
55
+ messages: f
56
+ }) : void 0, vt = s((e) => {
57
+ C((t) => {
58
+ let n = e ?? "";
59
+ return n === t.customerId ? t : ve({
60
+ ...t,
61
+ customerId: n
62
+ });
63
+ });
64
+ }, []), yt = i({
65
+ view: st,
66
+ setView: ct,
67
+ selectedId: S.customerId || void 0,
68
+ setSelectedId: vt,
69
+ messages: ft,
70
+ counterpartType: "customer",
71
+ counterpart: void 0,
72
+ primaryAddress: mt
73
+ }), bt = s((e) => C((t) => {
74
+ let n = e({
75
+ paymentTermsId: t.paymentTermsId,
76
+ paymentTermsCustomDate: t.paymentTermsCustomDate
77
+ });
78
+ return {
79
+ ...t,
80
+ ...n,
81
+ ...n.paymentTermsId === "receipt_due" ? { paymentReminderId: "" } : {}
82
+ };
83
+ }), []), xt = We({
84
+ paymentTermsId: S.paymentTermsId,
85
+ paymentTermsCustomDate: S.paymentTermsCustomDate,
86
+ isRecurring: S.type === "invoice" && o(S),
87
+ messages: f,
88
+ onChange: bt
89
+ }), V = xt.reset, St = s((e) => C((t) => ({
90
+ ...t,
91
+ ...e
92
+ })), []), Ct = Ke({
93
+ open: v,
94
+ bankAccountId: S.bankAccountId,
95
+ embeddedBankName: Qe,
96
+ messages: f,
97
+ onSelect: St
98
+ }), H = Ct.reset, wt = Ve(at), U = at ? wt.data : void 0, W = ye(U), G = W > 0, K = !!at && wt.isLoading, q = u(void 0);
99
+ c(() => {
100
+ U && q.current !== U.id && (q.current = U.id, C((e) => ({
101
+ ...e,
102
+ ...be(U)
103
+ })));
104
+ }, [U]);
105
+ let Tt = s((e) => C(e), []), Et = s((e) => w((t) => {
106
+ if (!e.some((e) => e in t)) return t;
107
+ let n = { ...t };
108
+ return e.forEach((e) => delete n[e]), n;
109
+ }), []), Dt = u([]), Ot = s((e) => {
110
+ if (!A) {
111
+ Et(e);
112
+ return;
113
+ }
114
+ Dt.current.push(...e);
115
+ }, [Et, A]);
116
+ c(() => {
117
+ let e = Dt.current;
118
+ if (!e.length) return;
119
+ Dt.current = [];
120
+ let t = xe({
121
+ fields: S,
122
+ issuedCount: W,
123
+ messages: f
124
+ });
125
+ w((n) => {
126
+ let r = { ...n };
127
+ return e.forEach((e) => {
128
+ t[e] ? r[e] = t[e] : delete r[e];
129
+ }), r;
130
+ });
35
131
  }, [
36
- E,
37
- _,
38
- T
132
+ W,
133
+ f,
134
+ S
39
135
  ]);
40
- let M = f((e, t) => {
41
- D(i(t)), k(e), j(!0), x?.(e, t);
42
- }, [x]), N = d({
43
- activeTab: E,
44
- messages: w
45
- }), P = c({
46
- selectedReceivableId: O,
47
- enabled: A,
48
- messages: w
49
- }), F = u({
50
- messages: w,
51
- counterpartMessageLabels: g,
52
- embeddedBankName: v,
53
- onCreated: M
54
- }), I = f(() => {
55
- let e = a(E);
56
- F.openCreate(e === "quote" ? "quote" : "invoice");
57
- }, [E, F.openCreate]), L = s({
58
- selectedReceivable: P.receivable,
59
- messages: w,
60
- onCreated: M,
61
- onDeleted: (e) => {
62
- e === O && (k(void 0), j(!1));
136
+ let kt = Ge({
137
+ values: S,
138
+ errors: ot,
139
+ lockSchedule: G,
140
+ messages: f,
141
+ onChange: Tt,
142
+ onClearErrors: Et,
143
+ onRevalidateErrors: Ot
144
+ }), J = kt.reset, At = s((e) => C((t) => ({
145
+ ...t,
146
+ ...e
147
+ })), []), jt = p.isPending || m.isPending || et.isPending || tt.isPending, Mt = qe({
148
+ open: v,
149
+ isInvoice: S.type === "invoice",
150
+ disabled: jt,
151
+ paymentTermsId: S.paymentTermsId,
152
+ paymentTermsCustomDate: S.paymentTermsCustomDate,
153
+ paymentReminderId: S.paymentReminderId,
154
+ overdueReminderId: S.overdueReminderId,
155
+ messages: f,
156
+ onSelect: At
157
+ }), Y = Mt.reset, Nt = s(() => {
158
+ g.current = [], k(void 0), nt("create"), it(void 0), x(void 0), q.current = void 0, h.current = void 0, C(Ae()), w({}), j(!1), I(!1), F.current = {
159
+ lines: !1,
160
+ discount: !1
161
+ }, z(), J();
162
+ }, [z, J]), Pt = s((e = "invoice") => {
163
+ V(), H(), J();
164
+ let t = {
165
+ ...Ae(),
166
+ type: e
167
+ };
168
+ Y(Le(t)), g.current = [], h.current = void 0, q.current = void 0, k(void 0), nt("create"), it(void 0), x(void 0), C(t), w({}), z(), j(!1), I(!1), F.current = {
169
+ lines: !1,
170
+ discount: !1
171
+ }, y(!0);
172
+ }, [
173
+ z,
174
+ V,
175
+ H,
176
+ J,
177
+ Y
178
+ ]), Ft = s((e) => {
179
+ if (e.type === "credit_note") return;
180
+ V(), H(), J();
181
+ let t = Fe(e, D);
182
+ Y(Le(t)), g.current = e.line_items, _.current = e.currency, h.current = void 0, q.current = void 0, k(void 0), nt("edit"), it(e.id), x(e.type === "invoice" ? e.recurrence_id ?? void 0 : void 0), C(t), w({}), j(!1), I(!1), F.current = {
183
+ lines: !1,
184
+ discount: !1
185
+ }, z(), y(!0);
186
+ }, [
187
+ z,
188
+ V,
189
+ H,
190
+ J,
191
+ Y,
192
+ D
193
+ ]);
194
+ c(() => {
195
+ D?.length && C((e) => {
196
+ let t = se(e.lineItems, D);
197
+ return t === e.lineItems ? e : {
198
+ ...e,
199
+ lineItems: t
200
+ };
201
+ });
202
+ }, [D]);
203
+ let X = R.isUploading, It = s(() => {
204
+ X || (B(), y(!1), w({}));
205
+ }, [B, X]), Lt = s((e) => {
206
+ let t = { ...e };
207
+ t.taxRate !== void 0 && (t.taxRate = le(t.taxRate), P.current = !0), t.type !== void 0 && t.type !== "invoice" && B(), t.discount !== void 0 && A && (N.current = !0), t.discountType !== void 0 && (N.current = !0), t.currency !== void 0 && (M.current = !0), C((e) => {
208
+ let n = {
209
+ ...e,
210
+ ...t
211
+ };
212
+ return t.discount !== void 0 && (n.discount = Te(t.discount, n.discountType, n.currency)), n.currency !== e.currency && (n.lineItems = e.lineItems.map((t) => ({
213
+ ...t,
214
+ price: ne(t.price, e.currency, n.currency)
215
+ }))), (n.currency !== e.currency || n.discountType !== e.discountType) && (n.discount = Se({
216
+ value: n.discount,
217
+ type: n.discountType,
218
+ currency: n.currency
219
+ })), n;
220
+ });
221
+ }, [B, A]), Rt = s(() => I(!0), []), zt = s(() => {
222
+ I(!1), N.current = !0, C((e) => ({
223
+ ...e,
224
+ discount: Se({
225
+ value: e.discount,
226
+ type: e.discountType,
227
+ currency: e.currency
228
+ })
229
+ }));
230
+ }, []), Bt = s(() => {
231
+ P.current = !0, C((e) => {
232
+ let t = te(e.taxRate);
233
+ return t === e.taxRate ? e : {
234
+ ...e,
235
+ taxRate: t
236
+ };
237
+ });
238
+ }, []), Z = s((e, { validate: t }) => {
239
+ t && (M.current = !0), C((t) => ({
240
+ ...t,
241
+ lineItems: e(t.lineItems)
242
+ }));
243
+ }, []);
244
+ c(() => {
245
+ let e = M.current, t = N.current;
246
+ if (!e && !t && !P.current) return;
247
+ M.current = !1, N.current = !1, P.current = !1, e && (F.current.lines = !0), t && (F.current.discount = !0);
248
+ let n = e ? me(S.lineItems, {
249
+ currency: S.currency,
250
+ messages: f
251
+ }) : void 0;
252
+ w((t) => {
253
+ let r = { ...t };
254
+ return F.current.lines && (r.lineItems = e ? n : t.lineItems, r.lineItemsSummary = fe(r.lineItems, ke(S, f))), F.current.discount && (r.discount = Oe(S, f)), r;
255
+ });
256
+ }, [f, S]);
257
+ let Vt = s((e, t) => {
258
+ let { unit: n, ...r } = t, i = ce(r);
259
+ 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 ? {
260
+ ...t,
261
+ ...i
262
+ } : t), { validate: A });
263
+ }, [Z, A]), Ht = s((e, t) => {
264
+ Z((n) => n.map((n) => n.id === e ? {
265
+ ...n,
266
+ ...ae({
267
+ product: t,
268
+ currency: S.currency,
269
+ unitNamesById: O
270
+ })
271
+ } : n), { validate: !0 });
272
+ }, [
273
+ Z,
274
+ O,
275
+ S.currency
276
+ ]), Q = s((e, t) => {
277
+ t && Z((n) => t.kind === "remove" ? n.filter((t) => t.id !== e) : n.map((n) => n.id === e ? {
278
+ ...n,
279
+ ...t.patch
280
+ } : n), { validate: !0 });
281
+ }, [Z]), Ut = s((e, t) => {
282
+ let n = S.lineItems.find((t) => t.id === e);
283
+ n && Q(e, ee({
284
+ lineItem: n,
285
+ field: t,
286
+ rowCount: S.lineItems.length,
287
+ currency: S.currency
288
+ }));
289
+ }, [
290
+ Q,
291
+ S.currency,
292
+ S.lineItems
293
+ ]), Wt = s((e, t) => {
294
+ let n = S.lineItems.find((t) => t.id === e);
295
+ n && Q(e, ue({
296
+ lineItem: n,
297
+ step: t,
298
+ rowCount: S.lineItems.length
299
+ }));
300
+ }, [Q, S.lineItems]), Gt = s(() => {
301
+ let e = re(S.currency);
302
+ k(e.id), C((t) => ({
303
+ ...t,
304
+ lineItems: [...t.lineItems, e]
305
+ }));
306
+ }, [S.currency]), Kt = s((e) => {
307
+ Z((t) => t.length <= 1 ? t : t.filter((t) => t.id !== e), { validate: !0 });
308
+ }, [Z]), qt = s(async () => {
309
+ if (X || K) return;
310
+ if (E.isLoading) {
311
+ w({ form: f.lineItemsLoading });
312
+ return;
63
313
  }
64
- }), R = f((e) => {
65
- l() || (k(e.id), j(!0), S?.(e.id, e.type));
66
- }, [S]);
67
- return {
68
- activeTab: E,
69
- enabledTabs: T,
70
- setActiveTab: D,
71
- table: N,
72
- details: P,
73
- detailsOpen: A,
74
- closeDetails: f(() => {
75
- j(!1), k(void 0);
76
- }, []),
77
- form: F,
78
- openCreate: I,
79
- actions: L,
80
- handleRowClick: R,
81
- handleActionClick: f((e, t) => {
82
- let n = N.getReceivableById(t.id);
83
- if (e === "edit") {
84
- if (n) {
85
- F.openEdit(n);
314
+ let e = de(S.lineItems), n = e.length === S.lineItems.length ? S : {
315
+ ...S,
316
+ lineItems: e
317
+ };
318
+ n !== S && C(n);
319
+ let r = n.type === "invoice" && o(n), i = {
320
+ ...Ie({
321
+ values: n,
322
+ billingAddressId: L,
323
+ messages: f
324
+ }),
325
+ ...r ? xe({
326
+ fields: n,
327
+ issuedCount: W,
328
+ messages: f
329
+ }) : {}
330
+ };
331
+ if (je(i)) {
332
+ w(i), j(!0), F.current = {
333
+ lines: !0,
334
+ discount: !0
335
+ };
336
+ return;
337
+ }
338
+ w({});
339
+ let a = b === "edit" ? rt : h.current;
340
+ try {
341
+ let e, t;
342
+ if (a) {
343
+ let i = await m.mutateAsync({
344
+ path: { receivable_id: a },
345
+ body: Pe({
346
+ values: n,
347
+ billingAddressId: L ?? "",
348
+ lineItemChanges: Ne({
349
+ values: n,
350
+ originalLineItems: g.current,
351
+ originalCurrency: _.current,
352
+ unitNamesById: O,
353
+ units: D
354
+ })
355
+ })
356
+ });
357
+ gt(), e = a, t = i?.type ?? n.type, r && i && (g.current = i.line_items, _.current = i.currency, n = {
358
+ ...n,
359
+ lineItems: oe(n.lineItems, i.line_items)
360
+ }, C(n));
361
+ } else {
362
+ let i = await p.mutateAsync({ body: Me({
363
+ values: n,
364
+ billingAddressId: L ?? "",
365
+ unitNamesById: O
366
+ }) });
367
+ if (!i?.id) {
368
+ y(!1), Nt();
86
369
  return;
87
370
  }
88
- k(t.id), j(!0);
89
- return;
371
+ e = i.id, t = i.type, r && (h.current = i.id, g.current = i.line_items, _.current = i.currency, n = {
372
+ ...n,
373
+ lineItems: oe(n.lineItems, i.line_items)
374
+ }, C(n));
90
375
  }
91
- k(t.id), L.openAction(e, t, n ?? null);
92
- }, [
93
- L,
94
- F.openEdit,
95
- N.getReceivableById
96
- ]),
97
- handleDetailsActionClick: f((e, t) => {
98
- if (e === "edit") {
99
- P.receivable && (F.openEdit(P.receivable), j(!1));
100
- return;
101
- }
102
- L.openAction(e, {
103
- id: t.id,
104
- title: t.title,
105
- type: t.type
106
- }, P.receivable ?? null);
107
- }, [
108
- L,
109
- P.receivable,
110
- F.openEdit
111
- ])
376
+ r && (U ? await tt.mutateAsync({
377
+ path: { recurrence_id: U.id },
378
+ body: _e(n, { lockSchedule: G })
379
+ }) : await et.mutateAsync({ body: ge(n, e) }));
380
+ let i = b === "create";
381
+ y(!1), Nt(), i && $e?.(e, t);
382
+ } catch (e) {
383
+ w({ form: t(e) ?? f.genericError });
384
+ }
385
+ }, [
386
+ L,
387
+ gt,
388
+ p,
389
+ et,
390
+ rt,
391
+ U,
392
+ X,
393
+ W,
394
+ G,
395
+ f,
396
+ b,
397
+ $e,
398
+ K,
399
+ Nt,
400
+ D,
401
+ O,
402
+ E.isLoading,
403
+ m,
404
+ tt,
405
+ S
406
+ ]), Jt = l(() => ({
407
+ ...S,
408
+ discount: ut ? S.discount : Ce(we(S.discount, S.discountType, S.currency), S.discountType, S.currency),
409
+ lineItems: S.lineItems.map(pe)
410
+ }), [ut, S]), Yt = l(() => a(S.lineItems), [S.lineItems]), $ = l(() => De(S), [S]), Xt = l(() => Ee($, S.currency), [$, S.currency]);
411
+ return {
412
+ open: v,
413
+ setOpen: y,
414
+ mode: b,
415
+ values: S,
416
+ sheetValues: Jt,
417
+ errors: ot,
418
+ setValues: C,
419
+ updateValues: Lt,
420
+ commitTaxRate: Bt,
421
+ focusDiscount: Rt,
422
+ commitDiscount: zt,
423
+ updateLineItem: Vt,
424
+ selectProduct: Ht,
425
+ commitLineItem: Ut,
426
+ stepLineItem: Wt,
427
+ addLineItem: Gt,
428
+ removeLineItem: Kt,
429
+ attachmentsView: _t,
430
+ attachmentsUploading: R.isUploading,
431
+ saveDisabled: E.isLoading || R.isUploading || K,
432
+ selectAttachmentFiles: R.selectFiles,
433
+ setAttachmentIncludeInEmail: R.setIncludeInEmail,
434
+ removeAttachment: R.remove,
435
+ autoFocusLineItemId: lt,
436
+ lineItemUnitOptions: T.unitOptions,
437
+ lineItemsLoading: E.isLoading,
438
+ lineItemControls: Yt,
439
+ totals: $,
440
+ totalsView: Xt,
441
+ currencySymbol: ie(S.currency),
442
+ isSubmitting: jt,
443
+ currencyOptions: Je(S.currency),
444
+ paymentTerms: xt,
445
+ showBillingSection: S.type === "invoice" || b === "edit",
446
+ recurrence: kt,
447
+ showRecurrenceSection: S.type === "invoice",
448
+ recurrenceLoading: K,
449
+ submitLabel: S.type === "invoice" && o(S) ? U ? f.recurrenceUpdateButton : f.recurrenceActivateButton : void 0,
450
+ showDueDateField: S.type === "quote",
451
+ openCreate: Pt,
452
+ openEdit: Ft,
453
+ close: It,
454
+ submit: qt,
455
+ units: T,
456
+ counterpartView: st,
457
+ counterpartForm: yt,
458
+ stateOptions: dt,
459
+ openCounterpartCreate: yt.openCreate,
460
+ bankAccount: Ct,
461
+ reminders: Mt
112
462
  };
113
463
  }
114
464
  //#endregion
115
- export { g as useReceivablesWidget };
465
+ export { f as useReceivableForm };