@agrada_digital/pbm 0.0.89 → 0.0.91
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.js +39 -57
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +45 -63
- package/dist/index.mjs.map +1 -1
- package/dist-wc/pbm-wc.js +63 -63
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -435,7 +435,7 @@ function Loading({ textColor }) {
|
|
|
435
435
|
var Loading_default = Loading;
|
|
436
436
|
|
|
437
437
|
// src/components/BenefitsTable/index.tsx
|
|
438
|
-
import { useEffect as useEffect2, useState as
|
|
438
|
+
import { useEffect as useEffect2, useState as useState2 } from "react";
|
|
439
439
|
|
|
440
440
|
// src/components/UI/Title/index.tsx
|
|
441
441
|
import classNames5 from "classnames";
|
|
@@ -472,7 +472,7 @@ var createModalStore = (set) => ({
|
|
|
472
472
|
var useModal = create(createModalStore);
|
|
473
473
|
|
|
474
474
|
// src/components/BenefitsTable/Item.tsx
|
|
475
|
-
import { useCallback, useEffect
|
|
475
|
+
import { useCallback, useEffect } from "react";
|
|
476
476
|
import classNames6 from "classnames";
|
|
477
477
|
|
|
478
478
|
// src/components/UI/Icons/index.tsx
|
|
@@ -528,7 +528,6 @@ import { jsx as jsx9, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
|
528
528
|
function Item({ data, onChange, checked }) {
|
|
529
529
|
const { setAvailableDiscountSelected, state, isAuthenticatedShopper } = usePBMStore();
|
|
530
530
|
const { setModal } = useModal();
|
|
531
|
-
const [openModalAlert, setOpenModalAlert] = useState2(false);
|
|
532
531
|
const ID_INPUT = "unity_quantity_" + data.authorizedQuantity;
|
|
533
532
|
const decimalDiscount = data.discountPercentual / 100;
|
|
534
533
|
const unitDiscountValue = data.grossPrice * decimalDiscount;
|
|
@@ -558,12 +557,15 @@ function Item({ data, onChange, checked }) {
|
|
|
558
557
|
useEffect(() => {
|
|
559
558
|
updateStorageData();
|
|
560
559
|
}, [updateStorageData]);
|
|
561
|
-
const
|
|
562
|
-
if (isAuthenticatedShopper)
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
560
|
+
const handleChange = (e) => {
|
|
561
|
+
if (!isAuthenticatedShopper && state === "isActivated") {
|
|
562
|
+
setModal({
|
|
563
|
+
id: "ShopperIsNotAuthenticated",
|
|
564
|
+
open: true
|
|
565
|
+
});
|
|
566
|
+
return;
|
|
567
|
+
}
|
|
568
|
+
onChange();
|
|
567
569
|
};
|
|
568
570
|
return /* @__PURE__ */ jsxs6(
|
|
569
571
|
"label",
|
|
@@ -574,7 +576,6 @@ function Item({ data, onChange, checked }) {
|
|
|
574
576
|
{ "cursor-not-allowed": state === "isPreview", "cursor-pointer": state === "isActivated" }
|
|
575
577
|
),
|
|
576
578
|
id: "label_benefits_" + ID_INPUT,
|
|
577
|
-
onClick: CheckUserIsAuthenticated,
|
|
578
579
|
children: [
|
|
579
580
|
/* @__PURE__ */ jsx9(
|
|
580
581
|
"input",
|
|
@@ -584,7 +585,7 @@ function Item({ data, onChange, checked }) {
|
|
|
584
585
|
id: ID_INPUT,
|
|
585
586
|
className: "hidden",
|
|
586
587
|
checked,
|
|
587
|
-
onChange,
|
|
588
|
+
onChange: handleChange,
|
|
588
589
|
disabled: state === "isPreview"
|
|
589
590
|
}
|
|
590
591
|
),
|
|
@@ -647,9 +648,9 @@ var CheckBenefistWithoutDocument = async ({ products }) => {
|
|
|
647
648
|
import { Fragment as Fragment3, jsx as jsx10, jsxs as jsxs7 } from "react/jsx-runtime";
|
|
648
649
|
function BenefitsTable() {
|
|
649
650
|
const { securityNumber, setState, state, targetProduct, customLoginUrl, isAuthenticatedShopper } = usePBMStore();
|
|
650
|
-
const [selectedDiscout, setSelectedDiscount] =
|
|
651
|
-
const [loading, setLoading] =
|
|
652
|
-
const [benefitsItems, setBenefitsItems] =
|
|
651
|
+
const [selectedDiscout, setSelectedDiscount] = useState2(null);
|
|
652
|
+
const [loading, setLoading] = useState2(true);
|
|
653
|
+
const [benefitsItems, setBenefitsItems] = useState2();
|
|
653
654
|
useEffect2(() => {
|
|
654
655
|
const fetchDicountsWithoutDocument = async () => {
|
|
655
656
|
if (!targetProduct?.productId) {
|
|
@@ -765,6 +766,7 @@ function BenefitsTable() {
|
|
|
765
766
|
{
|
|
766
767
|
className: "flex flex-col items-center justify-start w-full gap-4.5",
|
|
767
768
|
id: "form_benefits_table_pbm",
|
|
769
|
+
onSubmit: (e) => e.preventDefault(),
|
|
768
770
|
children: [
|
|
769
771
|
!benefitsItems && /* @__PURE__ */ jsx10("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." }),
|
|
770
772
|
benefitsItems && benefitsItems.map((item, index) => {
|
|
@@ -905,7 +907,7 @@ function SecurityNumberInvalid({ textColor }) {
|
|
|
905
907
|
var SecurityNumberInvalid_default = SecurityNumberInvalid;
|
|
906
908
|
|
|
907
909
|
// src/PBM.tsx
|
|
908
|
-
import { useCallback as
|
|
910
|
+
import { useCallback as useCallback2, useEffect as useEffect3, useState as useState3 } from "react";
|
|
909
911
|
|
|
910
912
|
// src/components/SecurityNumberRegitered/index.tsx
|
|
911
913
|
import { jsx as jsx14, jsxs as jsxs9 } from "react/jsx-runtime";
|
|
@@ -1024,9 +1026,6 @@ var Modal = ({ ID }) => {
|
|
|
1024
1026
|
};
|
|
1025
1027
|
var Modal_default = Modal;
|
|
1026
1028
|
|
|
1027
|
-
// src/hooks/useValidateProduct.tsx
|
|
1028
|
-
import { useCallback as useCallback2, useEffect as useEffect3, useState as useState4 } from "react";
|
|
1029
|
-
|
|
1030
1029
|
// src/services/get-list-products.ts
|
|
1031
1030
|
import Cookies5 from "js-cookie";
|
|
1032
1031
|
var GetProductsWithBenefits = async () => {
|
|
@@ -1049,33 +1048,8 @@ var GetProductsWithBenefits = async () => {
|
|
|
1049
1048
|
return dataResponse;
|
|
1050
1049
|
};
|
|
1051
1050
|
|
|
1052
|
-
// src/hooks/useValidateProduct.tsx
|
|
1053
|
-
function useValidateProduct({ eanProduct }) {
|
|
1054
|
-
const [IsValid, setIsValid] = useState4(false);
|
|
1055
|
-
const [Loading2, setLoading] = useState4(true);
|
|
1056
|
-
const [Error2, setError] = useState4();
|
|
1057
|
-
const fetchValidateProduct = useCallback2(async () => {
|
|
1058
|
-
try {
|
|
1059
|
-
const response = await GetProductsWithBenefits();
|
|
1060
|
-
if (response.success) {
|
|
1061
|
-
const data = response.data;
|
|
1062
|
-
const hasProductInList = data.some((product) => product.ean == eanProduct);
|
|
1063
|
-
setIsValid(hasProductInList);
|
|
1064
|
-
}
|
|
1065
|
-
} catch (error) {
|
|
1066
|
-
setError(error);
|
|
1067
|
-
console.error(error);
|
|
1068
|
-
} finally {
|
|
1069
|
-
}
|
|
1070
|
-
}, []);
|
|
1071
|
-
useEffect3(() => {
|
|
1072
|
-
fetchValidateProduct();
|
|
1073
|
-
}, [fetchValidateProduct]);
|
|
1074
|
-
return { IsValid, Loading: Loading2, Error: Error2 };
|
|
1075
|
-
}
|
|
1076
|
-
|
|
1077
1051
|
// src/PBM.tsx
|
|
1078
|
-
import { jsx as jsx16, jsxs as jsxs11 } from "react/jsx-runtime";
|
|
1052
|
+
import { Fragment as Fragment4, jsx as jsx16, jsxs as jsxs11 } from "react/jsx-runtime";
|
|
1079
1053
|
function PBM({
|
|
1080
1054
|
originalProductPrice,
|
|
1081
1055
|
clientID,
|
|
@@ -1086,13 +1060,26 @@ function PBM({
|
|
|
1086
1060
|
const formatedOriginalProductPrice = Number(
|
|
1087
1061
|
String(originalProductPrice).replace(",", ".")
|
|
1088
1062
|
);
|
|
1089
|
-
const [isReady, setIsReady] =
|
|
1090
|
-
const [loading, setLoading] =
|
|
1063
|
+
const [isReady, setIsReady] = useState3(false);
|
|
1064
|
+
const [loading, setLoading] = useState3(false);
|
|
1091
1065
|
const { state, setTargetProduct, targetProduct, setIsAuthenticatedShopper, setCustomLoginUrl } = usePBMStore();
|
|
1092
|
-
const [EanProductExist, setEanProductExist] =
|
|
1093
|
-
const
|
|
1066
|
+
const [EanProductExist, setEanProductExist] = useState3(true);
|
|
1067
|
+
const [IsValid, setIsValid] = useState3(false);
|
|
1068
|
+
const fetchValidateProduct = useCallback2(async () => {
|
|
1069
|
+
try {
|
|
1070
|
+
const response = await GetProductsWithBenefits();
|
|
1071
|
+
if (response.success) {
|
|
1072
|
+
const data = response.data;
|
|
1073
|
+
const hasProductInList = data.some((product) => product.ean == eanProduct);
|
|
1074
|
+
setIsValid(hasProductInList);
|
|
1075
|
+
}
|
|
1076
|
+
} catch (error) {
|
|
1077
|
+
console.error(error);
|
|
1078
|
+
}
|
|
1079
|
+
}, [eanProduct, IsValid]);
|
|
1094
1080
|
const fetchProductByEan = async () => {
|
|
1095
1081
|
try {
|
|
1082
|
+
if (!IsValid) return;
|
|
1096
1083
|
if (!eanProduct) {
|
|
1097
1084
|
console.error("PBMLOG: Ean is not defined.");
|
|
1098
1085
|
setEanProductExist(false);
|
|
@@ -1120,10 +1107,11 @@ function PBM({
|
|
|
1120
1107
|
setIsReady(true);
|
|
1121
1108
|
}
|
|
1122
1109
|
};
|
|
1123
|
-
const handleAuthorizationRequest =
|
|
1110
|
+
const handleAuthorizationRequest = useCallback2(async () => {
|
|
1124
1111
|
try {
|
|
1125
1112
|
const response = await GetAuthorization({ clientID });
|
|
1126
|
-
if (response.success
|
|
1113
|
+
if (response.success) {
|
|
1114
|
+
fetchValidateProduct();
|
|
1127
1115
|
fetchProductByEan();
|
|
1128
1116
|
} else {
|
|
1129
1117
|
console.error("PBMLOG: Authorization failed!");
|
|
@@ -1132,7 +1120,7 @@ function PBM({
|
|
|
1132
1120
|
console.error("Error fetching authorization:", error);
|
|
1133
1121
|
}
|
|
1134
1122
|
}, [clientID, IsValid]);
|
|
1135
|
-
|
|
1123
|
+
useEffect3(() => {
|
|
1136
1124
|
handleAuthorizationRequest();
|
|
1137
1125
|
}, [handleAuthorizationRequest]);
|
|
1138
1126
|
if (!isReady) {
|
|
@@ -1163,21 +1151,15 @@ function PBM({
|
|
|
1163
1151
|
if (!IsValid) {
|
|
1164
1152
|
return;
|
|
1165
1153
|
}
|
|
1166
|
-
const RenderStateComponent = () => {
|
|
1167
|
-
const StateMap = {
|
|
1168
|
-
"isEmpty": /* @__PURE__ */ jsx16(Form_default, { setLoading }),
|
|
1169
|
-
"isInvalid": /* @__PURE__ */ jsx16(SecurityNumberInvalid_default, {}),
|
|
1170
|
-
"isRegistered": /* @__PURE__ */ jsx16(SecurityNumberRegitered_default, {}),
|
|
1171
|
-
"isActivated": /* @__PURE__ */ jsx16(BenefitsTable_default, {}),
|
|
1172
|
-
"isPreview": /* @__PURE__ */ jsx16(BenefitsTable_default, {})
|
|
1173
|
-
};
|
|
1174
|
-
if (!loading) return StateMap[state];
|
|
1175
|
-
else return /* @__PURE__ */ jsx16(Loading_default, {});
|
|
1176
|
-
};
|
|
1177
1154
|
return /* @__PURE__ */ jsxs11("div", { id: "pbm-library-root", children: [
|
|
1178
1155
|
/* @__PURE__ */ jsxs11(Container_default, { variant: "main", children: [
|
|
1179
1156
|
/* @__PURE__ */ jsx16(Header_default, { originalProductPrice: formatedOriginalProductPrice || 0 }),
|
|
1180
|
-
/* @__PURE__ */ jsx16(Container_default, { variant: "simple", children: /* @__PURE__ */ jsx16(
|
|
1157
|
+
/* @__PURE__ */ jsx16(Container_default, { variant: "simple", children: loading ? /* @__PURE__ */ jsx16(Loading_default, {}) : /* @__PURE__ */ jsxs11(Fragment4, { children: [
|
|
1158
|
+
state === "isEmpty" && /* @__PURE__ */ jsx16(Form_default, { setLoading }),
|
|
1159
|
+
state === "isInvalid" && /* @__PURE__ */ jsx16(SecurityNumberInvalid_default, {}),
|
|
1160
|
+
state === "isRegistered" && /* @__PURE__ */ jsx16(SecurityNumberRegitered_default, {}),
|
|
1161
|
+
(state === "isActivated" || state === "isPreview") && /* @__PURE__ */ jsx16(BenefitsTable_default, {})
|
|
1162
|
+
] }) }),
|
|
1181
1163
|
/* @__PURE__ */ jsx16(Footer_default, {})
|
|
1182
1164
|
] }),
|
|
1183
1165
|
/* @__PURE__ */ jsx16(Modal_default, { ID: "ShopperIsNotAuthenticated" })
|