@tesouro/embedded-components-react 0.5.211 → 0.5.212

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 (33) 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/feature/dist/index.js +1 -1
  6. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index10.js +113 -109
  7. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index11.js +416 -132
  8. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index12.js +113 -211
  9. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index13.js +154 -37
  10. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index14.js +193 -135
  11. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index15.js +32 -37
  12. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index16.js +150 -58
  13. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index17.js +35 -89
  14. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index18.js +58 -116
  15. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index19.js +96 -47
  16. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index20.js +103 -347
  17. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index21.js +364 -64
  18. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index22.js +66 -106
  19. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index23.js +105 -275
  20. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index24.js +288 -0
  21. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index6.js +76 -61
  22. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index9.js +48 -422
  23. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index.js +5 -5
  24. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index22.js +38 -62
  25. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index23.js +61 -391
  26. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index24.js +457 -89
  27. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index25.js +91 -234
  28. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index26.js +234 -78
  29. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index27.js +80 -331
  30. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index28.js +344 -0
  31. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index3.js +10 -0
  32. package/dist/libs/tesouro-embedded-components-react/shared/feature/dist/lib/analytics/build-info.js +1 -1
  33. package/package.json +1 -1
@@ -2,364 +2,120 @@
2
2
  "use client";
3
3
  "use client";
4
4
  "use client";
5
- import { getStateOptions as e } from "../../../shared/util/dist/lib/usStates.js";
5
+ import { toast as e } from "../../../../../packages/shared-ui-shadcn/dist/index.js";
6
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/index9.js";
12
- import "../../ui/dist/index.js";
13
- import { buildLineItemControls as ee, commitLineItemField as te, commitTaxRateInput as ne, convertPriceInput as re, createLineItem as ie, getCurrencySymbol as ae, isBlankLineItem as oe, lineItemFromProduct as se, reconcileMeasureUnits as ce, sanitizeLineItemPatch as le, sanitizeTaxRateInput as ue, stepLineItemQuantity as de, stripBlankLineItems as fe, summarizeLineItemErrors as pe, toSheetLineItem as me, validateLineItems as he } from "./index6.js";
14
- import { buildReceivableAttachmentsView as ge } from "./index7.js";
15
- import { createEmptyReceivableFormValues as a, hasReceivableFormErrors as _e, receivableFormValuesToCreatePayload as ve, receivableFormValuesToLineItemChanges as ye, receivableFormValuesToUpdatePayload as be, receivableToFormValues as xe, validateReceivableForm as Se } from "./index9.js";
16
- import { shouldShowRemindersInitially as Ce } from "./index11.js";
17
- import { useCreateReceivableMutation as we, useUpdateReceivableMutation as Te } from "../../data-access/dist/index6.js";
7
+ import { usePaymentTermsQuery as n } from "../../../shared/data-access/dist/lib/reference-data/usePaymentTermsQuery.js";
8
+ import "../../../shared/ui/dist/index.js";
9
+ import { useWidgetConfig as r } from "../../../shared/feature/dist/lib/WidgetProvider/hooks.js";
10
+ import "../../../shared/feature/dist/index.js";
11
+ import { areOverdueTermsValid as i, buildOverdueReminderPayload as a, buildPaymentReminderPayload as o, buildRemindersView as s, canCreateReminders as c, getImpliedDueDate as l, isBeforeDueDaysValid as u, sanitizeReminderDays as d } from "./index13.js";
12
+ import { useCreateOverdueReminderMutation as f, useCreatePaymentReminderMutation as p, useOverdueRemindersQuery as m, usePaymentRemindersQuery as h } from "../../data-access/dist/index10.js";
18
13
  import "../../data-access/dist/index.js";
