@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.mjs CHANGED
@@ -212,7 +212,7 @@ import { useState as useState2 } from "react";
212
212
 
213
213
  // src/services/benefits-with-document.ts
214
214
  import Cookies2 from "js-cookie";
215
- var BenefitsWithDocument = async ({ document: document2, products }) => {
215
+ var BenefitsWithDocument = async ({ document, products }) => {
216
216
  const API_URL = import.meta.env.VITE_API_URL;
217
217
  if (!API_URL) {
218
218
  throw new Error("API URL is not defined in environment variables");
@@ -227,7 +227,7 @@ var BenefitsWithDocument = async ({ document: document2, products }) => {
227
227
  Authorization: `Bearer ${AUTH_TOKEN}`,
228
228
  "Content-Type": "application/json"
229
229
  },
230
- body: JSON.stringify({ consumer: { document: document2 }, products })
230
+ body: JSON.stringify({ consumer: { document }, products })
231
231
  });
232
232
  const dataResponse = await response.json();
233
233
  if (!dataResponse.success) {
@@ -644,7 +644,46 @@ function BenefitsTable() {
644
644
  }
645
645
  };
646
646
  const fetchDiscountWithDocument = async () => {
647
- console.log("consulta feita com documento");
647
+ if (!securityNumber) {
648
+ console.error("PBMLOG: Document is not defined");
649
+ return;
650
+ }
651
+ if (!targetProduct?.productId) {
652
+ console.error("PBMLOG: Product ID is not defined on targetProduct");
653
+ return;
654
+ }
655
+ if (!targetProduct.ean) {
656
+ console.error("PBMLOG: EAN is not defined on targetProduct");
657
+ return;
658
+ }
659
+ if (!targetProduct.listPrice) {
660
+ console.error("PBMLOG: List Price is not defined on targetProduct");
661
+ return;
662
+ }
663
+ if (!targetProduct.price) {
664
+ console.error("PBMLOG: Price is not defined on targetProduct");
665
+ return;
666
+ }
667
+ try {
668
+ const data = {
669
+ productId: Number(targetProduct.productId),
670
+ ean: targetProduct.ean,
671
+ requestedQuantity: 1,
672
+ listPrice: targetProduct.listPrice,
673
+ netPrice: targetProduct.price
674
+ };
675
+ const response = await BenefitsWithDocument({ document: securityNumber, products: [data] });
676
+ if (response.success && response.data) {
677
+ setBenefitsItems(response.data.product);
678
+ } else {
679
+ setBenefitsItems(void 0);
680
+ }
681
+ } catch (error) {
682
+ setBenefitsItems(void 0);
683
+ console.error(error);
684
+ } finally {
685
+ setLoading(false);
686
+ }
648
687
  };
649
688
  securityNumber ? fetchDiscountWithDocument() : fetchDicountsWithoutDocument();
650
689
  }, []);
@@ -746,129 +785,41 @@ function Text(props) {
746
785
  }
747
786
  var Text_default = Text;
748
787
 
749
- // src/components/Iframe/index.tsx
788
+ // src/components/UI/Link/index.tsx
750
789
  import classNames7 from "classnames";
