@tesouro/embedded-components-react 0.7.72 → 0.7.74

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/README.md +1 -1
  2. package/dist/index.css +9 -0
  3. package/dist/index.d.ts +12 -6
  4. package/dist/lib/ProductsWidget.d.ts +12 -6
  5. package/dist/lib/ReceivablesWidget.d.ts +1 -5
  6. package/dist/libs/tesouro-embedded-components-react/products-widget/feature/dist/lib/ProductsWidget/ProductsWidget.js +23 -24
  7. package/dist/libs/tesouro-embedded-components-react/products-widget/feature/dist/lib/ProductsWidget/constants.js +6 -2
  8. package/dist/libs/tesouro-embedded-components-react/products-widget/feature/dist/lib/ProductsWidget/useProductsTable.js +112 -51
  9. package/dist/libs/tesouro-embedded-components-react/products-widget/feature/dist/lib/ProductsWidget/useProductsWidget.js +80 -56
  10. package/dist/libs/tesouro-embedded-components-react/products-widget/ui/dist/index.js +6 -5
  11. package/dist/libs/tesouro-embedded-components-react/products-widget/ui/dist/index2.js +15 -6
  12. package/dist/libs/tesouro-embedded-components-react/products-widget/ui/dist/index4.js +170 -135
  13. package/dist/libs/tesouro-embedded-components-react/products-widget/ui/dist/index5.js +49 -150
  14. package/dist/libs/tesouro-embedded-components-react/products-widget/ui/dist/index6.js +152 -24
  15. package/dist/libs/tesouro-embedded-components-react/products-widget/ui/dist/index7.js +28 -0
  16. package/dist/libs/tesouro-embedded-components-react/shared/approval-policy/feature/dist/lib/labels.js +1 -2
  17. package/dist/libs/tesouro-embedded-components-react/shared/approval-policy/feature/dist/lib/policyViewModel.js +8 -9
  18. package/dist/libs/tesouro-embedded-components-react/shared/approval-policy/feature/dist/lib/useApprovalPolicyRules.js +127 -141
  19. package/dist/libs/tesouro-embedded-components-react/shared/approval-policy/util/dist/lib/validatePolicyDraft.js +1 -1
  20. package/dist/libs/tesouro-embedded-components-react/shared/feature/dist/lib/analytics/build-info.js +1 -1
  21. package/dist/libs/tesouro-embedded-components-react/shared/product-catalog/feature/dist/index.js +13 -12
  22. package/dist/libs/tesouro-embedded-components-react/shared/product-catalog/feature/dist/lib/MeasureUnitsManagerContainer.js +2 -2
  23. package/dist/libs/tesouro-embedded-components-react/shared/product-catalog/feature/dist/lib/ProductSelector.js +1 -1
  24. package/dist/libs/tesouro-embedded-components-react/shared/product-catalog/feature/dist/lib/helpers.js +41 -27
  25. package/dist/libs/tesouro-embedded-components-react/shared/product-catalog/feature/dist/lib/useProductForm.js +70 -52
  26. package/dist/libs/tesouro-embedded-components-react/shared/product-catalog/ui/dist/index.js +7 -6
  27. package/dist/libs/tesouro-embedded-components-react/shared/product-catalog/ui/dist/index2.js +19 -8
  28. package/dist/libs/tesouro-embedded-components-react/shared/product-catalog/ui/dist/index3.js +171 -218
  29. package/dist/libs/tesouro-embedded-components-react/shared/product-catalog/ui/dist/index4.js +52 -180
  30. package/dist/libs/tesouro-embedded-components-react/shared/product-catalog/ui/dist/index5.js +188 -46
  31. package/dist/libs/tesouro-embedded-components-react/shared/product-catalog/ui/dist/index6.js +47 -124
  32. package/dist/libs/tesouro-embedded-components-react/shared/product-catalog/ui/dist/index7.js +128 -0
  33. package/package.json +1 -1
@@ -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 };
@@ -1,9 +1,8 @@
1
- import { LABEL_LABELS_EN as e, REQUIRED_FIELDS_LEGEND_LABELS_EN as t } from "../../../../../../packages/shared-ui-shadcn/dist/index.js";
1
+ import { LABEL_LABELS_EN as e, REQUIRED_FIELDS_LEGEND_LABELS_EN as t, mergeRequiredFieldsLegendLabels as n } from "../../../../../../packages/shared-ui-shadcn/dist/index.js";
2
2
  //#region ../../libs/tesouro-embedded-components-react/shared/product-catalog/ui/dist/index2.js
3
- var n = {
3
+ var r = {
4
4
  createTitle: "Add a product or service",
5
5
  headerDescription: "Save the products and services you sell so you can quickly add them as line items on invoices.",
6
- editTitle: "Edit {type}",
7
6
  editingBanner: "Editing {type} details",
8
7
  nameLabel: "Name",
9
8
  namePlaceholder: "e.g. House blend espresso beans",
@@ -19,14 +18,26 @@ var n = {
19
18
  unitEmpty: "No units found",
20
19
  unitClearAriaLabel: "Clear unit",
21
20
  priceLabel: "Price per unit",
22
- pricePrefix: "$",
23
21
  pricePlaceholder: "0.00",
24
22
  cancelButton: "Cancel",
25
23
  createButton: "Save {type}",
26
24
  saveButton: "Save",
27
25
  fieldMarkers: e,
28
26
  requiredFieldsLegend: t
29
- }, r = {
27
+ };
28
+ function i(e) {
29
+ let t = {
30
+ ...r.fieldMarkers,
31
+ ...e?.fieldMarkers
32
+ };
33
+ return {
34
+ ...r,
35
+ ...e,
36
+ fieldMarkers: t,
37
+ requiredFieldsLegend: n(t, e?.requiredFieldsLegend)
38
+ };
39
+ }
40
+ var a = {
30
41
  title: "Manage measure units",
31
42
  hiddenDescription: "Create, edit, and delete measure units",
32
43
  searchPlaceholder: "Search",
@@ -42,7 +53,7 @@ var n = {
42
53
  saveAction: "Save unit",
43
54
  cancelAction: "Cancel edit",
44
55
  emptyText: "No measure units yet."
45
- }, i = {
56
+ }, o = {
46
57
  titleNoItems: "Delete “{name}” unit?",
47
58
  titleWithItems: "Delete “{name}” unit and associated items?",
48
59
  messageNoItems: "There are no items created with this measure unit.",
@@ -51,11 +62,11 @@ var n = {
51
62
  messageWithItemsHint: "Please, check the list of products and services that will get deleted:",
52
63
  confirmButton: "Delete",
53
64
  cancelButton: "Cancel"
54
- }, a = {
65
+ }, s = {
55
66
  fieldLabel: "Item name",
56
67
  placeholder: "e.g., Office supplies",
57
68
  emptyText: "No saved items found - type to add an item",
58
69
  toggleListButton: "Show saved items"
59
70
  };
60
71
  //#endregion
61
- export { r as MEASURE_UNITS_MANAGER_LABELS_EN, i as MEASURE_UNIT_DELETE_DIALOG_LABELS_EN, n as PRODUCT_FORM_SHEET_LABELS_EN, a as PRODUCT_SELECTOR_LABELS_EN };
72
+ export { a as MEASURE_UNITS_MANAGER_LABELS_EN, o as MEASURE_UNIT_DELETE_DIALOG_LABELS_EN, r as PRODUCT_FORM_SHEET_LABELS_EN, s as PRODUCT_SELECTOR_LABELS_EN, i as mergeProductFormSheetLabels };