@agrada_digital/pbm 0.0.65 → 0.0.66

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) {
@@ -786,127 +786,39 @@ function Text(props) {
786
786
  }
787
787
  var Text_default = Text;
788
788
 
789
- // src/components/Iframe/index.tsx
789
+ // src/components/UI/Link/index.tsx
790
790
  var import_classnames7 = __toESM(require("classnames"));
791
- var import_lucide_react3 = require("lucide-react");
792
- var import_react6 = require("react");
791
+
792
+ // src/utils/getParams.ts
793
+ var getParams = (params) => {
794
+ if (params === void 0) return "";
795
+ return "?" + Object.keys(params).map((paramter) => paramter + "=" + params[paramter]).join("&");
796
+ };
797
+
798
+ // src/components/UI/Link/index.tsx
793
799
  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",
800
+ function Link(props) {
801
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
802
+ "a",
826
803
  {
804
+ ...props,
805
+ target: "_blank",
806
+ href: typeof props.href === "string" ? props.href : props.href.pathname + getParams(props.href.param),
827
807
  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
- }
808
+ "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",
809
+ props.className
833
810
  ),
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
- ]
811
+ "data-testid": "test_id_link",
812
+ id: "link_pbm",
813
+ children: props.children
900
814
  }
901
815
  );
902
816
  }
903
- var Iframe_default = Iframe;
817
+ var Link_default = Link;
904
818
 
905
819
  // src/components/SecurityNumberInvalid/index.tsx
906
- var import_react7 = require("react");
907
820
  var import_jsx_runtime12 = require("react/jsx-runtime");
908
821
  function SecurityNumberInvalid({ textColor }) {
909
- const [openModal, setOpenModal] = (0, import_react7.useState)(false);
910
822
  const { urlAcceptTerms } = usePBMStore();
911
823
  return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(
912
824
  "section",
@@ -918,22 +830,11 @@ function SecurityNumberInvalid({ textColor }) {
918
830
  /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(Title_default, { className: "w-full", textColor, children: "CPF n\xE3o cadastrado!" }),
919
831
  /* @__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
832
  /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
921
- Button_default,
833
+ Link_default,
922
834
  {
923
- "data-testid": "test_id_openiframe",
924
- onClick: () => setOpenModal(true),
925
- id: "button_accept_terms_pbm",
835
+ href: urlAcceptTerms || "",
926
836
  children: "Aceitar os termos"
927
837
  }
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
838
  )
938
839
  ]
939
840
  }
@@ -942,52 +843,22 @@ function SecurityNumberInvalid({ textColor }) {
942
843
  var SecurityNumberInvalid_default = SecurityNumberInvalid;
943
844
 
944
845
  // 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;
846
+ var import_react6 = require("react");
976
847
 
977
848
  // src/components/SecurityNumberRegitered/index.tsx
978
- var import_jsx_runtime14 = require("react/jsx-runtime");
849
+ var import_jsx_runtime13 = require("react/jsx-runtime");
979
850
  function SecurityNumberRegitered({ textColor }) {
980
851
  const { urlRegisterIndustry } = usePBMStore();
981
- return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(
852
+ return /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(
982
853
  "section",
983
854
  {
984
855
  "data-testid": "test_id_registered",
985
856
  className: "flex items-end justify-center gap-2 w-full h-auto flex-col border-y border-zinc-300 py-6",
986
857
  id: "security_number_registered_container_pbm",
987
858
  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)(
859
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(Title_default, { className: "w-full", textColor, children: "CPF n\xE3o habilitado no produto!" }),
860
+ /* @__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." }),
861
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
991
862
  Link_default,
992
863
  {
993
864
  href: urlRegisterIndustry || "",
@@ -1042,8 +913,8 @@ var GetAuthorization = async ({ clientID }) => {
1042
913
  };
1043
914
 
1044
915
  // src/PBM.tsx
1045
- var import_lucide_react4 = require("lucide-react");
1046
- var import_jsx_runtime15 = require("react/jsx-runtime");
916
+ var import_lucide_react3 = require("lucide-react");
917
+ var import_jsx_runtime14 = require("react/jsx-runtime");
1047
918
  function PBM({
1048
919
  originalProductPrice,
1049
920
  clientID,
@@ -1052,14 +923,14 @@ function PBM({
1052
923
  const formatedOriginalProductPrice = Number(
1053
924
  String(originalProductPrice).replace(",", ".")
1054
925
  );
1055
- const [loading, setLoading] = (0, import_react8.useState)(false);
926
+ const [loading, setLoading] = (0, import_react6.useState)(false);
1056
927
  const { setState, state, setTargetProduct } = usePBMStore();
1057
- (0, import_react8.useEffect)(() => {
928
+ (0, import_react6.useEffect)(() => {
1058
929
  if (eanProduct) {
1059
930
  setTargetProduct({ ean: eanProduct });
1060
931
  }
1061
932
  }, [eanProduct, setTargetProduct]);
1062
- const handleAuthorizationRequest = (0, import_react8.useCallback)(async () => {
933
+ const handleAuthorizationRequest = (0, import_react6.useCallback)(async () => {
1063
934
  try {
1064
935
  const response = await GetAuthorization({ clientID });
1065
936
  if (!response.success) {
@@ -1069,33 +940,33 @@ function PBM({
1069
940
  console.error("Error fetching authorization:", error);
1070
941
  }
1071
942
  }, [clientID]);
1072
- (0, import_react8.useEffect)(() => {
943
+ (0, import_react6.useEffect)(() => {
1073
944
  handleAuthorizationRequest();
1074
945
  }, [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)(
946
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("div", { id: "pbm-library-root", children: /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(Container_default, { variant: "main", children: [
947
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(Header_default, { originalProductPrice: formatedOriginalProductPrice || 0 }),
948
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(Container_default, { variant: "simple", children: [
949
+ state === "isEmpty" && !loading && /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_jsx_runtime14.Fragment, { children: [
950
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(Form_default, { setLoading }),
951
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(
1081
952
  Button_default,
1082
953
  {
1083
954
  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
955
  onClick: () => setState("isActivated"),
1085
956
  id: "check_benefits_button",
1086
957
  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 })
958
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("span", { children: "Consultar benef\xEDcios" }),
959
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_lucide_react3.ArrowRight, { size: 16 })
1089
960
  ]
1090
961
  }
1091
962
  )
1092
963
  ] }),
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, {})
964
+ state === "isEmpty" && loading && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(Loading_default, {}),
965
+ state === "isInvalid" && !loading && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(SecurityNumberInvalid_default, {}),
966
+ state === "isRegistered" && !loading && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(SecurityNumberRegitered_default, {}),
967
+ state === "isActivated" && !loading && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(BenefitsTable_default, {})
1097
968
  ] }),
1098
- /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(Footer_default, {})
969
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(Footer_default, {})
1099
970
  ] }) });
1100
971
  }
1101
972
  var PBM_default = PBM;