751
- import { TriangleAlert, ExternalLink } from "lucide-react";
752
- import { useState as useState4, useEffect as useEffect4 } from "react";
753
- import { jsx as jsx11, jsxs as jsxs7 } from "react/jsx-runtime";
754
- function Iframe({ url, title, openModal, setOpenModal }) {
755
- const [_, setIframeError] = useState4(false);
756
- const [showFallback, setShowFallback] = useState4(false);
757
- useEffect4(() => {
758
- if (openModal && url) {
759
- setIframeError(false);
760
- setShowFallback(false);
761
- const timeout = setTimeout(() => {
762
- const iframe = document.querySelector('iframe[src="' + url + '"]');
763
- if (iframe) {
764
- try {
765
- const iframeDoc = iframe.contentDocument || iframe.contentWindow?.document;
766
- if (!iframeDoc) {
767
- setIframeError(true);
768
- setShowFallback(true);
769
- }
770
- } catch (e) {
771
- setIframeError(true);
772
- setShowFallback(true);
773
- }
774
- }
775
- }, 2e3);
776
- return () => clearTimeout(timeout);
777
- }
778
- }, [openModal, url]);
779
- const handleOpenInNewWindow = () => {
780
- if (url) {
781
- window.open(url, "_blank", "noopener,noreferrer");
782
- }
783
- };
784
- return /* @__PURE__ */ jsxs7(
785
- "main",
790
+
791
+ // src/utils/getParams.ts
792
+ var getParams = (params) => {
793
+ if (params === void 0) return "";
794
+ return "?" + Object.keys(params).map((paramter) => paramter + "=" + params[paramter]).join("&");
795
+ };
796
+
797
+ // src/components/UI/Link/index.tsx
798
+ import { jsx as jsx11 } from "react/jsx-runtime";
799
+ function Link(props) {
800
+ return /* @__PURE__ */ jsx11(
801
+ "a",
786
802
  {
803
+ ...props,
804
+ target: "_blank",
805
+ href: typeof props.href === "string" ? props.href : props.href.pathname + getParams(props.href.param),
787
806
  className: classNames7(
788
- "fixed inset-0 flex items-center justify-center z-50 flex-col transition-all shadow",
789
- {
790
- "opacity-100 pointer-events-auto": openModal,
791
- "opacity-0 pointer-events-none": !openModal
792
- }
807
+ "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",
808
+ props.className
793
809
  ),
794
- "data-testid": "test_id_iframe",
795
- id: "iframe_pbm",
796
- children: [
797
- /* @__PURE__ */ jsx11(
798
- "div",
799
- {
800
- className: "bg-black/35 inset-0 absolute",
801
- onClick: () => {
802
- setOpenModal(false);
803
- window.location.reload();
804
- }
805
- }
806
- ),
807
- /* @__PURE__ */ jsx11("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__ */ jsx11(
808
- "button",
809
- {
810
- className: "shadow-2xl cursor-pointer text-white font-bold bg-red-500 w-auto h-auto px-8 py-2 rounded-full",
811
- "aria-label": "Fechar o modal",
812
- "data-testid": "test_id_buttonclose",
813
- onClick: () => {
814
- setOpenModal(false);
815
- window.location.reload();
816
- },
817
- children: "Fechar"
818
- }
819
- ) }),
820
- showFallback ? /* @__PURE__ */ jsxs7("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: [
821
- /* @__PURE__ */ jsx11(TriangleAlert, { size: 48, className: "text-yellow-500 mb-4" }),
822
- /* @__PURE__ */ jsx11("h3", { className: "text-white text-xl font-bold mb-4 text-center", children: "N\xE3o foi poss\xEDvel carregar o conte\xFAdo" }),
823
- /* @__PURE__ */ jsx11("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." }),
824
- /* @__PURE__ */ jsxs7(
825
- "button",
826
- {
827
- onClick: handleOpenInNewWindow,
828
- 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",
829
- children: [
830
- /* @__PURE__ */ jsx11(ExternalLink, { size: 20 }),
831
- "Abrir em nova janela"
832
- ]
833
- }
834
- )
835
- ] }) : /* @__PURE__ */ jsx11(
836
- "iframe",
837
- {
838
- src: url,
839
- title,
840
- width: "80%",
841
- height: "80%",
842
- allowFullScreen: true,
843
- className: "z-10",
844
- onError: () => {
845
- setIframeError(true);
846
- setShowFallback(true);
847
- }
848
- }
849
- ),
850
- /* @__PURE__ */ jsxs7("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: [
851
- /* @__PURE__ */ jsx11(TriangleAlert, { size: 20, className: "shrink-0 text-red-500 " }),
852
- /* @__PURE__ */ jsxs7("p", { className: "text-start text-sm text-white", children: [
853
- /* @__PURE__ */ jsx11("span", { className: "text-red-500 font-semibold text-base mr-1", children: "Aten\xE7\xE3o:" }),
854
- "Ap\xF3s finalizar os termos de aceite, voc\xEA j\xE1 poder\xE1 fechar essa janela. Pode levar ",
855
- /* @__PURE__ */ jsx11("strong", { children: "alguns minutos" }),
856
- " para os seus dados serem aprovados."
857
- ] })
858
- ] })
859
- ]
810
+ "data-testid": "test_id_link",
811
+ id: "link_pbm",
812
+ children: props.children
860
813
  }
861
814
  );
862
815
  }
863
- var Iframe_default = Iframe;
816
+ var Link_default = Link;
864
817
 
865
818
  // src/components/SecurityNumberInvalid/index.tsx
