import React, { useState, useEffect, useCallback } from "react"; import { useNavigate, useSearchParams } from "react-router-dom"; import { SimProduct } from "../../services/types"; import HomeBanner from "./components/HomeBanner"; import HomeTestimonial from "./components/HomeTestimonial"; import HomeProduct from "./components/HomeProduct"; import HomeSearch from "./components/HomeSearch"; import HomeFaq from "./components/HomeFaq"; import { useAppDispatch } from "../../hooks/useRedux"; import { openPopup } from "../../features/popup/popupSlice"; import partner1 from "../../assets/img/partner1.png"; import partner2 from "../../assets/img/partner2.png"; import { authApi } from "../../apis/authApi"; import { accountLogin } from "../../features/account/accuntSlice"; import { useTranslation } from "react-i18next"; import i18n from "../../i18n"; const HomeView: React.FC = () => { const [simType, setSimType] = useState<"eSIM" | "Physical">("eSIM"); const [searchParams] = useSearchParams(); const navigate = useNavigate(); const dispatch = useAppDispatch(); const { t } = useTranslation(); const langNow = localStorage.getItem("lang") || "en"; useEffect(() => { // set language in i18n i18n.changeLanguage(langNow); localStorage.setItem("lang", langNow); }, [langNow]); useEffect(() => { const params = new URLSearchParams(window.location.search); console.log("URL Params: ", params.toString()); const status = params.get("vpc_TxnResponseCode"); console.log("searchParams: ", searchParams.toString()); // google callback const code = searchParams.get("code"); if (status) { console.log("URL Params:", params); if (status === "0") { dispatch( openPopup({ isSuccess: true, message: t("paymentSuccess"), title: t("paymentStatus"), buttonText: t("close"), hasRightButton: true, rightButtonText: t("viewOrder"), rightButtonAction: "OPEN_ORDER_HISTORY", }), ); } else { dispatch( openPopup({ isSuccess: false, message: t("paymentFailed"), title: t("paymentStatus"), buttonText: t("close"), }), ); } } else if (code) { console.log("Handling Google callback with code:", code); handleGoogleCallback(code); } }, []); const handleGoogleCallback = async (code: string) => { try { const response = await authApi.googleCallback({ code }); if (response.errorCode === "0") { dispatch(accountLogin(response.data)); navigate("/"); } else { console.error("Google callback failed:", response.message); } } catch (error) { console.error("Google callback error:", error); } }; const steps = [ { number: "1", title: t("compatibleDevice"), description: t("checkIfYourPhoneSupportsESIMTechnology"), }, { number: "2", title: t("pickPlan"), description: t("selectADataPackageForYourDestination"), }, { number: "3", title: t("instantActivation"), description: t("scanTheQRCodeAndConnectToHighSpeedData"), }, ]; return (
{/* Main Search Section */} {/* Hero Banner */} {/* Product Selection */} {/* Customer Testimonials */} {/* WHY CHOOSE INFIGATE */}

{t("chooseGetgo")}

{t("fastCost")}

  • {t("internationalTravelStarts")}
  • {t("easilyChooseSuitableSim")}
  • {t("eSIMReceiveQR")}
  • {t("physicalSIMDelivery")}

{t("globalAnywhere")}

  • {t("fastestData")}
  • {t("worldLeadingNetwork")}
  • {t("flexibleDiversePackages")}

{t("customerSupport")}

  • {t("customerServiceAvailable")}
  • {t("supportChannels")}

{t("customerPolicy")}

  • {t("refundDefective")}
  • {t("commitmentPeaceOfMind")}
{/* PARTNERSHIP */}

SkySimHub {t("getgoWith")}

{t("partnershipNetwork")}

{/* How it Works */}

{t("buyExplore")}

{steps.map((step, index) => (
{step.number}

{step.title}

{step.description}

))}
{/* FAQ */} {/* Refund */}

{t("refundDefective")}

); }; export default HomeView;