@agrada_digital/pbm 0.0.69 → 0.0.71
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 +99 -101
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +88 -90
- package/dist/index.mjs.map +1 -1
- package/dist-wc/pbm-wc.js +76 -76
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -144,73 +144,20 @@ var Container_default = Container;
|
|
|
144
144
|
|
|
145
145
|
// src/components/Footer/index.tsx
|
|
146
146
|
var import_classnames2 = __toESM(require("classnames"));
|
|
147
|
-
var import_react2 = require("react");
|
|
148
|
-
|
|
149
|
-
// src/services/get-product-by-ean.ts
|
|
150
|
-
var import_js_cookie = __toESM(require("js-cookie"));
|
|
151
|
-
var import_meta = {};
|
|
152
|
-
var GetProductByEAN = async ({ PRODUCT_EAN }) => {
|
|
153
|
-
const API_URL = import_meta.env.VITE_API_URL;
|
|
154
|
-
const AUTH_TOKEN = import_js_cookie.default.get("pbm-token");
|
|
155
|
-
if (!AUTH_TOKEN) {
|
|
156
|
-
throw new Error("Token is not defined in cookies or is expired");
|
|
157
|
-
}
|
|
158
|
-
const response = await fetch(`${API_URL}/products/ean/${PRODUCT_EAN}`, {
|
|
159
|
-
method: "GET",
|
|
160
|
-
headers: {
|
|
161
|
-
Authorization: `Bearer ${AUTH_TOKEN}`,
|
|
162
|
-
"Content-Type": "application/json"
|
|
163
|
-
}
|
|
164
|
-
});
|
|
165
|
-
const dataResponse = await response.json();
|
|
166
|
-
if (!dataResponse.success) {
|
|
167
|
-
throw new Error(dataResponse.message || "Failed to fetch authorization");
|
|
168
|
-
}
|
|
169
|
-
return dataResponse;
|
|
170
|
-
};
|
|
171
|
-
|
|
172
|
-
// src/components/Footer/index.tsx
|
|
173
147
|
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
174
148
|
function Footer() {
|
|
175
|
-
const [industryLogo, setIndustryLogo] = (0, import_react2.useState)(null);
|
|
176
149
|
const { targetProduct, setTargetProduct, state } = usePBMStore();
|
|
177
|
-
(0, import_react2.useEffect)(() => {
|
|
178
|
-
if (!targetProduct?.ean) return;
|
|
179
|
-
let isMounted = true;
|
|
180
|
-
const fetchProductByEan = async () => {
|
|
181
|
-
try {
|
|
182
|
-
const response = await GetProductByEAN({ PRODUCT_EAN: targetProduct.ean });
|
|
183
|
-
if (response.success && response.data) {
|
|
184
|
-
setIndustryLogo(response.data.pbm.imageLink);
|
|
185
|
-
const { pbm, sku, ...targetProductNewData } = response.data;
|
|
186
|
-
setTargetProduct({
|
|
187
|
-
...targetProduct,
|
|
188
|
-
...targetProductNewData,
|
|
189
|
-
productId: Number(targetProductNewData.productId),
|
|
190
|
-
informativeMessage: pbm.informativeMessage ?? "",
|
|
191
|
-
discountMax: pbm.discountMax ?? 0
|
|
192
|
-
});
|
|
193
|
-
}
|
|
194
|
-
} catch (error) {
|
|
195
|
-
console.error(error);
|
|
196
|
-
}
|
|
197
|
-
};
|
|
198
|
-
fetchProductByEan();
|
|
199
|
-
return () => {
|
|
200
|
-
isMounted = false;
|
|
201
|
-
};
|
|
202
|
-
}, [targetProduct?.ean]);
|
|
203
150
|
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("footer", { className: "w-full h-auto relative", id: "footer_pbm", children: [
|
|
204
151
|
state !== "isActivated" && targetProduct?.informativeMessage && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: "text-start mb-3 font-semibold text-sm text-amber-500", children: targetProduct?.informativeMessage }),
|
|
205
|
-
/* @__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: [
|
|
152
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("section", { className: (0, import_classnames2.default)("flex items-center w-full h-auto gap-4", { "justify-center": targetProduct?.industryLogo, "justify-start": !targetProduct?.industryLogo }), children: [
|
|
206
153
|
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("section", { className: "w-4/5 h-auto", children: [
|
|
207
154
|
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("h3", { className: "text-start font-semibold text-sm", children: "Economize com o benef\xEDcio do laborat\xF3rio." }),
|
|
208
155
|
/* @__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." })
|
|
209
156
|
] }),
|
|
210
|
-
industryLogo && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
157
|
+
targetProduct?.industryLogo && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
211
158
|
"img",
|
|
212
159
|
{
|
|
213
|
-
src: industryLogo,
|
|
160
|
+
src: targetProduct.industryLogo,
|
|
214
161
|
alt: "parceiro",
|
|
215
162
|
className: "w-1/5 min-w-20 h-auto aspect-auto rounded-xl",
|
|
216
163
|
loading: "eager",
|
|
@@ -251,17 +198,17 @@ var import_classnames4 = __toESM(require("classnames"));
|
|
|
251
198
|
var import_zod2 = require("@hookform/resolvers/zod");
|
|
252
199
|
var import_react_hook_form = require("react-hook-form");
|
|
253
200
|
var import_lucide_react = require("lucide-react");
|
|
254
|
-
var
|
|
201
|
+
var import_react2 = require("react");
|
|
255
202
|
|
|
256
203
|
// src/services/benefits-with-document.ts
|
|
257
|
-
var
|
|
258
|
-
var
|
|
204
|
+
var import_js_cookie = __toESM(require("js-cookie"));
|
|
205
|
+
var import_meta = {};
|
|
259
206
|
var BenefitsWithDocument = async ({ document, products }) => {
|
|
260
|
-
const API_URL =
|
|
207
|
+
const API_URL = import_meta.env.VITE_API_URL;
|
|
261
208
|
if (!API_URL) {
|
|
262
209
|
throw new Error("API URL is not defined in environment variables");
|
|
263
210
|
}
|
|
264
|
-
const AUTH_TOKEN =
|
|
211
|
+
const AUTH_TOKEN = import_js_cookie.default.get("pbm-token");
|
|
265
212
|
if (!AUTH_TOKEN) {
|
|
266
213
|
throw new Error("Token is not defined in cookies or is expired");
|
|
267
214
|
}
|
|
@@ -289,7 +236,7 @@ function Button(props) {
|
|
|
289
236
|
{
|
|
290
237
|
...props,
|
|
291
238
|
className: (0, import_classnames3.default)(
|
|
292
|
-
"w-3xs cursor-pointer h-10 rounded-
|
|
239
|
+
"w-3xs cursor-pointer h-10 rounded-lg bg-emerald-500 hover:bg-emerald-400 text-white text-sm font-semibold transition-colors",
|
|
293
240
|
props.className
|
|
294
241
|
),
|
|
295
242
|
children: props.children
|
|
@@ -302,7 +249,7 @@ var Button_default = Button;
|
|
|
302
249
|
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
303
250
|
function Form({ setLoading }) {
|
|
304
251
|
const { setSecurityNumber, setState, securityNumber, targetProduct, setUrlAcceptTerms, setUrlRegisterIndustry } = usePBMStore();
|
|
305
|
-
const [showCoupoField, setShowCoupoField] = (0,
|
|
252
|
+
const [showCoupoField, setShowCoupoField] = (0, import_react2.useState)(false);
|
|
306
253
|
const {
|
|
307
254
|
handleSubmit,
|
|
308
255
|
register,
|
|
@@ -453,7 +400,7 @@ function Form({ setLoading }) {
|
|
|
453
400
|
type: "submit",
|
|
454
401
|
className: (0, import_classnames4.default)(
|
|
455
402
|
"bg-emerald-500 w-1/5 h-10 rounded-e-lg flex items-center justify-center cursor-pointer",
|
|
456
|
-
{ "rounded-
|
|
403
|
+
{ "rounded-lg": showCoupoField }
|
|
457
404
|
),
|
|
458
405
|
id: "button_submit_security_number_pbm",
|
|
459
406
|
children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react.ArrowRight, { size: 24, color: "white", strokeWidth: 2 })
|
|
@@ -511,7 +458,7 @@ function Loading({ textColor }) {
|
|
|
511
458
|
var Loading_default = Loading;
|
|
512
459
|
|
|
513
460
|
// src/components/BenefitsTable/index.tsx
|
|
514
|
-
var
|
|
461
|
+
var import_react4 = require("react");
|
|
515
462
|
|
|
516
463
|
// src/components/UI/Title/index.tsx
|
|
517
464
|
var import_classnames5 = __toESM(require("classnames"));
|
|
@@ -535,7 +482,7 @@ var Title_default = Title;
|
|
|
535
482
|
|
|
536
483
|
// src/components/BenefitsTable/Item.tsx
|
|
537
484
|
var import_lucide_react2 = require("lucide-react");
|
|
538
|
-
var
|
|
485
|
+
var import_react3 = require("react");
|
|
539
486
|
var import_jsx_runtime8 = require("react/jsx-runtime");
|
|
540
487
|
function Item({ data, onChange, checked }) {
|
|
541
488
|
const { setAvailableDiscountSelected, securityNumber } = usePBMStore();
|
|
@@ -544,7 +491,7 @@ function Item({ data, onChange, checked }) {
|
|
|
544
491
|
const unitDiscountValue = data.grossPrice * decimalDiscount;
|
|
545
492
|
const discountValue = unitDiscountValue * data.authorizedQuantity;
|
|
546
493
|
const totalPriceProductWithDiscountBenefit = data.grossPrice * data.authorizedQuantity - discountValue;
|
|
547
|
-
const updateStorageData = (0,
|
|
494
|
+
const updateStorageData = (0, import_react3.useCallback)(() => {
|
|
548
495
|
if (checked) {
|
|
549
496
|
const roundToTwoDecimals = (value) => Math.round(value * 100) / 100;
|
|
550
497
|
setAvailableDiscountSelected({
|
|
@@ -565,14 +512,14 @@ function Item({ data, onChange, checked }) {
|
|
|
565
512
|
totalPriceProductWithDiscountBenefit,
|
|
566
513
|
unitDiscountValue
|
|
567
514
|
]);
|
|
568
|
-
(0,
|
|
515
|
+
(0, import_react3.useEffect)(() => {
|
|
569
516
|
updateStorageData();
|
|
570
517
|
}, [updateStorageData]);
|
|
571
518
|
return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
|
|
572
519
|
"label",
|
|
573
520
|
{
|
|
574
521
|
htmlFor: ID_INPUT,
|
|
575
|
-
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-
|
|
522
|
+
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",
|
|
576
523
|
id: "label_benefits_" + ID_INPUT,
|
|
577
524
|
children: [
|
|
578
525
|
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
@@ -593,7 +540,7 @@ function Item({ data, onChange, checked }) {
|
|
|
593
540
|
"un"
|
|
594
541
|
] }),
|
|
595
542
|
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("section", { className: "ml-auto relative", children: [
|
|
596
|
-
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("span", { className: "absolute -top-4
|
|
543
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("span", { className: "absolute text-white -top-4 py-0.5 font-semibold text-xs bg-[#32b316] px-2 w-auto text-nowrap rounded-2xl -right-3", children: [
|
|
597
544
|
discountValue.toLocaleString("pt-BR", {
|
|
598
545
|
currency: "BRL",
|
|
599
546
|
currencyDisplay: "symbol",
|
|
@@ -617,14 +564,14 @@ function Item({ data, onChange, checked }) {
|
|
|
617
564
|
var Item_default = Item;
|
|
618
565
|
|
|
619
566
|
// src/services/benefits-without-document.ts
|
|
620
|
-
var
|
|
621
|
-
var
|
|
567
|
+
var import_js_cookie2 = __toESM(require("js-cookie"));
|
|
568
|
+
var import_meta2 = {};
|
|
622
569
|
var CheckBenefistWithoutDocument = async ({ products }) => {
|
|
623
|
-
const API_URL =
|
|
570
|
+
const API_URL = import_meta2.env.VITE_API_URL;
|
|
624
571
|
if (!API_URL) {
|
|
625
572
|
throw new Error("API URL is not defined in environment variables");
|
|
626
573
|
}
|
|
627
|
-
const AUTH_TOKEN =
|
|
574
|
+
const AUTH_TOKEN = import_js_cookie2.default.get("pbm-token");
|
|
628
575
|
if (!AUTH_TOKEN) {
|
|
629
576
|
throw new Error("Token is not defined in cookies or is expired");
|
|
630
577
|
}
|
|
@@ -647,10 +594,10 @@ var CheckBenefistWithoutDocument = async ({ products }) => {
|
|
|
647
594
|
var import_jsx_runtime9 = require("react/jsx-runtime");
|
|
648
595
|
function BenefitsTable() {
|
|
649
596
|
const { securityNumber, setState, targetProduct } = usePBMStore();
|
|
650
|
-
const [selectedDiscout, setSelectedDiscount] = (0,
|
|
651
|
-
const [loading, setLoading] = (0,
|
|
652
|
-
const [benefitsItems, setBenefitsItems] = (0,
|
|
653
|
-
(0,
|
|
597
|
+
const [selectedDiscout, setSelectedDiscount] = (0, import_react4.useState)(null);
|
|
598
|
+
const [loading, setLoading] = (0, import_react4.useState)(true);
|
|
599
|
+
const [benefitsItems, setBenefitsItems] = (0, import_react4.useState)();
|
|
600
|
+
(0, import_react4.useEffect)(() => {
|
|
654
601
|
const fetchDicountsWithoutDocument = async () => {
|
|
655
602
|
if (!targetProduct?.productId) {
|
|
656
603
|
console.error("PBMLOG: Product ID is not defined on targetProduct");
|
|
@@ -763,7 +710,7 @@ function BenefitsTable() {
|
|
|
763
710
|
/* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
|
|
764
711
|
"form",
|
|
765
712
|
{
|
|
766
|
-
className: "flex flex-col items-center justify-start w-full gap-
|
|
713
|
+
className: "flex flex-col items-center justify-start w-full gap-4.5",
|
|
767
714
|
id: "form_benefits_table_pbm",
|
|
768
715
|
children: [
|
|
769
716
|
!benefitsItems && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("p", { className: "text-sm font-semibold text-start text-zinc-900", id: "benefits_empty_pbm", children: "N\xE3o foi poss\xEDvel encontrar benef\xEDcios para esse produto." }),
|
|
@@ -843,6 +790,7 @@ var getParams = (params) => {
|
|
|
843
790
|
// src/components/UI/Link/index.tsx
|
|
844
791
|
var import_jsx_runtime11 = require("react/jsx-runtime");
|
|
845
792
|
function Link(props) {
|
|
793
|
+
const { setState } = usePBMStore();
|
|
846
794
|
return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
|
|
847
795
|
"a",
|
|
848
796
|
{
|
|
@@ -850,11 +798,12 @@ function Link(props) {
|
|
|
850
798
|
target: "_blank",
|
|
851
799
|
href: typeof props.href === "string" ? props.href : props.href.pathname + getParams(props.href.param),
|
|
852
800
|
className: (0, import_classnames7.default)(
|
|
853
|
-
"w-3xs cursor-pointer h-10 rounded-
|
|
801
|
+
"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",
|
|
854
802
|
props.className
|
|
855
803
|
),
|
|
856
804
|
"data-testid": "test_id_link",
|
|
857
805
|
id: "link_pbm",
|
|
806
|
+
onClick: () => setState("isEmpty"),
|
|
858
807
|
children: props.children
|
|
859
808
|
}
|
|
860
809
|
);
|
|
@@ -872,8 +821,12 @@ function SecurityNumberInvalid({ textColor }) {
|
|
|
872
821
|
className: "flex items-end justify-center gap-2 w-full h-auto flex-col border-y border-zinc-300 py-6",
|
|
873
822
|
id: "security_number_invalid_container_pbm",
|
|
874
823
|
children: [
|
|
875
|
-
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)(Title_default, { className: "w-full", textColor, children: "CPF n\xE3o cadastrado
|
|
876
|
-
/* @__PURE__ */ (0, import_jsx_runtime12.
|
|
824
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)(Title_default, { className: "w-full", textColor, children: "CPF n\xE3o cadastrado." }),
|
|
825
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(Text_default, { className: "w-full", textColor, children: [
|
|
826
|
+
"Conclua seu cadastro para habilitar o benef\xEDcio. ",
|
|
827
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)("br", {}),
|
|
828
|
+
"Ao clicar em \u201CAceitar os termos\u201D, voc\xEA ir\xE1 para uma p\xE1gina externa. Aceite os termos e volte para continuar."
|
|
829
|
+
] }),
|
|
877
830
|
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
|
|
878
831
|
Link_default,
|
|
879
832
|
{
|
|
@@ -888,7 +841,7 @@ function SecurityNumberInvalid({ textColor }) {
|
|
|
888
841
|
var SecurityNumberInvalid_default = SecurityNumberInvalid;
|
|
889
842
|
|
|
890
843
|
// src/PBM.tsx
|
|
891
|
-
var
|
|
844
|
+
var import_react5 = require("react");
|
|
892
845
|
|
|
893
846
|
// src/components/SecurityNumberRegitered/index.tsx
|
|
894
847
|
var import_jsx_runtime13 = require("react/jsx-runtime");
|
|
@@ -901,8 +854,8 @@ function SecurityNumberRegitered({ textColor }) {
|
|
|
901
854
|
className: "flex items-end justify-center gap-2 w-full h-auto flex-col border-y border-zinc-300 py-6",
|
|
902
855
|
id: "security_number_registered_container_pbm",
|
|
903
856
|
children: [
|
|
904
|
-
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)(Title_default, { className: "w-full", textColor, children: "CPF n\xE3o habilitado
|
|
905
|
-
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)(Text_default, { className: "w-full", textColor, children: "
|
|
857
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)(Title_default, { className: "w-full", textColor, children: "Ops, seu CPF ainda n\xE3o est\xE1 habilitado para este produto." }),
|
|
858
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)(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." }),
|
|
906
859
|
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
|
907
860
|
Link_default,
|
|
908
861
|
{
|
|
@@ -917,12 +870,12 @@ function SecurityNumberRegitered({ textColor }) {
|
|
|
917
870
|
var SecurityNumberRegitered_default = SecurityNumberRegitered;
|
|
918
871
|
|
|
919
872
|
// src/services/authorization.ts
|
|
920
|
-
var
|
|
921
|
-
var
|
|
873
|
+
var import_js_cookie3 = __toESM(require("js-cookie"));
|
|
874
|
+
var import_meta3 = {};
|
|
922
875
|
var GetAuthorization = async ({ clientID }) => {
|
|
923
|
-
const API_URL =
|
|
924
|
-
const STORE_ID =
|
|
925
|
-
const STORE_NAME =
|
|
876
|
+
const API_URL = import_meta3.env.VITE_API_URL;
|
|
877
|
+
const STORE_ID = import_meta3.env.VITE_STORE_ID;
|
|
878
|
+
const STORE_NAME = import_meta3.env.VITE_STORE_NAME;
|
|
926
879
|
if (!API_URL) {
|
|
927
880
|
throw new Error("API URL is not defined in environment variables");
|
|
928
881
|
}
|
|
@@ -944,12 +897,12 @@ var GetAuthorization = async ({ clientID }) => {
|
|
|
944
897
|
if (!dataResponse.success) {
|
|
945
898
|
throw new Error(dataResponse.message || "Failed to fetch authorization");
|
|
946
899
|
}
|
|
947
|
-
|
|
900
|
+
import_js_cookie3.default.set("pbm-token", dataResponse.data.token, {
|
|
948
901
|
expires: dataResponse.data.expiresIn / (60 * 60),
|
|
949
902
|
secure: true,
|
|
950
903
|
sameSite: "Strict"
|
|
951
904
|
});
|
|
952
|
-
|
|
905
|
+
import_js_cookie3.default.set("pbm-token-refresh", dataResponse.data.refreshToken, {
|
|
953
906
|
expires: dataResponse.data.refreshExpiresIn / (60 * 60),
|
|
954
907
|
secure: true,
|
|
955
908
|
sameSite: "Strict"
|
|
@@ -959,6 +912,31 @@ var GetAuthorization = async ({ clientID }) => {
|
|
|
959
912
|
|
|
960
913
|
// src/PBM.tsx
|
|
961
914
|
var import_lucide_react3 = require("lucide-react");
|
|
915
|
+
|
|
916
|
+
// src/services/get-product-by-ean.ts
|
|
917
|
+
var import_js_cookie4 = __toESM(require("js-cookie"));
|
|
918
|
+
var import_meta4 = {};
|
|
919
|
+
var GetProductByEAN = async ({ PRODUCT_EAN }) => {
|
|
920
|
+
const API_URL = import_meta4.env.VITE_API_URL;
|
|
921
|
+
const AUTH_TOKEN = import_js_cookie4.default.get("pbm-token");
|
|
922
|
+
if (!AUTH_TOKEN) {
|
|
923
|
+
throw new Error("Token is not defined in cookies or is expired");
|
|
924
|
+
}
|
|
925
|
+
const response = await fetch(`${API_URL}/products/ean/${PRODUCT_EAN}`, {
|
|
926
|
+
method: "GET",
|
|
927
|
+
headers: {
|
|
928
|
+
Authorization: `Bearer ${AUTH_TOKEN}`,
|
|
929
|
+
"Content-Type": "application/json"
|
|
930
|
+
}
|
|
931
|
+
});
|
|
932
|
+
const dataResponse = await response.json();
|
|
933
|
+
if (!dataResponse.success) {
|
|
934
|
+
throw new Error(dataResponse.message || "Failed to fetch authorization");
|
|
935
|
+
}
|
|
936
|
+
return dataResponse;
|
|
937
|
+
};
|
|
938
|
+
|
|
939
|
+
// src/PBM.tsx
|
|
962
940
|
var import_jsx_runtime14 = require("react/jsx-runtime");
|
|
963
941
|
function PBM({
|
|
964
942
|
originalProductPrice,
|
|
@@ -968,24 +946,44 @@ function PBM({
|
|
|
968
946
|
const formatedOriginalProductPrice = Number(
|
|
969
947
|
String(originalProductPrice).replace(",", ".")
|
|
970
948
|
);
|
|
971
|
-
const [loading, setLoading] = (0,
|
|
972
|
-
const { setState, state, setTargetProduct } = usePBMStore();
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
949
|
+
const [loading, setLoading] = (0, import_react5.useState)(false);
|
|
950
|
+
const { setState, state, setTargetProduct, targetProduct } = usePBMStore();
|
|
951
|
+
const fetchProductByEan = async () => {
|
|
952
|
+
try {
|
|
953
|
+
if (!eanProduct) {
|
|
954
|
+
console.error("PBMLOG: Ean is not defined.");
|
|
955
|
+
return;
|
|
956
|
+
}
|
|
957
|
+
const response = await GetProductByEAN({ PRODUCT_EAN: eanProduct });
|
|
958
|
+
if (response.success && response.data) {
|
|
959
|
+
const { pbm, sku, ...targetProductNewData } = response.data;
|
|
960
|
+
setTargetProduct({
|
|
961
|
+
...targetProduct,
|
|
962
|
+
...targetProductNewData,
|
|
963
|
+
productId: Number(targetProductNewData.productId),
|
|
964
|
+
informativeMessage: pbm.informativeMessage ?? "",
|
|
965
|
+
discountMax: pbm.discountMax ?? 0,
|
|
966
|
+
industryLogo: pbm.imageLink ?? void 0,
|
|
967
|
+
ean: eanProduct
|
|
968
|
+
});
|
|
969
|
+
}
|
|
970
|
+
} catch (error) {
|
|
971
|
+
console.error(error);
|
|
976
972
|
}
|
|
977
|
-
}
|
|
978
|
-
const handleAuthorizationRequest = (0,
|
|
973
|
+
};
|
|
974
|
+
const handleAuthorizationRequest = (0, import_react5.useCallback)(async () => {
|
|
979
975
|
try {
|
|
980
976
|
const response = await GetAuthorization({ clientID });
|
|
981
|
-
if (
|
|
977
|
+
if (response.success) {
|
|
978
|
+
fetchProductByEan();
|
|
979
|
+
} else {
|
|
982
980
|
console.error("PBMLOG: Authorization failed!");
|
|
983
981
|
}
|
|
984
982
|
} catch (error) {
|
|
985
983
|
console.error("Error fetching authorization:", error);
|
|
986
984
|
}
|
|
987
985
|
}, [clientID]);
|
|
988
|
-
(0,
|
|
986
|
+
(0, import_react5.useEffect)(() => {
|
|
989
987
|
handleAuthorizationRequest();
|
|
990
988
|
}, [handleAuthorizationRequest]);
|
|
991
989
|
return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("div", { id: "pbm-library-root", children: /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(Container_default, { variant: "main", children: [
|