@tesouro/embedded-components-react 0.5.201 → 0.5.202

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 (45) hide show
  1. package/dist/index.d.ts +16 -0
  2. package/dist/index.js +1 -1
  3. package/dist/lib/ReceivablesWidget.d.ts +16 -0
  4. package/dist/lib/ReceivablesWidget.js +1 -1
  5. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/data-access/dist/index.js +6 -6
  6. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/data-access/dist/index2.js +24 -18
  7. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/data-access/dist/index4.js +65 -2
  8. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index.js +1 -1
  9. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index10.js +188 -45
  10. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index11.js +30 -265
  11. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index12.js +144 -64
  12. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index13.js +47 -109
  13. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index14.js +293 -216
  14. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index15.js +75 -0
  15. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index16.js +114 -0
  16. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index17.js +237 -0
  17. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index4.js +14 -1
  18. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index5.js +28 -243
  19. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index6.js +212 -375
  20. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index7.js +64 -62
  21. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index8.js +409 -187
  22. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index9.js +73 -40
  23. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index.js +10 -9
  24. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index10.js +0 -9
  25. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index11.js +4 -1
  26. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index12.js +10 -263
  27. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index13.js +1 -72
  28. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index14.js +241 -398
  29. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index15.js +66 -100
  30. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index16.js +406 -76
  31. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index17.js +92 -330
  32. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index18.js +93 -0
  33. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index19.js +344 -0
  34. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index2.js +6 -1
  35. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index4.js +157 -20
  36. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index5.js +24 -1
  37. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index6.js +1 -3
  38. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index7.js +3 -18
  39. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index8.js +2 -0
  40. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index9.js +18 -4
  41. package/dist/libs/tesouro-embedded-components-react/shared/data-access/dist/index.js +37 -37
  42. package/dist/libs/tesouro-embedded-components-react/shared/data-access/dist/lib/rest/@tanstack/react-query.gen.js +54 -54
  43. package/dist/libs/tesouro-embedded-components-react/shared/data-access/dist/lib/rest/sdk.gen.js +115 -94
  44. package/dist/libs/tesouro-embedded-components-react/shared/feature/dist/lib/analytics/build-info.js +1 -1
  45. package/package.json +1 -1
@@ -2,225 +2,302 @@
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 { WidgetProvider as t } from "../../../shared/feature/dist/lib/WidgetProvider/WidgetProvider.js";
7
- import "../../../shared/feature/dist/index.js";
8
- import { CounterpartFormSheet as n } from "../../../shared/counterpart-management/ui/dist/index9.js";
9
- import { CounterpartSelector as r } from "../../../shared/counterpart-management/feature/dist/lib/CounterpartSelector.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 { usePaymentTermsQuery as n } from "../../../shared/data-access/dist/lib/reference-data/usePaymentTermsQuery.js";
8
+ import { COUNTERPART_MESSAGE_LABELS_EN as r } from "../../../shared/counterpart-management/feature/dist/lib/labels.js";
9
+ import { useCounterpartAddressesQuery as i } from "../../../shared/counterpart-management/data-access/dist/index7.js";
10
+ import { useCounterpartForm as a } from "../../../shared/counterpart-management/feature/dist/lib/useCounterpartForm.js";
10
11
  import "../../../shared/counterpart-management/feature/dist/index.js";
