@tesouro/embedded-components-react 0.7.66 → 0.7.67

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.
@@ -72,13 +72,11 @@ function _({ pageSizeOptions: n = s, screenLabels: o, formLabels: _, detailsLabe
72
72
  values: O.values,
73
73
  errors: O.errors,
74
74
  unitOptions: T.unitOptions,
75
- currencyOptions: O.currencyOptions,
76
75
  inProgress: O.isSubmitting || I,
77
76
  onChange: (e) => O.setValues((t) => ({
78
77
  ...t,
79
78
  ...e
80
79
  })),
81
- onManageUnits: R,
82
80
  onSubmit: B,
83
81
  onCancel: O.close,
84
82
  labels: _
@@ -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.66", n = "6104c73d61228502ff326ac8761a846765fe16ee", r = Object.freeze({
2
+ var e = "@tesouro/embedded-components-react", t = "0.7.67", n = "c1366f2557aed45958299b0d0c108f4151bf95f0", r = Object.freeze({
3
3
  library_name: e,
4
4
  library_version: t,
5
5
  library_sha: n
@@ -1,33 +1,7 @@
1
- import { PRODUCT_MESSAGE_LABELS_EN as e } from "./labels.js";
1
+ import { extractApiErrorMessage as e } from "../../../../util/dist/lib/apiErrors.js";
2
+ import { parseApiValidationErrors as t } from "../../../../util/dist/lib/apiValidationErrors.js";
3
+ import { PRODUCT_MESSAGE_LABELS_EN as n } from "./labels.js";
2
4
  //#region ../../libs/tesouro-embedded-components-react/shared/product-catalog/feature/dist/lib/helpers.js
3
- var t = [
4
- "USD",
5
- "EUR",
6
- "GBP",
7
- "CAD",
8
- "AUD",
9
- "JPY",
10
- "CHF",
11
- "CNY",
12
- "INR",
13
- "BRL",
14
- "MXN",
15
- "SEK",
16
- "NOK",
17
- "DKK",
18
- "NZD",
19
- "SGD",
20
- "HKD",
21
- "ZAR",
22
- "PLN",
23
- "AED"
24
- ];
25
- function n(e) {
26
- return Array.from(/* @__PURE__ */ new Set([...t, ...e ? [e] : []])).sort().map((e) => ({
27
- value: e,
28
- label: e
29
- }));
30
- }
31
5
  function r(e) {
32
6
  try {
33
7
  return new Intl.NumberFormat("en-US", {
@@ -125,8 +99,8 @@ function h(e) {
125
99
  type: e.type,
126
100
  measure_unit_id: e.unitId || void 0,
127
101
  price: t === "" ? void 0 : {
128
- value: i(Number(t), e.currency),
129
- currency: e.currency
102
+ value: i(Number(t), "USD"),
103
+ currency: "USD"
130
104
  },
131
105
  description: e.description.trim() ? e.description.trim() : void 0
132
106
  };
@@ -145,25 +119,43 @@ function g(e) {
145
119
  };
146
120
  }
147
121
  var _ = 100, v = 255;
148
- function y(t, n = e) {
122
+ function y(e, t = n) {
149
123
  let r = {};
150
- t.name.trim().length === 0 ? r.name = n.nameRequired : t.name.trim().length > _ && (r.name = n.nameTooLong), t.type !== "product" && t.type !== "service" && (r.type = n.typeRequired);
151
- let i = t.pricePerUnit.trim();
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);
125
+ let i = e.pricePerUnit.trim();
152
126
  if (i !== "") {
153
127
  let e = Number(i);
154
- (!Number.isFinite(e) || e < 0) && (r.pricePerUnit = n.priceInvalid);
128
+ (!Number.isFinite(e) || e < 0) && (r.pricePerUnit = t.priceInvalid);
129
+ }
130
+ return e.description.trim().length > v && (r.description = t.descriptionTooLong), r;
131
+ }
132
+ var b = {
133
+ name: "name",
134
+ type: "type",
135
+ description: "description",
136
+ "price.value": "pricePerUnit",
137
+ "price.currency": "pricePerUnit",
138
+ measure_unit_id: "unitId"
139
+ };
140
+ function x(r, i = n) {
141
+ let a = t(r);
142
+ if (!a.length) return { form: e(r) ?? i.genericError };
143
+ let o = {}, s = [];
144
+ for (let { path: e, msg: t } of a) {
145
+ let n = b[e];
146
+ n ? o[n] = t : s.push(t);
155
147
  }
156
- return t.currency.trim().length === 0 && (r.currency = n.currencyRequired), t.description.trim().length > v && (r.description = n.descriptionTooLong), r;
148
+ return s.length && (o.form = [...new Set(s)].join("; ")), o;
157
149
  }
158
- function b(e) {
150
+ function S(e) {
159
151
  return Object.values(e).some(Boolean);
160
152
  }
161
- function x(t, n = e) {
162
- return t.name.trim().length === 0 ? n.unitNameRequired : void 0;
153
+ function C(e, t = n) {
154
+ return e.name.trim().length === 0 ? t.unitNameRequired : void 0;
163
155
  }
164
- function S() {
156
+ function w() {
165
157
  let e = globalThis.getSelection?.();
166
158
  return !!(e && e.toString().length > 0);
167
159
  }
168
160
  //#endregion
169
- export { p as EMPTY_PRODUCT_FORM_VALUES, f as buildProductDetailsView, d as buildProductRows, l as buildUnitNamesById, u as buildUnitOptions, o as formatPrice, c as formatProductDate, a as fromMinorUnits, n as getCurrencyOptions, b as hasProductFormErrors, S as hasSelectedText, h as productFormValuesToRequest, g as productFormValuesToUpdateRequest, m as productToFormValues, i as toMinorUnits, x as validateMeasureUnit, y as validateProductForm };
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 };
@@ -4,7 +4,6 @@ var e = {
4
4
  nameTooLong: "Product name must be 100 characters or less",
5
5
  typeRequired: "Product type is required",
6
6
  priceInvalid: "Price per unit must be 0 or greater",
7
- currencyRequired: "Currency is required",
8
7
  descriptionTooLong: "Description must be 255 characters or less",
9
8
  unitNameRequired: "Unit label is required",
10
9
  genericError: "Something went wrong. Please try again.",
@@ -15,10 +14,10 @@ var e = {
15
14
  serviceUpdated: "Service {name} was updated.",
16
15
  productDeleted: "Product was deleted.",
17
16
  deleteProductError: "Failed to delete product.",
18
- measureUnitCreated: "Unit {name} was added to the list",
19
- measureUnitUpdated: "Unit {name} was updated",
17
+ measureUnitCreated: "Unit {name} was added to the list.",
18
+ measureUnitUpdated: "Unit {name} was updated.",
20
19
  measureUnitDeleted: "Unit {name} was deleted from the list.",
21
- deleteMeasureUnitError: "Failed to delete Unit."
20
+ deleteMeasureUnitError: "Failed to delete measure unit."
22
21
  };
23
22
  //#endregion
24
23
  export { e as PRODUCT_MESSAGE_LABELS_EN };
@@ -2,64 +2,62 @@
2
2
  "use client";
3
3
  "use client";
4
4
  "use client";
5
- import { extractApiErrorMessage as e } from "../../../../util/dist/lib/apiErrors.js";
6
- import { EMPTY_PRODUCT_FORM_VALUES as t, getCurrencyOptions as n, hasProductFormErrors as r, productFormValuesToRequest as i, productFormValuesToUpdateRequest as a, productToFormValues as o, validateProductForm as s } from "./helpers.js";
7
- import { toastSuccessWithName as c } from "./toasts.js";
8
- import { useCreateProductMutation as l } from "../../../data-access/dist/index6.js";
9
- import { useUpdateProductMutation as u } from "../../../data-access/dist/index7.js";
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";
10
9
  import "../../../data-access/dist/index.js";
11
- import { useCallback as d, useMemo as f, useState as p } from "react";
10
+ import { useCallback as u, useState as d } from "react";
12
11
  //#region ../../libs/tesouro-embedded-components-react/shared/product-catalog/feature/dist/lib/useProductForm.js
13
- function m({ view: m, setView: h, selectedProductId: g, setSelectedProductId: _, product: v, messages: y }) {
14
- let b = l(), x = u(), S = b.isPending || x.isPending, [C, w] = p(t), [T, E] = p({});
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({});
15
14
  return {
16
- values: C,
17
- errors: T,
18
- setValues: w,
19
- currencyOptions: f(() => n(C.currency), [C.currency]),
20
- isSubmitting: S,
21
- openCreate: d(() => {
22
- _(void 0), w(t), E({}), h("create");
23
- }, [_, h]),
24
- openEdit: d(() => {
25
- v && (w(o(v)), E({}), h("edit"));
26
- }, [v, h]),
27
- close: d(() => {
28
- h("none"), _(void 0);
29
- }, [_, h]),
30
- submit: d(async () => {
31
- let t = s(C, y);
32
- if (r(t)) {
33
- E(t);
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);
34
32
  return;
35
33
  }
36
- E({});
34
+ w({});
37
35
  try {
38
- if (m === "edit" && g) {
39
- let e = await x.mutateAsync({
40
- path: { product_id: g },
41
- body: a(C)
36
+ if (f === "edit" && m) {
37
+ let e = await y.mutateAsync({
38
+ path: { product_id: m },
39
+ body: i(x)
42
40
  });
43
- c(e.type === "service" ? y.serviceUpdated : y.productUpdated, e.name);
41
+ s(e.type === "service" ? _.serviceUpdated : _.productUpdated, e.name);
44
42
  } else {
45
- let e = await b.mutateAsync({ body: i(C) });
46
- c(y.productCreated, e.name);
43
+ let e = await v.mutateAsync({ body: r(x) });
44
+ s(_.productCreated, e.name);
47
45
  }
48
- h("none"), _(void 0);
49
- } catch (t) {
50
- E({ form: e(t) ?? y.genericError });
46
+ p("none"), h(void 0);
47
+ } catch (e) {
48
+ w(t(e, _));
51
49
  }
52
50
  }, [
53
- C,
54
- m,
55
- g,
56
- b,
57
51
  x,
52
+ f,
53
+ m,
54
+ v,
58
55
  y,
59
- h,
60
- _
56
+ _,
57
+ p,
58
+ h
61
59
  ])
62
60
  };
63
61
  }
64
62
  //#endregion
65
- export { m as useProductForm };
63
+ export { f as useProductForm };
@@ -1,5 +1,6 @@
1
+ import { LABEL_LABELS_EN as e, REQUIRED_FIELDS_LEGEND_LABELS_EN as t } from "../../../../../../packages/shared-ui-shadcn/dist/index.js";
1
2
  //#region ../../libs/tesouro-embedded-components-react/shared/product-catalog/ui/dist/index2.js
2
- var e = {
3
+ var n = {
3
4
  createTitle: "Add a product or service",
4
5
  headerDescription: "Save the products and services you sell so you can quickly add them as line items on invoices.",
5
6
  editTitle: "Edit {type}",
@@ -7,25 +8,25 @@ var e = {
7
8
  nameLabel: "Name",
8
9
  namePlaceholder: "e.g. House blend espresso beans",
9
10
  descriptionLabel: "Description",
10
- descriptionOptional: "(optional)",
11
11
  descriptionPlaceholder: "e.g. 16oz whole bean, medium-dark roast, ground to order",
12
12
  descriptionCount: "{count}/255 characters",
13
13
  typeLabel: "Type",
14
14
  typeProduct: "Product",
15
- typeProductDescription: "A physical or digital item",
16
15
  typeService: "Service",
17
- typeServiceDescription: "Work or labor you provide",
18
16
  unitLabel: "Unit",
19
17
  unitPlaceholder: "Select a unit",
20
- noUnit: "No unit",
21
- manageUnits: "Manage units of measure",
18
+ noUnit: "None",
19
+ unitEmpty: "No units found",
20
+ unitClearAriaLabel: "Clear unit",
22
21
  priceLabel: "Price per unit",
23
- currencyLabel: "Currency",
24
- currencyPlaceholder: "Select a currency",
22
+ pricePrefix: "$",
23
+ pricePlaceholder: "0.00",
25
24
  cancelButton: "Cancel",
26
25
  createButton: "Save {type}",
27
- saveButton: "Save"
28
- }, t = {
26
+ saveButton: "Save",
27
+ fieldMarkers: e,
28
+ requiredFieldsLegend: t
29
+ }, r = {
29
30
  title: "Manage measure units",
30
31
  hiddenDescription: "Create, edit, and delete measure units",
31
32
  searchPlaceholder: "Search",
@@ -41,7 +42,7 @@ var e = {
41
42
  saveAction: "Save unit",
42
43
  cancelAction: "Cancel edit",
43
44
  emptyText: "No measure units yet."
44
- }, n = {
45
+ }, i = {
45
46
  titleNoItems: "Delete “{name}” unit?",
46
47
  titleWithItems: "Delete “{name}” unit and associated items?",
47
48
  messageNoItems: "There are no items created with this measure unit.",
@@ -50,11 +51,11 @@ var e = {
50
51
  messageWithItemsHint: "Please, check the list of products and services that will get deleted:",
51
52
  confirmButton: "Delete",
52
53
  cancelButton: "Cancel"
53
- }, r = {
54
+ }, a = {
54
55
  fieldLabel: "Item name",
55
56
  placeholder: "e.g., Office supplies",
56
57
  emptyText: "No saved items found - type to add an item",
57
58
  toggleListButton: "Show saved items"
58
59
  };
59
60
  //#endregion
60
- export { t as MEASURE_UNITS_MANAGER_LABELS_EN, n as MEASURE_UNIT_DELETE_DIALOG_LABELS_EN, e as PRODUCT_FORM_SHEET_LABELS_EN, r as PRODUCT_SELECTOR_LABELS_EN };
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 };