@plurix/ecom-components 1.14.2-commerce.6 → 1.14.2-commerce.7

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.
@@ -11,8 +11,9 @@ export interface ChangeOrderModalProps {
11
11
  isClubClient?: boolean;
12
12
  orderFormId: string;
13
13
  saveSelectedSimilarProduct?: (similarProduct: SimilarProductsProps | undefined) => void;
14
+ account: string;
14
15
  }
15
16
  export interface idSubstitutionCriteriasProps {
16
17
  [key: string]: string;
17
18
  }
18
- export declare const ChangeOrderModal: ({ selectedItem, postalCode, orderFormId, isClubClient, isOpen, environment, setIsOpen, saveSelectedSimilarProduct }: ChangeOrderModalProps) => import("react/jsx-runtime").JSX.Element;
19
+ export declare const ChangeOrderModal: ({ selectedItem, postalCode, orderFormId, isClubClient, isOpen, environment, setIsOpen, saveSelectedSimilarProduct, account }: ChangeOrderModalProps) => import("react/jsx-runtime").JSX.Element;
@@ -1,103 +1,108 @@
1
- import { jsx as n, jsxs as j, Fragment as q } from "react/jsx-runtime";
2
- import { useState as c, useEffect as w } from "react";
3
- import { Modal as M } from "../Modal/Modal.js";
4
- import { ProductSelected as N } from "./components/ProductSelected.js";
5
- import { SimilarProducts as k } from "./components/SimilarProducts.js";
6
- import { ModalFooter as v } from "./components/ModalFooter.js";
7
- /* empty css */import { getProductsSimilars as A } from "./api/getProductsSimilars.js";
8
- import E from "../../hooks/useAnalitcsEvents.js";
9
- import { NoSimilarProduct as _ } from "./components/NoSimilarProduct.js";
10
- import { getOrderForm as J } from "./api/getOrderForm.js";
11
- import { postChangeOrder as L } from "./api/postChangeOrder.js";
12
- import { Skeleton as T } from "../Skeleton/index.js";
13
- const oo = ({
14
- selectedItem: o,
15
- postalCode: S,
16
- orderFormId: e,
17
- isClubClient: h,
18
- isOpen: y,
19
- environment: O,
20
- setIsOpen: f,
21
- saveSelectedSimilarProduct: d
1
+ import { jsx as n, jsxs as q, Fragment as w } from "react/jsx-runtime";
2
+ import { useState as l, useEffect as M } from "react";
3
+ import { Modal as N } from "../Modal/Modal.js";
4
+ import { ProductSelected as k } from "./components/ProductSelected.js";
5
+ import { SimilarProducts as v } from "./components/SimilarProducts.js";
6
+ import { ModalFooter as A } from "./components/ModalFooter.js";
7
+ /* empty css */import { getProductsSimilars as E } from "./api/getProductsSimilars.js";
8
+ import _ from "../../hooks/useAnalitcsEvents.js";
9
+ import { NoSimilarProduct as J } from "./components/NoSimilarProduct.js";
10
+ import { getOrderForm as L } from "./api/getOrderForm.js";
11
+ import { postChangeOrder as T } from "./api/postChangeOrder.js";
12
+ import { Skeleton as $ } from "../Skeleton/index.js";
13
+ const or = ({
14
+ selectedItem: r,
15
+ postalCode: h,
16
+ orderFormId: c,
17
+ isClubClient: y,
18
+ isOpen: O,
19
+ environment: b,
20
+ setIsOpen: p,
21
+ saveSelectedSimilarProduct: m,
22
+ account: u
22
23
  }) => {
23
- const [m, b] = c(), [P, a] = c(!1), l = O === "io", { genericTaggingEvent: C } = E(), [r, p] = c({ itemId: "" });
24
- return w(() => {
24
+ const [e, P] = l(), [C, s] = l(!1), a = b === "io", { genericTaggingEvent: F } = _(), [o, g] = l({ itemId: "" });
25
+ return M(() => {
25
26
  (async () => {
26
- a(!0);
27
+ s(!0);
27
28
  try {
28
- const t = await A({
29
- postalCode: S,
30
- selectedItem: o
31
- }), s = (t == null ? void 0 : t.products) || [];
32
- b(s);
29
+ const i = await E({
30
+ postalCode: h,
31
+ selectedItem: r,
32
+ isIO: a,
33
+ account: u
34
+ }), d = (i == null ? void 0 : i.products) || [];
35
+ P(d);
33
36
  } finally {
34
- a(!1);
37
+ s(!1);
35
38
  }
36
39
  })(), (async () => {
37
- var t, s;
38
- a(!0);
40
+ var i, d;
41
+ s(!0);
39
42
  try {
40
- const u = await J(e), i = ((s = (t = u == null ? void 0 : u.customData) == null ? void 0 : t.customApps) == null ? void 0 : s.find(
41
- (x) => x.id === "janis"
43
+ const f = await L(c, a, u), t = ((d = (i = f == null ? void 0 : f.customData) == null ? void 0 : i.customApps) == null ? void 0 : d.find(
44
+ (j) => j.id === "janis"
42
45
  )) || null;
43
- let g = {};
44
- i != null && i.fields.idSubstitutionCriterias && (g = JSON.parse(
45
- i == null ? void 0 : i.fields.idSubstitutionCriterias
46
+ let S = {};
47
+ t != null && t.fields.idSubstitutionCriterias && (S = JSON.parse(
48
+ t == null ? void 0 : t.fields.idSubstitutionCriterias
46
49
  ));
47
- const F = o == null ? void 0 : o.productOriginId;
48
- p({
49
- itemId: `${g[F]}`
50
+ const x = r == null ? void 0 : r.productOriginId;
51
+ g({
52
+ itemId: `${S[x]}`
50
53
  });
51
54
  } finally {
52
- a(!1);
55
+ s(!1);
53
56
  }
54
57
  })();
55
58
  }, []), /* @__PURE__ */ n(
56
- M,
59
+ N,
57
60
  {
58
- isOpen: y,
59
- setIsOpen: f,
61
+ isOpen: O,
62
+ setIsOpen: p,
60
63
  className: "change-order-modal",
61
64
  title: "Produto com estoque baixo",
62
65
  Footer: /* @__PURE__ */ n(
63
- v,
66
+ A,
64
67
  {
65
68
  saveSelectedSimilarProduct: () => {
66
- L(
67
- e,
68
- o.productOriginId,
69
- r.itemId
70
- ), r && (d == null || d(r), C("salvar_substituto", {
71
- name: o.name,
72
- replacement_item: r == null ? void 0 : r.name
73
- })), f(!1);
69
+ T(
70
+ c,
71
+ a,
72
+ r.productOriginId,
73
+ o.itemId,
74
+ u
75
+ ), o && (m == null || m(o), F("salvar_substituto", {
76
+ name: r.name,
77
+ replacement_item: o == null ? void 0 : o.name
78
+ })), p(!1);
74
79
  }
75
80
  }
76
81
  ),
77
- children: P ? /* @__PURE__ */ n(
78
- T,
82
+ children: C ? /* @__PURE__ */ n(
83
+ $,
79
84
  {
80
- width: l ? "100%" : "90%",
81
- height: l ? 600 : 425,
85
+ width: a ? "100%" : "90%",
86
+ height: a ? 600 : 425,
82
87
  backgroundColor: "var(--color-grayScale-faded)",
83
88
  margin: "auto",
84
89
  animation: !0
85
90
  }
86
- ) : /* @__PURE__ */ j(q, { children: [
87
- o && /* @__PURE__ */ n(N, { selectedItem: o }),
88
- m && m.length > 0 ? /* @__PURE__ */ n(
89
- k,
91
+ ) : /* @__PURE__ */ q(w, { children: [
92
+ r && /* @__PURE__ */ n(k, { selectedItem: r }),
93
+ e && e.length > 0 ? /* @__PURE__ */ n(
94
+ v,
90
95
  {
91
- isClubClient: h,
92
- similarProductSelect: r,
93
- setSimilarProductSelect: p,
94
- products: m
96
+ isClubClient: y,
97
+ similarProductSelect: o,
98
+ setSimilarProductSelect: g,
99
+ products: e
95
100
  }
96
- ) : /* @__PURE__ */ n(_, {})
101
+ ) : /* @__PURE__ */ n(J, {})
97
102
  ] })
98
103
  }
99
104
  );
100
105
  };
101
106
  export {
102
- oo as ChangeOrderModal
107
+ or as ChangeOrderModal
103
108
  };
@@ -1 +1 @@
1
- export declare const getOrderForm: (orderFormId: string) => Promise<any>;
1
+ export declare const getOrderForm: (orderFormId: string, isIO: boolean, account: string) => Promise<any>;
@@ -1,14 +1,18 @@
1
- import t from "axios";
2
- const a = async (o) => {
1
+ import o from "axios";
2
+ const n = async (t, a, e) => {
3
3
  try {
4
- const { data: r } = await t.post(
5
- `/api/checkout/pub/orderForm/${o}`
6
- );
4
+ if (a) {
5
+ const { data: c } = await o.post(
6
+ `/api/checkout/pub/orderForm/${t}`
7
+ );
8
+ return c;
9
+ }
10
+ const { data: r } = await o.get(`https://${e}.myvtex.com/_v/faststoreapi/checkout/pub/orderForm/${t}`);
7
11
  return r;
8
12
  } catch (r) {
9
13
  console.error("Error in Change Order Modal", r);
10
14
  }
11
15
  };
12
16
  export {
13
- a as getOrderForm
17
+ n as getOrderForm
14
18
  };
@@ -2,9 +2,11 @@ import { SelectedItemProps } from '../components/ProductSelected';
2
2
 
3
3
  interface GetProductsSimilarsProps {
4
4
  postalCode: string;
5
+ isIO: boolean;
5
6
  selectedItem: SelectedItemProps;
7
+ account: string;
6
8
  }
7
- export declare const getProductsSimilars: ({ postalCode, selectedItem }: GetProductsSimilarsProps) => Promise<{
9
+ export declare const getProductsSimilars: ({ postalCode, isIO, selectedItem, account }: GetProductsSimilarsProps) => Promise<{
8
10
  productOrigin: string;
9
11
  products: import('../../../main').SimilarProducts[];
10
12
  } | undefined>;
@@ -1,19 +1,34 @@
1
- import s from "axios";
2
- const p = async ({
3
- postalCode: i,
4
- selectedItem: r
1
+ import n from "axios";
2
+ const f = async ({
3
+ postalCode: a,
4
+ isIO: p,
5
+ selectedItem: r,
6
+ account: s
5
7
  }) => {
6
8
  try {
7
- const { data: o } = await s.get(
8
- `/_v/commerce/products/productsSimilar?postalCode=${i}&skus=${r == null ? void 0 : r.productOriginId}&field=sku`
9
- ), { similarProducts: a } = o;
10
- return a.find(
11
- (n) => n.productOrigin === (r == null ? void 0 : r.productOriginId)
9
+ if (p) {
10
+ const { data: o } = await n.get(
11
+ `/_v/commerce/products/productsSimilar?postalCode=${a}&skus=${r == null ? void 0 : r.productOriginId}&field=sku`
12
+ ), { similarProducts: c } = o;
13
+ return c.find(
14
+ (t) => t.productOrigin === (r == null ? void 0 : r.productOriginId)
15
+ );
16
+ }
17
+ const { data: i } = await n.post("/api/proxy", {
18
+ targetUrl: `https://${s}.myvtex.com/_v/commerce/products/productsSimilar?postalCode=${a}&skus=${r == null ? void 0 : r.productOriginId}&field=sku`,
19
+ method: "GET",
20
+ headers: {
21
+ "Content-Type": "application/json",
22
+ Accept: "application/json"
23
+ }
24
+ }), { similarProducts: u } = i;
25
+ return u.find(
26
+ (o) => o.productOrigin === r.productOriginId
12
27
  );
13
- } catch (o) {
14
- console.error("Error in Change Order Modal", o);
28
+ } catch (i) {
29
+ console.error("Error in Change Order Modal", i);
15
30
  }
16
31
  };
17
32
  export {
18
- p as getProductsSimilars
33
+ f as getProductsSimilars
19
34
  };
@@ -1 +1 @@
1
- export declare const postChangeOrder: (orderFormId: string, skuId: string, substitutionId: string) => Promise<any>;
1
+ export declare const postChangeOrder: (orderFormId: string, isIO: boolean, skuId: string, substitutionId: string, account: string) => Promise<any>;
@@ -1,19 +1,32 @@
1
- import c from "axios";
2
- const s = async (o, e, t) => {
1
+ import o from "axios";
2
+ const i = async (t, e, a, c, n) => {
3
3
  try {
4
4
  const r = {
5
- orderFormId: o,
6
- skuId: e,
7
- substitutionId: t
8
- }, { data: a } = await c.post(
9
- "/_v/commerce/orderform/changeOrder",
10
- r
11
- );
12
- return a;
5
+ orderFormId: t,
6
+ skuId: a,
7
+ substitutionId: c
8
+ };
9
+ if (e) {
10
+ const { data: s } = await o.post(
11
+ "/_v/commerce/orderform/changeOrder",
12
+ r
13
+ );
14
+ return s;
15
+ }
16
+ const { data: p } = await o.post("/api/proxy", {
17
+ targetUrl: `https://${n}.myvtex.com/_v/commerce/orderform/changeOrder`,
18
+ method: "POST",
19
+ headers: {
20
+ "Content-Type": "application/json",
21
+ Accept: "application/json"
22
+ },
23
+ body: r
24
+ });
25
+ return p;
13
26
  } catch (r) {
14
27
  console.error("Error in Change Order Modal", r);
15
28
  }
16
29
  };
17
30
  export {
18
- s as postChangeOrder
31
+ i as postChangeOrder
19
32
  };
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@plurix/ecom-components",
3
3
  "author": "Plurix",
4
4
  "private": false,
5
- "version": "1.14.2-commerce.6",
5
+ "version": "1.14.2-commerce.7",
6
6
  "type": "module",
7
7
  "main": "dist/main.js",
8
8
  "types": "dist/main.d.ts",