@agrada_digital/pbm 0.0.80 → 0.0.83
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 +7 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.js +88 -29
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +92 -33
- package/dist/index.mjs.map +1 -1
- package/dist-wc/pbm-wc.js +95 -87
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -14,7 +14,9 @@ var initialPBMState = {
|
|
|
14
14
|
grossPrice: 0
|
|
15
15
|
},
|
|
16
16
|
targetProduct: null,
|
|
17
|
-
campaign: "pbm_campaign"
|
|
17
|
+
campaign: "pbm_campaign",
|
|
18
|
+
isAuthenticatedShopper: false,
|
|
19
|
+
customLoginUrl: "/login"
|
|
18
20
|
};
|
|
19
21
|
var createPBMStore = (set) => ({
|
|
20
22
|
...initialPBMState,
|
|
@@ -23,7 +25,9 @@ var createPBMStore = (set) => ({
|
|
|
23
25
|
setTargetProduct: (targetProduct) => set({ targetProduct }),
|
|
24
26
|
setAvailableDiscountSelected: (availableDiscount) => set({ availableDiscountSelected: availableDiscount }),
|
|
25
27
|
setUrlAcceptTerms: (urlAcceptTerms) => set({ urlAcceptTerms }),
|
|
26
|
-
setUrlRegisterIndustry: (urlRegisterIndustry) => set({ urlRegisterIndustry })
|
|
28
|
+
setUrlRegisterIndustry: (urlRegisterIndustry) => set({ urlRegisterIndustry }),
|
|
29
|
+
setIsAuthenticatedShopper: (isAuthenticatedShopper) => set({ isAuthenticatedShopper }),
|
|
30
|
+
setCustomLoginUrl: (customLoginUrl) => set({ customLoginUrl })
|
|
27
31
|
});
|
|
28
32
|
var pbmStore = createStore(createPBMStore);
|
|
29
33
|
function usePBMStore(selector) {
|
|
@@ -56,7 +60,7 @@ function Header({ originalProductPrice }) {
|
|
|
56
60
|
targetProduct?.discountMax,
|
|
57
61
|
"% OFF"
|
|
58
62
|
] }),
|
|
59
|
-
/* @__PURE__ */ jsxs("svg", { width: "
|
|
63
|
+
/* @__PURE__ */ jsxs("svg", { width: "36px", height: "36px", viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: [
|
|
60
64
|
/* @__PURE__ */ jsx("g", { id: "SVGRepo_bgCarrier", strokeWidth: "0" }),
|
|
61
65
|
/* @__PURE__ */ jsx("g", { id: "SVGRepo_tracerCarrier", strokeLinecap: "round", strokeLinejoin: "round" }),
|
|
62
66
|
/* @__PURE__ */ jsxs("g", { id: "SVGRepo_iconCarrier", children: [
|
|
@@ -66,12 +70,20 @@ function Header({ originalProductPrice }) {
|
|
|
66
70
|
/* @__PURE__ */ 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" })
|
|
67
71
|
] })
|
|
68
72
|
] }),
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
73
|
+
/* @__PURE__ */ jsxs("section", { className: "flex flex-col items-start justify-center-safe gap-0", children: [
|
|
74
|
+
/* @__PURE__ */ jsx("span", { className: "line-through text-sm font-light", children: Number(Price)?.toLocaleString("pt-BR", {
|
|
75
|
+
currency: "BRL",
|
|
76
|
+
currencyDisplay: "symbol",
|
|
77
|
+
currencySign: "standard",
|
|
78
|
+
style: "currency"
|
|
79
|
+
}) }),
|
|
80
|
+
Number(Price - Discount)?.toLocaleString("pt-BR", {
|
|
81
|
+
currency: "BRL",
|
|
82
|
+
currencyDisplay: "symbol",
|
|
83
|
+
currencySign: "standard",
|
|
84
|
+
style: "currency"
|
|
85
|
+
})
|
|
86
|
+
] })
|
|
75
87
|
]
|
|
76
88
|
}
|
|
77
89
|
),
|
|
@@ -448,7 +460,7 @@ import { useCallback, useEffect } from "react";
|
|
|
448
460
|
import classNames6 from "classnames";
|
|
449
461
|
import { jsx as jsx8, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
450
462
|
function Item({ data, onChange, checked }) {
|
|
451
|
-
const { setAvailableDiscountSelected,
|
|
463
|
+
const { setAvailableDiscountSelected, state, isAuthenticatedShopper } = usePBMStore();
|
|
452
464
|
const ID_INPUT = "unity_quantity_" + data.authorizedQuantity;
|
|
453
465
|
const decimalDiscount = data.discountPercentual / 100;
|
|
454
466
|
const unitDiscountValue = data.grossPrice * decimalDiscount;
|
|
@@ -484,9 +496,10 @@ function Item({ data, onChange, checked }) {
|
|
|
484
496
|
htmlFor: ID_INPUT,
|
|
485
497
|
className: classNames6(
|
|
486
498
|
"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 rounded-lg gap-1",
|
|
487
|
-
{ "cursor-not-allowed": state === "isPreview", "cursor-pointer": state === "isActivated" }
|
|
499
|
+
{ "cursor-not-allowed": state === "isPreview" || !isAuthenticatedShopper, "cursor-pointer": state === "isActivated" && isAuthenticatedShopper }
|
|
488
500
|
),
|
|
489
501
|
id: "label_benefits_" + ID_INPUT,
|
|
502
|
+
title: !isAuthenticatedShopper ? "Necess\xE1rio fazer login!" : "",
|
|
490
503
|
children: [
|
|
491
504
|
/* @__PURE__ */ jsx8(
|
|
492
505
|
"input",
|
|
@@ -497,7 +510,7 @@ function Item({ data, onChange, checked }) {
|
|
|
497
510
|
className: "hidden",
|
|
498
511
|
checked,
|
|
499
512
|
onChange,
|
|
500
|
-
disabled: state === "isPreview"
|
|
513
|
+
disabled: state === "isPreview" || !isAuthenticatedShopper
|
|
501
514
|
}
|
|
502
515
|
),
|
|
503
516
|
!checked ? /* @__PURE__ */ jsx8(Badge, { color: "#9f9fa9", size: 20 }) : /* @__PURE__ */ jsx8(BadgeCheck, { color: "#32b316", size: 20 }),
|
|
@@ -505,8 +518,8 @@ function Item({ data, onChange, checked }) {
|
|
|
505
518
|
data.authorizedQuantity,
|
|
506
519
|
"un"
|
|
507
520
|
] }),
|
|
508
|
-
/* @__PURE__ */ jsxs5("section", { className: "ml-auto relative", children: [
|
|
509
|
-
/* @__PURE__ */ jsxs5("span", { className: "
|
|
521
|
+
/* @__PURE__ */ jsxs5("section", { className: "ml-auto relative gap-2 flex items-center-safe justify-end-safe", children: [
|
|
522
|
+
/* @__PURE__ */ jsxs5("span", { className: "text-white -top-4 py-0.5 font-semibold text-xs bg-[#32b316] px-2 w-auto text-nowrap rounded-2xl -right-3", children: [
|
|
510
523
|
discountValue.toLocaleString("pt-BR", {
|
|
511
524
|
currency: "BRL",
|
|
512
525
|
currencyDisplay: "symbol",
|
|
@@ -556,9 +569,9 @@ var CheckBenefistWithoutDocument = async ({ products }) => {
|
|
|
556
569
|
};
|
|
557
570
|
|
|
558
571
|
// src/components/BenefitsTable/index.tsx
|
|
559
|
-
import { jsx as jsx9, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
572
|
+
import { Fragment as Fragment2, jsx as jsx9, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
560
573
|
function BenefitsTable() {
|
|
561
|
-
const { securityNumber, setState, state, targetProduct } = usePBMStore();
|
|
574
|
+
const { securityNumber, setState, state, targetProduct, customLoginUrl, isAuthenticatedShopper } = usePBMStore();
|
|
562
575
|
const [selectedDiscout, setSelectedDiscount] = useState2(null);
|
|
563
576
|
const [loading, setLoading] = useState2(true);
|
|
564
577
|
const [benefitsItems, setBenefitsItems] = useState2();
|
|
@@ -702,21 +715,32 @@ function BenefitsTable() {
|
|
|
702
715
|
className: "bg-transparent p-0 w-auto h-auto text-zinc-600 cursor-pointer hover:text-zinc-900 hover:bg-transparent text-start",
|
|
703
716
|
id: "unauthorized_benefits_button",
|
|
704
717
|
children: [
|
|
705
|
-
"Aten\xE7\xE3o:
|
|
718
|
+
"Aten\xE7\xE3o: N\xE3o \xE9 poss\xEDvel utilizar os benef\xEDcos sem realizar a consulta do CPF e o Login, por favor",
|
|
706
719
|
" ",
|
|
707
720
|
/* @__PURE__ */ jsx9("span", { className: "underline", children: "insira seu cpf para utilizar os benef\xEDcios" })
|
|
708
721
|
]
|
|
709
722
|
}
|
|
710
723
|
),
|
|
711
|
-
state === "isActivated" && /* @__PURE__ */
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
724
|
+
state === "isActivated" && /* @__PURE__ */ jsxs6(Fragment2, { children: [
|
|
725
|
+
!isAuthenticatedShopper && /* @__PURE__ */ jsx9(
|
|
726
|
+
Button_default,
|
|
727
|
+
{
|
|
728
|
+
onClick: () => window.location.href = customLoginUrl || "/login",
|
|
729
|
+
className: "bg-transparent p-0 pl-2 w-auto h-auto text-zinc-600 cursor-pointer hover:text-zinc-900 hover:bg-transparent text-start",
|
|
730
|
+
id: "login",
|
|
731
|
+
children: /* @__PURE__ */ jsx9("span", { className: "underline", children: "Por favor, fa\xE7a o Login para aproveitar os benef\xEDcios!" })
|
|
732
|
+
}
|
|
733
|
+
),
|
|
734
|
+
/* @__PURE__ */ jsx9(
|
|
735
|
+
Button_default,
|
|
736
|
+
{
|
|
737
|
+
onClick: () => setState("isEmpty"),
|
|
738
|
+
className: "bg-transparent p-0 pl-2 w-auto h-auto text-zinc-600 cursor-pointer hover:text-zinc-900 hover:bg-transparent text-start",
|
|
739
|
+
id: "change_security_number",
|
|
740
|
+
children: /* @__PURE__ */ jsx9("span", { className: "underline", children: "Deseja editar o cpf digitado?" })
|
|
741
|
+
}
|
|
742
|
+
)
|
|
743
|
+
] })
|
|
720
744
|
]
|
|
721
745
|
}
|
|
722
746
|
);
|
|
@@ -731,10 +755,11 @@ function Text(props) {
|
|
|
731
755
|
"p",
|
|
732
756
|
{
|
|
733
757
|
className: classNames7(
|
|
734
|
-
"
|
|
758
|
+
"font-normal text-sm text-zinc-900",
|
|
759
|
+
props.textAlign && `text-${props.textAlign}`,
|
|
735
760
|
props.className
|
|
736
761
|
),
|
|
737
|
-
style: { color: props.textColor, fontSize: props.textSize },
|
|
762
|
+
style: { color: props.textColor, fontSize: props.textSize, textAlign: props.textAlign },
|
|
738
763
|
"data-testid": "test_id_text",
|
|
739
764
|
id: "text_pbm",
|
|
740
765
|
children: props.children
|
|
@@ -866,7 +891,7 @@ var GetAuthorization = async ({ clientID }) => {
|
|
|
866
891
|
};
|
|
867
892
|
|
|
868
893
|
// src/PBM.tsx
|
|
869
|
-
import { ArrowRight as ArrowRight2 } from "lucide-react";
|
|
894
|
+
import { ArrowRight as ArrowRight2, RefreshCw } from "lucide-react";
|
|
870
895
|
|
|
871
896
|
// src/services/get-product-by-ean.ts
|
|
872
897
|
import Cookies4 from "js-cookie";
|
|
@@ -891,25 +916,31 @@ var GetProductByEAN = async ({ PRODUCT_EAN }) => {
|
|
|
891
916
|
};
|
|
892
917
|
|
|
893
918
|
// src/PBM.tsx
|
|
894
|
-
import { Fragment as
|
|
919
|
+
import { Fragment as Fragment3, jsx as jsx14, jsxs as jsxs9 } from "react/jsx-runtime";
|
|
895
920
|
function PBM({
|
|
896
921
|
originalProductPrice,
|
|
897
922
|
clientID,
|
|
898
|
-
eanProduct
|
|
923
|
+
eanProduct,
|
|
924
|
+
isAuthenticatedShopper,
|
|
925
|
+
customLoginUrl
|
|
899
926
|
}) {
|
|
900
927
|
const formatedOriginalProductPrice = Number(
|
|
901
928
|
String(originalProductPrice).replace(",", ".")
|
|
902
929
|
);
|
|
930
|
+
const [isReady, setIsReady] = useState3(false);
|
|
903
931
|
const [loading, setLoading] = useState3(false);
|
|
904
|
-
const { setState, state, setTargetProduct, targetProduct } = usePBMStore();
|
|
932
|
+
const { setState, state, setTargetProduct, targetProduct, setIsAuthenticatedShopper, setCustomLoginUrl } = usePBMStore();
|
|
933
|
+
const [EanProductExist, setEanProductExist] = useState3(true);
|
|
905
934
|
const fetchProductByEan = async () => {
|
|
906
935
|
try {
|
|
907
936
|
if (!eanProduct) {
|
|
908
937
|
console.error("PBMLOG: Ean is not defined.");
|
|
938
|
+
setEanProductExist(false);
|
|
909
939
|
return;
|
|
910
940
|
}
|
|
911
941
|
const response = await GetProductByEAN({ PRODUCT_EAN: eanProduct });
|
|
912
942
|
if (response.success && response.data) {
|
|
943
|
+
setEanProductExist(true);
|
|
913
944
|
const { pbm, sku, ...targetProductNewData } = response.data;
|
|
914
945
|
setTargetProduct({
|
|
915
946
|
...targetProduct,
|
|
@@ -920,9 +951,12 @@ function PBM({
|
|
|
920
951
|
industryLogo: pbm.imageLink ?? void 0,
|
|
921
952
|
ean: eanProduct
|
|
922
953
|
});
|
|
954
|
+
setIsAuthenticatedShopper(isAuthenticatedShopper);
|
|
955
|
+
setCustomLoginUrl(customLoginUrl);
|
|
923
956
|
}
|
|
924
957
|
} catch (error) {
|
|
925
958
|
console.error(error);
|
|
959
|
+
} finally {
|
|
926
960
|
}
|
|
927
961
|
};
|
|
928
962
|
const handleAuthorizationRequest = useCallback2(async () => {
|
|
@@ -940,10 +974,35 @@ function PBM({
|
|
|
940
974
|
useEffect3(() => {
|
|
941
975
|
handleAuthorizationRequest();
|
|
942
976
|
}, [handleAuthorizationRequest]);
|
|
977
|
+
if (!isReady) {
|
|
978
|
+
return /* @__PURE__ */ jsx14("div", { className: "rounded-xl w-[556px] h-[358px] bg-zinc-500/20 \n shadow-[0_0_15px_rgba(0,0,0,0.1)] \n hover:shadow-[0_0_30px_rgba(0,0,0,0.3)] \n transition-all duration-500 ease-in-out" });
|
|
979
|
+
}
|
|
980
|
+
if (!EanProductExist) {
|
|
981
|
+
return /* @__PURE__ */ jsx14("div", { id: "pbm-library-root", children: /* @__PURE__ */ jsxs9(Container_default, { variant: "main", children: [
|
|
982
|
+
/* @__PURE__ */ jsx14(Title_default, { children: "Erro ao Aplicar o Benef\xEDcio" }),
|
|
983
|
+
/* @__PURE__ */ jsxs9(Text_default, { textAlign: "center", children: [
|
|
984
|
+
"O produto n\xE3o foi encontrado no sistema. ",
|
|
985
|
+
/* @__PURE__ */ jsx14("br", {}),
|
|
986
|
+
" Por favor, tente novamente mais tarde ou contate o suporte."
|
|
987
|
+
] }),
|
|
988
|
+
/* @__PURE__ */ jsxs9(
|
|
989
|
+
Button_default,
|
|
990
|
+
{
|
|
991
|
+
className: "bg-transparent p-0 pl-2 w-auto h-auto text-zinc-600 underline cursor-pointer hover:text-zinc-900 hover:bg-transparent flex items-center justify-start gap-1",
|
|
992
|
+
onClick: () => window.location.reload(),
|
|
993
|
+
id: "check_benefits_button",
|
|
994
|
+
children: [
|
|
995
|
+
/* @__PURE__ */ jsx14("span", { children: "Tentar novamente" }),
|
|
996
|
+
/* @__PURE__ */ jsx14(RefreshCw, { size: 16 })
|
|
997
|
+
]
|
|
998
|
+
}
|
|
999
|
+
)
|
|
1000
|
+
] }) });
|
|
1001
|
+
}
|
|
943
1002
|
return /* @__PURE__ */ jsx14("div", { id: "pbm-library-root", children: /* @__PURE__ */ jsxs9(Container_default, { variant: "main", children: [
|
|
944
1003
|
/* @__PURE__ */ jsx14(Header_default, { originalProductPrice: formatedOriginalProductPrice || 0 }),
|
|
945
1004
|
/* @__PURE__ */ jsxs9(Container_default, { variant: "simple", children: [
|
|
946
|
-
state === "isEmpty" && !loading && /* @__PURE__ */ jsxs9(
|
|
1005
|
+
state === "isEmpty" && !loading && /* @__PURE__ */ jsxs9(Fragment3, { children: [
|
|
947
1006
|
/* @__PURE__ */ jsx14(Form_default, { setLoading }),
|
|
948
1007
|
/* @__PURE__ */ jsxs9(
|
|
949
1008
|
Button_default,
|