@tesouro/embedded-components-react 0.5.292 → 0.5.294

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