@tesouro/embedded-components-react 0.7.70 → 0.7.73

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 (46) hide show
  1. package/README.md +15 -12
  2. package/dist/index.css +24 -6
  3. package/dist/index.d.ts +76 -8
  4. package/dist/lib/LinkedAccountsWidget.d.ts +9 -0
  5. package/dist/lib/ProductsWidget.d.ts +12 -6
  6. package/dist/lib/ReceivablesWidget.d.ts +1 -5
  7. package/dist/lib/TransfersWidget.d.ts +55 -2
  8. package/dist/lib/WidgetSuite.d.ts +63 -1
  9. package/dist/libs/tesouro-embedded-components-react/linked-accounts-widget/feature/dist/lib/LinkedAccountsWidget.js +6 -4
  10. package/dist/libs/tesouro-embedded-components-react/linked-accounts-widget/feature/dist/lib/useLinkedAccountsWidget.js +199 -182
  11. package/dist/libs/tesouro-embedded-components-react/products-widget/feature/dist/lib/ProductsWidget/ProductsWidget.js +23 -24
  12. package/dist/libs/tesouro-embedded-components-react/products-widget/feature/dist/lib/ProductsWidget/constants.js +6 -2
  13. package/dist/libs/tesouro-embedded-components-react/products-widget/feature/dist/lib/ProductsWidget/useProductsTable.js +112 -51
  14. package/dist/libs/tesouro-embedded-components-react/products-widget/feature/dist/lib/ProductsWidget/useProductsWidget.js +80 -56
  15. package/dist/libs/tesouro-embedded-components-react/products-widget/ui/dist/index.js +6 -5
  16. package/dist/libs/tesouro-embedded-components-react/products-widget/ui/dist/index2.js +15 -6
  17. package/dist/libs/tesouro-embedded-components-react/products-widget/ui/dist/index4.js +170 -135
  18. package/dist/libs/tesouro-embedded-components-react/products-widget/ui/dist/index5.js +49 -150
  19. package/dist/libs/tesouro-embedded-components-react/products-widget/ui/dist/index6.js +152 -24
  20. package/dist/libs/tesouro-embedded-components-react/products-widget/ui/dist/index7.js +28 -0
  21. package/dist/libs/tesouro-embedded-components-react/shared/feature/dist/lib/analytics/build-info.js +1 -1
  22. package/dist/libs/tesouro-embedded-components-react/shared/product-catalog/feature/dist/index.js +13 -12
  23. package/dist/libs/tesouro-embedded-components-react/shared/product-catalog/feature/dist/lib/MeasureUnitsManagerContainer.js +2 -2
  24. package/dist/libs/tesouro-embedded-components-react/shared/product-catalog/feature/dist/lib/ProductSelector.js +1 -1
  25. package/dist/libs/tesouro-embedded-components-react/shared/product-catalog/feature/dist/lib/helpers.js +41 -27
  26. package/dist/libs/tesouro-embedded-components-react/shared/product-catalog/feature/dist/lib/useProductForm.js +70 -52
  27. package/dist/libs/tesouro-embedded-components-react/shared/product-catalog/ui/dist/index.js +7 -6
  28. package/dist/libs/tesouro-embedded-components-react/shared/product-catalog/ui/dist/index2.js +19 -8
  29. package/dist/libs/tesouro-embedded-components-react/shared/product-catalog/ui/dist/index3.js +171 -218
  30. package/dist/libs/tesouro-embedded-components-react/shared/product-catalog/ui/dist/index4.js +52 -180
  31. package/dist/libs/tesouro-embedded-components-react/shared/product-catalog/ui/dist/index5.js +188 -46
  32. package/dist/libs/tesouro-embedded-components-react/shared/product-catalog/ui/dist/index6.js +47 -124
  33. package/dist/libs/tesouro-embedded-components-react/shared/product-catalog/ui/dist/index7.js +128 -0
  34. package/dist/libs/tesouro-embedded-components-react/transfers-widget/feature/dist/lib/TransfersWidget/TransfersWidgetFeature.js +4 -3
  35. package/dist/libs/tesouro-embedded-components-react/transfers-widget/feature/dist/lib/TransfersWidget/TransfersWidgetInner.js +99 -108
  36. package/dist/libs/tesouro-embedded-components-react/transfers-widget/feature/dist/lib/TransfersWidget/testIds.js +2 -0
  37. package/dist/libs/tesouro-embedded-components-react/transfers-widget/feature/dist/lib/TransfersWidget/transferViews.js +135 -0
  38. package/dist/libs/tesouro-embedded-components-react/transfers-widget/feature/dist/lib/TransfersWidget/useTransferMoneyModalController.js +140 -153
  39. package/dist/libs/tesouro-embedded-components-react/transfers-widget/ui/dist/lib/TransfersWidget/TransferAccountTile.js +15 -0
  40. package/dist/libs/tesouro-embedded-components-react/transfers-widget/ui/dist/lib/TransfersWidget/TransferDetailSheet.js +111 -0
  41. package/dist/libs/tesouro-embedded-components-react/transfers-widget/ui/dist/lib/TransfersWidget/TransferStatusBadge.js +18 -0
  42. package/dist/libs/tesouro-embedded-components-react/transfers-widget/ui/dist/lib/TransfersWidget/TransfersWidget.js +181 -126
  43. package/dist/libs/tesouro-embedded-components-react/transfers-widget/ui/dist/lib/TransfersWidget/labels.js +33 -0
  44. package/dist/libs/tesouro-embedded-components-react/widget-suite/feature/dist/lib/WidgetSuite/sections/TransfersSection.js +16 -8
  45. package/dist/packages/shared-ui-shadcn/dist/index.js +328 -327
  46. package/package.json +1 -1
