@agrada_digital/pbm 0.0.91 → 0.0.92

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
@@ -94,7 +94,7 @@ function Container({
94
94
  "main",
95
95
  {
96
96
  className: classNames({
97
- "border-3 border-[#44c2c0] flex flex-col items-center justify-center min-w-[var(--min-container)] max-w-[var(--max-container)] w-full h-auto rounded-xl p-4 bg-white gap-4 relative": variant === "main",
97
+ "border-3 border-[#44c2c0] flex flex-col items-center justify-center min-w-(--min-container) max-w-(--max-container) w-full h-auto rounded-xl p-4 bg-white gap-4 relative": variant === "main",
98
98
  "w-full h-auto relative": variant === "simple"
99
99
  }),
100
100
  "data-testid": "test_id_container",
@@ -110,7 +110,7 @@ var Container_default = Container;
110
110
  import classNames2 from "classnames";
111
111
  import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
112
112
  function Footer() {
113
- const { targetProduct, state } = usePBMStore();
113
+ const { targetProduct } = usePBMStore();
114
114
  return /* @__PURE__ */ jsx3("footer", { className: "w-full h-auto relative", id: "footer_pbm", children: /* @__PURE__ */ jsxs2("section", { className: classNames2("flex items-center w-full h-auto gap-4", { "justify-center": targetProduct?.industryLogo, "justify-start": !targetProduct?.industryLogo }), children: [
115
115
  /* @__PURE__ */ jsxs2("section", { className: "w-4/5 h-auto", children: [
116
116
  /* @__PURE__ */ jsx3("h3", { className: "text-start font-semibold text-sm", children: "Economize com o benef\xEDcio do laborat\xF3rio." }),
@@ -146,7 +146,7 @@ var validationSchema = z.object({
146
146
  coupon: z.string({ required_error: "Cupom / ID do Cart\xE3o obrigat\xF3rio." }).optional()
147
147
  });
148
148
 
149
- // src/utils/format.ts
149
+ // src/utils/format-security-number.ts
150
150
  var toFormat = (value) => {
151
151
  const cleanedValue = value.replace(/\D/g, "");
152
152
  if (cleanedValue.length <= 11) {
@@ -154,12 +154,15 @@ var toFormat = (value) => {
154
154
  }
155
155
  };
156
156
 
157
- // src/components/Form/index.tsx
158
- import classNames4 from "classnames";
159
- import { zodResolver } from "@hookform/resolvers/zod";
160
- import { useForm } from "react-hook-form";
161
- import { ArrowRight } from "lucide-react";
162
- import { useState } from "react";
157
+ // src/utils/mapping-internal-states.ts
158
+ var mappingInternalStates = (outContextState) => {
159
+ const status = {
160
+ "acceptance": "isInvalid",
161
+ "industry registration": "isRegistered",
162
+ "active": "isActivated"
163
+ };
164
+ return status[outContextState];
165
+ };
163
166
 
164
167
  // src/services/benefits-with-document.ts
165
168
  import Cookies from "js-cookie";
@@ -206,9 +209,14 @@ function Button(props) {
206
209
  var Button_default = Button;
207
210
 
208
211
  // src/components/Form/index.tsx
212
+ import { zodResolver } from "@hookform/resolvers/zod";
213
+ import { useForm } from "react-hook-form";
214
+ import { ArrowRight } from "lucide-react";
215
+ import classNames4 from "classnames";
216
+ import { Activity, useState } from "react";
209
217
  import { Fragment as Fragment2, jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
210
- function Form({ setLoading }) {
211
- const { setSecurityNumber, setState, securityNumber, targetProduct, setUrlAcceptTerms, setUrlRegisterIndustry, setCardID } = usePBMStore();
218
+ function Form({ startTransition }) {
219
+ const store = usePBMStore();
212
220
  const [showCardIDField, setShowCardIDField] = useState(false);
213
221
  const {
214
222
  handleSubmit,
@@ -221,64 +229,62 @@ function Form({ setLoading }) {
221
229
  resolver: zodResolver(validationSchema),
222
230
  mode: "onSubmit",
223
231
  defaultValues: {
224
- securityNumber: securityNumber || "",
232
+ securityNumber: store.securityNumber || "",
225
233
  coupon: ""
226
234
  }
227
235
  });
228
- const onSubmitDefault = async (values) => {
229
- if (!showCardIDField) {
230
- setValue("coupon", void 0, { shouldValidate: false });
231
- }
232
- if (showCardIDField && values.coupon != void 0) {
233
- setCardID(values.coupon);
234
- }
235
- setLoading(true);
236
+ const checkSecurityNumberBenefits = async (values) => {
236
237
  try {
237
- if (targetProduct === null) {
238
+ if (store.targetProduct === null) {
238
239
  console.error("PBMLOG: Product is not defined!");
239
240
  return;
240
241
  }
241
- if (!targetProduct.productId) {
242
+ if (!store.targetProduct.productId) {
242
243
  console.error("PBMLOG: Product ID is not defined!");
243
244
  return;
244
245
  }
245
- if (!targetProduct.listPrice) {
246
+ if (!store.targetProduct.listPrice) {
246
247
  console.error("PBMLOG: List Price is not defined!");
247
248
  return;
248
249
  }
250
+ const product = {
251
+ productId: store.targetProduct.productId,
252
+ ean: store.targetProduct.ean,
253
+ requestedQuantity: 1,
254
+ listPrice: store.targetProduct.listPrice,
255
+ netPrice: store.targetProduct.netPrice ?? store.targetProduct.listPrice
256
+ };
249
257
  const response = await BenefitsWithDocument({
250
258
  document: values.securityNumber.replace(/\D/g, ""),
251
- products: [{
252
- productId: targetProduct.productId,
253
- ean: targetProduct.ean,
254
- requestedQuantity: 1,
255
- listPrice: targetProduct.listPrice,
256
- netPrice: targetProduct.netPrice ?? targetProduct.listPrice
257
- }]
259
+ products: [product]
258
260
  });
259
261
  if (response.success) {
260
- const status = {
261
- "acceptance": "isInvalid",
262
- "industry registration": "isRegistered",
263
- "active": "isActivated"
264
- };
265
- setSecurityNumber(values.securityNumber);
266
- setState(status[response.data.product[0].statusCustomer]);
267
- if (status[response.data.product[0].statusCustomer] === "isInvalid") {
268
- setUrlAcceptTerms(response.data.product[0].urlAcceptTerm || void 0);
262
+ const status = mappingInternalStates(response.data.product[0].statusCustomer);
263
+ store.setSecurityNumber(values.securityNumber);
264
+ store.setState(status);
265
+ if (status === "isInvalid") {
266
+ store.setUrlAcceptTerms(response.data.product[0].urlAcceptTerm || void 0);
269
267
  return;
270
268
  }
271
- if (status[response.data.product[0].statusCustomer] === "isRegistered") {
272
- setUrlRegisterIndustry(response.data.product[0].informativeLink);
269
+ if (status === "isRegistered") {
270
+ store.setUrlRegisterIndustry(response.data.product[0].informativeLink);
273
271
  return;
274
272
  }
275
273
  }
276
274
  } catch (error) {
277
275
  console.error("PBMLOG: Error validating document -", error);
278
- } finally {
279
- setLoading(false);
280
276
  }
281
- ;
277
+ };
278
+ const onSubmitDefault = async (values) => {
279
+ if (!showCardIDField) {
280
+ setValue("coupon", void 0, { shouldValidate: false });
281
+ }
282
+ if (showCardIDField && values.coupon != void 0) {
283
+ store.setCardID(values.coupon);
284
+ }
285
+ startTransition(async () => {
286
+ await checkSecurityNumberBenefits(values);
287
+ });
282
288
  };
283
289
  return /* @__PURE__ */ jsxs3(Fragment2, { children: [
284
290
  /* @__PURE__ */ jsxs3(
@@ -317,7 +323,7 @@ function Form({ setLoading }) {
317
323
  });
318
324
  }
319
325
  }),
320
- defaultValue: securityNumber || "",
326
+ defaultValue: store.securityNumber || "",
321
327
  id: "input_security_number_pbm"
322
328
  }
323
329
  ),
@@ -325,7 +331,7 @@ function Form({ setLoading }) {
325
331
  ]
326
332
  }
327
333
  ),
328
- showCardIDField && /* @__PURE__ */ jsxs3(
334
+ /* @__PURE__ */ jsx5(Activity, { mode: showCardIDField ? "visible" : "hidden", children: /* @__PURE__ */ jsxs3(
329
335
  "label",
330
336
  {
331
337
  htmlFor: "coupon",
@@ -356,7 +362,7 @@ function Form({ setLoading }) {
356
362
  errors.coupon && /* @__PURE__ */ jsx5("span", { className: "text-red-400 text-xs font-semibold absolute -bottom-3 left-2 text-nowrap", id: "coupon_form_error", children: errors.coupon.message })
357
363
  ]
358
364
  }
359
- ),
365
+ ) }),
360
366
  /* @__PURE__ */ jsx5(
361
367
  "button",
362
368
  {
@@ -396,7 +402,7 @@ function Form({ setLoading }) {
396
402
  Button_default,
397
403
  {
398
404
  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",
399
- onClick: () => setState("isPreview"),
405
+ onClick: () => store.setState("isPreview"),
400
406
  id: "check_benefits_button",
401
407
  children: [
402
408
  /* @__PURE__ */ jsx5("span", { children: "Consultar Benef\xEDcios" }),
@@ -434,9 +440,6 @@ function Loading({ textColor }) {
434
440
  }
435
441
  var Loading_default = Loading;
436
442
 
437
- // src/components/BenefitsTable/index.tsx
438
- import { useEffect as useEffect2, useState as useState2 } from "react";
439
-
440
443
  // src/components/UI/Title/index.tsx
441
444
  import classNames5 from "classnames";
442
445
  import { jsx as jsx7 } from "react/jsx-runtime";
@@ -457,6 +460,35 @@ function Title(props) {
457
460
  }
458
461
  var Title_default = Title;
459
462
 
463
+ // src/services/benefits-without-document.ts
464
+ import Cookies2 from "js-cookie";
465
+ var CheckBenefistWithoutDocument = async ({ products }) => {
466
+ const API_URL = import.meta.env.VITE_API_URL;
467
+ if (!API_URL) {
468
+ throw new Error("API URL is not defined in environment variables");
469
+ }
470
+ const AUTH_TOKEN = Cookies2.get("pbm-token");
471
+ if (!AUTH_TOKEN) {
472
+ throw new Error("Token is not defined in cookies or is expired");
473
+ }
474
+ const response = await fetch(`${API_URL}/products/genericBenefit`, {
475
+ method: "POST",
476
+ headers: {
477
+ Authorization: `Bearer ${AUTH_TOKEN}`,
478
+ "Content-Type": "application/json"
479
+ },
480
+ body: JSON.stringify({ products })
481
+ });
482
+ const dataResponse = await response.json();
483
+ if (!dataResponse.success) {
484
+ throw new Error(dataResponse.message || "Failed to fetch benefits without document");
485
+ }
486
+ return dataResponse;
487
+ };
488
+
489
+ // src/components/BenefitsTable/index.tsx
490
+ import { useEffect as useEffect2, useState as useState2, useTransition } from "react";
491
+
460
492
  // src/libs/zustand/useModal.tsx
461
493
  import { create } from "zustand";
462
494
  var initialModalState = {
@@ -557,7 +589,7 @@ function Item({ data, onChange, checked }) {
557
589
  useEffect(() => {
558
590
  updateStorageData();
559
591
  }, [updateStorageData]);
560
- const handleChange = (e) => {
592
+ const handleChange = () => {
561
593
  if (!isAuthenticatedShopper && state === "isActivated") {
562
594
  setModal({
563
595
  id: "ShopperIsNotAuthenticated",
@@ -618,57 +650,31 @@ function Item({ data, onChange, checked }) {
618
650
  }
619
651
  var Item_default = Item;
620
652
 
621
- // src/services/benefits-without-document.ts
622
- import Cookies2 from "js-cookie";
623
- var CheckBenefistWithoutDocument = async ({ products }) => {
624
- const API_URL = import.meta.env.VITE_API_URL;
625
- if (!API_URL) {
626
- throw new Error("API URL is not defined in environment variables");
627
- }
628
- const AUTH_TOKEN = Cookies2.get("pbm-token");
629
- if (!AUTH_TOKEN) {
630
- throw new Error("Token is not defined in cookies or is expired");
631
- }
632
- const response = await fetch(`${API_URL}/products/genericBenefit`, {
633
- method: "POST",
634
- headers: {
635
- Authorization: `Bearer ${AUTH_TOKEN}`,
636
- "Content-Type": "application/json"
637
- },
638
- body: JSON.stringify({ products })
639
- });
640
- const dataResponse = await response.json();
641
- if (!dataResponse.success) {
642
- throw new Error(dataResponse.message || "Failed to fetch benefits without document");
643
- }
644
- return dataResponse;
645
- };
646
-
647
653
  // src/components/BenefitsTable/index.tsx
648
654
  import { Fragment as Fragment3, jsx as jsx10, jsxs as jsxs7 } from "react/jsx-runtime";
649
655
  function BenefitsTable() {
656
+ const [isPending, startTransition] = useTransition();
650
657
  const { securityNumber, setState, state, targetProduct, customLoginUrl, isAuthenticatedShopper } = usePBMStore();
651
658
  const [selectedDiscout, setSelectedDiscount] = useState2(null);
652
- const [loading, setLoading] = useState2(true);
653
659
  const [benefitsItems, setBenefitsItems] = useState2();
654
660
  useEffect2(() => {
661
+ if (!targetProduct?.productId) {
662
+ console.error("PBMLOG: Product ID is not defined on targetProduct");
663
+ return;
664
+ }
665
+ if (!targetProduct.ean) {
666
+ console.error("PBMLOG: EAN is not defined on targetProduct");
667
+ return;
668
+ }
669
+ if (!targetProduct.listPrice) {
670
+ console.error("PBMLOG: List Price is not defined on targetProduct");
671
+ return;
672
+ }
673
+ if (!targetProduct.price) {
674
+ console.error("PBMLOG: Price is not defined on targetProduct");
675
+ return;
676
+ }
655
677
  const fetchDicountsWithoutDocument = async () => {
656
- if (!targetProduct?.productId) {
657
- console.error("PBMLOG: Product ID is not defined on targetProduct");
658
- return;
659
- }
660
- if (!targetProduct.ean) {
661
- console.error("PBMLOG: EAN is not defined on targetProduct");
662
- return;
663
- }
664
- if (!targetProduct.listPrice) {
665
- console.error("PBMLOG: List Price is not defined on targetProduct");
666
- return;
667
- }
668
- if (!targetProduct.price) {
669
- console.error("PBMLOG: Price is not defined on targetProduct");
670
- return;
671
- }
672
678
  try {
673
679
  const data = {
674
680
  productId: Number(targetProduct.productId),
@@ -686,8 +692,6 @@ function BenefitsTable() {
686
692
  } catch (error) {
687
693
  setBenefitsItems(void 0);
688
694
  console.error(error);
689
- } finally {
690
- setLoading(false);
691
695
  }
692
696
  };
693
697
  const fetchDiscountWithDocument = async () => {
@@ -695,22 +699,6 @@ function BenefitsTable() {
695
699
  console.error("PBMLOG: Document is not defined");
696
700
  return;
697
701
  }
698
- if (!targetProduct?.productId) {
699
- console.error("PBMLOG: Product ID is not defined on targetProduct");
700
- return;
701
- }
702
- if (!targetProduct.ean) {
703
- console.error("PBMLOG: EAN is not defined on targetProduct");
704
- return;
705
- }
706
- if (!targetProduct.listPrice) {
707
- console.error("PBMLOG: List Price is not defined on targetProduct");
708
- return;
709
- }
710
- if (!targetProduct.price) {
711
- console.error("PBMLOG: Price is not defined on targetProduct");
712
- return;
713
- }
714
702
  try {
715
703
  const data = {
716
704
  productId: Number(targetProduct.productId),
@@ -728,13 +716,13 @@ function BenefitsTable() {
728
716
  } catch (error) {
729
717
  setBenefitsItems(void 0);
730
718
  console.error(error);
731
- } finally {
732
- setLoading(false);
733
719
  }
734
720
  };
735
- state === "isActivated" ? fetchDiscountWithDocument() : fetchDicountsWithoutDocument();
721
+ startTransition(async () => {
722
+ state === "isActivated" ? await fetchDiscountWithDocument() : await fetchDicountsWithoutDocument();
723
+ });
736
724
  }, []);
737
- if (loading) {
725
+ if (isPending) {
738
726
  return /* @__PURE__ */ jsxs7("main", { className: "flex items-center justify-center gap-4", id: "loading_pbm", children: [
739
727
  /* @__PURE__ */ jsx10(
740
728
  "div",
@@ -893,22 +881,13 @@ function SecurityNumberInvalid({ textColor }) {
893
881
  /* @__PURE__ */ jsx13("br", {}),
894
882
  "Ao clicar em \u201CAceitar os termos\u201D, voc\xEA ir\xE1 para uma p\xE1gina externa. Aceite os termos e volte para continuar."
895
883
  ] }),
896
- /* @__PURE__ */ jsx13(
897
- Link_default,
898
- {
899
- href: urlAcceptTerms || "",
900
- children: "Aceitar os termos"
901
- }
902
- )
884
+ /* @__PURE__ */ jsx13(Link_default, { href: urlAcceptTerms || "", children: "Aceitar os termos" })
903
885
  ]
904
886
  }
905
887
  );
906
888
  }
907
889
  var SecurityNumberInvalid_default = SecurityNumberInvalid;
908
890
 
909
- // src/PBM.tsx
910
- import { useCallback as useCallback2, useEffect as useEffect3, useState as useState3 } from "react";
911
-
912
891
  // src/components/SecurityNumberRegitered/index.tsx
913
892
  import { jsx as jsx14, jsxs as jsxs9 } from "react/jsx-runtime";
914
893
  function SecurityNumberRegitered({ textColor }) {
@@ -922,19 +901,87 @@ function SecurityNumberRegitered({ textColor }) {
922
901
  children: [
923
902
  /* @__PURE__ */ jsx14(Title_default, { className: "w-full", textColor, children: "Ops, seu CPF ainda n\xE3o est\xE1 habilitado para este produto." }),
924
903
  /* @__PURE__ */ jsx14(Text_default, { className: "w-full", textColor, children: "Para ativar o benef\xEDcio, clique em \u201CAtivar CPF\u201D e conclua a etapa na p\xE1gina externa. Depois, \xE9 s\xF3 voltar para continuar \u2014 vamos aguardar voc\xEA aqui." }),
925
- /* @__PURE__ */ jsx14(
926
- Link_default,
927
- {
928
- href: urlRegisterIndustry || "",
929
- children: "Ativar CPF"
930
- }
931
- )
904
+ /* @__PURE__ */ jsx14(Link_default, { href: urlRegisterIndustry || "", children: "Ativar CPF" })
932
905
  ]
933
906
  }
934
907
  );
935
908
  }
936
909
  var SecurityNumberRegitered_default = SecurityNumberRegitered;
937
910
 
911
+ // src/components/Errors/ErrorToApplyBenefits.tsx
912
+ import { RefreshCw } from "lucide-react";
913
+ import { jsx as jsx15, jsxs as jsxs10 } from "react/jsx-runtime";
914
+ var ErrorToApplyBenefits = () => {
915
+ return /* @__PURE__ */ jsxs10(Container_default, { variant: "main", children: [
916
+ /* @__PURE__ */ jsx15(Title_default, { children: "Erro ao Aplicar o Benef\xEDcio" }),
917
+ /* @__PURE__ */ jsxs10(Text_default, { textAlign: "center", children: [
918
+ "O produto n\xE3o foi encontrado no sistema. ",
919
+ /* @__PURE__ */ jsx15("br", {}),
920
+ " Por favor, tente novamente mais tarde ou contate o suporte."
921
+ ] }),
922
+ /* @__PURE__ */ jsxs10(
923
+ Button_default,
924
+ {
925
+ 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",
926
+ onClick: () => window.location.reload(),
927
+ id: "check_benefits_button",
928
+ children: [
929
+ /* @__PURE__ */ jsx15("span", { children: "Tentar novamente" }),
930
+ /* @__PURE__ */ jsx15(RefreshCw, { size: 16 })
931
+ ]
932
+ }
933
+ )
934
+ ] });
935
+ };
936
+ var ErrorToApplyBenefits_default = ErrorToApplyBenefits;
937
+
938
+ // src/components/Modal/index.tsx
939
+ import classNames9 from "classnames";
940
+ import { jsx as jsx16, jsxs as jsxs11 } from "react/jsx-runtime";
941
+ var Modal = ({ ID }) => {
942
+ const { customLoginUrl } = usePBMStore();
943
+ const { modal, setModal } = useModal();
944
+ return /* @__PURE__ */ jsxs11("main", { className: classNames9(
945
+ "fixed inset-0 flex items-center justify-center z-50 flex-col transition-all shadow bg-black/40",
946
+ {
947
+ "opacity-100 pointer-events-auto": modal.id === ID && modal.open,
948
+ "opacity-0 pointer-events-none": modal.id != ID || !modal.open
949
+ }
950
+ ), children: [
951
+ /* @__PURE__ */ jsx16("div", { className: "absolute inset-0", onClick: () => setModal({ id: "", open: false }) }),
952
+ /* @__PURE__ */ jsxs11("section", { className: "z-10 bg-white gap-2 flex-col items-center-safe justify-center-safe p-8 rounded-xl", children: [
953
+ /* @__PURE__ */ jsx16(Title_default, { textColor: "tomato", textSize: "18px", textAlign: "center", className: "mb-2", children: "Opa! Parece que voc\xEA n\xE3o est\xE1 Logado" }),
954
+ /* @__PURE__ */ jsxs11(Text_default, { className: "mb-2", textAlign: "center", children: [
955
+ "Para aproveitar os benef\xEDcios \xE9 necess\xE1rio realizar o ",
956
+ /* @__PURE__ */ jsx16("strong", { children: "Login" }),
957
+ " ou ",
958
+ /* @__PURE__ */ jsx16("strong", { children: "Cadastro" }),
959
+ " no site!"
960
+ ] }),
961
+ /* @__PURE__ */ jsxs11("section", { className: "flex items-center-safe justify-center-safe gap-4", children: [
962
+ /* @__PURE__ */ jsx16(Button_default, { className: "bg-gray-600 hover:bg-gray-500", onClick: () => setModal({ id: "", open: false }), children: "Seguir sem Benef\xEDcios" }),
963
+ /* @__PURE__ */ jsx16(Link_default, { href: customLoginUrl || "/login", children: "Aproveitar Benef\xEDcios" })
964
+ ] })
965
+ ] })
966
+ ] });
967
+ };
968
+ var Modal_default = Modal;
969
+
970
+ // src/PBM.tsx
971
+ import Skeleton from "@mui/material/Skeleton";
972
+
973
+ // src/utils/format-price.ts
974
+ var formatedPrice = (price) => {
975
+ const result = Number(String(price).replace(",", "."));
976
+ return result;
977
+ };
978
+
979
+ // src/PBM.tsx
980
+ import { useTransition as useTransition2 } from "react";
981
+
982
+ // src/hooks/useAppStartup.tsx
983
+ import { useCallback as useCallback2, useEffect as useEffect3, useState as useState3 } from "react";
984
+
938
985
  // src/services/authorization.ts
939
986
  import Cookies3 from "js-cookie";
940
987
  var GetAuthorization = async ({ clientID }) => {
@@ -966,9 +1013,6 @@ var GetAuthorization = async ({ clientID }) => {
966
1013
  return data;
967
1014
  };
968
1015
 
969
- // src/PBM.tsx
970
- import { RefreshCw } from "lucide-react";
971
-
972
1016
  // src/services/get-product-by-ean.ts
973
1017
  import Cookies4 from "js-cookie";
974
1018
  var GetProductByEAN = async ({ PRODUCT_EAN }) => {
@@ -991,41 +1035,6 @@ var GetProductByEAN = async ({ PRODUCT_EAN }) => {
991
1035
  return dataResponse;
992
1036
  };
993
1037
 
994
- // src/PBM.tsx
995
- import Skeleton from "@mui/material/Skeleton";
996
-
997
- // src/components/Modal/index.tsx
998
- import classNames9 from "classnames";
999
- import { jsx as jsx15, jsxs as jsxs10 } from "react/jsx-runtime";
1000
- var Modal = ({ ID }) => {
1001
- const { customLoginUrl } = usePBMStore();
1002
- const { modal, setModal } = useModal();
1003
- return /* @__PURE__ */ jsxs10("main", { className: classNames9(
1004
- "fixed inset-0 flex items-center justify-center z-50 flex-col transition-all shadow bg-black/40",
1005
- {
1006
- "opacity-100 pointer-events-auto": modal.id === ID && modal.open,
1007
- "opacity-0 pointer-events-none": modal.id != ID || !modal.open
1008
- }
1009
- ), children: [
1010
- /* @__PURE__ */ jsx15("div", { className: "absolute inset-0", onClick: () => setModal({ id: "", open: false }) }),
1011
- /* @__PURE__ */ jsxs10("section", { className: "z-10 bg-white gap-2 flex-col items-center-safe justify-center-safe p-8 rounded-xl", children: [
1012
- /* @__PURE__ */ jsx15(Title_default, { textColor: "tomato", textSize: "18px", textAlign: "center", className: "mb-2", children: "Opa! Parece que voc\xEA n\xE3o est\xE1 Logado" }),
1013
- /* @__PURE__ */ jsxs10(Text_default, { className: "mb-2", textAlign: "center", children: [
1014
- "Para aproveitar os benef\xEDcios \xE9 necess\xE1rio realizar o ",
1015
- /* @__PURE__ */ jsx15("strong", { children: "Login" }),
1016
- " ou ",
1017
- /* @__PURE__ */ jsx15("strong", { children: "Cadastro" }),
1018
- " no site!"
1019
- ] }),
1020
- /* @__PURE__ */ jsxs10("section", { className: "flex items-center-safe justify-center-safe gap-4", children: [
1021
- /* @__PURE__ */ jsx15(Button_default, { className: "bg-gray-600 hover:bg-gray-500", onClick: () => setModal({ id: "", open: false }), children: "Seguir sem Benef\xEDcios" }),
1022
- /* @__PURE__ */ jsx15(Link_default, { href: customLoginUrl || "/login", children: "Aproveitar Benef\xEDcios" })
1023
- ] })
1024
- ] })
1025
- ] });
1026
- };
1027
- var Modal_default = Modal;
1028
-
1029
1038
  // src/services/get-list-products.ts
1030
1039
  import Cookies5 from "js-cookie";
1031
1040
  var GetProductsWithBenefits = async () => {
@@ -1048,44 +1057,33 @@ var GetProductsWithBenefits = async () => {
1048
1057
  return dataResponse;
1049
1058
  };
1050
1059
 
1051
- // src/PBM.tsx
1052
- import { Fragment as Fragment4, jsx as jsx16, jsxs as jsxs11 } from "react/jsx-runtime";
1053
- function PBM({
1054
- originalProductPrice,
1055
- clientID,
1056
- eanProduct,
1057
- isAuthenticatedShopper,
1058
- customLoginUrl
1059
- }) {
1060
- const formatedOriginalProductPrice = Number(
1061
- String(originalProductPrice).replace(",", ".")
1062
- );
1063
- const [isReady, setIsReady] = useState3(false);
1064
- const [loading, setLoading] = useState3(false);
1065
- const { state, setTargetProduct, targetProduct, setIsAuthenticatedShopper, setCustomLoginUrl } = usePBMStore();
1066
- const [EanProductExist, setEanProductExist] = useState3(true);
1060
+ // src/hooks/useAppStartup.tsx
1061
+ var useAppStartup = (props) => {
1062
+ const { setTargetProduct, targetProduct, setIsAuthenticatedShopper, setCustomLoginUrl } = usePBMStore();
1063
+ const [IsReady, setIsReady] = useState3(false);
1067
1064
  const [IsValid, setIsValid] = useState3(false);
1065
+ const [EanProductExist, setEanProductExist] = useState3(true);
1068
1066
  const fetchValidateProduct = useCallback2(async () => {
1069
1067
  try {
1070
1068
  const response = await GetProductsWithBenefits();
1071
1069
  if (response.success) {
1072
1070
  const data = response.data;
1073
- const hasProductInList = data.some((product) => product.ean == eanProduct);
1071
+ const hasProductInList = data.some((product) => product.ean == props.eanProduct);
1074
1072
  setIsValid(hasProductInList);
1075
1073
  }
1076
1074
  } catch (error) {
1077
1075
  console.error(error);
1078
1076
  }
1079
- }, [eanProduct, IsValid]);
1077
+ }, [props.eanProduct, IsValid]);
1080
1078
  const fetchProductByEan = async () => {
1081
1079
  try {
1082
1080
  if (!IsValid) return;
1083
- if (!eanProduct) {
1081
+ if (!props.eanProduct) {
1084
1082
  console.error("PBMLOG: Ean is not defined.");
1085
1083
  setEanProductExist(false);
1086
1084
  return;
1087
1085
  }
1088
- const response = await GetProductByEAN({ PRODUCT_EAN: eanProduct });
1086
+ const response = await GetProductByEAN({ PRODUCT_EAN: props.eanProduct });
1089
1087
  if (response.success && response.data) {
1090
1088
  setEanProductExist(true);
1091
1089
  const { pbm, sku, ...targetProductNewData } = response.data;
@@ -1096,10 +1094,10 @@ function PBM({
1096
1094
  informativeMessage: pbm.informativeMessage ?? "",
1097
1095
  discountMax: pbm.discountMax ?? 0,
1098
1096
  industryLogo: pbm.imageLink ?? void 0,
1099
- ean: eanProduct
1097
+ ean: props.eanProduct
1100
1098
  });
1101
- setIsAuthenticatedShopper(isAuthenticatedShopper);
1102
- setCustomLoginUrl(customLoginUrl);
1099
+ setIsAuthenticatedShopper(props.isAuthenticatedShopper);
1100
+ setCustomLoginUrl(props.customLoginUrl);
1103
1101
  }
1104
1102
  } catch (error) {
1105
1103
  console.error(error);
@@ -1107,9 +1105,9 @@ function PBM({
1107
1105
  setIsReady(true);
1108
1106
  }
1109
1107
  };
1110
- const handleAuthorizationRequest = useCallback2(async () => {
1108
+ const fetchAuthorizationRequest = useCallback2(async () => {
1111
1109
  try {
1112
- const response = await GetAuthorization({ clientID });
1110
+ const response = await GetAuthorization({ clientID: props.clientID });
1113
1111
  if (response.success) {
1114
1112
  fetchValidateProduct();
1115
1113
  fetchProductByEan();
@@ -1119,50 +1117,40 @@ function PBM({
1119
1117
  } catch (error) {
1120
1118
  console.error("Error fetching authorization:", error);
1121
1119
  }
1122
- }, [clientID, IsValid]);
1120
+ }, [props.clientID, IsValid]);
1123
1121
  useEffect3(() => {
1124
- handleAuthorizationRequest();
1125
- }, [handleAuthorizationRequest]);
1126
- if (!isReady) {
1127
- return /* @__PURE__ */ jsx16(Skeleton, { variant: "rectangular", style: { borderRadius: "12px" }, width: 460, height: 358 });
1122
+ fetchAuthorizationRequest();
1123
+ }, [fetchAuthorizationRequest]);
1124
+ return { IsReady, IsValid, EanProductExist };
1125
+ };
1126
+ var useAppStartup_default = useAppStartup;
1127
+
1128
+ // src/PBM.tsx
1129
+ import { Fragment as Fragment4, jsx as jsx17, jsxs as jsxs12 } from "react/jsx-runtime";
1130
+ function PBM(props) {
1131
+ const { state } = usePBMStore();
1132
+ const { IsReady, EanProductExist, IsValid } = useAppStartup_default(props);
1133
+ const [isPending, startTransition] = useTransition2();
1134
+ const formatedProductPrice = formatedPrice(props.originalProductPrice);
1135
+ if (!IsReady) {
1136
+ return /* @__PURE__ */ jsx17(Skeleton, { variant: "rectangular", style: { borderRadius: "12px" }, width: 460, height: 358 });
1128
1137
  }
1129
1138
  if (!EanProductExist) {
1130
- return /* @__PURE__ */ jsx16("div", { id: "pbm-library-root", children: /* @__PURE__ */ jsxs11(Container_default, { variant: "main", children: [
1131
- /* @__PURE__ */ jsx16(Title_default, { children: "Erro ao Aplicar o Benef\xEDcio" }),
1132
- /* @__PURE__ */ jsxs11(Text_default, { textAlign: "center", children: [
1133
- "O produto n\xE3o foi encontrado no sistema. ",
1134
- /* @__PURE__ */ jsx16("br", {}),
1135
- " Por favor, tente novamente mais tarde ou contate o suporte."
1136
- ] }),
1137
- /* @__PURE__ */ jsxs11(
1138
- Button_default,
1139
- {
1140
- 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",
1141
- onClick: () => window.location.reload(),
1142
- id: "check_benefits_button",
1143
- children: [
1144
- /* @__PURE__ */ jsx16("span", { children: "Tentar novamente" }),
1145
- /* @__PURE__ */ jsx16(RefreshCw, { size: 16 })
1146
- ]
1147
- }
1148
- )
1149
- ] }) });
1150
- }
1151
- if (!IsValid) {
1152
- return;
1139
+ return /* @__PURE__ */ jsx17("div", { id: "pbm-library-root", children: /* @__PURE__ */ jsx17(ErrorToApplyBenefits_default, {}) });
1153
1140
  }
1154
- return /* @__PURE__ */ jsxs11("div", { id: "pbm-library-root", children: [
1155
- /* @__PURE__ */ jsxs11(Container_default, { variant: "main", children: [
1156
- /* @__PURE__ */ jsx16(Header_default, { originalProductPrice: formatedOriginalProductPrice || 0 }),
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, {})
1141
+ if (!IsValid) return;
1142
+ return /* @__PURE__ */ jsxs12("div", { id: "pbm-library-root", children: [
1143
+ /* @__PURE__ */ jsxs12(Container_default, { variant: "main", children: [
1144
+ /* @__PURE__ */ jsx17(Header_default, { originalProductPrice: formatedProductPrice || 0 }),
1145
+ /* @__PURE__ */ jsx17(Container_default, { variant: "simple", children: isPending ? /* @__PURE__ */ jsx17(Loading_default, {}) : /* @__PURE__ */ jsxs12(Fragment4, { children: [
1146
+ state === "isEmpty" && /* @__PURE__ */ jsx17(Form_default, { startTransition }),
1147
+ state === "isInvalid" && /* @__PURE__ */ jsx17(SecurityNumberInvalid_default, {}),
1148
+ state === "isRegistered" && /* @__PURE__ */ jsx17(SecurityNumberRegitered_default, {}),
1149
+ (state === "isActivated" || state === "isPreview") && /* @__PURE__ */ jsx17(BenefitsTable_default, {})
1162
1150
  ] }) }),
1163
- /* @__PURE__ */ jsx16(Footer_default, {})
1151
+ /* @__PURE__ */ jsx17(Footer_default, {})
1164
1152
  ] }),
1165
- /* @__PURE__ */ jsx16(Modal_default, { ID: "ShopperIsNotAuthenticated" })
1153
+ /* @__PURE__ */ jsx17(Modal_default, { ID: "ShopperIsNotAuthenticated" })
1166
1154
  ] });
1167
1155
  }
1168
1156
  var PBM_default = PBM;