11
- import { ReceivablesWidgetAnalyticsEvent as i, WIDGET_NAME as a } from "./index2.js";
12
- import { PAGE_SIZE_OPTIONS as o } from "./index4.js";
13
- import { MeasureUnitsManagerContainer as s } from "../../../shared/product-catalog/feature/dist/lib/MeasureUnitsManagerContainer.js";
14
- import { ProductSelector as c } from "../../../shared/product-catalog/feature/dist/lib/ProductSelector.js";
12
+ import { buildLineItemControls as ee, commitLineItemField as te, commitTaxRateInput as ne, convertPriceInput as re, createLineItem as o, getCurrencySymbol as ie, isBlankLineItem as ae, lineItemFromProduct 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";
13
+ import { buildReceivableAttachmentsView as he } from "./index7.js";
14
+ import { createEmptyReceivableFormValues as s, getPaymentTermOptions as ge, hasReceivableFormErrors as _e, receivableFormValuesToCreatePayload as ve, receivableFormValuesToLineItemChanges as ye, receivableFormValuesToUpdatePayload as be, receivableToFormValues as xe, validateReceivableForm as Se } from "./index8.js";
15
+ import { useCreateReceivableMutation as c, useUpdateReceivableMutation as Ce } from "../../data-access/dist/index6.js";
16
+ import "../../data-access/dist/index.js";
17
+ import { useReceivableAttachmentUploads as we } from "./index12.js";
18
+ import { calculateInvoiceTotals as Te } from "./index13.js";
19
+ import { getCurrencyOptions as Ee } from "../../../shared/product-catalog/feature/dist/lib/helpers.js";
20
+ import { useMeasureUnitsQuery as De } from "../../../shared/product-catalog/data-access/dist/index9.js";
21
+ import { useMeasureUnits as l } from "../../../shared/product-catalog/feature/dist/lib/useMeasureUnits.js";
15
22
  import "../../../shared/product-catalog/feature/dist/index.js";
16
- import { useReceivablesWidget as l } from "./index13.js";
17
- import { ReceivableActionDialog as u } from "../../ui/dist/index3.js";
18
- import { ReceivableDetailsSheet as d } from "../../ui/dist/index12.js";
19
- import { ReceivableFormSheet as f } from "../../ui/dist/index14.js";
20
- import { ReceivablePaymentDialog as p } from "../../ui/dist/index15.js";
21
- import { ReceivableSendDialog as m } from "../../ui/dist/index16.js";
22
- import { ReceivablesScreen as h } from "../../ui/dist/index17.js";
23
- import "../../ui/dist/index.js";
24
- import { useEffect as g, useState as _ } from "react";
25
- import { Fragment as v, jsx as y, jsxs as b } from "react/jsx-runtime";
23
+ import { useCallback as u, useEffect as d, useMemo as f, useRef as p, useState as m } from "react";
26
24
  //#region ../../libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index14.js
27
- function x({ counterpartFormLabels: t, counterpartMessageLabels: a, defaultTab: x, detailsLabels: S, enabledTabs: C, formLabels: w, measureUnitDeleteLabels: T, measureUnitsLabels: E, messageLabels: D, onReceivableCreated: O, onReceivableOpened: k, onTemplateSettingsClick: A, pageSizeOptions: j = o, paymentLabels: M, productMessageLabels: N, screenLabels: P, sendLabels: F, actionLabels: I }) {
28
- let L = e();
29
- g(() => {
30
- L(i.Mounted);
31
- }, [L]);
32
- let R = l({
33
- counterpartMessageLabels: a,
34
- defaultTab: x,
35
- enabledTabs: C,
36
- messageLabels: D,
37
- onReceivableCreated: O,
38
- onReceivableOpened: k
39
- }), [z, B] = _(!1);
40
- return /* @__PURE__ */ b(v, { children: [
41
- /* @__PURE__ */ y(h, {
42
- rows: R.table.rows,
43
- activeTab: R.activeTab,
44
- enabledTabs: R.enabledTabs,
45
- onTabChange: R.setActiveTab,
46
- isLoading: R.table.isLoading,
47
- isError: R.table.isError,
48
- sorting: R.table.sorting,
49
- onSortingChange: R.table.onSortingChange,
50
- pageSize: R.table.pageSize,
51
- onPageSizeChange: R.table.onPageSizeChange,
52
- pageSizeOptions: j,
53
- hasNextPage: R.table.hasNextPage,
54
- hasPrevPage: R.table.hasPrevPage,
55
- onNextPage: R.table.onNextPage,
56
- onPrevPage: R.table.onPrevPage,
57
- searchValue: R.table.searchValue,
58
- onSearchChange: R.table.onSearchChange,
59
- statusFilter: R.table.statusFilter,
60
- statusOptions: R.table.statusOptions,
61
- onStatusFilterChange: R.table.onStatusFilterChange,
62
- isFiltering: R.table.isFiltering,
63
- onCreateClick: R.openCreate,
64
- onTemplateSettingsClick: A,
65
- onRowClick: R.handleRowClick,
66
- onActionClick: R.handleActionClick,
67
- onRetry: R.table.onRetry,
68
- labels: P
69
- }),
70
- /* @__PURE__ */ y(f, {
71
- open: R.form.open,
72
- onOpenChange: (e) => {
73
- e || R.form.close();
74
- },
75
- mode: R.form.mode,
76
- values: R.form.sheetValues,
77
- errors: R.form.errors,
78
- currencyOptions: R.form.currencyOptions,
79
- paymentTermsOptions: R.form.paymentTermsOptions,
80
- unitOptions: R.form.lineItemUnitOptions,
81
- currencySymbol: R.form.currencySymbol,
82
- lineItemControls: R.form.lineItemControls,
83
- autoFocusLineItemId: R.form.autoFocusLineItemId,
84
- lineItemsLoading: R.form.lineItemsLoading,
85
- inProgress: R.form.isSubmitting,
86
- customerSelector: /* @__PURE__ */ y(r, {
87
- mode: "customer",
88
- value: R.form.values.customerId || void 0,
89
- onValueChange: (e) => R.form.updateValues({ customerId: e }),
90
- onCreateClick: R.form.openCounterpartCreate
91
- }),
92
- renderProductSelector: (e, t) => /* @__PURE__ */ y(c, {
25
+ function h({ messages: h, counterpartMessageLabels: g, onCreated: _ }) {
26
+ let v = c(), y = Ce(), b = p([]), x = p(""), S = n(), [C, w] = m(!1), [T, E] = m("create"), [D, O] = m(), [k, A] = m(() => s()), [Oe, j] = m({}), [M, ke] = m("none"), N = l(), P = De(), F = P.data?.data, { unitNamesById: I } = N, [Ae, L] = m(), [R, z] = m(!1), B = p(!1), V = f(() => e(), []), je = f(() => ({
27
+ ...r,
28
+ ...g
29
+ }), [g]), H = i(k.customerId), Me = H.data?.data?.[0], U = H.data?.data?.[0]?.id, Ne = u((e) => {
30
+ A((t) => ({
31
+ ...t,
32
+ attachments: e(t.attachments)
33
+ }));
34
+ }, []), W = we({
35
+ attachments: k.attachments,
36
+ setAttachments: Ne,
37
+ receivableId: D
38
+ }), { reset: G, discardUploads: K, commitRemovals: q } = W, Pe = k.type === "invoice" ? he({
39
+ attachments: k.attachments,
40
+ pendingUploads: W.pendingUploads,
41
+ isCountLimitReached: W.isCountLimitReached,
42
+ isRecurring: !1,
43
+ messages: h
44
+ }) : void 0, Fe = u((e) => {
45
+ A((t) => ({
46
+ ...t,
47
+ customerId: e ?? ""
48
+ }));
49
+ }, []), J = a({
50
+ view: M,
51
+ setView: ke,
52
+ selectedId: k.customerId || void 0,
53
+ setSelectedId: Fe,
54
+ messages: je,
55
+ counterpartType: "customer",
56
+ counterpart: void 0,
57
+ primaryAddress: Me
58
+ }), Y = u(() => {
59
+ b.current = [], L(void 0), E("create"), O(void 0), A(s()), j({}), z(!1), G();
60
+ }, [G]), Ie = u((e = "invoice") => {
61
+ b.current = [], L(void 0), E("create"), O(void 0), A({
62
+ ...s(),
63
+ type: e
64
+ }), j({}), G(), z(!1), w(!0);
65
+ }, [G]), Le = u((e) => {
66
+ e.type !== "credit_note" && (b.current = e.line_items, x.current = e.currency, L(void 0), E("edit"), O(e.id), A(xe(e, F)), j({}), z(!1), G(), w(!0));
67
+ }, [G, F]);
68
+ d(() => {
69
+ F?.length && A((e) => {
70
+ let t = se(e.lineItems, F);
71
+ return t === e.lineItems ? e : {
72
+ ...e,
73
+ lineItems: t
74
+ };
75
+ });
76
+ }, [F]);
77
+ let X = W.isUploading, Re = u(() => {
78
+ X || (K(), w(!1), j({}));
79
+ }, [K, X]), ze = u((e) => {
80
+ let t = e.taxRate === void 0 ? e : {
81
+ ...e,
82
+ taxRate: le(e.taxRate)
83
+ }, { currency: n, type: r } = t;
84
+ if (r !== void 0 && r !== "invoice" && K(), n === void 0) {
85
+ A((e) => ({
86
+ ...e,
87
+ ...t
88
+ }));
89
+ return;
90
+ }
91
+ B.current = !0, A((e) => e.currency === n ? {
92
+ ...e,
93
+ ...t
94
+ } : {
95
+ ...e,
96
+ ...t,
97
+ lineItems: e.lineItems.map((t) => ({
93
98
  ...t,
94
- inputValue: e.name,
95
- selectedProductId: R.form.values.lineItems.find((t) => t.id === e.id)?.productId || void 0,
96
- currency: R.form.values.currency,
97
- maxLength: 100,
98
- onInputValueChange: (t) => R.form.updateLineItem(e.id, { name: t }),
99
- onProductSelect: (t) => R.form.selectProduct(e.id, t)
100
- }),
101
- onChange: R.form.updateValues,
102
- onLineItemChange: R.form.updateLineItem,
103
- onLineItemCommit: R.form.commitLineItem,
104
- onLineItemQuantityStep: R.form.stepLineItem,
105
- onTaxRateCommit: R.form.commitTaxRate,
106
- onManageUnits: () => B(!0),
107
- onAddLineItem: R.form.addLineItem,
108
- onRemoveLineItem: R.form.removeLineItem,
109
- onSubmit: R.form.submit,
110
- onCancel: R.form.close,
111
- labels: w
112
- }),
113
- /* @__PURE__ */ y(d, {
114
- open: R.detailsOpen,
115
- onOpenChange: (e) => {
116
- e || R.closeDetails();
117
- },
118
- details: R.details.detailsView,
119
- isLoading: R.details.isLoading,
120
- isError: R.details.isError,
121
- onActionClick: R.handleDetailsActionClick,
122
- onClose: R.closeDetails,
123
- labels: S
124
- }),
125
- /* @__PURE__ */ y(m, {
126
- open: R.actions.sendOpen,
127
- onOpenChange: (e) => {
128
- e || R.actions.closeSend();
129
- },
130
- values: R.actions.sendValues,
131
- errors: R.actions.sendErrors,
132
- inProgress: R.actions.sendInProgress,
133
- onChange: (e) => R.actions.setSendValues((t) => ({
134
- ...t,
135
- ...e
136
- })),
137
- onSubmit: R.actions.submitSend,
138
- onCancel: R.actions.closeSend,
139
- labels: F
140
- }),
141
- /* @__PURE__ */ y(p, {
142
- open: R.actions.paymentOpen,
143
- onOpenChange: (e) => {
144
- e || R.actions.closePayment();
145
- },
146
- values: R.actions.paymentValues,
147
- errors: R.actions.paymentErrors,
148
- inProgress: R.actions.paymentInProgress,
149
- onChange: (e) => R.actions.setPaymentValues((t) => ({
150
- ...t,
151
- ...e
152
- })),
153
- onSubmit: R.actions.submitPayment,
154
- onCancel: R.actions.closePayment,
155
- labels: M
156
- }),
157
- R.actions.actionDialog && /* @__PURE__ */ y(u, {
158
- open: !!R.actions.actionTarget,
159
- onOpenChange: (e) => {
160
- e || R.actions.closeAction();
161
- },
162
- title: R.actions.actionDialog.title,
163
- description: R.actions.actionDialog.description,
164
- confirmLabel: R.actions.actionDialog.confirmLabel,
165
- destructive: R.actions.actionDialog.destructive,
166
- error: R.actions.actionError,
167
- inProgress: R.actions.actionInProgress,
168
- onConfirm: R.actions.confirmAction,
169
- onCancel: R.actions.closeAction,
170
- labels: I
171
- }),
172
- /* @__PURE__ */ y(n, {
173
- open: R.form.counterpartView === "create",
174
- onOpenChange: (e) => {
175
- e || R.form.counterpartForm.close();
176
- },
177
- mode: "create",
178
- values: R.form.counterpartForm.values,
179
- errors: R.form.counterpartForm.errors,
180
- stateOptions: R.form.stateOptions,
181
- inProgress: R.form.counterpartForm.isSubmitting,
182
- onChange: (e) => R.form.counterpartForm.setValues((t) => ({
183
- ...t,
184
- ...e
185
- })),
186
- onAddressChange: (e) => R.form.counterpartForm.setValues((t) => ({
187
- ...t,
188
- address: {
189
- ...t.address,
190
- ...e
191
- }
192
- })),
193
- onSubmit: R.form.counterpartForm.submit,
194
- onCancel: R.form.counterpartForm.close,
195
- labels: t
196
- }),
197
- /* @__PURE__ */ y(s, {
198
- open: z,
199
- onClose: () => B(!1),
200
- managerLabels: E,
201
- deleteLabels: T,
202
- messageLabels: N
203
- })
204
- ] });
205
- }
206
- function S({ baseUrl: e, widgetToken: n, organizationId: r, configClient: i, gatewayRouting: o, linkComponent: s, implementation: c, uiFramework: l, errorFallback: u, onError: d, analytics: f, disclosuresAcceptance: p, providerLabels: m, ...h }) {
207
- return /* @__PURE__ */ y(t, {
208
- widgetName: a,
209
- baseUrl: e,
210
- widgetToken: n,
211
- organizationId: r,
212
- configClient: i,
213
- gatewayRouting: o,
214
- linkComponent: s,
215
- implementation: c,
216
- uiFramework: l,
217
- errorFallback: u,
218
- onError: d,
219
- analytics: f,
220
- disclosuresAcceptance: p,
221
- providerLabels: m,
222
- children: /* @__PURE__ */ y(x, { ...h })
223
- });
99
+ price: re(t.price, e.currency, n)
100
+ }))
101
+ });
102
+ }, [K]), Be = u(() => {
103
+ A((e) => {
104
+ let t = ne(e.taxRate);
105
+ return t === e.taxRate ? e : {
106
+ ...e,
107
+ taxRate: t
108
+ };
109
+ });
110
+ }, []), Z = u((e, t) => {
111
+ let n = me(e, {
112
+ currency: t,
113
+ messages: h
114
+ });
115
+ j((e) => ({
116
+ ...e,
117
+ lineItems: n,
118
+ lineItemsSummary: fe(n)
119
+ }));
120
+ }, [h]), Q = u((e, { validate: t }) => {
121
+ t && (B.current = !0), A((t) => ({
122
+ ...t,
123
+ lineItems: e(t.lineItems)
124
+ }));
125
+ }, []);
126
+ d(() => {
127
+ B.current && (B.current = !1, Z(k.lineItems, k.currency));
128
+ }, [
129
+ Z,
130
+ k.currency,
131
+ k.lineItems
132
+ ]);
133
+ let Ve = u((e, t) => {
134
+ let { unit: n, ...r } = t, i = ce(r);
135
+ i.name !== void 0 && (i.productId = ""), n !== void 0 && (i.measureUnitId = n, i.measureUnitName = ""), Q((t) => t.map((t) => t.id === e ? {
136
+ ...t,
137
+ ...i
138
+ } : t), { validate: R });
139
+ }, [Q, R]), He = u((e, t) => {
140
+ Q((n) => n.map((n) => n.id === e ? {
141
+ ...n,
142
+ ...oe({
143
+ product: t,
144
+ currency: k.currency,
145
+ unitNamesById: I
146
+ })
147
+ } : n), { validate: !0 });
148
+ }, [
149
+ Q,
150
+ I,
151
+ k.currency
152
+ ]), $ = u((e, t) => {
153
+ t && Q((n) => t.kind === "remove" ? n.filter((t) => t.id !== e) : n.map((n) => n.id === e ? {
154
+ ...n,
155
+ ...t.patch
156
+ } : n), { validate: !0 });
157
+ }, [Q]), Ue = u((e, t) => {
158
+ let n = k.lineItems.find((t) => t.id === e);
159
+ n && $(e, te({
160
+ lineItem: n,
161
+ field: t,
162
+ rowCount: k.lineItems.length,
163
+ currency: k.currency
164
+ }));
165
+ }, [
166
+ $,
167
+ k.currency,
168
+ k.lineItems
169
+ ]), We = u((e, t) => {
170
+ let n = k.lineItems.find((t) => t.id === e);
171
+ n && $(e, ue({
172
+ lineItem: n,
173
+ step: t,
174
+ rowCount: k.lineItems.length
175
+ }));
176
+ }, [$, k.lineItems]), Ge = u(() => {
177
+ let e = o(k.currency);
178
+ L(e.id), A((t) => ({
179
+ ...t,
180
+ lineItems: [...t.lineItems, e]
181
+ }));
182
+ }, [k.currency]), Ke = u((e) => {
183
+ Q((t) => t.length <= 1 ? t : t.filter((t) => t.id !== e), { validate: !0 });
184
+ }, [Q]), qe = u(async () => {
185
+ if (X) return;
186
+ if (P.isLoading) {
187
+ j({ form: h.lineItemsLoading });
188
+ return;
189
+ }
190
+ let e = de(k.lineItems), n = e.length === k.lineItems.length ? k : {
191
+ ...k,
192
+ lineItems: e
193
+ };
194
+ n !== k && A(n);
195
+ let r = Se({
196
+ values: n,
197
+ billingAddressId: U,
198
+ messages: h
199
+ });
200
+ if (_e(r)) {
201
+ j(r), z(!0);
202
+ return;
203
+ }
204
+ j({});
205
+ try {
206
+ if (T === "edit" && D) {
207
+ let e = { receivable_id: D };
208
+ await y.mutateAsync({
209
+ path: e,
210
+ body: be({
211
+ values: n,
212
+ billingAddressId: U ?? "",
213
+ lineItemChanges: ye({
214
+ values: n,
215
+ originalLineItems: b.current,
216
+ originalCurrency: x.current,
217
+ unitNamesById: I,
218
+ units: F
219
+ })
220
+ })
221
+ }), q(), w(!1), Y();
222
+ return;
223
+ }
224
+ let e = await v.mutateAsync({ body: ve({
225
+ values: n,
226
+ billingAddressId: U ?? "",
227
+ unitNamesById: I
228
+ }) });
229
+ w(!1), Y(), e?.id && _?.(e.id, e.type);
230
+ } catch (e) {
231
+ j({ form: t(e) ?? h.genericError });
232
+ }
233
+ }, [
234
+ U,
235
+ q,
236
+ v,
237
+ D,
238
+ X,
239
+ h,
240
+ T,
241
+ _,
242
+ Y,
243
+ F,
244
+ I,
245
+ P.isLoading,
246
+ y,
247
+ k
248
+ ]), Je = f(() => ({
249
+ ...k,
250
+ lineItems: k.lineItems.map(pe)
251
+ }), [k]), Ye = f(() => ee(k.lineItems), [k.lineItems]), Xe = f(() => Te({
252
+ lineItems: k.lineItems.filter((e) => !ae(e)),
253
+ currency: k.currency,
254
+ taxRate: Number(k.taxRate) || void 0
255
+ }), [
256
+ k.currency,
257
+ k.lineItems,
258
+ k.taxRate
259
+ ]);
260
+ return {
261
+ open: C,
262
+ setOpen: w,
263
+ mode: T,
264
+ values: k,
265
+ sheetValues: Je,
266
+ errors: Oe,
267
+ setValues: A,
268
+ updateValues: ze,
269
+ commitTaxRate: Be,
270
+ updateLineItem: Ve,
271
+ selectProduct: He,
272
+ commitLineItem: Ue,
273
+ stepLineItem: We,
274
+ addLineItem: Ge,
275
+ removeLineItem: Ke,
276
+ attachmentsView: Pe,
277
+ attachmentsUploading: W.isUploading,
278
+ saveDisabled: P.isLoading || W.isUploading,
279
+ selectAttachmentFiles: W.selectFiles,
280
+ setAttachmentIncludeInEmail: W.setIncludeInEmail,
281
+ removeAttachment: W.remove,
282
+ autoFocusLineItemId: Ae,
283
+ lineItemUnitOptions: N.unitOptions,
284
+ lineItemsLoading: P.isLoading,
285
+ lineItemControls: Ye,
286
+ totals: Xe,
287
+ currencySymbol: ie(k.currency),
288
+ isSubmitting: v.isPending || y.isPending,
289
+ currencyOptions: Ee(k.currency),
290
+ paymentTermsOptions: ge(S.data?.data),
291
+ openCreate: Ie,
292
+ openEdit: Le,
293
+ close: Re,
294
+ submit: qe,
295
+ units: N,
296
+ counterpartView: M,
297
+ counterpartForm: J,
298
+ stateOptions: V,
299
+ openCounterpartCreate: J.openCreate
300
+ };
224
301
  }
225
302
  //#endregion
226
- export { S as ReceivablesWidget, S as default };
303
+ export { h as useReceivableForm };
@@ -0,0 +1,75 @@
1
+ "use client";
2
+ "use client";
3
+ "use client";
4
+ "use client";
5
+ import { buildReceivableRows as e, statusFilterOptions as t, typeForTab as n } from "./index8.js";
6
+ import { useReceivablesQuery as r } from "../../data-access/dist/index9.js";
7
+ import "../../data-access/dist/index.js";
8
+ import { useCallback as i, useEffect as a, useMemo as o, useState as s } from "react";
9
+ //#region ../../libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index15.js
10
+ var c = [];
11
+ function l({ activeTab: l, messages: d }) {
12
+ let [f, p] = s([]), [m, h] = s(10), [g, _] = s(), [v, y] = s(""), [b, x] = s(""), [S, C] = s("all");
13
+ a(() => {
14
+ _(void 0), C("all");
15
+ }, [l]), a(() => {
16
+ let e = setTimeout(() => {
17
+ x(v), _(void 0);
18
+ }, 300);
19
+ return () => clearTimeout(e);
20
+ }, [v]);
21
+ let w = f[0]?.id, T = w ? u[w] : void 0, E = f[0] ? f[0].desc ? "desc" : "asc" : void 0, D = r({
22
+ type: n(l),
23
+ limit: m,
24
+ pagination_token: g,
25
+ search_text: b || void 0,
26
+ status: S === "all" ? void 0 : S,
27
+ ...T ? {
28
+ sort: T,
29
+ order: E
30
+ } : {}
31
+ }), O = D.data?.data ?? c, k = o(() => new Map(O.map((e) => [e.id, e])), [O]), A = i((e) => k.get(e), [k]), j = o(() => e({
32
+ receivables: O,
33
+ messages: d
34
+ }), [d, O]), M = !!b || S !== "all", N = i((e) => {
35
+ let t = typeof e == "function" ? e(f) : e;
36
+ p(t), _(void 0);
37
+ }, [f]), P = i((e) => {
38
+ h(e), _(void 0);
39
+ }, []), F = i((e) => {
40
+ C(e), _(void 0);
41
+ }, []), I = i(() => _(D.data?.next_pagination_token ?? void 0), [D.data?.next_pagination_token]), L = i(() => _(D.data?.prev_pagination_token ?? void 0), [D.data?.prev_pagination_token]), R = i(() => {
42
+ D.refetch();
43
+ }, [D]);
44
+ return {
45
+ rows: j,
46
+ isLoading: D.isLoading,
47
+ isError: D.isError,
48
+ sorting: f,
49
+ onSortingChange: N,
50
+ pageSize: m,
51
+ onPageSizeChange: P,
52
+ hasNextPage: !!D.data?.next_pagination_token,
53
+ hasPrevPage: !!D.data?.prev_pagination_token,
54
+ onNextPage: I,
55
+ onPrevPage: L,
56
+ searchValue: v,
57
+ onSearchChange: y,
58
+ statusFilter: S,
59
+ statusOptions: t(),
60
+ onStatusFilterChange: F,
61
+ isFiltering: M,
62
+ onRetry: R,
63
+ getReceivableById: A
64
+ };
65
+ }
66
+ var u = {
67
+ documentLabel: "document_id",
68
+ customerLabel: "counterpart_name",
69
+ status: "status",
70
+ issueDateLabel: "issue_date",
71
+ dueDateLabel: "due_date",
72
+ totalLabel: "total_amount"
73
+ };
74
+ //#endregion
75
+ export { l as useReceivablesTable };