@agrada_digital/pbm 0.0.65 → 0.0.67

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 CHANGED
@@ -251,7 +251,7 @@ var import_react3 = require("react");
251
251
  // src/services/benefits-with-document.ts
252
252
  var import_js_cookie2 = __toESM(require("js-cookie"));
253
253
  var import_meta2 = {};
254
- var BenefitsWithDocument = async ({ document: document2, products }) => {
254
+ var BenefitsWithDocument = async ({ document, products }) => {
255
255
  const API_URL = import_meta2.env.VITE_API_URL;
256
256
  if (!API_URL) {
257
257
  throw new Error("API URL is not defined in environment variables");
@@ -266,7 +266,7 @@ var BenefitsWithDocument = async ({ document: document2, products }) => {
266
266
  Authorization: `Bearer ${AUTH_TOKEN}`,
267
267
  "Content-Type": "application/json"
268
268
  },
269
- body: JSON.stringify({ consumer: { document: document2 }, products })
269
+ body: JSON.stringify({ consumer: { document }, products })
270
270
  });
271
271
  const dataResponse = await response.json();
272
272
  if (!dataResponse.success) {
@@ -684,7 +684,46 @@ function BenefitsTable() {
684
684
  }
685
685
  };
686
686
  const fetchDiscountWithDocument = async () => {
687
- console.log("consulta feita com documento");
687
+ if (!securityNumber) {
688
+ console.error("PBMLOG: Document is not defined");
689
+ return;
690
+ }
691
+ if (!targetProduct?.productId) {
692
+ console.error("PBMLOG: Product ID is not defined on targetProduct");
693
+ return;
694
+ }
695
+ if (!targetProduct.ean) {
696
+ console.error("PBMLOG: EAN is not defined on targetProduct");
697
+ return;
698
+ }
699
+ if (!targetProduct.listPrice) {
700
+ console.error("PBMLOG: List Price is not defined on targetProduct");
701
+ return;
702
+ }
703
+ if (!targetProduct.price) {
704
+ console.error("PBMLOG: Price is not defined on targetProduct");
705
+ return;
706
+ }
707
+ try {
708
+ const data = {
709
+ productId: Number(targetProduct.productId),
710
+ ean: targetProduct.ean,
711
+ requestedQuantity: 1,
712
+ listPrice: targetProduct.listPrice,
713
+ netPrice: targetProduct.price
714
+ };
715
+ const response = await BenefitsWithDocument({ document: securityNumber, products: [data] });
716
+ if (response.success && response.data) {
717
+ setBenefitsItems(response.data.product);
718
+ } else {
719
+ setBenefitsItems(void 0);
720
+ }
721
+ } catch (error) {
722
+ setBenefitsItems(void 0);
723
+ console.error(error);
724
+ } finally {
725
+ setLoading(false);
726
+ }
688
727
  };
689
728
  securityNumber ? fetchDiscountWithDocument() : fetchDicountsWithoutDocument();
690
729
  }, []);
@@ -786,127 +825,39 @@ function Text(props) {
786
825
  }
787
826
  var Text_default = Text;
788
827
 
789
- // src/components/Iframe/index.tsx
828
+ // src/components/UI/Link/index.tsx
790
829
  var import_classnames7 = __toESM(require("classnames"));
791
- var import_lucide_react3 = require("lucide-react");
792
- var import_react6 = require("react");
830
+
831
+ // src/utils/getParams.ts
832
+ var getParams = (params) => {
833
+ if (params === void 0) return "";
834
+ return "?" + Object.keys(params).map((paramter) => paramter + "=" + params[paramter]).join("&");
835
+ };
836
+
837
+ // src/components/UI/Link/index.tsx
793
838
  var import_jsx_runtime11 = require("react/jsx-runtime");