866
- import { useState as useState5 } from "react";
867
- import { jsx as jsx12, jsxs as jsxs8 } from "react/jsx-runtime";
819
+ import { jsx as jsx12, jsxs as jsxs7 } from "react/jsx-runtime";
868
820
  function SecurityNumberInvalid({ textColor }) {
869
- const [openModal, setOpenModal] = useState5(false);
870
821
  const { urlAcceptTerms } = usePBMStore();
871
- return /* @__PURE__ */ jsxs8(
822
+ return /* @__PURE__ */ jsxs7(
872
823
  "section",
873
824
  {
874
825
  "data-testid": "test_id_invalid",
@@ -878,22 +829,11 @@ function SecurityNumberInvalid({ textColor }) {
878
829
  /* @__PURE__ */ jsx12(Title_default, { className: "w-full", textColor, children: "CPF n\xE3o cadastrado!" }),
879
830
  /* @__PURE__ */ jsx12(Text_default, { className: "w-full", textColor, children: "Por favor, conclua seu cadastro para habilitar os benef\xEDcios deste laborat\xF3rio." }),
880
831
  /* @__PURE__ */ jsx12(
881
- Button_default,
832
+ Link_default,
882
833
  {
883
- "data-testid": "test_id_openiframe",
884
- onClick: () => setOpenModal(true),
885
- id: "button_accept_terms_pbm",
834
+ href: urlAcceptTerms || "",
886
835
  children: "Aceitar os termos"
887
836
  }
888
- ),
889
- /* @__PURE__ */ jsx12(
890
- Iframe_default,
891
- {
892
- url: urlAcceptTerms || "",
893
- title: "Aceitar termos PBM",
894
- openModal,
895
- setOpenModal
896
- }
897
837
  )
898
838
  ]
899
839
  }
@@ -902,52 +842,22 @@ function SecurityNumberInvalid({ textColor }) {
902
842
  var SecurityNumberInvalid_default = SecurityNumberInvalid;
903
843
 
904
844
  // src/PBM.tsx
905
- import { useCallback as useCallback2, useEffect as useEffect5, useState as useState6 } from "react";
906
-
907
- // src/components/UI/Link/index.tsx
908
- import classNames8 from "classnames";
909
-
910
- // src/utils/getParams.ts
911
- var getParams = (params) => {
912
- if (params === void 0) return "";
913
- return "?" + Object.keys(params).map((paramter) => paramter + "=" + params[paramter]).join("&");
914
- };
915
-
916
- // src/components/UI/Link/index.tsx
917
- import { jsx as jsx13 } from "react/jsx-runtime";
918
- function Link(props) {
919
- return /* @__PURE__ */ jsx13(
920
- "a",
921
- {
922
- ...props,
923
- target: "_blank",
924
- href: typeof props.href === "string" ? props.href : props.href.pathname + getParams(props.href.param),
925
- className: classNames8(
926
- "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",
927
- props.className
928
- ),
929
- "data-testid": "test_id_link",
930
- id: "link_pbm",
931
- children: props.children
932
- }
933
- );
934
- }
935
- var Link_default = Link;
845
+ import { useCallback as useCallback2, useEffect as useEffect4, useState as useState4 } from "react";
936
846
 
937
847
  // src/components/SecurityNumberRegitered/index.tsx
938
- import { jsx as jsx14, jsxs as jsxs9 } from "react/jsx-runtime";
848
+ import { jsx as jsx13, jsxs as jsxs8 } from "react/jsx-runtime";
939
849
  function SecurityNumberRegitered({ textColor }) {
940
850
  const { urlRegisterIndustry } = usePBMStore();
941
- return /* @__PURE__ */ jsxs9(
851
+ return /* @__PURE__ */ jsxs8(
942
852
  "section",
943
853
  {
944
854
  "data-testid": "test_id_registered",
945
855
  className: "flex items-end justify-center gap-2 w-full h-auto flex-col border-y border-zinc-300 py-6",
946
856
  id: "security_number_registered_container_pbm",
947
857
  children: [
948
- /* @__PURE__ */ jsx14(Title_default, { className: "w-full", textColor, children: "CPF n\xE3o habilitado no produto!" }),
949
- /* @__PURE__ */ jsx14(Text_default, { className: "w-full", textColor, children: "Por favor, conclua seu cadastro para habilitar os benef\xEDcios deste laborat\xF3rio." }),
950
- /* @__PURE__ */ jsx14(
858
+ /* @__PURE__ */ jsx13(Title_default, { className: "w-full", textColor, children: "CPF n\xE3o habilitado no produto!" }),
859
+ /* @__PURE__ */ jsx13(Text_default, { className: "w-full", textColor, children: "Por favor, conclua seu cadastro para habilitar os benef\xEDcios deste laborat\xF3rio." }),
860
+ /* @__PURE__ */ jsx13(
951
861
  Link_default,
952
862
  {
953
863
  href: urlRegisterIndustry || "",
@@ -1002,7 +912,7 @@ var GetAuthorization = async ({ clientID }) => {
1002
912
 
1003
913
  // src/PBM.tsx
1004
914
  import { ArrowRight as ArrowRight2 } from "lucide-react";
1005
- import { Fragment as Fragment2, jsx as jsx15, jsxs as jsxs10 } from "react/jsx-runtime";
915
+ import { Fragment as Fragment2, jsx as jsx14, jsxs as jsxs9 } from "react/jsx-runtime";
1006
916
  function PBM({
1007
917
  originalProductPrice,
1008
918
  clientID,
@@ -1011,9 +921,9 @@ function PBM({
1011
921
  const formatedOriginalProductPrice = Number(
1012
922
  String(originalProductPrice).replace(",", ".")
1013
923
  );
1014
- const [loading, setLoading] = useState6(false);
924
+ const [loading, setLoading] = useState4(false);
1015
925
  const { setState, state, setTargetProduct } = usePBMStore();
1016
- useEffect5(() => {
926
+ useEffect4(() => {
1017
927
  if (eanProduct) {
1018
928
  setTargetProduct({ ean: eanProduct });
1019
929
  }
@@ -1028,33 +938,33 @@ function PBM({
1028
938
  console.error("Error fetching authorization:", error);
1029
939
  }
1030
940
  }, [clientID]);
1031
- useEffect5(() => {
941
+ useEffect4(() => {
1032
942
  handleAuthorizationRequest();
1033
943
  }, [handleAuthorizationRequest]);
1034
- return /* @__PURE__ */ jsx15("div", { id: "pbm-library-root", children: /* @__PURE__ */ jsxs10(Container_default, { variant: "main", children: [
1035
- /* @__PURE__ */ jsx15(Header_default, { originalProductPrice: formatedOriginalProductPrice || 0 }),
1036
- /* @__PURE__ */ jsxs10(Container_default, { variant: "simple", children: [
1037
- state === "isEmpty" && !loading && /* @__PURE__ */ jsxs10(Fragment2, { children: [
1038
- /* @__PURE__ */ jsx15(Form_default, { setLoading }),
1039
- /* @__PURE__ */ jsxs10(
944
+ return /* @__PURE__ */ jsx14("div", { id: "pbm-library-root", children: /* @__PURE__ */ jsxs9(Container_default, { variant: "main", children: [
945
+ /* @__PURE__ */ jsx14(Header_default, { originalProductPrice: formatedOriginalProductPrice || 0 }),
946
+ /* @__PURE__ */ jsxs9(Container_default, { variant: "simple", children: [
947
+ state === "isEmpty" && !loading && /* @__PURE__ */ jsxs9(Fragment2, { children: [
948
+ /* @__PURE__ */ jsx14(Form_default, { setLoading }),
949
+ /* @__PURE__ */ jsxs9(
1040
950
  Button_default,
1041
951
  {
1042
952
  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",
1043
953
  onClick: () => setState("isActivated"),
1044
954
  id: "check_benefits_button",
1045
955
  children: [
1046
- /* @__PURE__ */ jsx15("span", { children: "Consultar benef\xEDcios" }),
1047
- /* @__PURE__ */ jsx15(ArrowRight2, { size: 16 })
956
+ /* @__PURE__ */ jsx14("span", { children: "Consultar benef\xEDcios" }),
957
+ /* @__PURE__ */ jsx14(ArrowRight2, { size: 16 })
1048
958
  ]
1049
959
  }
1050
960
  )
1051
961
  ] }),
1052
- state === "isEmpty" && loading && /* @__PURE__ */ jsx15(Loading_default, {}),
1053
- state === "isInvalid" && !loading && /* @__PURE__ */ jsx15(SecurityNumberInvalid_default, {}),
1054
- state === "isRegistered" && !loading && /* @__PURE__ */ jsx15(SecurityNumberRegitered_default, {}),
1055
- state === "isActivated" && !loading && /* @__PURE__ */ jsx15(BenefitsTable_default, {})
962
+ state === "isEmpty" && loading && /* @__PURE__ */ jsx14(Loading_default, {}),
963
+ state === "isInvalid" && !loading && /* @__PURE__ */ jsx14(SecurityNumberInvalid_default, {}),
964
+ state === "isRegistered" && !loading && /* @__PURE__ */ jsx14(SecurityNumberRegitered_default, {}),
965
+ state === "isActivated" && !loading && /* @__PURE__ */ jsx14(BenefitsTable_default, {})
1056
966
  ] }),
1057
- /* @__PURE__ */ jsx15(Footer_default, {})
967
+ /* @__PURE__ */ jsx14(Footer_default, {})
1058
968
  ] }) });
1059
969
  }
1060
970
  var PBM_default = PBM;