19
- import { useReceivableAttachmentUploads as Ee } from "./index14.js";
20
- import { useReceivablePaymentTerms as De } from "./index15.js";
21
- import { useReceivableBankAccount as Oe } from "./index17.js";
22
- import { useReceivableReminders as ke } from "./index18.js";
23
- import { calculateInvoiceTotals as Ae } from "./index19.js";
24
- import { getCurrencyOptions as je } from "../../../shared/product-catalog/feature/dist/lib/helpers.js";
25
- import { useMeasureUnitsQuery as Me } from "../../../shared/product-catalog/data-access/dist/index9.js";
26
- import { useMeasureUnits as Ne } from "../../../shared/product-catalog/feature/dist/lib/useMeasureUnits.js";
27
- import "../../../shared/product-catalog/feature/dist/index.js";
28
- import { useCallback as o, useEffect as s, useMemo as c, useRef as l, useState as u } from "react";
14
+ import { useCallback as g, useMemo as _, useState as v } from "react";
29
15
  //#region ../../libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index20.js
30
- function d({ messages: d, counterpartMessageLabels: f, embeddedBankName: Pe, onCreated: p }) {
31
- let m = we(), h = Te(), g = l([]), _ = l(""), [v, y] = u(!1), [b, x] = u("create"), [S, C] = u(), [w, T] = u(() => a()), [Fe, E] = u({}), [D, Ie] = u("none"), O = Ne(), k = Me(), A = k.data?.data, { unitNamesById: j } = O, [Le, M] = u(), [N, P] = u(!1), F = l(!1), Re = c(() => e(), []), ze = c(() => ({
32
- ...n,
33
- ...f
34
- }), [f]), I = r(w.customerId), Be = I.data?.data?.[0], L = I.data?.data?.[0]?.id, Ve = o((e) => {
35
- T((t) => ({
36
- ...t,
37
- attachments: e(t.attachments)
38
- }));
39
- }, []), R = Ee({
40
- attachments: w.attachments,
41
- setAttachments: Ve,
42
- receivableId: S
43
- }), { reset: z, discardUploads: B, commitRemovals: V } = R, He = w.type === "invoice" ? ge({
44
- attachments: w.attachments,
45
- pendingUploads: R.pendingUploads,
46
- isCountLimitReached: R.isCountLimitReached,
47
- isRecurring: !1,
48
- messages: d
49
- }) : void 0, Ue = o((e) => {
50
- T((t) => ({
51
- ...t,
52
- customerId: e ?? ""
53
- }));
54
- }, []), H = i({
55
- view: D,
56
- setView: Ie,
57
- selectedId: w.customerId || void 0,
58
- setSelectedId: Ue,
59
- messages: ze,
60
- counterpartType: "customer",
61
- counterpart: void 0,
62
- primaryAddress: Be
63
- }), We = o((e) => T((t) => {
64
- let n = e({
65
- paymentTermsId: t.paymentTermsId,
66
- paymentTermsCustomDate: t.paymentTermsCustomDate
67
- });
68
- return {
69
- ...t,
70
- ...n,
71
- ...n.paymentTermsId === "receipt_due" ? { paymentReminderId: "" } : {}
72
- };
73
- }), []), U = De({
74
- paymentTermsId: w.paymentTermsId,
75
- paymentTermsCustomDate: w.paymentTermsCustomDate,
76
- messages: d,
77
- onChange: We
78
- }), W = U.reset, Ge = o((e) => T((t) => ({
79
- ...t,
80
- ...e
81
- })), []), G = Oe({
82
- open: v,
83
- bankAccountId: w.bankAccountId,
84
- embeddedBankName: Pe,
85
- messages: d,
86
- onSelect: Ge
87
- }), K = G.reset, Ke = o((e) => T((t) => ({
88
- ...t,
89
- ...e
90
- })), []), q = m.isPending || h.isPending, qe = ke({
91
- open: v,
92
- isInvoice: w.type === "invoice",
93
- disabled: q,
94
- paymentTermsId: w.paymentTermsId,
95
- paymentTermsCustomDate: w.paymentTermsCustomDate,
96
- paymentReminderId: w.paymentReminderId,
97
- overdueReminderId: w.overdueReminderId,
98
- messages: d,
99
- onSelect: Ke
100
- }), J = qe.reset, Y = o(() => {
101
- g.current = [], M(void 0), x("create"), C(void 0), T(a()), E({}), P(!1), z();
102
- }, [z]), Je = o((e = "invoice") => {
103
- W(), K();
104
- let t = {
105
- ...a(),
106
- type: e
107
- };
108
- J(Ce(t)), g.current = [], M(void 0), x("create"), C(void 0), T(t), E({}), z(), P(!1), y(!0);
109
- }, [
110
- z,
111
- W,
112
- K,
113
- J
114
- ]), Ye = o((e) => {
115
- if (e.type === "credit_note") return;
116
- W(), K();
117
- let t = xe(e, A);
118
- J(Ce(t)), g.current = e.line_items, _.current = e.currency, M(void 0), x("edit"), C(e.id), T(t), E({}), P(!1), z(), y(!0);
119
- }, [
120
- z,
121
- W,
122
- K,
123
- J,
124
- A
125
- ]);
126
- s(() => {
127
- A?.length && T((e) => {
128
- let t = ce(e.lineItems, A);
129
- return t === e.lineItems ? e : {
130
- ...e,
131
- lineItems: t
132
- };
133
- });
134
- }, [A]);
135
- let X = R.isUploading, Xe = o(() => {
136
- X || (B(), y(!1), E({}));
137
- }, [B, X]), Ze = o((e) => {
138
- let t = e.taxRate === void 0 ? e : {
139
- ...e,
140
- taxRate: ue(e.taxRate)
141
- }, { currency: n, type: r } = t;
142
- if (r !== void 0 && r !== "invoice" && B(), n === void 0) {
143
- T((e) => ({
144
- ...e,
145
- ...t
146
- }));
147
- return;
16
+ var y = [""];
17
+ function b({ open: b, isInvoice: x, disabled: S, paymentTermsId: C, paymentTermsCustomDate: w, paymentReminderId: T, overdueReminderId: E, messages: D, onSelect: O }) {
18
+ let { initResponse: k } = r(), A = n().data?.data, j = _(() => c(k?.scopes), [k?.scopes]), [M, N] = v(!1), [P, F] = v(""), [I, L] = v(y), R = b && x && M, z = h({ enabled: R }), B = m({ enabled: R }), V = p(), H = f(), U = g((e) => {
19
+ N(e), F(""), L(y);
20
+ }, []), W = g((e) => {
21
+ e || (O({
22
+ paymentReminderId: "",
23
+ overdueReminderId: ""
24
+ }), F(""), L(y)), N(e);
25
+ }, [O]), G = g((e) => O({ paymentReminderId: e }), [O]), K = g((e) => O({ overdueReminderId: e }), [O]), q = g((e) => F(d(e)), []), J = g((e, t) => {
26
+ let n = d(t);
27
+ L((t) => t.map((t, r) => r === e ? n : t));
28
+ }, []), Y = g(() => {
29
+ L((e) => e.length < 3 ? [...e, ""] : e);
30
+ }, []), X = g(() => L(y), []), Z = g(() => l({
31
+ paymentTermsId: C,
32
+ paymentTermsCustomDate: w,
33
+ paymentTerms: A,
34
+ today: /* @__PURE__ */ new Date()
35
+ }), [
36
+ A,
37
+ w,
38
+ C
39
+ ]), Q = g(async () => {
40
+ if (u(P)) try {
41
+ let t = await V.mutateAsync({ body: o({
42
+ daysBefore: Number(P),
43
+ dueDate: Z(),
44
+ messages: D
45
+ }) });
46
+ F(""), O({ paymentReminderId: t.id }), e.success(D.reminderAdded);
47
+ } catch (n) {
48
+ e.error(t(n) ?? D.genericError);
148
49
  }
149
- F.current = !0, T((e) => e.currency === n ? {
150
- ...e,
151
- ...t
152
- } : {
153
- ...e,
154
- ...t,
155
- lineItems: e.lineItems.map((t) => ({
156
- ...t,
157
- price: re(t.price, e.currency, n)
158
- }))
159
- });
160
- }, [B]), Qe = o(() => {
161
- T((e) => {
162
- let t = ne(e.taxRate);
163
- return t === e.taxRate ? e : {
164
- ...e,
165
- taxRate: t
166
- };
167
- });
168
- }, []), Z = o((e, t) => {
169
- let n = he(e, {
170
- currency: t,
171
- messages: d
172
- });
173
- E((e) => ({
174
- ...e,
175
- lineItems: n,
176
- lineItemsSummary: pe(n)
177
- }));
178
- }, [d]), Q = o((e, { validate: t }) => {
179
- t && (F.current = !0), T((t) => ({
180
- ...t,
181
- lineItems: e(t.lineItems)
182
- }));
183
- }, []);
184
- s(() => {
185
- F.current && (F.current = !1, Z(w.lineItems, w.currency));
186
50
  }, [
51
+ P,
52
+ V,
187
53
  Z,
188
- w.currency,
189
- w.lineItems
190
- ]);
191
- let $e = o((e, t) => {
192
- let { unit: n, ...r } = t, i = le(r);
193
- i.name !== void 0 && (i.productId = ""), n !== void 0 && (i.measureUnitId = n, i.measureUnitName = ""), Q((t) => t.map((t) => t.id === e ? {
194
- ...t,
195
- ...i
196
- } : t), { validate: N });
197
- }, [Q, N]), et = o((e, t) => {
198
- Q((n) => n.map((n) => n.id === e ? {
199
- ...n,
200
- ...se({
201
- product: t,
202
- currency: w.currency,
203
- unitNamesById: j
204
- })
205
- } : n), { validate: !0 });
206
- }, [
207
- Q,
208
- j,
209
- w.currency
210
- ]), $ = o((e, t) => {
211
- t && Q((n) => t.kind === "remove" ? n.filter((t) => t.id !== e) : n.map((n) => n.id === e ? {
212
- ...n,
213
- ...t.patch
214
- } : n), { validate: !0 });
215
- }, [Q]), tt = o((e, t) => {
216
- let n = w.lineItems.find((t) => t.id === e);
217
- n && $(e, te({
218
- lineItem: n,
219
- field: t,
220
- rowCount: w.lineItems.length,
221
- currency: w.currency
222
- }));
223
- }, [
224
- $,
225
- w.currency,
226
- w.lineItems
227
- ]), nt = o((e, t) => {
228
- let n = w.lineItems.find((t) => t.id === e);
229
- n && $(e, de({
230
- lineItem: n,
231
- step: t,
232
- rowCount: w.lineItems.length
233
- }));
234
- }, [$, w.lineItems]), rt = o(() => {
235
- let e = ie(w.currency);
236
- M(e.id), T((t) => ({
237
- ...t,
238
- lineItems: [...t.lineItems, e]
239
- }));
240
- }, [w.currency]), it = o((e) => {
241
- Q((t) => t.length <= 1 ? t : t.filter((t) => t.id !== e), { validate: !0 });
242
- }, [Q]), at = o(async () => {
243
- if (X) return;
244
- if (k.isLoading) {
245
- E({ form: d.lineItemsLoading });
246
- return;
247
- }
248
- let e = fe(w.lineItems), n = e.length === w.lineItems.length ? w : {
249
- ...w,
250
- lineItems: e
251
- };
252
- n !== w && T(n);
253
- let r = Se({
254
- values: n,
255
- billingAddressId: L,
256
- messages: d
257
- });
258
- if (_e(r)) {
259
- E(r), P(!0);
260
- return;
261
- }
262
- E({});
263
- try {
264
- if (b === "edit" && S) {
265
- let e = { receivable_id: S };
266
- await h.mutateAsync({
267
- path: e,
268
- body: be({
269
- values: n,
270
- billingAddressId: L ?? "",
271
- lineItemChanges: ye({
272
- values: n,
273
- originalLineItems: g.current,
274
- originalCurrency: _.current,
275
- unitNamesById: j,
276
- units: A
277
- })
278
- })
279
- }), V(), y(!1), Y();
280
- return;
281
- }
282
- let e = await m.mutateAsync({ body: ve({
283
- values: n,
284
- billingAddressId: L ?? "",
285
- unitNamesById: j
54
+ D,
55
+ O
56
+ ]), $ = g(async () => {
57
+ if (i(I)) try {
58
+ let t = await H.mutateAsync({ body: a({
59
+ terms: I,
60
+ dueDate: Z(),
61
+ messages: D
286
62
  }) });
287
- y(!1), Y(), e?.id && p?.(e.id, e.type);
288
- } catch (e) {
289
- E({ form: t(e) ?? d.genericError });
63
+ L(y), O({ overdueReminderId: t.id }), e.success(D.reminderAdded);
64
+ } catch (n) {
65
+ e.error(t(n) ?? D.genericError);
290
66
  }
291
67
  }, [
292
- L,
293
- V,
294
- m,
295
- S,
296
- X,
297
- d,
298
- b,
299
- p,
300
- Y,
301
- A,
302
- j,
303
- k.isLoading,
304
- h,
305
- w
306
- ]), ot = c(() => ({
307
- ...w,
308
- lineItems: w.lineItems.map(me)
309
- }), [w]), st = c(() => ee(w.lineItems), [w.lineItems]), ct = c(() => Ae({
310
- lineItems: w.lineItems.filter((e) => !oe(e)),
311
- currency: w.currency,
312
- taxRate: Number(w.taxRate) || void 0
313
- }), [
314
- w.currency,
315
- w.lineItems,
316
- w.taxRate
68
+ H,
69
+ Z,
70
+ D,
71
+ O,
72
+ I
317
73
  ]);
318
74
  return {
319
- open: v,
320
- setOpen: y,
321
- mode: b,
322
- values: w,
323
- sheetValues: ot,
324
- errors: Fe,
325
- setValues: T,
326
- updateValues: Ze,
327
- commitTaxRate: Qe,
328
- updateLineItem: $e,
329
- selectProduct: et,
330
- commitLineItem: tt,
331
- stepLineItem: nt,
332
- addLineItem: rt,
333
- removeLineItem: it,
334
- attachmentsView: He,
335
- attachmentsUploading: R.isUploading,
336
- saveDisabled: k.isLoading || R.isUploading,
337
- selectAttachmentFiles: R.selectFiles,
338
- setAttachmentIncludeInEmail: R.setIncludeInEmail,
339
- removeAttachment: R.remove,
340
- autoFocusLineItemId: Le,
341
- lineItemUnitOptions: O.unitOptions,
342
- lineItemsLoading: k.isLoading,
343
- lineItemControls: st,
344
- totals: ct,
345
- currencySymbol: ae(w.currency),
346
- isSubmitting: q,
347
- currencyOptions: je(w.currency),
348
- paymentTerms: U,
349
- showBillingSection: w.type === "invoice" || b === "edit",
350
- showDueDateField: w.type === "quote",
351
- openCreate: Je,
352
- openEdit: Ye,
353
- close: Xe,
354
- submit: at,
355
- units: O,
356
- counterpartView: D,
357
- counterpartForm: H,
358
- stateOptions: Re,
359
- openCounterpartCreate: H.openCreate,
360
- bankAccount: G,
361
- reminders: qe
75
+ view: _(() => x ? s({
76
+ showReminders: M,
77
+ paymentTermsId: C,
78
+ paymentTermsCustomDate: w,
79
+ paymentReminderId: T,
80
+ overdueReminderId: E,
81
+ paymentReminders: z.data?.data,
82
+ overdueReminders: B.data?.data,
83
+ canCreate: j,
84
+ disabled: S,
85
+ beforeDueInput: P,
86
+ overdueTerms: I,
87
+ isCreatingPaymentReminder: V.isPending,
88
+ isCreatingOverdueReminder: H.isPending,
89
+ today: /* @__PURE__ */ new Date(),
90
+ messages: D
91
+ }) : void 0, [
92
+ P,
93
+ j,
94
+ H.isPending,
95
+ V.isPending,
96
+ S,
97
+ x,
98
+ D,
99
+ E,
100
+ B.data?.data,
101
+ I,
102
+ T,
103
+ z.data?.data,
104
+ w,
105
+ C,
106
+ M
107
+ ]),
108
+ reset: U,
109
+ toggle: W,
110
+ selectPaymentReminder: G,
111
+ selectOverdueReminder: K,
112
+ changeBeforeDueInput: q,
113
+ saveBeforeDue: Q,
114
+ changeOverdueTerm: J,
115
+ addOverdueTerm: Y,
116
+ clearOverdueTerms: X,
117
+ saveOverdue: $
362
118
  };
363
119
  }
364
120
  //#endregion
365
- export { d as useReceivableForm };
121
+ export { b as useReceivableReminders };