794
- function Iframe({ url, title, openModal, setOpenModal }) {
795
- const [_, setIframeError] = (0, import_react6.useState)(false);
796
- const [showFallback, setShowFallback] = (0, import_react6.useState)(false);
797
- (0, import_react6.useEffect)(() => {
798
- if (openModal && url) {
799
- setIframeError(false);
800
- setShowFallback(false);
801
- const timeout = setTimeout(() => {
802
- const iframe = document.querySelector('iframe[src="' + url + '"]');
803
- if (iframe) {
804
- try {
805
- const iframeDoc = iframe.contentDocument || iframe.contentWindow?.document;
806
- if (!iframeDoc) {
807
- setIframeError(true);
808
- setShowFallback(true);
809
- }
810
- } catch (e) {
811
- setIframeError(true);
812
- setShowFallback(true);
813
- }
814
- }
815
- }, 2e3);
816
- return () => clearTimeout(timeout);
817
- }
818
- }, [openModal, url]);
819
- const handleOpenInNewWindow = () => {
820
- if (url) {
821
- window.open(url, "_blank", "noopener,noreferrer");
822
- }
823
- };
824
- return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(
825
- "main",
839
+ function Link(props) {
840
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
841
+ "a",
826
842
  {
843
+ ...props,
844
+ target: "_blank",
845
+ href: typeof props.href === "string" ? props.href : props.href.pathname + getParams(props.href.param),
827
846
  className: (0, import_classnames7.default)(
828
- "fixed inset-0 flex items-center justify-center z-50 flex-col transition-all shadow",
829
- {
830
- "opacity-100 pointer-events-auto": openModal,
831
- "opacity-0 pointer-events-none": !openModal
832
- }
847
+ "w-3xs cursor-pointer h-10 rounded-full bg-emerald-500 hover:bg-emerald-400 text-white text-sm font-semibold transition-colors flex items-center justify-center",
848
+ props.className
833
849
  ),
834
- "data-testid": "test_id_iframe",
835
- id: "iframe_pbm",
836
- children: [
837
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
838
- "div",
839
- {
840
- className: "bg-black/35 inset-0 absolute",
841
- onClick: () => {
842
- setOpenModal(false);
843
- window.location.reload();
844
- }
845
- }
846
- ),
847
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("section", { className: "w-4/5 h-auto bg-zinc-800 py-2 px-4 flex items-center justify-end rounded-ss-2xl rounded-se-2xl border-b-2 border-gray-100 z-10", children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
848
- "button",
849
- {
850
- className: "shadow-2xl cursor-pointer text-white font-bold bg-red-500 w-auto h-auto px-8 py-2 rounded-full",
851
- "aria-label": "Fechar o modal",
852
- "data-testid": "test_id_buttonclose",
853
- onClick: () => {
854
- setOpenModal(false);
855
- window.location.reload();
856
- },
857
- children: "Fechar"
858
- }
859
- ) }),
860
- 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: [
861
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_lucide_react3.TriangleAlert, { size: 48, className: "text-yellow-500 mb-4" }),
862
- /* @__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" }),
863
- /* @__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." }),
864
- /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(
865
- "button",
866
- {
867
- onClick: handleOpenInNewWindow,
868
- 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",
869
- children: [
870
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_lucide_react3.ExternalLink, { size: 20 }),
871
- "Abrir em nova janela"
872
- ]
873
- }
874
- )
875
- ] }) : /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
876
- "iframe",
877
- {
878
- src: url,
879
- title,
880
- width: "80%",
881
- height: "80%",
882
- allowFullScreen: true,
883
- className: "z-10",
884
- onError: () => {
885
- setIframeError(true);
886
- setShowFallback(true);
887
- }
888
- }
889
- ),
890
- /* @__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: [
891
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_lucide_react3.TriangleAlert, { size: 20, className: "shrink-0 text-red-500 " }),
892
- /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("p", { className: "text-start text-sm text-white", children: [
893
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("span", { className: "text-red-500 font-semibold text-base mr-1", children: "Aten\xE7\xE3o:" }),
894
- "Ap\xF3s finalizar os termos de aceite, voc\xEA j\xE1 poder\xE1 fechar essa janela. Pode levar ",
895
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("strong", { children: "alguns minutos" }),
896
- " para os seus dados serem aprovados."
897
- ] })
898
- ] })
899
- ]
850
+ "data-testid": "test_id_link",
851
+ id: "link_pbm",
852
+ children: props.children
900
853
  }
901
854
  );
902
855
  }
903
- var Iframe_default = Iframe;
856
+ var Link_default = Link;
904
857
 
905
858
  // src/components/SecurityNumberInvalid/index.tsx
906
- var import_react7 = require("react");
907
859
  var import_jsx_runtime12 = require("react/jsx-runtime");
908
860
  function SecurityNumberInvalid({ textColor }) {
909
- const [openModal, setOpenModal] = (0, import_react7.useState)(false);
910
861
  const { urlAcceptTerms } = usePBMStore();
911
862
  return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(
912
863
  "section",
@@ -918,22 +869,11 @@ function SecurityNumberInvalid({ textColor }) {
918
869
  /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(Title_default, { className: "w-full", textColor, children: "CPF n\xE3o cadastrado!" }),
919
870
  /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(Text_default, { className: "w-full", textColor, children: "Por favor, conclua seu cadastro para habilitar os benef\xEDcios deste laborat\xF3rio." }),
920
871
  /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
921
- Button_default,
872
+ Link_default,
922
873
  {
923
- "data-testid": "test_id_openiframe",
924
- onClick: () => setOpenModal(true),
925
- id: "button_accept_terms_pbm",
874
+ href: urlAcceptTerms || "",
926
875
  children: "Aceitar os termos"
927
876
  }
928
- ),
929
- /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
930
- Iframe_default,
931
- {
932
- url: urlAcceptTerms || "",
933
- title: "Aceitar termos PBM",
934
- openModal,
935
- setOpenModal
936
- }
937
877
  )
938
878
  ]
939
879
  }
@@ -942,52 +882,22 @@ function SecurityNumberInvalid({ textColor }) {
942
882
  var SecurityNumberInvalid_default = SecurityNumberInvalid;
943
883
 
944
884
  // src/PBM.tsx
945
- var import_react8 = require("react");
946
-
947
- // src/components/UI/Link/index.tsx
948
- var import_classnames8 = __toESM(require("classnames"));
949
-
950
- // src/utils/getParams.ts
951
- var getParams = (params) => {
952
- if (params === void 0) return "";
953
- return "?" + Object.keys(params).map((paramter) => paramter + "=" + params[paramter]).join("&");
954
- };
955
-
956
- // src/components/UI/Link/index.tsx
957
- var import_jsx_runtime13 = require("react/jsx-runtime");
958
- function Link(props) {
959
- return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
960
- "a",
961
- {
962
- ...props,
963
- target: "_blank",
964
- href: typeof props.href === "string" ? props.href : props.href.pathname + getParams(props.href.param),
965
- className: (0, import_classnames8.default)(
966
- "w-3xs cursor-pointer h-10 rounded-full bg-emerald-500 hover:bg-emerald-400 text-white text-sm font-semibold transition-colors flex items-center justify-center",
967
- props.className
968
- ),
969
- "data-testid": "test_id_link",
970
- id: "link_pbm",
971
- children: props.children
972
- }
973
- );
974
- }
975
- var Link_default = Link;
885
+ var import_react6 = require("react");
976
886
 
977
887
  // src/components/SecurityNumberRegitered/index.tsx
978
- var import_jsx_runtime14 = require("react/jsx-runtime");
888
+ var import_jsx_runtime13 = require("react/jsx-runtime");
979
889
  function SecurityNumberRegitered({ textColor }) {
980
890
  const { urlRegisterIndustry } = usePBMStore();
981
- return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(
891
+ return /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(
982
892
  "section",
983
893
  {
984
894
  "data-testid": "test_id_registered",
985
895
  className: "flex items-end justify-center gap-2 w-full h-auto flex-col border-y border-zinc-300 py-6",
986
896
  id: "security_number_registered_container_pbm",
987
897
  children: [
988
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(Title_default, { className: "w-full", textColor, children: "CPF n\xE3o habilitado no produto!" }),
989
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(Text_default, { className: "w-full", textColor, children: "Por favor, conclua seu cadastro para habilitar os benef\xEDcios deste laborat\xF3rio." }),
990
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
898
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(Title_default, { className: "w-full", textColor, children: "CPF n\xE3o habilitado no produto!" }),
899
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(Text_default, { className: "w-full", textColor, children: "Por favor, conclua seu cadastro para habilitar os benef\xEDcios deste laborat\xF3rio." }),
900
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
991
901
  Link_default,
992
902
  {
993
903
  href: urlRegisterIndustry || "",
@@ -1042,8 +952,8 @@ var GetAuthorization = async ({ clientID }) => {
1042
952
  };
1043
953
 
1044
954
  // src/PBM.tsx
1045
- var import_lucide_react4 = require("lucide-react");
1046
- var import_jsx_runtime15 = require("react/jsx-runtime");
955
+ var import_lucide_react3 = require("lucide-react");
956
+ var import_jsx_runtime14 = require("react/jsx-runtime");
1047
957
  function PBM({
1048
958
  originalProductPrice,
1049
959
  clientID,
@@ -1052,14 +962,14 @@ function PBM({
1052
962
  const formatedOriginalProductPrice = Number(
1053
963
  String(originalProductPrice).replace(",", ".")
1054
964
  );
1055
- const [loading, setLoading] = (0, import_react8.useState)(false);
965
+ const [loading, setLoading] = (0, import_react6.useState)(false);
1056
966
  const { setState, state, setTargetProduct } = usePBMStore();
1057
- (0, import_react8.useEffect)(() => {
967
+ (0, import_react6.useEffect)(() => {
1058
968
  if (eanProduct) {
1059
969
  setTargetProduct({ ean: eanProduct });
1060
970
  }
1061
971
  }, [eanProduct, setTargetProduct]);
1062
- const handleAuthorizationRequest = (0, import_react8.useCallback)(async () => {
972
+ const handleAuthorizationRequest = (0, import_react6.useCallback)(async () => {
1063
973
  try {
1064
974
  const response = await GetAuthorization({ clientID });
1065
975
  if (!response.success) {
@@ -1069,33 +979,33 @@ function PBM({
1069
979
  console.error("Error fetching authorization:", error);
1070
980
  }
1071
981
  }, [clientID]);
1072
- (0, import_react8.useEffect)(() => {
982
+ (0, import_react6.useEffect)(() => {
1073
983
  handleAuthorizationRequest();
1074
984
  }, [handleAuthorizationRequest]);
1075
- return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("div", { id: "pbm-library-root", children: /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(Container_default, { variant: "main", children: [
1076
- /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(Header_default, { originalProductPrice: formatedOriginalProductPrice || 0 }),
1077
- /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(Container_default, { variant: "simple", children: [
1078
- state === "isEmpty" && !loading && /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(import_jsx_runtime15.Fragment, { children: [
1079
- /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(Form_default, { setLoading }),
1080
- /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(
985
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("div", { id: "pbm-library-root", children: /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(Container_default, { variant: "main", children: [
986
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(Header_default, { originalProductPrice: formatedOriginalProductPrice || 0 }),
987
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(Container_default, { variant: "simple", children: [
988
+ state === "isEmpty" && !loading && /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_jsx_runtime14.Fragment, { children: [
989
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(Form_default, { setLoading }),
990
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(
1081
991
  Button_default,
1082
992
  {
1083
993
  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",
1084
994
  onClick: () => setState("isActivated"),
1085
995
  id: "check_benefits_button",
1086
996
  children: [
1087
- /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("span", { children: "Consultar benef\xEDcios" }),
1088
- /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_lucide_react4.ArrowRight, { size: 16 })
997
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("span", { children: "Consultar benef\xEDcios" }),
998
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_lucide_react3.ArrowRight, { size: 16 })
1089
999
  ]
1090
1000
  }
1091
1001
  )
1092
1002
  ] }),
1093
- state === "isEmpty" && loading && /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(Loading_default, {}),
1094
- state === "isInvalid" && !loading && /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(SecurityNumberInvalid_default, {}),
1095
- state === "isRegistered" && !loading && /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(SecurityNumberRegitered_default, {}),
1096
- state === "isActivated" && !loading && /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(BenefitsTable_default, {})
1003
+ state === "isEmpty" && loading && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(Loading_default, {}),
1004
+ state === "isInvalid" && !loading && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(SecurityNumberInvalid_default, {}),
1005
+ state === "isRegistered" && !loading && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(SecurityNumberRegitered_default, {}),
1006
+ state === "isActivated" && !loading && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(BenefitsTable_default, {})
1097
1007
  ] }),
1098
- /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(Footer_default, {})
1008
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(Footer_default, {})
1099
1009
  ] }) });
1100
1010
  }
1101
1011
  var PBM_default = PBM;