@@ -1,28 +1,156 @@
1
- import { AlertDialog as e, AlertDialogContent as t, AlertDialogDescription as n, AlertDialogFooter as r, AlertDialogHeader as i, AlertDialogTitle as a, Button as o } from "../../../../../packages/shared-ui-shadcn/dist/index.js";
2
- import { PRODUCT_DELETE_DIALOG_LABELS_EN as s } from "./index2.js";
3
- import { jsx as c, jsxs as l } from "react/jsx-runtime";
1
+ import { Button as e, DropdownMenu as t, DropdownMenuContent as n, DropdownMenuItem as r, DropdownMenuTrigger as i, Sheet as a, SheetClose as o, SheetContent as s, SheetDescription as c, SheetHeader as l, SheetTitle as u, Skeleton as d, Spinner as f, Typography as p } from "../../../../../packages/shared-ui-shadcn/dist/index.js";
2
+ import { ErrorState as m } from "../../../shared/ui/dist/lib/ErrorState/ErrorState.js";
3
+ import "../../../shared/ui/dist/index.js";
4
+ import { PRODUCT_DETAILS_SHEET_LABELS_EN as h } from "./index2.js";
5
+ import { ProductTypeBadge as g } from "./index3.js";
6
+ import { ProductEditForm as _ } from "./index5.js";
7
+ import { jsx as v, jsxs as y } from "react/jsx-runtime";
8
+ import { MoreVertical as b, Trash2 as x, X as S } from "lucide-react";
9
+ import { twMerge as C } from "tailwind-merge";
4
10
  //#region ../../libs/tesouro-embedded-components-react/products-widget/ui/dist/index6.js
