@agrada_digital/pbm 0.0.68 → 0.0.70
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 +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +107 -105
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +96 -94
- package/dist/index.mjs.map +1 -1
- package/dist-wc/pbm-wc.js +77 -77
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -42,17 +42,17 @@ function Header({ originalProductPrice }) {
|
|
|
42
42
|
return /* @__PURE__ */ jsxs(
|
|
43
43
|
"header",
|
|
44
44
|
{
|
|
45
|
-
className: "flex items-center justify-between w-full p-0.5 rounded-
|
|
45
|
+
className: "flex items-center justify-between w-full p-0.5 rounded-xl bg-[#44c2c0]/30 mt-5",
|
|
46
46
|
id: "header_pbm",
|
|
47
47
|
children: [
|
|
48
48
|
/* @__PURE__ */ jsxs(
|
|
49
49
|
"span",
|
|
50
50
|
{
|
|
51
|
-
className: "py-1 px-6 rounded-
|
|
51
|
+
className: "py-1 px-6 rounded-xl bg-[#44c2c0] shrink-0 text-white text-xl font-bold flex items-center justify-start gap-2 relative",
|
|
52
52
|
"data-testid": "test_id_header_price",
|
|
53
53
|
id: "header_price",
|
|
54
54
|
children: [
|
|
55
|
-
/* @__PURE__ */ jsxs("span", { className: "absolute -top-6 left-10 bg-emerald-500 px-4 py-1 rounded-t-
|
|
55
|
+
/* @__PURE__ */ jsxs("span", { className: "absolute -top-6 left-10 bg-emerald-500 px-4 py-1 rounded-t-lg text-xs font-medium text-white", children: [
|
|
56
56
|
targetProduct?.discountMax,
|
|
57
57
|
"% OFF"
|
|
58
58
|
] }),
|
|
@@ -93,7 +93,7 @@ function Container({
|
|
|
93
93
|
"main",
|
|
94
94
|
{
|
|
95
95
|
className: classNames({
|
|
96
|
-
"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-
|
|
96
|
+
"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-xl p-4 bg-white gap-4 relative": variant === "main",
|
|
97
97
|
"w-full h-auto relative": variant === "simple"
|
|
98
98
|
}),
|
|
99
99
|
"data-testid": "test_id_container",
|
|
@@ -107,68 +107,20 @@ var Container_default = Container;
|
|
|
107
107
|
|
|
108
108
|
// src/components/Footer/index.tsx
|
|
109
109
|
import classNames2 from "classnames";
|
|
110
|
-
import { useEffect, useState } from "react";
|
|
111
|
-
|
|
112
|
-
// src/services/get-product-by-ean.ts
|
|
113
|
-
import Cookies from "js-cookie";
|
|
114
|
-
var GetProductByEAN = async ({ PRODUCT_EAN }) => {
|
|
115
|
-
const API_URL = import.meta.env.VITE_API_URL;
|
|
116
|
-
const AUTH_TOKEN = Cookies.get("pbm-token");
|
|
117
|
-
if (!AUTH_TOKEN) {
|
|
118
|
-
throw new Error("Token is not defined in cookies or is expired");
|
|
119
|
-
}
|
|
120
|
-
const response = await fetch(`${API_URL}/products/ean/${PRODUCT_EAN}`, {
|
|
121
|
-
method: "GET",
|
|
122
|
-
headers: {
|
|
123
|
-
Authorization: `Bearer ${AUTH_TOKEN}`,
|
|
124
|
-
"Content-Type": "application/json"
|
|
125
|
-
}
|
|
126
|
-
});
|
|
127
|
-
const dataResponse = await response.json();
|
|
128
|
-
if (!dataResponse.success) {
|
|
129
|
-
throw new Error(dataResponse.message || "Failed to fetch authorization");
|
|
130
|
-
}
|
|
131
|
-
return dataResponse;
|
|
132
|
-
};
|
|
133
|
-
|
|
134
|
-
// src/components/Footer/index.tsx
|
|
135
110
|
import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
136
111
|
function Footer() {
|
|
137
|
-
const [industryLogo, setIndustryLogo] = useState(null);
|
|
138
112
|
const { targetProduct, setTargetProduct, state } = usePBMStore();
|
|
139
|
-
useEffect(() => {
|
|
140
|
-
const fetchProductByEan = async () => {
|
|
141
|
-
if (!targetProduct?.ean) return;
|
|
142
|
-
try {
|
|
143
|
-
const response = await GetProductByEAN({ PRODUCT_EAN: targetProduct.ean });
|
|
144
|
-
if (response.success && response.data) {
|
|
145
|
-
setIndustryLogo(response.data.pbm.imageLink);
|
|
146
|
-
const { pbm, sku, ...targetProductNewData } = response.data;
|
|
147
|
-
setTargetProduct({
|
|
148
|
-
...targetProduct,
|
|
149
|
-
...targetProductNewData,
|
|
150
|
-
productId: Number(targetProductNewData.productId),
|
|
151
|
-
informativeMessage: pbm.informativeMessage ?? "",
|
|
152
|
-
discountMax: pbm.discountMax ?? 0
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
} catch (error) {
|
|
156
|
-
console.error(error);
|
|
157
|
-
}
|
|
158
|
-
};
|
|
159
|
-
fetchProductByEan();
|
|
160
|
-
}, [targetProduct?.ean]);
|
|
161
113
|
return /* @__PURE__ */ jsxs2("footer", { className: "w-full h-auto relative", id: "footer_pbm", children: [
|
|
162
114
|
state !== "isActivated" && targetProduct?.informativeMessage && /* @__PURE__ */ jsx3("p", { className: "text-start mb-3 font-semibold text-sm text-amber-500", children: targetProduct?.informativeMessage }),
|
|
163
|
-
/* @__PURE__ */ jsxs2("section", { className: classNames2("flex items-center w-full h-auto gap-4", { "justify-center": industryLogo, "justify-start": !industryLogo }), children: [
|
|
115
|
+
/* @__PURE__ */ jsxs2("section", { className: classNames2("flex items-center w-full h-auto gap-4", { "justify-center": targetProduct?.industryLogo, "justify-start": !targetProduct?.industryLogo }), children: [
|
|
164
116
|
/* @__PURE__ */ jsxs2("section", { className: "w-4/5 h-auto", children: [
|
|
165
117
|
/* @__PURE__ */ jsx3("h3", { className: "text-start font-semibold text-sm", children: "Economize com o benef\xEDcio do laborat\xF3rio." }),
|
|
166
118
|
/* @__PURE__ */ jsx3("p", { className: "text-start font-normal text-sm", children: "Este produto tem pre\xE7o exclusivo para clientes cadastrados no programa." })
|
|
167
119
|
] }),
|
|
168
|
-
industryLogo && /* @__PURE__ */ jsx3(
|
|
120
|
+
targetProduct?.industryLogo && /* @__PURE__ */ jsx3(
|
|
169
121
|
"img",
|
|
170
122
|
{
|
|
171
|
-
src: industryLogo,
|
|
123
|
+
src: targetProduct.industryLogo,
|
|
172
124
|
alt: "parceiro",
|
|
173
125
|
className: "w-1/5 min-w-20 h-auto aspect-auto rounded-xl",
|
|
174
126
|
loading: "eager",
|
|
@@ -209,16 +161,16 @@ import classNames4 from "classnames";
|
|
|
209
161
|
import { zodResolver } from "@hookform/resolvers/zod";
|
|
210
162
|
import { useForm } from "react-hook-form";
|
|
211
163
|
import { ArrowRight } from "lucide-react";
|
|
212
|
-
import { useState
|
|
164
|
+
import { useState } from "react";
|
|
213
165
|
|
|
214
166
|
// src/services/benefits-with-document.ts
|
|
215
|
-
import
|
|
167
|
+
import Cookies from "js-cookie";
|
|
216
168
|
var BenefitsWithDocument = async ({ document, products }) => {
|
|
217
169
|
const API_URL = import.meta.env.VITE_API_URL;
|
|
218
170
|
if (!API_URL) {
|
|
219
171
|
throw new Error("API URL is not defined in environment variables");
|
|
220
172
|
}
|
|
221
|
-
const AUTH_TOKEN =
|
|
173
|
+
const AUTH_TOKEN = Cookies.get("pbm-token");
|
|
222
174
|
if (!AUTH_TOKEN) {
|
|
223
175
|
throw new Error("Token is not defined in cookies or is expired");
|
|
224
176
|
}
|
|
@@ -246,7 +198,7 @@ function Button(props) {
|
|
|
246
198
|
{
|
|
247
199
|
...props,
|
|
248
200
|
className: classNames3(
|
|
249
|
-
"w-3xs cursor-pointer h-10 rounded-
|
|
201
|
+
"w-3xs cursor-pointer h-10 rounded-lg bg-emerald-500 hover:bg-emerald-400 text-white text-sm font-semibold transition-colors",
|
|
250
202
|
props.className
|
|
251
203
|
),
|
|
252
204
|
children: props.children
|
|
@@ -259,7 +211,7 @@ var Button_default = Button;
|
|
|
259
211
|
import { Fragment, jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
260
212
|
function Form({ setLoading }) {
|
|
261
213
|
const { setSecurityNumber, setState, securityNumber, targetProduct, setUrlAcceptTerms, setUrlRegisterIndustry } = usePBMStore();
|
|
262
|
-
const [showCoupoField, setShowCoupoField] =
|
|
214
|
+
const [showCoupoField, setShowCoupoField] = useState(false);
|
|
263
215
|
const {
|
|
264
216
|
handleSubmit,
|
|
265
217
|
register,
|
|
@@ -350,8 +302,8 @@ function Form({ setLoading }) {
|
|
|
350
302
|
{
|
|
351
303
|
type: "text",
|
|
352
304
|
className: classNames4(
|
|
353
|
-
"w-full h-
|
|
354
|
-
{ "outline outline-red-600": errors.securityNumber, "rounded-
|
|
305
|
+
"w-full h-10 bg-gray-100 rounded-s-lg 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",
|
|
306
|
+
{ "outline outline-red-600": errors.securityNumber, "rounded-lg": showCoupoField }
|
|
355
307
|
),
|
|
356
308
|
placeholder: "Digite seu CPF aqui...",
|
|
357
309
|
required: true,
|
|
@@ -384,8 +336,8 @@ function Form({ setLoading }) {
|
|
|
384
336
|
{
|
|
385
337
|
type: "text",
|
|
386
338
|
className: classNames4(
|
|
387
|
-
"w-full h-
|
|
388
|
-
{ "outline outline-red-600": errors.coupon, "rounded-
|
|
339
|
+
"w-full h-10 bg-gray-100 rounded-s-lg text-sm font-semibold focus:outline focus:outline-[#339c9b] focus:bg-[#44c2c0]/30 text-zinc-600 placeholder:text-zinc-600 px-4 placeholder:text-sm placeholder:font-semibold",
|
|
340
|
+
{ "outline outline-red-600": errors.coupon, "rounded-lg": showCoupoField }
|
|
389
341
|
),
|
|
390
342
|
placeholder: "Cupom / ID do Cart\xE3o",
|
|
391
343
|
...register("coupon", {
|
|
@@ -409,8 +361,8 @@ function Form({ setLoading }) {
|
|
|
409
361
|
{
|
|
410
362
|
type: "submit",
|
|
411
363
|
className: classNames4(
|
|
412
|
-
"bg-emerald-500 w-1/5 h-
|
|
413
|
-
{ "rounded-
|
|
364
|
+
"bg-emerald-500 w-1/5 h-10 rounded-e-lg flex items-center justify-center cursor-pointer",
|
|
365
|
+
{ "rounded-lg": showCoupoField }
|
|
414
366
|
),
|
|
415
367
|
id: "button_submit_security_number_pbm",
|
|
416
368
|
children: /* @__PURE__ */ jsx5(ArrowRight, { size: 24, color: "white", strokeWidth: 2 })
|
|
@@ -468,7 +420,7 @@ function Loading({ textColor }) {
|
|
|
468
420
|
var Loading_default = Loading;
|
|
469
421
|
|
|
470
422
|
// src/components/BenefitsTable/index.tsx
|
|
471
|
-
import { useEffect as
|
|
423
|
+
import { useEffect as useEffect2, useState as useState2 } from "react";
|
|
472
424
|
|
|
473
425
|
// src/components/UI/Title/index.tsx
|
|
474
426
|
import classNames5 from "classnames";
|
|
@@ -492,7 +444,7 @@ var Title_default = Title;
|
|
|
492
444
|
|
|
493
445
|
// src/components/BenefitsTable/Item.tsx
|
|
494
446
|
import { Badge, BadgeCheck } from "lucide-react";
|
|
495
|
-
import { useCallback, useEffect
|
|
447
|
+
import { useCallback, useEffect } from "react";
|
|
496
448
|
import { jsx as jsx8, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
497
449
|
function Item({ data, onChange, checked }) {
|
|
498
450
|
const { setAvailableDiscountSelected, securityNumber } = usePBMStore();
|
|
@@ -522,14 +474,14 @@ function Item({ data, onChange, checked }) {
|
|
|
522
474
|
totalPriceProductWithDiscountBenefit,
|
|
523
475
|
unitDiscountValue
|
|
524
476
|
]);
|
|
525
|
-
|
|
477
|
+
useEffect(() => {
|
|
526
478
|
updateStorageData();
|
|
527
479
|
}, [updateStorageData]);
|
|
528
480
|
return /* @__PURE__ */ jsxs5(
|
|
529
481
|
"label",
|
|
530
482
|
{
|
|
531
483
|
htmlFor: ID_INPUT,
|
|
532
|
-
className: "label_benefits w-full flex items-center justify-start bg-zinc-300/60 border border-zinc-400/50 px-4 py-2 hover:bg-zinc-300 transition-colors cursor-pointer rounded-
|
|
484
|
+
className: "label_benefits w-full flex items-center justify-start bg-zinc-300/60 border border-zinc-400/50 px-4 py-2 hover:bg-zinc-300 transition-colors cursor-pointer rounded-lg gap-1",
|
|
533
485
|
id: "label_benefits_" + ID_INPUT,
|
|
534
486
|
children: [
|
|
535
487
|
/* @__PURE__ */ jsx8(
|
|
@@ -550,7 +502,7 @@ function Item({ data, onChange, checked }) {
|
|
|
550
502
|
"un"
|
|
551
503
|
] }),
|
|
552
504
|
/* @__PURE__ */ jsxs5("section", { className: "ml-auto relative", children: [
|
|
553
|
-
/* @__PURE__ */ jsxs5("span", { className: "absolute -top-4 text-emerald-900 py-0.5 font-semibold text-xs bg-[#32b316] px-2 w-auto text-nowrap rounded-2xl -right-
|
|
505
|
+
/* @__PURE__ */ jsxs5("span", { className: "absolute -top-4 text-emerald-900 py-0.5 font-semibold text-xs bg-[#32b316] px-2 w-auto text-nowrap rounded-2xl -right-3", children: [
|
|
554
506
|
discountValue.toLocaleString("pt-BR", {
|
|
555
507
|
currency: "BRL",
|
|
556
508
|
currencyDisplay: "symbol",
|
|
@@ -574,13 +526,13 @@ function Item({ data, onChange, checked }) {
|
|
|
574
526
|
var Item_default = Item;
|
|
575
527
|
|
|
576
528
|
// src/services/benefits-without-document.ts
|
|
577
|
-
import
|
|
529
|
+
import Cookies2 from "js-cookie";
|
|
578
530
|
var CheckBenefistWithoutDocument = async ({ products }) => {
|
|
579
531
|
const API_URL = import.meta.env.VITE_API_URL;
|
|
580
532
|
if (!API_URL) {
|
|
581
533
|
throw new Error("API URL is not defined in environment variables");
|
|
582
534
|
}
|
|
583
|
-
const AUTH_TOKEN =
|
|
535
|
+
const AUTH_TOKEN = Cookies2.get("pbm-token");
|
|
584
536
|
if (!AUTH_TOKEN) {
|
|
585
537
|
throw new Error("Token is not defined in cookies or is expired");
|
|
586
538
|
}
|
|
@@ -603,10 +555,10 @@ var CheckBenefistWithoutDocument = async ({ products }) => {
|
|
|
603
555
|
import { jsx as jsx9, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
604
556
|
function BenefitsTable() {
|
|
605
557
|
const { securityNumber, setState, targetProduct } = usePBMStore();
|
|
606
|
-
const [selectedDiscout, setSelectedDiscount] =
|
|
607
|
-
const [loading, setLoading] =
|
|
608
|
-
const [benefitsItems, setBenefitsItems] =
|
|
609
|
-
|
|
558
|
+
const [selectedDiscout, setSelectedDiscount] = useState2(null);
|
|
559
|
+
const [loading, setLoading] = useState2(true);
|
|
560
|
+
const [benefitsItems, setBenefitsItems] = useState2();
|
|
561
|
+
useEffect2(() => {
|
|
610
562
|
const fetchDicountsWithoutDocument = async () => {
|
|
611
563
|
if (!targetProduct?.productId) {
|
|
612
564
|
console.error("PBMLOG: Product ID is not defined on targetProduct");
|
|
@@ -799,6 +751,7 @@ var getParams = (params) => {
|
|
|
799
751
|
// src/components/UI/Link/index.tsx
|
|
800
752
|
import { jsx as jsx11 } from "react/jsx-runtime";
|
|
801
753
|
function Link(props) {
|
|
754
|
+
const { setState } = usePBMStore();
|
|
802
755
|
return /* @__PURE__ */ jsx11(
|
|
803
756
|
"a",
|
|
804
757
|
{
|
|
@@ -806,11 +759,12 @@ function Link(props) {
|
|
|
806
759
|
target: "_blank",
|
|
807
760
|
href: typeof props.href === "string" ? props.href : props.href.pathname + getParams(props.href.param),
|
|
808
761
|
className: classNames7(
|
|
809
|
-
"w-3xs cursor-pointer h-10 rounded-
|
|
762
|
+
"w-3xs cursor-pointer h-10 rounded-lg bg-emerald-500 hover:bg-emerald-400 text-white text-sm font-semibold transition-colors flex items-center justify-center",
|
|
810
763
|
props.className
|
|
811
764
|
),
|
|
812
765
|
"data-testid": "test_id_link",
|
|
813
766
|
id: "link_pbm",
|
|
767
|
+
onClick: () => setState("isEmpty"),
|
|
814
768
|
children: props.children
|
|
815
769
|
}
|
|
816
770
|
);
|
|
@@ -828,8 +782,12 @@ function SecurityNumberInvalid({ textColor }) {
|
|
|
828
782
|
className: "flex items-end justify-center gap-2 w-full h-auto flex-col border-y border-zinc-300 py-6",
|
|
829
783
|
id: "security_number_invalid_container_pbm",
|
|
830
784
|
children: [
|
|
831
|
-
/* @__PURE__ */ jsx12(Title_default, { className: "w-full", textColor, children: "CPF n\xE3o cadastrado
|
|
832
|
-
/* @__PURE__ */
|
|
785
|
+
/* @__PURE__ */ jsx12(Title_default, { className: "w-full", textColor, children: "CPF n\xE3o cadastrado." }),
|
|
786
|
+
/* @__PURE__ */ jsxs7(Text_default, { className: "w-full", textColor, children: [
|
|
787
|
+
"Conclua seu cadastro para habilitar o benef\xEDcio. ",
|
|
788
|
+
/* @__PURE__ */ jsx12("br", {}),
|
|
789
|
+
"Ao clicar em \u201CAceitar os termos\u201D, voc\xEA ir\xE1 para uma p\xE1gina externa. Aceite os termos e volte para continuar."
|
|
790
|
+
] }),
|
|
833
791
|
/* @__PURE__ */ jsx12(
|
|
834
792
|
Link_default,
|
|
835
793
|
{
|
|
@@ -844,7 +802,7 @@ function SecurityNumberInvalid({ textColor }) {
|
|
|
844
802
|
var SecurityNumberInvalid_default = SecurityNumberInvalid;
|
|
845
803
|
|
|
846
804
|
// src/PBM.tsx
|
|
847
|
-
import { useCallback as useCallback2, useEffect as
|
|
805
|
+
import { useCallback as useCallback2, useEffect as useEffect3, useState as useState3 } from "react";
|
|
848
806
|
|
|
849
807
|
// src/components/SecurityNumberRegitered/index.tsx
|
|
850
808
|
import { jsx as jsx13, jsxs as jsxs8 } from "react/jsx-runtime";
|
|
@@ -857,8 +815,8 @@ function SecurityNumberRegitered({ textColor }) {
|
|
|
857
815
|
className: "flex items-end justify-center gap-2 w-full h-auto flex-col border-y border-zinc-300 py-6",
|
|
858
816
|
id: "security_number_registered_container_pbm",
|
|
859
817
|
children: [
|
|
860
|
-
/* @__PURE__ */ jsx13(Title_default, { className: "w-full", textColor, children: "CPF n\xE3o habilitado
|
|
861
|
-
/* @__PURE__ */ jsx13(Text_default, { className: "w-full", textColor, children: "
|
|
818
|
+
/* @__PURE__ */ jsx13(Title_default, { className: "w-full", textColor, children: "Ops, seu CPF ainda n\xE3o est\xE1 habilitado para este produto." }),
|
|
819
|
+
/* @__PURE__ */ jsx13(Text_default, { className: "w-full", textColor, children: "Para ativar o benef\xEDcio, clique em \u201CAtivar CPF\u201D e conclua a etapa na p\xE1gina externa. Depois, \xE9 s\xF3 voltar para continuar \u2014 vamos aguardar voc\xEA aqui." }),
|
|
862
820
|
/* @__PURE__ */ jsx13(
|
|
863
821
|
Link_default,
|
|
864
822
|
{
|
|
@@ -873,7 +831,7 @@ function SecurityNumberRegitered({ textColor }) {
|
|
|
873
831
|
var SecurityNumberRegitered_default = SecurityNumberRegitered;
|
|
874
832
|
|
|
875
833
|
// src/services/authorization.ts
|
|
876
|
-
import
|
|
834
|
+
import Cookies3 from "js-cookie";
|
|
877
835
|
var GetAuthorization = async ({ clientID }) => {
|
|
878
836
|
const API_URL = import.meta.env.VITE_API_URL;
|
|
879
837
|
const STORE_ID = import.meta.env.VITE_STORE_ID;
|
|
@@ -899,12 +857,12 @@ var GetAuthorization = async ({ clientID }) => {
|
|
|
899
857
|
if (!dataResponse.success) {
|
|
900
858
|
throw new Error(dataResponse.message || "Failed to fetch authorization");
|
|
901
859
|
}
|
|
902
|
-
|
|
860
|
+
Cookies3.set("pbm-token", dataResponse.data.token, {
|
|
903
861
|
expires: dataResponse.data.expiresIn / (60 * 60),
|
|
904
862
|
secure: true,
|
|
905
863
|
sameSite: "Strict"
|
|
906
864
|
});
|
|
907
|
-
|
|
865
|
+
Cookies3.set("pbm-token-refresh", dataResponse.data.refreshToken, {
|
|
908
866
|
expires: dataResponse.data.refreshExpiresIn / (60 * 60),
|
|
909
867
|
secure: true,
|
|
910
868
|
sameSite: "Strict"
|
|
@@ -914,6 +872,30 @@ var GetAuthorization = async ({ clientID }) => {
|
|
|
914
872
|
|
|
915
873
|
// src/PBM.tsx
|
|
916
874
|
import { ArrowRight as ArrowRight2 } from "lucide-react";
|
|
875
|
+
|
|
876
|
+
// src/services/get-product-by-ean.ts
|
|
877
|
+
import Cookies4 from "js-cookie";
|
|
878
|
+
var GetProductByEAN = async ({ PRODUCT_EAN }) => {
|
|
879
|
+
const API_URL = import.meta.env.VITE_API_URL;
|
|
880
|
+
const AUTH_TOKEN = Cookies4.get("pbm-token");
|
|
881
|
+
if (!AUTH_TOKEN) {
|
|
882
|
+
throw new Error("Token is not defined in cookies or is expired");
|
|
883
|
+
}
|
|
884
|
+
const response = await fetch(`${API_URL}/products/ean/${PRODUCT_EAN}`, {
|
|
885
|
+
method: "GET",
|
|
886
|
+
headers: {
|
|
887
|
+
Authorization: `Bearer ${AUTH_TOKEN}`,
|
|
888
|
+
"Content-Type": "application/json"
|
|
889
|
+
}
|
|
890
|
+
});
|
|
891
|
+
const dataResponse = await response.json();
|
|
892
|
+
if (!dataResponse.success) {
|
|
893
|
+
throw new Error(dataResponse.message || "Failed to fetch authorization");
|
|
894
|
+
}
|
|
895
|
+
return dataResponse;
|
|
896
|
+
};
|
|
897
|
+
|
|
898
|
+
// src/PBM.tsx
|
|
917
899
|
import { Fragment as Fragment2, jsx as jsx14, jsxs as jsxs9 } from "react/jsx-runtime";
|
|
918
900
|
function PBM({
|
|
919
901
|
originalProductPrice,
|
|
@@ -923,24 +905,44 @@ function PBM({
|
|
|
923
905
|
const formatedOriginalProductPrice = Number(
|
|
924
906
|
String(originalProductPrice).replace(",", ".")
|
|
925
907
|
);
|
|
926
|
-
const [loading, setLoading] =
|
|
927
|
-
const { setState, state, setTargetProduct } = usePBMStore();
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
908
|
+
const [loading, setLoading] = useState3(false);
|
|
909
|
+
const { setState, state, setTargetProduct, targetProduct } = usePBMStore();
|
|
910
|
+
const fetchProductByEan = async () => {
|
|
911
|
+
try {
|
|
912
|
+
if (!eanProduct) {
|
|
913
|
+
console.error("PBMLOG: Ean is not defined.");
|
|
914
|
+
return;
|
|
915
|
+
}
|
|
916
|
+
const response = await GetProductByEAN({ PRODUCT_EAN: eanProduct });
|
|
917
|
+
if (response.success && response.data) {
|
|
918
|
+
const { pbm, sku, ...targetProductNewData } = response.data;
|
|
919
|
+
setTargetProduct({
|
|
920
|
+
...targetProduct,
|
|
921
|
+
...targetProductNewData,
|
|
922
|
+
productId: Number(targetProductNewData.productId),
|
|
923
|
+
informativeMessage: pbm.informativeMessage ?? "",
|
|
924
|
+
discountMax: pbm.discountMax ?? 0,
|
|
925
|
+
industryLogo: pbm.imageLink ?? void 0,
|
|
926
|
+
ean: eanProduct
|
|
927
|
+
});
|
|
928
|
+
}
|
|
929
|
+
} catch (error) {
|
|
930
|
+
console.error(error);
|
|
931
931
|
}
|
|
932
|
-
}
|
|
932
|
+
};
|
|
933
933
|
const handleAuthorizationRequest = useCallback2(async () => {
|
|
934
934
|
try {
|
|
935
935
|
const response = await GetAuthorization({ clientID });
|
|
936
|
-
if (
|
|
936
|
+
if (response.success) {
|
|
937
|
+
fetchProductByEan();
|
|
938
|
+
} else {
|
|
937
939
|
console.error("PBMLOG: Authorization failed!");
|
|
938
940
|
}
|
|
939
941
|
} catch (error) {
|
|
940
942
|
console.error("Error fetching authorization:", error);
|
|
941
943
|
}
|
|
942
944
|
}, [clientID]);
|
|
943
|
-
|
|
945
|
+
useEffect3(() => {
|
|
944
946
|
handleAuthorizationRequest();
|
|
945
947
|
}, [handleAuthorizationRequest]);
|
|
946
948
|
return /* @__PURE__ */ jsx14("div", { id: "pbm-library-root", children: /* @__PURE__ */ jsxs9(Container_default, { variant: "main", children: [
|