@agrada_digital/pbm 0.0.57 → 0.0.62
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.
- package/dist/index.d.mts +6 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.js +181 -84
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +181 -84
- package/dist/index.mjs.map +1 -1
- package/dist-wc/pbm-wc.js +106 -101
- package/package.json +12 -12
package/dist/index.d.mts
CHANGED
|
@@ -21,6 +21,7 @@ interface usePBMTypes {
|
|
|
21
21
|
};
|
|
22
22
|
campaign: "pbm_campaign";
|
|
23
23
|
targetProduct: IProduct | null;
|
|
24
|
+
urlAcceptTerms?: string;
|
|
24
25
|
}
|
|
25
26
|
interface IProduct {
|
|
26
27
|
ean: string;
|
|
@@ -31,10 +32,13 @@ interface IProduct {
|
|
|
31
32
|
listPrice?: number;
|
|
32
33
|
stockBalance?: number;
|
|
33
34
|
productName?: string;
|
|
34
|
-
productId?:
|
|
35
|
+
productId?: number;
|
|
35
36
|
availabilityText?: string;
|
|
36
37
|
brandName?: string;
|
|
37
38
|
categoryName?: string;
|
|
39
|
+
netPrice?: number;
|
|
40
|
+
informativeMessage?: string;
|
|
41
|
+
discountMax?: number;
|
|
38
42
|
}
|
|
39
43
|
|
|
40
44
|
interface PBMStore extends usePBMTypes {
|
|
@@ -42,6 +46,7 @@ interface PBMStore extends usePBMTypes {
|
|
|
42
46
|
setState: (state: usePBMTypes["state"]) => void;
|
|
43
47
|
setAvailableDiscountSelected: (availableDiscount: usePBMTypes["availableDiscountSelected"]) => void;
|
|
44
48
|
setTargetProduct: (targetProduct: usePBMTypes["targetProduct"]) => void;
|
|
49
|
+
setUrlAcceptTerms: (urlAcceptTerms: usePBMTypes["urlAcceptTerms"]) => void;
|
|
45
50
|
}
|
|
46
51
|
declare function usePBMStore(): PBMStore;
|
|
47
52
|
declare function usePBMStore<T>(selector: (state: PBMStore) => T): T;
|
package/dist/index.d.ts
CHANGED
|
@@ -21,6 +21,7 @@ interface usePBMTypes {
|
|
|
21
21
|
};
|
|
22
22
|
campaign: "pbm_campaign";
|
|
23
23
|
targetProduct: IProduct | null;
|
|
24
|
+
urlAcceptTerms?: string;
|
|
24
25
|
}
|
|
25
26
|
interface IProduct {
|
|
26
27
|
ean: string;
|
|
@@ -31,10 +32,13 @@ interface IProduct {
|
|
|
31
32
|
listPrice?: number;
|
|
32
33
|
stockBalance?: number;
|
|
33
34
|
productName?: string;
|
|
34
|
-
productId?:
|
|
35
|
+
productId?: number;
|
|
35
36
|
availabilityText?: string;
|
|
36
37
|
brandName?: string;
|
|
37
38
|
categoryName?: string;
|
|
39
|
+
netPrice?: number;
|
|
40
|
+
informativeMessage?: string;
|
|
41
|
+
discountMax?: number;
|
|
38
42
|
}
|
|
39
43
|
|
|
40
44
|
interface PBMStore extends usePBMTypes {
|
|
@@ -42,6 +46,7 @@ interface PBMStore extends usePBMTypes {
|
|
|
42
46
|
setState: (state: usePBMTypes["state"]) => void;
|
|
43
47
|
setAvailableDiscountSelected: (availableDiscount: usePBMTypes["availableDiscountSelected"]) => void;
|
|
44
48
|
setTargetProduct: (targetProduct: usePBMTypes["targetProduct"]) => void;
|
|
49
|
+
setUrlAcceptTerms: (urlAcceptTerms: usePBMTypes["urlAcceptTerms"]) => void;
|
|
45
50
|
}
|
|
46
51
|
declare function usePBMStore(): PBMStore;
|
|
47
52
|
declare function usePBMStore<T>(selector: (state: PBMStore) => T): T;
|
package/dist/index.js
CHANGED
|
@@ -35,30 +35,87 @@ __export(index_exports, {
|
|
|
35
35
|
});
|
|
36
36
|
module.exports = __toCommonJS(index_exports);
|
|
37
37
|
|
|
38
|
+
// src/libs/zustand/usePBM.tsx
|
|
39
|
+
var import_zustand = require("zustand");
|
|
40
|
+
var import_react = require("zustand/react");
|
|
41
|
+
var initialPBMState = {
|
|
42
|
+
securityNumber: "",
|
|
43
|
+
state: "isEmpty",
|
|
44
|
+
availableDiscountSelected: {
|
|
45
|
+
quantity: 0,
|
|
46
|
+
discount: {
|
|
47
|
+
unit: 0,
|
|
48
|
+
total: 0
|
|
49
|
+
},
|
|
50
|
+
totalPrice: 0
|
|
51
|
+
},
|
|
52
|
+
targetProduct: null,
|
|
53
|
+
campaign: "pbm_campaign"
|
|
54
|
+
};
|
|
55
|
+
var createPBMStore = (set) => ({
|
|
56
|
+
...initialPBMState,
|
|
57
|
+
setSecurityNumber: (securityNumber) => set({ securityNumber }),
|
|
58
|
+
setState: (state) => set({ state }),
|
|
59
|
+
setTargetProduct: (targetProduct) => set({ targetProduct }),
|
|
60
|
+
setAvailableDiscountSelected: (availableDiscount) => set({ availableDiscountSelected: availableDiscount }),
|
|
61
|
+
setUrlAcceptTerms: (urlAcceptTerms) => set({ urlAcceptTerms })
|
|
62
|
+
});
|
|
63
|
+
var pbmStore = (0, import_zustand.createStore)(createPBMStore);
|
|
64
|
+
function usePBMStore(selector) {
|
|
65
|
+
if (selector) {
|
|
66
|
+
return (0, import_react.useStore)(pbmStore, selector);
|
|
67
|
+
}
|
|
68
|
+
return (0, import_react.useStore)(pbmStore, (state) => state);
|
|
69
|
+
}
|
|
70
|
+
|
|
38
71
|
// src/components/Header/index.tsx
|
|
39
72
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
40
73
|
function Header({ originalProductPrice }) {
|
|
74
|
+
const { targetProduct } = usePBMStore();
|
|
75
|
+
const Price = targetProduct?.listPrice || originalProductPrice;
|
|
76
|
+
const Discount = Price * ((targetProduct?.discountMax || 0) / 100);
|
|
41
77
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
42
78
|
"header",
|
|
43
79
|
{
|
|
44
|
-
className: "flex items-center justify-between w-full p-0.5 rounded-full bg-[#44c2c0]/30",
|
|
80
|
+
className: "flex items-center justify-between w-full p-0.5 rounded-full bg-[#44c2c0]/30 mt-5",
|
|
45
81
|
id: "header_pbm",
|
|
46
82
|
children: [
|
|
47
|
-
/* @__PURE__ */ (0, import_jsx_runtime.
|
|
83
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
48
84
|
"span",
|
|
49
85
|
{
|
|
50
|
-
className: "py-1 px-6 rounded-full bg-[#44c2c0] shrink-0 text-white text-
|
|
86
|
+
className: "py-1 px-6 rounded-full bg-[#44c2c0] shrink-0 text-white text-xl font-bold flex items-center justify-start gap-2 relative",
|
|
51
87
|
"data-testid": "test_id_header_price",
|
|
52
88
|
id: "header_price",
|
|
53
|
-
children:
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
89
|
+
children: [
|
|
90
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { className: "absolute -top-6 left-10 bg-emerald-500 px-4 py-1 rounded-t-2xl text-xs font-medium text-white", children: [
|
|
91
|
+
Discount.toLocaleString("pt-BR", {
|
|
92
|
+
currency: "BRL",
|
|
93
|
+
currencyDisplay: "symbol",
|
|
94
|
+
currencySign: "standard",
|
|
95
|
+
style: "currency"
|
|
96
|
+
}),
|
|
97
|
+
" OFF"
|
|
98
|
+
] }),
|
|
99
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("svg", { width: "32px", height: "32px", viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: [
|
|
100
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("g", { id: "SVGRepo_bgCarrier", strokeWidth: "0" }),
|
|
101
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("g", { id: "SVGRepo_tracerCarrier", strokeLinecap: "round", strokeLinejoin: "round" }),
|
|
102
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("g", { id: "SVGRepo_iconCarrier", children: [
|
|
103
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M10 8.99998C10.5523 8.99998 11 9.44769 11 9.99998C11 10.5523 10.5523 11 10 11C9.44775 11 9.00004 10.5523 9.00004 9.99998C9.00004 9.44769 9.44775 8.99998 10 8.99998Z", fill: "#fff" }),
|
|
104
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M13 14C13 14.5523 13.4478 15 14 15C14.5523 15 15 14.5523 15 14C15 13.4477 14.5523 13 14 13C13.4478 13 13 13.4477 13 14Z", fill: "#fff" }),
|
|
105
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M10.7071 14.7071L14.7071 10.7071C15.0977 10.3166 15.0977 9.6834 14.7071 9.29287C14.3166 8.90235 13.6835 8.90235 13.2929 9.29287L9.29293 13.2929C8.90241 13.6834 8.90241 14.3166 9.29293 14.7071C9.68346 15.0976 10.3166 15.0976 10.7071 14.7071Z", fill: "#fff" }),
|
|
106
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { fillRule: "evenodd", clipRule: "evenodd", d: "M16.3117 4.07145L15.1708 4.34503L14.5575 3.34485C13.3869 1.43575 10.6131 1.43575 9.44254 3.34485L8.82926 4.34503L7.68836 4.07145C5.51069 3.54925 3.54931 5.51063 4.07151 7.6883L4.34509 8.8292L3.34491 9.44248C1.43581 10.6131 1.43581 13.3869 3.34491 14.5575L4.34509 15.1708L4.07151 16.3117C3.54931 18.4893 5.51069 20.4507 7.68836 19.9285L8.82926 19.6549L9.44254 20.6551C10.6131 22.5642 13.3869 22.5642 14.5575 20.6551L15.1708 19.6549L16.3117 19.9285C18.4894 20.4507 20.4508 18.4893 19.9286 16.3117L19.655 15.1708L20.6552 14.5575C22.5643 13.3869 22.5643 10.6131 20.6552 9.44248L19.655 8.8292L19.9286 7.6883C20.4508 5.51063 18.4894 3.54925 16.3117 4.07145ZM11.1475 4.3903C11.5377 3.75393 12.4623 3.75393 12.8525 4.3903L13.8454 6.00951C14.0717 6.37867 14.51 6.56019 14.9311 6.45922L16.7781 6.01631C17.504 5.84225 18.1578 6.49604 17.9837 7.22193L17.5408 9.06894C17.4398 9.49003 17.6213 9.92827 17.9905 10.1546L19.6097 11.1475C20.2461 11.5377 20.2461 12.4623 19.6097 12.8525L17.9905 13.8453C17.6213 14.0717 17.4398 14.5099 17.5408 14.931L17.9837 16.778C18.1578 17.5039 17.504 18.1577 16.7781 17.9836L14.9311 17.5407C14.51 17.4398 14.0717 17.6213 13.8454 17.9904L12.8525 19.6097C12.4623 20.246 11.5377 20.246 11.1475 19.6097L10.1547 17.9904C9.92833 17.6213 9.49009 17.4398 9.069 17.5407L7.22199 17.9836C6.4961 18.1577 5.84231 17.5039 6.01637 16.778L6.45928 14.931C6.56026 14.5099 6.37873 14.0717 6.00957 13.8453L4.39036 12.8525C3.75399 12.4623 3.75399 11.5377 4.39036 11.1475L6.00957 10.1546C6.37873 9.92827 6.56026 9.49003 6.45928 9.06894L6.01637 7.22193C5.84231 6.49604 6.4961 5.84225 7.22199 6.01631L9.069 6.45922C9.49009 6.56019 9.92833 6.37867 10.1547 6.00951L11.1475 4.3903Z", fill: "#fff" })
|
|
107
|
+
] })
|
|
108
|
+
] }),
|
|
109
|
+
Number(Price - Discount)?.toLocaleString("pt-BR", {
|
|
110
|
+
currency: "BRL",
|
|
111
|
+
currencyDisplay: "symbol",
|
|
112
|
+
currencySign: "standard",
|
|
113
|
+
style: "currency"
|
|
114
|
+
})
|
|
115
|
+
]
|
|
59
116
|
}
|
|
60
117
|
),
|
|
61
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("h1", { id: "header_title", className: "text-center w-full text-[#339c9b] font-bold text-xs px-4 md:text-sm", children: "
|
|
118
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("h1", { id: "header_title", className: "text-center w-full text-[#339c9b] font-bold text-xs px-4 md:text-sm", children: "Desconto de Laborat\xF3rio" })
|
|
62
119
|
]
|
|
63
120
|
}
|
|
64
121
|
);
|
|
@@ -76,7 +133,7 @@ function Container({
|
|
|
76
133
|
"main",
|
|
77
134
|
{
|
|
78
135
|
className: (0, import_classnames.default)({
|
|
79
|
-
"flex flex-col items-center justify-center min-w-[var(--min-container)] max-w-[var(--max-container)] w-full h-auto rounded-2xl p-4 bg-gray-100 gap-4": variant === "main",
|
|
136
|
+
"border-3 border-[#44c2c0] flex flex-col items-center justify-center min-w-[var(--min-container)] max-w-[var(--max-container)] w-full h-auto rounded-2xl p-4 bg-gray-100 gap-4 relative": variant === "main",
|
|
80
137
|
"w-full h-auto relative": variant === "simple"
|
|
81
138
|
}),
|
|
82
139
|
"data-testid": "test_id_container",
|
|
@@ -92,38 +149,6 @@ var Container_default = Container;
|
|
|
92
149
|
var import_classnames2 = __toESM(require("classnames"));
|
|
93
150
|
var import_react2 = require("react");
|
|
94
151
|
|
|
95
|
-
// src/libs/zustand/usePBM.tsx
|
|
96
|
-
var import_zustand = require("zustand");
|
|
97
|
-
var import_react = require("zustand/react");
|
|
98
|
-
var initialPBMState = {
|
|
99
|
-
securityNumber: "",
|
|
100
|
-
state: "isEmpty",
|
|
101
|
-
availableDiscountSelected: {
|
|
102
|
-
quantity: 0,
|
|
103
|
-
discount: {
|
|
104
|
-
unit: 0,
|
|
105
|
-
total: 0
|
|
106
|
-
},
|
|
107
|
-
totalPrice: 0
|
|
108
|
-
},
|
|
109
|
-
targetProduct: null,
|
|
110
|
-
campaign: "pbm_campaign"
|
|
111
|
-
};
|
|
112
|
-
var createPBMStore = (set) => ({
|
|
113
|
-
...initialPBMState,
|
|
114
|
-
setSecurityNumber: (securityNumber) => set({ securityNumber }),
|
|
115
|
-
setState: (state) => set({ state }),
|
|
116
|
-
setTargetProduct: (targetProduct) => set({ targetProduct }),
|
|
117
|
-
setAvailableDiscountSelected: (availableDiscount) => set({ availableDiscountSelected: availableDiscount })
|
|
118
|
-
});
|
|
119
|
-
var pbmStore = (0, import_zustand.createStore)(createPBMStore);
|
|
120
|
-
function usePBMStore(selector) {
|
|
121
|
-
if (selector) {
|
|
122
|
-
return (0, import_react.useStore)(pbmStore, selector);
|
|
123
|
-
}
|
|
124
|
-
return (0, import_react.useStore)(pbmStore, (state) => state);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
152
|
// src/services/get-product-by-ean.ts
|
|
128
153
|
var import_js_cookie = __toESM(require("js-cookie"));
|
|
129
154
|
var import_meta = {};
|
|
@@ -151,7 +176,7 @@ var GetProductByEAN = async ({ PRODUCT_EAN }) => {
|
|
|
151
176
|
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
152
177
|
function Footer() {
|
|
153
178
|
const [industryLogo, setIndustryLogo] = (0, import_react2.useState)(null);
|
|
154
|
-
const { targetProduct, setTargetProduct } = usePBMStore();
|
|
179
|
+
const { targetProduct, setTargetProduct, state } = usePBMStore();
|
|
155
180
|
(0, import_react2.useEffect)(() => {
|
|
156
181
|
const fetchProductByEan = async () => {
|
|
157
182
|
if (!targetProduct?.ean) return;
|
|
@@ -162,7 +187,10 @@ function Footer() {
|
|
|
162
187
|
const { pbm, sku, ...targetProductNewData } = response.data;
|
|
163
188
|
setTargetProduct({
|
|
164
189
|
...targetProduct,
|
|
165
|
-
...targetProductNewData
|
|
190
|
+
...targetProductNewData,
|
|
191
|
+
productId: Number(targetProductNewData.productId),
|
|
192
|
+
informativeMessage: pbm.informativeMessage ?? "",
|
|
193
|
+
discountMax: pbm.discountMax ?? 0
|
|
166
194
|
});
|
|
167
195
|
}
|
|
168
196
|
} catch (error) {
|
|
@@ -171,23 +199,26 @@ function Footer() {
|
|
|
171
199
|
};
|
|
172
200
|
fetchProductByEan();
|
|
173
201
|
}, [targetProduct?.ean]);
|
|
174
|
-
return /* @__PURE__ */ (0, import_jsx_runtime3.
|
|
175
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("section", { className: "w-
|
|
176
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.
|
|
177
|
-
|
|
202
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("footer", { className: "w-full h-auto relative", id: "footer_pbm", children: [
|
|
203
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("section", { className: (0, import_classnames2.default)("flex items-center w-full h-auto gap-4", { "justify-center": industryLogo, "justify-start": !industryLogo }), children: [
|
|
204
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("section", { className: "w-4/5 h-auto", children: [
|
|
205
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("h3", { className: "text-start font-semibold text-sm", children: "Economize com o benef\xEDcio do laborat\xF3rio." }),
|
|
206
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: "text-start font-normal text-sm", children: "Este produto tem pre\xE7o exclusivo para clientes cadastrados no programa." })
|
|
207
|
+
] }),
|
|
208
|
+
industryLogo && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
209
|
+
"img",
|
|
210
|
+
{
|
|
211
|
+
src: industryLogo,
|
|
212
|
+
alt: "parceiro",
|
|
213
|
+
className: "w-1/5 min-w-20 h-auto aspect-auto rounded-xl",
|
|
214
|
+
loading: "eager",
|
|
215
|
+
id: "footer_industry_logo_pbm",
|
|
216
|
+
"data-testid": "footer_industry_logo_pbm"
|
|
217
|
+
}
|
|
218
|
+
)
|
|
178
219
|
] }),
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
{
|
|
182
|
-
src: industryLogo,
|
|
183
|
-
alt: "parceiro",
|
|
184
|
-
className: "w-1/5 min-w-20 h-auto aspect-auto",
|
|
185
|
-
loading: "eager",
|
|
186
|
-
id: "footer_industry_logo_pbm",
|
|
187
|
-
"data-testid": "footer_industry_logo_pbm"
|
|
188
|
-
}
|
|
189
|
-
)
|
|
190
|
-
] }) });
|
|
220
|
+
state !== "isActivated" && targetProduct?.informativeMessage && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: "text-start font-semibold text-sm", children: targetProduct?.informativeMessage })
|
|
221
|
+
] });
|
|
191
222
|
}
|
|
192
223
|
var Footer_default = Footer;
|
|
193
224
|
|
|
@@ -221,10 +252,10 @@ var import_react_hook_form = require("react-hook-form");
|
|
|
221
252
|
var import_lucide_react = require("lucide-react");
|
|
222
253
|
var import_react3 = require("react");
|
|
223
254
|
|
|
224
|
-
// src/services/
|
|
255
|
+
// src/services/benefits-with-document.ts
|
|
225
256
|
var import_js_cookie2 = __toESM(require("js-cookie"));
|
|
226
257
|
var import_meta2 = {};
|
|
227
|
-
var
|
|
258
|
+
var BenefitsWithDocument = async ({ document: document2, products }) => {
|
|
228
259
|
const API_URL = import_meta2.env.VITE_API_URL;
|
|
229
260
|
if (!API_URL) {
|
|
230
261
|
throw new Error("API URL is not defined in environment variables");
|
|
@@ -233,13 +264,13 @@ var ValidateDocument = async ({ document, products }) => {
|
|
|
233
264
|
if (!AUTH_TOKEN) {
|
|
234
265
|
throw new Error("Token is not defined in cookies or is expired");
|
|
235
266
|
}
|
|
236
|
-
const response = await fetch(`${API_URL}/
|
|
267
|
+
const response = await fetch(`${API_URL}/products/benefitByDocument`, {
|
|
237
268
|
method: "POST",
|
|
238
269
|
headers: {
|
|
239
270
|
Authorization: `Bearer ${AUTH_TOKEN}`,
|
|
240
271
|
"Content-Type": "application/json"
|
|
241
272
|
},
|
|
242
|
-
body: JSON.stringify({ document, products })
|
|
273
|
+
body: JSON.stringify({ consumer: { document: document2 }, products })
|
|
243
274
|
});
|
|
244
275
|
const dataResponse = await response.json();
|
|
245
276
|
if (!dataResponse.success) {
|
|
@@ -257,7 +288,7 @@ function Button(props) {
|
|
|
257
288
|
{
|
|
258
289
|
...props,
|
|
259
290
|
className: (0, import_classnames3.default)(
|
|
260
|
-
"w-3xs cursor-pointer h-10 rounded-full bg-
|
|
291
|
+
"w-3xs cursor-pointer h-10 rounded-full bg-emerald-500 hover:bg-emerald-400 text-white text-sm font-semibold transition-colors",
|
|
261
292
|
props.className
|
|
262
293
|
),
|
|
263
294
|
children: props.children
|
|
@@ -269,7 +300,7 @@ var Button_default = Button;
|
|
|
269
300
|
// src/components/Form/index.tsx
|
|
270
301
|
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
271
302
|
function Form({ setLoading }) {
|
|
272
|
-
const { setSecurityNumber, setState, securityNumber, targetProduct } = usePBMStore();
|
|
303
|
+
const { setSecurityNumber, setState, securityNumber, targetProduct, setUrlAcceptTerms } = usePBMStore();
|
|
273
304
|
const [showCoupoField, setShowCoupoField] = (0, import_react3.useState)(false);
|
|
274
305
|
const {
|
|
275
306
|
handleSubmit,
|
|
@@ -296,17 +327,33 @@ function Form({ setLoading }) {
|
|
|
296
327
|
console.error("PBMLOG: Product is not defined!");
|
|
297
328
|
return;
|
|
298
329
|
}
|
|
299
|
-
|
|
330
|
+
if (!targetProduct.productId) {
|
|
331
|
+
console.error("PBMLOG: Product ID is not defined!");
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
334
|
+
if (!targetProduct.listPrice) {
|
|
335
|
+
console.error("PBMLOG: List Price is not defined!");
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
const response = await BenefitsWithDocument({
|
|
300
339
|
document: values.securityNumber.replace(/\D/g, ""),
|
|
301
|
-
products: [{
|
|
340
|
+
products: [{
|
|
341
|
+
productId: targetProduct.productId,
|
|
342
|
+
ean: targetProduct.ean,
|
|
343
|
+
requestedQuantity: 1,
|
|
344
|
+
listPrice: targetProduct.listPrice,
|
|
345
|
+
netPrice: targetProduct.netPrice ?? targetProduct.listPrice
|
|
346
|
+
}]
|
|
302
347
|
});
|
|
303
348
|
if (response.success) {
|
|
304
349
|
const status = {
|
|
305
|
-
"
|
|
306
|
-
"
|
|
350
|
+
"acceptance": "isInvalid",
|
|
351
|
+
"industry registration": "isRegistered",
|
|
352
|
+
"active": "isActivated"
|
|
307
353
|
};
|
|
308
354
|
setSecurityNumber(values.securityNumber);
|
|
309
|
-
setState(status[response.data.
|
|
355
|
+
setState(status[response.data.product[0].statusCustumer]);
|
|
356
|
+
setUrlAcceptTerms(response.data.product[0].urlAcceptTerm || void 0);
|
|
310
357
|
}
|
|
311
358
|
} catch (error) {
|
|
312
359
|
console.error("PBMLOG: Error validating document -", error);
|
|
@@ -338,7 +385,7 @@ function Form({ setLoading }) {
|
|
|
338
385
|
{
|
|
339
386
|
type: "text",
|
|
340
387
|
className: (0, import_classnames4.default)(
|
|
341
|
-
"w-full h-8 bg-
|
|
388
|
+
"w-full h-8 bg-white rounded-s-full text-sm font-semibold focus:outline focus:outline-[#339c9b] focus:bg-white text-zinc-600 placeholder:text-zinc-600 px-4 placeholder:text-sm placeholder:font-semibold",
|
|
342
389
|
{ "outline outline-red-600": errors.securityNumber, "rounded-full": showCoupoField }
|
|
343
390
|
),
|
|
344
391
|
placeholder: "Digite seu CPF aqui...",
|
|
@@ -397,7 +444,7 @@ function Form({ setLoading }) {
|
|
|
397
444
|
{
|
|
398
445
|
type: "submit",
|
|
399
446
|
className: (0, import_classnames4.default)(
|
|
400
|
-
"bg-
|
|
447
|
+
"bg-emerald-500 w-1/5 h-8 flex items-center justify-center rounded-e-full cursor-pointer",
|
|
401
448
|
{ "rounded-full": showCoupoField }
|
|
402
449
|
),
|
|
403
450
|
id: "button_submit_security_number_pbm",
|
|
@@ -739,8 +786,38 @@ var Text_default = Text;
|
|
|
739
786
|
// src/components/Iframe/index.tsx
|
|
740
787
|
var import_classnames7 = __toESM(require("classnames"));
|
|
741
788
|
var import_lucide_react3 = require("lucide-react");
|
|
789
|
+
var import_react6 = require("react");
|
|
742
790
|
var import_jsx_runtime11 = require("react/jsx-runtime");
|
|
743
791
|
function Iframe({ url, title, openModal, setOpenModal }) {
|
|
792
|
+
const [_, setIframeError] = (0, import_react6.useState)(false);
|
|
793
|
+
const [showFallback, setShowFallback] = (0, import_react6.useState)(false);
|
|
794
|
+
(0, import_react6.useEffect)(() => {
|
|
795
|
+
if (openModal && url) {
|
|
796
|
+
setIframeError(false);
|
|
797
|
+
setShowFallback(false);
|
|
798
|
+
const timeout = setTimeout(() => {
|
|
799
|
+
const iframe = document.querySelector('iframe[src="' + url + '"]');
|
|
800
|
+
if (iframe) {
|
|
801
|
+
try {
|
|
802
|
+
const iframeDoc = iframe.contentDocument || iframe.contentWindow?.document;
|
|
803
|
+
if (!iframeDoc) {
|
|
804
|
+
setIframeError(true);
|
|
805
|
+
setShowFallback(true);
|
|
806
|
+
}
|
|
807
|
+
} catch (e) {
|
|
808
|
+
setIframeError(true);
|
|
809
|
+
setShowFallback(true);
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
}, 2e3);
|
|
813
|
+
return () => clearTimeout(timeout);
|
|
814
|
+
}
|
|
815
|
+
}, [openModal, url]);
|
|
816
|
+
const handleOpenInNewWindow = () => {
|
|
817
|
+
if (url) {
|
|
818
|
+
window.open(url, "_blank", "noopener,noreferrer");
|
|
819
|
+
}
|
|
820
|
+
};
|
|
744
821
|
return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(
|
|
745
822
|
"main",
|
|
746
823
|
{
|
|
@@ -777,7 +854,22 @@ function Iframe({ url, title, openModal, setOpenModal }) {
|
|
|
777
854
|
children: "Fechar"
|
|
778
855
|
}
|
|
779
856
|
) }),
|
|
780
|
-
/* @__PURE__ */ (0, import_jsx_runtime11.
|
|
857
|
+
showFallback ? /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: "w-4/5 h-[80%] bg-zinc-800 z-10 flex flex-col items-center justify-center p-8 rounded-lg border-2 border-yellow-500", children: [
|
|
858
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_lucide_react3.TriangleAlert, { size: 48, className: "text-yellow-500 mb-4" }),
|
|
859
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)("h3", { className: "text-white text-xl font-bold mb-4 text-center", children: "N\xE3o foi poss\xEDvel carregar o conte\xFAdo" }),
|
|
860
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)("p", { className: "text-white text-sm mb-6 text-center max-w-md", children: "O servidor bloqueou a exibi\xE7\xE3o deste conte\xFAdo em um iframe devido \xE0s pol\xEDticas de seguran\xE7a. Voc\xEA pode abrir o link em uma nova janela para continuar." }),
|
|
861
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(
|
|
862
|
+
"button",
|
|
863
|
+
{
|
|
864
|
+
onClick: handleOpenInNewWindow,
|
|
865
|
+
className: "flex items-center gap-2 bg-emerald-500 hover:bg-emerald-600 text-white font-semibold px-6 py-3 rounded-lg transition-colors",
|
|
866
|
+
children: [
|
|
867
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_lucide_react3.ExternalLink, { size: 20 }),
|
|
868
|
+
"Abrir em nova janela"
|
|
869
|
+
]
|
|
870
|
+
}
|
|
871
|
+
)
|
|
872
|
+
] }) : /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
|
|
781
873
|
"iframe",
|
|
782
874
|
{
|
|
783
875
|
src: url,
|
|
@@ -785,7 +877,11 @@ function Iframe({ url, title, openModal, setOpenModal }) {
|
|
|
785
877
|
width: "80%",
|
|
786
878
|
height: "80%",
|
|
787
879
|
allowFullScreen: true,
|
|
788
|
-
className: "z-10"
|
|
880
|
+
className: "z-10",
|
|
881
|
+
onError: () => {
|
|
882
|
+
setIframeError(true);
|
|
883
|
+
setShowFallback(true);
|
|
884
|
+
}
|
|
789
885
|
}
|
|
790
886
|
),
|
|
791
887
|
/* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("section", { className: "items-center justify-center flex flex-wrap gap-1 bg-zinc-800 z-10 w-4/5 py-2 px-4 rounded-ee-2xl rounded-es-2xl border-t-2 border-gray-100", children: [
|
|
@@ -804,10 +900,11 @@ function Iframe({ url, title, openModal, setOpenModal }) {
|
|
|
804
900
|
var Iframe_default = Iframe;
|
|
805
901
|
|
|
806
902
|
// src/components/SecurityNumberInvalid/index.tsx
|
|
807
|
-
var
|
|
903
|
+
var import_react7 = require("react");
|
|
808
904
|
var import_jsx_runtime12 = require("react/jsx-runtime");
|
|
809
905
|
function SecurityNumberInvalid({ textColor }) {
|
|
810
|
-
const [openModal, setOpenModal] = (0,
|
|
906
|
+
const [openModal, setOpenModal] = (0, import_react7.useState)(false);
|
|
907
|
+
const { urlAcceptTerms } = usePBMStore();
|
|
811
908
|
return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(
|
|
812
909
|
"section",
|
|
813
910
|
{
|
|
@@ -829,7 +926,7 @@ function SecurityNumberInvalid({ textColor }) {
|
|
|
829
926
|
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
|
|
830
927
|
Iframe_default,
|
|
831
928
|
{
|
|
832
|
-
url: "
|
|
929
|
+
url: urlAcceptTerms || "",
|
|
833
930
|
title: "Aceitar termos PBM",
|
|
834
931
|
openModal,
|
|
835
932
|
setOpenModal
|
|
@@ -842,7 +939,7 @@ function SecurityNumberInvalid({ textColor }) {
|
|
|
842
939
|
var SecurityNumberInvalid_default = SecurityNumberInvalid;
|
|
843
940
|
|
|
844
941
|
// src/PBM.tsx
|
|
845
|
-
var
|
|
942
|
+
var import_react8 = require("react");
|
|
846
943
|
|
|
847
944
|
// src/components/UI/Link/index.tsx
|
|
848
945
|
var import_classnames8 = __toESM(require("classnames"));
|
|
@@ -954,14 +1051,14 @@ function PBM({
|
|
|
954
1051
|
const formatedOriginalProductPrice = Number(
|
|
955
1052
|
String(originalProductPrice).replace(",", ".")
|
|
956
1053
|
);
|
|
957
|
-
const [loading, setLoading] = (0,
|
|
1054
|
+
const [loading, setLoading] = (0, import_react8.useState)(false);
|
|
958
1055
|
const { setState, state, setTargetProduct } = usePBMStore();
|
|
959
|
-
(0,
|
|
1056
|
+
(0, import_react8.useEffect)(() => {
|
|
960
1057
|
if (eanProduct) {
|
|
961
1058
|
setTargetProduct({ ean: eanProduct });
|
|
962
1059
|
}
|
|
963
1060
|
}, [eanProduct, setTargetProduct]);
|
|
964
|
-
const handleAuthorizationRequest = (0,
|
|
1061
|
+
const handleAuthorizationRequest = (0, import_react8.useCallback)(async () => {
|
|
965
1062
|
try {
|
|
966
1063
|
const response = await GetAuthorization({ clientID });
|
|
967
1064
|
if (!response.success) {
|
|
@@ -971,7 +1068,7 @@ function PBM({
|
|
|
971
1068
|
console.error("Error fetching authorization:", error);
|
|
972
1069
|
}
|
|
973
1070
|
}, [clientID]);
|
|
974
|
-
(0,
|
|
1071
|
+
(0, import_react8.useEffect)(() => {
|
|
975
1072
|
handleAuthorizationRequest();
|
|
976
1073
|
}, [handleAuthorizationRequest]);
|
|
977
1074
|
return /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(Container_default, { variant: "main", children: [
|