5
- function u({ open: u, onOpenChange: d, productName: f, isDeleting: p, onConfirm: m, onCancel: h, labels: g }) {
6
- let _ = {
7
- ...s,
8
- ...g
9
- };
10
- return /* @__PURE__ */ c(e, {
11
- open: u,
12
- onOpenChange: d,
13
- children: /* @__PURE__ */ l(t, { children: [/* @__PURE__ */ l(i, { children: [/* @__PURE__ */ c(a, { children: _.title.replace("{name}", f) }), /* @__PURE__ */ c(n, { children: _.message })] }), /* @__PURE__ */ l(r, { children: [/* @__PURE__ */ c(o, {
14
- variant: "ghost",
15
- onClick: h,
16
- disabled: p,
17
- children: _.cancelButton
18
- }), /* @__PURE__ */ c(o, {
19
- variant: "destructive",
20
- onClick: m,
21
- disabled: p,
22
- loading: p,
23
- children: _.confirmButton
24
- })] })] })
11
+ function w({ label: e, value: t, isLast: n, emptyValue: r = "—" }) {
12
+ return /* @__PURE__ */ y("li", {
13
+ className: C("ttw:flex ttw:gap-4 ttw:py-2.5", !n && "ttw:border-b ttw:border-border"),
14
+ children: [/* @__PURE__ */ v(p, {
15
+ variant: "body2",
16
+ color: "muted",
17
+ className: "ttw:w-35 ttw:min-w-35 ttw:font-medium",
18
+ children: e
19
+ }), typeof t == "string" ? /* @__PURE__ */ v(p, {
20
+ variant: "body2",
21
+ className: "ttw:min-w-0 ttw:font-medium ttw:wrap-break-word",
22
+ children: t || r
23
+ }) : t]
24
+ });
25
+ }
26
+ function T({ open: C, onOpenChange: T, product: E, isLoading: D, isError: O, onEdit: k, onDelete: A, canEdit: j = !0, canDelete: M = !0, editForm: N, labels: P }) {
27
+ let F = {
28
+ ...h,
29
+ ...P,
30
+ typeBadge: {
31
+ ...h.typeBadge,
32
+ ...P?.typeBadge
33
+ }
34
+ }, I = E?.type !== "service", L = I ? F.typeBadge.product : F.typeBadge.service, R = E ? F.subtitle.replace("{type}", L).replace("{createdAt}", E.createdAtLabel) : F.hiddenDescription;
35
+ return /* @__PURE__ */ v(a, {
36
+ open: C,
37
+ onOpenChange: T,
38
+ children: /* @__PURE__ */ y(s, {
39
+ className: "ttw:w-150 ttw:sm:max-w-150 ttw:gap-0",
40
+ showCloseButton: !1,
41
+ children: [/* @__PURE__ */ y(l, {
42
+ className: "ttw:pt-6 ttw:pl-6 ttw:pr-4 ttw:pb-7 ttw:flex-row ttw:gap-3 ttw:border-b ttw:border-border",
43
+ children: [/* @__PURE__ */ y("div", {
44
+ className: "ttw:flex ttw:flex-col ttw:gap-1.5 ttw:flex-1 ttw:min-w-0",
45
+ children: [/* @__PURE__ */ v(u, {
46
+ className: "ttw:truncate ttw:text-2xl",
47
+ children: D ? /* @__PURE__ */ v(d, { className: "ttw:h-7 ttw:w-40" }) : E?.name ?? F.loadingTitle
48
+ }), /* @__PURE__ */ v(c, {
49
+ asChild: !0,
50
+ children: /* @__PURE__ */ v("div", { children: D ? /* @__PURE__ */ v(d, { className: "ttw:h-4 ttw:w-60" }) : R })
51
+ })]
52
+ }), /* @__PURE__ */ y("div", {
53
+ className: "ttw:flex ttw:gap-2 ttw:shrink-0",
54
+ children: [M && /* @__PURE__ */ y(t, { children: [/* @__PURE__ */ v(i, {
55
+ asChild: !0,
56
+ children: /* @__PURE__ */ v(e, {
57
+ type: "button",
58
+ variant: "outline",
59
+ disabled: !E,
60
+ "aria-label": F.moreActionsLabel,
61
+ className: "ttw:p-2 ttw:size-9 ttw:border-none ttw:bg-muted",
62
+ children: /* @__PURE__ */ v(b, { className: "ttw:size-4" })
63
+ })
64
+ }), /* @__PURE__ */ v(n, {
65
+ align: "end",
66
+ children: /* @__PURE__ */ y(r, {
67
+ onClick: A,
68
+ variant: "destructive",
69
+ children: [/* @__PURE__ */ v(x, { className: "ttw:size-4" }), F.deleteProductOption.replace("{type}", L)]
70
+ })
71
+ })] }), /* @__PURE__ */ v(o, {
72
+ "aria-label": F.closeLabel,
73
+ className: "ttw:size-9 ttw:bg-muted ttw:p-2 ttw:flex ttw:items-center ttw:justify-center ttw:rounded-md ttw:cursor-pointer",
74
+ children: /* @__PURE__ */ v(S, { className: "ttw:size-4" })
75
+ })]
76
+ })]
77
+ }), O ? /* @__PURE__ */ v(m, {
78
+ title: F.errorTitle,
79
+ description: F.errorDescription
80
+ }) : D || !E ? /* @__PURE__ */ v("div", {
81
+ className: "ttw:flex ttw:w-full ttw:h-full ttw:items-center ttw:justify-center",
82
+ children: /* @__PURE__ */ v(f, {})
83
+ }) : /* @__PURE__ */ v("main", {
84
+ className: "ttw:p-6 ttw:overflow-auto ttw:flex ttw:flex-col ttw:gap-4",
85
+ children: /* @__PURE__ */ y("div", {
86
+ className: "ttw:flex ttw:flex-col ttw:gap-4",
87
+ children: [/* @__PURE__ */ y("div", {
88
+ className: "ttw:flex ttw:items-center ttw:justify-between ttw:gap-3 ttw:pt-6 ttw:pb-7 ttw:border-b ttw:border-border",
89
+ children: [/* @__PURE__ */ y("div", {
90
+ className: "ttw:flex ttw:flex-col ttw:gap-1.5",
91
+ children: [/* @__PURE__ */ v(p, {
92
+ variant: "body1",
93
+ className: "ttw:font-medium",
94
+ children: F.sectionHeading.replace("{type}", L)
95
+ }), /* @__PURE__ */ v(p, {
96
+ variant: "body2",
97
+ color: "muted",
98
+ children: I ? F.typeProductDescription : F.typeServiceDescription
99
+ })]
100
+ }), j && !N && /* @__PURE__ */ v(e, {
101
+ type: "button",
102
+ variant: "ghost",
103
+ className: "ttw:text-primary ttw:hover:text-primary",
104
+ onClick: k,
105
+ children: F.editButton
106
+ })]
107
+ }), N ? /* @__PURE__ */ v(_, { form: N }) : /* @__PURE__ */ y("ul", {
108
+ className: "ttw:list-none ttw:p-0 ttw:m-0",
109
+ children: [
110
+ /* @__PURE__ */ v(w, {
111
+ label: F.rowName.replace("{type}", L),
112
+ value: E.name,
113
+ emptyValue: F.rowEmptyValue
114
+ }),
115
+ /* @__PURE__ */ v(w, {
116
+ label: F.rowPrice,
117
+ value: E.priceLabel,
118
+ emptyValue: F.rowEmptyValue
119
+ }),
120
+ /* @__PURE__ */ v(w, {
121
+ label: F.rowDescription,
122
+ value: E.description,
123
+ emptyValue: F.rowEmptyValue
124
+ }),
125
+ /* @__PURE__ */ v(w, {
126
+ label: F.rowType,
127
+ value: E.type ? /* @__PURE__ */ v(g, {
128
+ type: E.type,
129
+ labels: F.typeBadge
130
+ }) : F.rowEmptyValue
131
+ }),
132
+ /* @__PURE__ */ v(w, {
133
+ label: F.rowUnit,
134
+ value: E.unitLabel,
135
+ emptyValue: F.rowEmptyValue
136
+ }),
137
+ /* @__PURE__ */ v(w, {
138
+ label: F.rowCreatedOn,
139
+ value: E.createdAtLabel,
140
+ emptyValue: F.rowEmptyValue
141
+ }),
142
+ /* @__PURE__ */ v(w, {
143
+ label: F.rowLastUpdate,
144
+ value: E.updatedAtLabel,
145
+ emptyValue: F.rowEmptyValue,
146
+ isLast: !0
147
+ })
148
+ ]
149
+ })]
150
+ })
151
+ })]
152
+ })
25
153
  });
26
154
  }
27
155
  //#endregion
28
- export { u as ProductDeleteDialog, u as default };
156
+ export { T as ProductDetailsSheet, T as default };
@@ -0,0 +1,28 @@
1
+ import { AlertDialog as e, AlertDialogContent as t, AlertDialogDescription as n, AlertDialogFooter as r, AlertDialogHeader as i, AlertDialogTitle as a, Button as o } from "../../../../../packages/shared-ui-shadcn/dist/index.js";
2
+ import { PRODUCT_DELETE_DIALOG_LABELS_EN as s } from "./index2.js";
3
+ import { jsx as c, jsxs as l } from "react/jsx-runtime";
4
+ //#region ../../libs/tesouro-embedded-components-react/products-widget/ui/dist/index7.js
5
+ function u({ open: u, onOpenChange: d, productName: f, isDeleting: p, onConfirm: m, onCancel: h, labels: g }) {
6
+ let _ = {
7
+ ...s,
8
+ ...g
9
+ };
10
+ return /* @__PURE__ */ c(e, {
11
+ open: u,
12
+ onOpenChange: d,
13
+ children: /* @__PURE__ */ l(t, { children: [/* @__PURE__ */ l(i, { children: [/* @__PURE__ */ c(a, { children: _.title.replace("{name}", f) }), /* @__PURE__ */ c(n, { children: _.message })] }), /* @__PURE__ */ l(r, { children: [/* @__PURE__ */ c(o, {
14
+ variant: "ghost",
15
+ onClick: h,
16
+ disabled: p,
17
+ children: _.cancelButton
18
+ }), /* @__PURE__ */ c(o, {
19
+ variant: "destructive",
20
+ onClick: m,
21
+ disabled: p,
22
+ loading: p,
23
+ children: _.confirmButton
24
+ })] })] })
25
+ });
26
+ }
27
+ //#endregion
28
+ export { u as ProductDeleteDialog, u as default };
@@ -1,5 +1,5 @@
1
1
  //#region ../../libs/tesouro-embedded-components-react/shared/feature/dist/lib/analytics/build-info.js
2
- var e = "@tesouro/embedded-components-react", t = "0.7.70", n = "88a5d6cac853f3f9cb7ced8b403acaebf709be82", r = Object.freeze({
2
+ var e = "@tesouro/embedded-components-react", t = "0.7.73", n = "6460d41dcd6d9cc7806778015e14814d4bfd495d", r = Object.freeze({
3
3
  library_name: e,
4
4
  library_version: t,
5
5
  library_sha: n
@@ -1,25 +1,26 @@
1
1
  import { extractApiErrorMessage as e } from "../../../util/dist/lib/apiErrors.js";
2
2
  import { PRODUCT_MESSAGE_LABELS_EN as t } from "./lib/labels.js";
3
3
  import { buildProductDetailsView as n, buildProductRows as r, formatPrice as i, hasSelectedText as a } from "./lib/helpers.js";
4
- import { ProductFormSheet as o } from "../../ui/dist/index3.js";
5
- import "../../ui/dist/index4.js";
4
+ import { PRODUCT_FORM_SHEET_LABELS_EN as o } from "../../ui/dist/index2.js";
5
+ import { ProductFormSheet as s } from "../../ui/dist/index4.js";
6
6
  import "../../ui/dist/index5.js";
7
+ import "../../ui/dist/index6.js";
7
8
  import "../../ui/dist/index.js";
8
- import { useProductsQuery as s } from "../../data-access/dist/index2.js";
9
+ import { useProductsQuery as c } from "../../data-access/dist/index2.js";
9
10
  import "../../data-access/dist/index3.js";
10
- import { useProductQuery as c } from "../../data-access/dist/index4.js";
11
- import { useCreateProductMutation as l } from "../../data-access/dist/index6.js";
11
+ import { useProductQuery as l } from "../../data-access/dist/index4.js";
12
+ import { useCreateProductMutation as u } from "../../data-access/dist/index6.js";
12
13
  import "../../data-access/dist/index7.js";
13
- import { useDeleteProductMutation as u } from "../../data-access/dist/index8.js";
14
- import { useMeasureUnitsQuery as d } from "../../data-access/dist/index9.js";
14
+ import { useDeleteProductMutation as d } from "../../data-access/dist/index8.js";
15
+ import { useMeasureUnitsQuery as f } from "../../data-access/dist/index9.js";
15
16
  import "../../data-access/dist/index10.js";
16
17
  import "../../data-access/dist/index11.js";
17
18
  import "../../data-access/dist/index12.js";
18
19
  import "../../data-access/dist/index13.js";
19
20
  import "../../data-access/dist/index.js";
20
- import { MeasureUnitsManagerContainer as f } from "./lib/MeasureUnitsManagerContainer.js";
21
- import { useMeasureUnits as p } from "./lib/useMeasureUnits.js";
22
- import { useProductForm as m } from "./lib/useProductForm.js";
21
+ import { MeasureUnitsManagerContainer as p } from "./lib/MeasureUnitsManagerContainer.js";
22
+ import { useMeasureUnits as m } from "./lib/useMeasureUnits.js";
23
+ import { useProductForm as h } from "./lib/useProductForm.js";
23
24
  import "./lib/useProductSelector.js";
24
- import { ProductSelector as h } from "./lib/ProductSelector.js";
25
- export { f as MeasureUnitsManagerContainer, t as PRODUCT_MESSAGE_LABELS_EN, o as ProductFormSheet, h as ProductSelector, n as buildProductDetailsView, r as buildProductRows, e as extractApiErrorMessage, i as formatPrice, a as hasSelectedText, l as useCreateProductMutation, u as useDeleteProductMutation, p as useMeasureUnits, d as useMeasureUnitsQuery, m as useProductForm, c as useProductQuery, s as useProductsQuery };
25
+ import { ProductSelector as g } from "./lib/ProductSelector.js";
26
+ export { p as MeasureUnitsManagerContainer, o as PRODUCT_FORM_SHEET_LABELS_EN, t as PRODUCT_MESSAGE_LABELS_EN, s as ProductFormSheet, g as ProductSelector, n as buildProductDetailsView, r as buildProductRows, e as extractApiErrorMessage, i as formatPrice, a as hasSelectedText, u as useCreateProductMutation, d as useDeleteProductMutation, m as useMeasureUnits, f as useMeasureUnitsQuery, h as useProductForm, l as useProductQuery, c as useProductsQuery };
@@ -8,8 +8,8 @@ import "../../../../ui/dist/index.js";
8
8
  import { PRODUCT_MESSAGE_LABELS_EN as n } from "./labels.js";
9
9
  import { formatPrice as r, validateMeasureUnit as i } from "./helpers.js";
10
10
  import { toastSuccessWithName as a } from "./toasts.js";
11
- import { MeasureUnitsManager as o } from "../../../ui/dist/index4.js";
12
- import { MeasureUnitDeleteDialog as s } from "../../../ui/dist/index5.js";
11
+ import { MeasureUnitsManager as o } from "../../../ui/dist/index5.js";
12
+ import { MeasureUnitDeleteDialog as s } from "../../../ui/dist/index6.js";
13
13
  import "../../../ui/dist/index.js";
14
14
  import { useMeasureUnitsQuery as c } from "../../../data-access/dist/index9.js";
15
15
  import { useProductsByMeasureUnitQuery as l } from "../../../data-access/dist/index10.js";
@@ -2,7 +2,7 @@
2
2
  "use client";
3
3
  "use client";
4
4
  "use client";
5
- import { ProductSelector as e } from "../../../ui/dist/index6.js";
5
+ import { ProductSelector as e } from "../../../ui/dist/index7.js";
6
6
  import "../../../ui/dist/index.js";
7
7
  import { useProductSelector as t } from "./useProductSelector.js";
8
8
  import { jsx as n } from "react/jsx-runtime";
@@ -20,6 +20,17 @@ function a(e, t) {
20
20
  return e / 10 ** r(t);
21
21
  }
22
22
  function o(e) {
23
+ try {
24
+ return new Intl.NumberFormat(void 0, {
25
+ style: "currency",
26
+ currency: e,
27
+ currencyDisplay: e.toUpperCase() === "USD" ? "narrowSymbol" : "symbol"
28
+ }).formatToParts(0).find((e) => e.type === "currency")?.value ?? e;
29
+ } catch {
30
+ return e;
31
+ }
32
+ }
33
+ function s(e) {
23
34
  if (!e) return "";
24
35
  let t = a(e.value, e.currency);
25
36
  try {
@@ -31,49 +42,49 @@ function o(e) {
31
42
  return `${t} ${e.currency}`;
32
43
  }
33
44
  }
34
- var s = new Intl.DateTimeFormat(void 0, {
45
+ var c = new Intl.DateTimeFormat(void 0, {
35
46
  year: "numeric",
36
47
  month: "short",
37
- day: "numeric"
48
+ day: "2-digit"
38
49
  });
39
- function c(e) {
50
+ function l(e) {
40
51
  if (!e) return "";
41
52
  let t = new Date(e);
42
- return Number.isNaN(t.getTime()) ? "" : s.format(t);
53
+ return Number.isNaN(t.getTime()) ? "" : c.format(t);
43
54
  }
44
- function l(e) {
55
+ function u(e) {
45
56
  let t = {};
46
57
  for (let n of e ?? []) t[n.id] = n.name;
47
58
  return t;
48
59
  }
49
- function u(e) {
60
+ function d(e) {
50
61
  return (e ?? []).map((e) => ({
51
62
  value: e.id,
52
63
  label: e.name
53
64
  }));
54
65
  }
55
- function d({ products: e, unitNamesById: t }) {
66
+ function f({ products: e, unitNamesById: t }) {
56
67
  return e.map((e) => ({
57
68
  id: e.id,
58
69
  name: e.name,
59
70
  type: e.type,
60
71
  description: e.description ?? "",
61
72
  unitLabel: e.measure_unit_id ? t[e.measure_unit_id] ?? "" : "",
62
- priceLabel: o(e.price)
73
+ priceLabel: s(e.price)
63
74
  }));
64
75
  }
65
- function f({ product: e, unitNamesById: t }) {
76
+ function p({ product: e, unitNamesById: t }) {
66
77
  return {
67
78
  name: e.name,
68
79
  description: e.description ?? "",
69
80
  type: e.type,
70
81
  unitLabel: e.measure_unit_id ? t[e.measure_unit_id] ?? "" : "",
71
- priceLabel: o(e.price),
72
- createdAtLabel: c(e.created_at),
73
- updatedAtLabel: c(e.updated_at)
82
+ priceLabel: s(e.price),
83
+ createdAtLabel: l(e.created_at),
84
+ updatedAtLabel: l(e.updated_at)
74
85
  };
75
86
  }
76
- var p = {
87
+ var m = {
77
88
  name: "",
78
89
  description: "",
79
90
  type: "product",
@@ -81,7 +92,10 @@ var p = {
81
92
  pricePerUnit: "",
82
93
  currency: "USD"
83
94
  };
84
- function m(e) {
95
+ function h(e, t) {
96
+ return Object.keys(e).every((n) => e[n] === t[n]);
97
+ }
98
+ function g(e) {
85
99
  let t = e.price?.currency ?? "USD";
86
100
  return {
87
101
  name: e.name,
@@ -92,7 +106,7 @@ function m(e) {
92
106
  currency: t
93
107
  };
94
108
  }
95
- function h(e) {
109
+ function _(e) {
96
110
  let t = e.pricePerUnit.trim();
97
111
  return {
98
112
  name: e.name.trim(),
@@ -105,7 +119,7 @@ function h(e) {
105
119
  description: e.description.trim() ? e.description.trim() : void 0
106
120
  };
107
121
  }
108
- function g(e) {
122
+ function v(e) {
109
123
  let t = e.pricePerUnit.trim();
110
124
  return {
111
125
  name: e.name.trim(),
@@ -118,18 +132,18 @@ function g(e) {
118
132
  description: e.description.trim()
119
133
  };
120
134
  }
121
- var _ = 100, v = 255;
122
- function y(e, t = n) {
135
+ var y = 100, b = 255;
136
+ function x(e, t = n) {
123
137
  let r = {};
124
- e.name.trim().length === 0 ? r.name = t.nameRequired : e.name.trim().length > _ && (r.name = t.nameTooLong), e.type !== "product" && e.type !== "service" && (r.type = t.typeRequired);
138
+ e.name.trim().length === 0 ? r.name = t.nameRequired : e.name.trim().length > y && (r.name = t.nameTooLong), e.type !== "product" && e.type !== "service" && (r.type = t.typeRequired);
125
139
  let i = e.pricePerUnit.trim();
126
140
  if (i !== "") {
127
141
  let e = Number(i);
128
142
  (!Number.isFinite(e) || e < 0) && (r.pricePerUnit = t.priceInvalid);
129
143
  }
130
- return e.description.trim().length > v && (r.description = t.descriptionTooLong), r;
144
+ return e.description.trim().length > b && (r.description = t.descriptionTooLong), r;
131
145
  }
132
- var b = {
146
+ var S = {
133
147
  name: "name",
134
148
  type: "type",
135
149
  description: "description",
@@ -137,25 +151,25 @@ var b = {
137
151
  "price.currency": "pricePerUnit",
138
152
  measure_unit_id: "unitId"
139
153
  };
140
- function x(r, i = n) {
154
+ function C(r, i = n) {
141
155
  let a = t(r);
142
156
  if (!a.length) return { form: e(r) ?? i.genericError };
143
157
  let o = {}, s = [];
144
158
  for (let { path: e, msg: t } of a) {
145
- let n = b[e];
159
+ let n = S[e];
146
160
  n ? o[n] = t : s.push(t);
147
161
  }
148
162
  return s.length && (o.form = [...new Set(s)].join("; ")), o;
149
163
  }
150
- function S(e) {
164
+ function w(e) {
151
165
  return Object.values(e).some(Boolean);
152
166
  }
153
- function C(e, t = n) {
167
+ function T(e, t = n) {
154
168
  return e.name.trim().length === 0 ? t.unitNameRequired : void 0;
155
169
  }
156
- function w() {
170
+ function E() {
157
171
  let e = globalThis.getSelection?.();
158
172
  return !!(e && e.toString().length > 0);
159
173
  }
160
174
  //#endregion
161
- export { p as EMPTY_PRODUCT_FORM_VALUES, x as apiErrorToProductFormErrors, f as buildProductDetailsView, d as buildProductRows, l as buildUnitNamesById, u as buildUnitOptions, o as formatPrice, c as formatProductDate, a as fromMinorUnits, S as hasProductFormErrors, w as hasSelectedText, h as productFormValuesToRequest, g as productFormValuesToUpdateRequest, m as productToFormValues, i as toMinorUnits, C as validateMeasureUnit, y as validateProductForm };
175
+ export { m as EMPTY_PRODUCT_FORM_VALUES, C as apiErrorToProductFormErrors, h as areProductFormValuesEqual, p as buildProductDetailsView, f as buildProductRows, u as buildUnitNamesById, d as buildUnitOptions, o as currencySymbol, s as formatPrice, l as formatProductDate, a as fromMinorUnits, w as hasProductFormErrors, E as hasSelectedText, _ as productFormValuesToRequest, v as productFormValuesToUpdateRequest, g as productToFormValues, i as toMinorUnits, T as validateMeasureUnit, x as validateProductForm };
@@ -2,62 +2,80 @@
2
2
  "use client";
3
3
  "use client";
4
4
  "use client";
5
- import { EMPTY_PRODUCT_FORM_VALUES as e, apiErrorToProductFormErrors as t, hasProductFormErrors as n, productFormValuesToRequest as r, productFormValuesToUpdateRequest as i, productToFormValues as a, validateProductForm as o } from "./helpers.js";
6
- import { toastSuccessWithName as s } from "./toasts.js";
7
- import { useCreateProductMutation as c } from "../../../data-access/dist/index6.js";
8
- import { useUpdateProductMutation as l } from "../../../data-access/dist/index7.js";
5
+ import { EMPTY_PRODUCT_FORM_VALUES as e, apiErrorToProductFormErrors as t, areProductFormValuesEqual as n, currencySymbol as r, hasProductFormErrors as i, productFormValuesToRequest as a, productFormValuesToUpdateRequest as o, productToFormValues as s, validateProductForm as c } from "./helpers.js";
6
+ import { toastSuccessWithName as l } from "./toasts.js";
7
+ import { useCreateProductMutation as u } from "../../../data-access/dist/index6.js";
8
+ import { useUpdateProductMutation as d } from "../../../data-access/dist/index7.js";
9
9
  import "../../../data-access/dist/index.js";
10
- import { useCallback as u, useState as d } from "react";
10
+ import { useCallback as f, useEffect as p, useMemo as m, useRef as h, useState as g } from "react";
11
11
  //#region ../../libs/tesouro-embedded-components-react/shared/product-catalog/feature/dist/lib/useProductForm.js
12
- function f({ view: f, setView: p, selectedProductId: m, setSelectedProductId: h, product: g, messages: _ }) {
13
- let v = c(), y = l(), b = v.isPending || y.isPending, [x, S] = d(e), [C, w] = d({});
14
- return {
15
- values: x,
16
- errors: C,
17
- setValues: S,
18
- isSubmitting: b,
19
- openCreate: u(() => {
20
- h(void 0), S(e), w({}), p("create");
21
- }, [h, p]),
22
- openEdit: u(() => {
23
- g && (S(a(g)), w({}), p("edit"));
24
- }, [g, p]),
25
- close: u(() => {
26
- p("none"), h(void 0);
27
- }, [h, p]),
28
- submit: u(async () => {
29
- let e = o(x, _);
30
- if (n(e)) {
31
- w(e);
12
+ function _({ view: _, setView: v, selectedProductId: y, setSelectedProductId: b, product: x, messages: S }) {
13
+ let C = u(), w = d(), T = C.isPending || w.isPending, [E, D] = g(e), [O, k] = g({}), A = h({
14
+ view: _,
15
+ selectedProductId: y
16
+ });
17
+ p(() => {
18
+ A.current = {
19
+ view: _,
20
+ selectedProductId: y
21
+ };
22
+ });
23
+ let j = f(() => {
24
+ b(void 0), D(e), k({}), v("create");
25
+ }, [b, v]), M = f(() => {
26
+ x && (D(s(x)), k({}), v("edit"));
27
+ }, [x, v]), N = f(() => {
28
+ v("none"), b(void 0);
29
+ }, [b, v]), P = f(() => {
30
+ k({}), v("details");
31
+ }, [v]), F = m(() => _ === "edit" && x ? !n(E, s(x)) : !1, [
32
+ _,
33
+ x,
34
+ E
35
+ ]), I = f(async () => {
36
+ let e = c(E, S);
37
+ if (i(e)) {
38
+ k(e);
39
+ return;
40
+ }
41
+ k({});
42
+ try {
43
+ if (_ === "edit" && y) {
44
+ let e = y, t = await w.mutateAsync({
45
+ path: { product_id: y },
46
+ body: o(E)
47
+ });
48
+ l(t.type === "service" ? S.serviceUpdated : S.productUpdated, t.name), A.current.view === "edit" && A.current.selectedProductId === e && v("details");
32
49
  return;
33
50
  }
34
- w({});
35
- try {
36
- if (f === "edit" && m) {
37
- let e = await y.mutateAsync({
38
- path: { product_id: m },
39
- body: i(x)
40
- });
41
- s(e.type === "service" ? _.serviceUpdated : _.productUpdated, e.name);
42
- } else {
43
- let e = await v.mutateAsync({ body: r(x) });
44
- s(_.productCreated, e.name);
45
- }
46
- p("none"), h(void 0);
47
- } catch (e) {
48
- w(t(e, _));
49
- }
50
- }, [
51
- x,
52
- f,
53
- m,
54
- v,
55
- y,
56
- _,
57
- p,
58
- h
59
- ])
51
+ let e = await C.mutateAsync({ body: a(E) });
52
+ l(S.productCreated, e.name), v("none"), b(void 0);
53
+ } catch (e) {
54
+ k(t(e, S));
55
+ }
56
+ }, [
57
+ E,
58
+ _,
59
+ y,
60
+ C,
61
+ w,
62
+ S,
63
+ v,
64
+ b
65
+ ]);
66
+ return {
67
+ values: E,
68
+ errors: O,
69
+ pricePrefix: r(E.currency),
70
+ setValues: D,
71
+ isSubmitting: T,
72
+ isDirty: F,
73
+ openCreate: j,
74
+ openEdit: M,
75
+ cancelEdit: P,
76
+ close: N,
77
+ submit: I
60
78
  };
61
79
  }
62
80
  //#endregion
63
- export { f as useProductForm };
81
+ export { _ as useProductForm };
@@ -1,6 +1,7 @@
1
- import "./index2.js";
2
- import { ProductFormSheet as e } from "./index3.js";
3
- import { MeasureUnitsManager as t } from "./index4.js";
4
- import { MeasureUnitDeleteDialog as n } from "./index5.js";
5
- import { ProductSelector as r } from "./index6.js";
6
- export { n as MeasureUnitDeleteDialog, t as MeasureUnitsManager, e as ProductFormSheet, r as ProductSelector };
1
+ import { PRODUCT_FORM_SHEET_LABELS_EN as e, mergeProductFormSheetLabels as t } from "./index2.js";
2
+ import { ProductFormFields as n } from "./index3.js";
3
+ import { ProductFormSheet as r } from "./index4.js";
4
+ import { MeasureUnitsManager as i } from "./index5.js";
5
+ import { MeasureUnitDeleteDialog as a } from "./index6.js";
6
+ import { ProductSelector as o } from "./index7.js";
7
+ export { a as MeasureUnitDeleteDialog, i as MeasureUnitsManager, e as PRODUCT_FORM_SHEET_LABELS_EN, n as ProductFormFields, r as ProductFormSheet, o as ProductSelector, t as mergeProductFormSheetLabels };