芝麻web文件管理V1.00
编辑当前文件:/home/qrafawbu/rentandbuyrealty.com/rentandbuyrealty.com/web/src/Components/Navbar/Navbar.jsx
"use client" import React, { useState, useEffect } from "react"; import ebroker from "@/assets/Logo_Color.png"; import { RiUserSmileLine } from "react-icons/ri"; import { CloseButton, Dropdown } from "react-bootstrap"; import Offcanvas from "react-bootstrap/Offcanvas"; import Link from "next/link"; import { FiPlusCircle } from "react-icons/fi"; import LoginModal from "../LoginModal/LoginModal"; import AreaConverter from "../AreaConverter/AreaConverter"; import { GiHamburgerMenu } from "react-icons/gi"; import { useSelector } from "react-redux"; import { logoutSuccess, userSignUpData } from "@/store/reducer/authSlice"; import "react-confirm-alert/src/react-confirm-alert.css"; import { toast } from "react-hot-toast"; import { settingsData } from "@/store/reducer/settingsSlice"; import { languageLoaded, setLanguage } from "@/store/reducer/languageSlice"; import { placeholderImage, translate } from "@/utils"; import { store } from "@/store/store"; import Swal from "sweetalert2"; import { useRouter } from "next/router"; import Image from "next/image"; import { silderCacheData } from "@/store/reducer/momentSlice"; import FirebaseData from "@/utils/Firebase"; const Nav = () => { const router = useRouter(); const language = store.getState().Language.languages; const { signOut } = FirebaseData(); const isHomePage = router.pathname === '/'; const user_register = router.pathname === '/user-register'; const signupData = useSelector(userSignUpData); const sliderdata = useSelector(silderCacheData); const settingData = useSelector(settingsData); const isSubscription = settingData?.subscription; const LanguageList = settingData && settingData.languages; const systemDefaultLanguageCode = settingData?.default_language; const [showModal, setShowModal] = useState(false); const [areaconverterModal, setAreaConverterModal] = useState(false); const [selectedLanguage, setSelectedLanguage] = useState(); const [defaultlang, setDefaultlang] = useState(language.name); const [show, setShow] = useState(false); const [headerTop, setHeaderTop] = useState(0); const [scroll, setScroll] = useState(0); const handleClose = () => setShow(false); const handleShow = () => setShow(true); useEffect(() => { if (language && language.rtl === 1) { document.documentElement.dir = "rtl"; } else { document.documentElement.dir = "ltr"; } }, [language]); useEffect(() => { if (signupData?.data?.data.name === "" || signupData?.data?.data.email === "" || signupData?.data?.data?.mobile === "" && !user_register) { Swal.fire({ title: 'Complete Profile First', icon: 'info', customClass: { confirmButton: 'Swal-confirm-buttons', cancelButton: "Swal-cancel-buttons" }, confirmButtonText: 'OK', backdrop: 'static', }).then((result) => { if (result.isConfirmed) { // If the user clicks "OK," navigate to "/user-register" router.push('/user-register'); } }); } }, [signupData]); useEffect(() => { const header = document.querySelector(".header"); setHeaderTop(header.offsetTop); window.addEventListener("scroll", handleScroll); return () => { window.removeEventListener("scroll", handleScroll); }; }, []); useEffect(() => { if (!language || Object.keys(language).length === 0) { languageLoaded( systemDefaultLanguageCode, "1", (response) => { const currentLang = response && response.data.name; // Dispatch the setLanguage action to update the selected language in Redux store.dispatch(setLanguage(currentLang)); setSelectedLanguage(currentLang); setDefaultlang(currentLang); }, (error) => { console.log(error); } ); } }, []); const handleLanguageChange = (languageCode) => { languageLoaded( languageCode, "1", (response) => { const currentLang = response && response.data.name; setSelectedLanguage(currentLang); // Dispatch the setLanguage action to update the selected language in Redux store.dispatch(setLanguage(currentLang)); }, (error) => { toast.error(error) console.log(error); } ); }; useEffect(() => { }, [selectedLanguage, language, defaultlang]) const handleScroll = () => { setScroll(window.scrollY); }; const handleOpenModal = () => { setShow(false); setShowModal(true); }; const handleCloseModal = () => { setShowModal(false); }; const handleOpenAcModal = () => { setShow(false); setAreaConverterModal(true); }; const handleCloseAcModal = () => { setAreaConverterModal(false); }; const handleShowDashboard = () => { if (isSubscription === true) { // Corrected the condition router.push("/user/dashboard"); // Use an absolute path here } else { router.push("/user/profile"); // Redirect to the subscription page } }; const handleAddProperty = () => { if (isSubscription === true) { // Corrected the condition router.push("/user/properties"); // Use an absolute path here } else { Swal.fire({ icon: "error", title: "Oops...", text: "You have not subscribed. Please subscribe first", customClass: { confirmButton: 'Swal-confirm-buttons', }, // footer: '
Why do I have this issue?
' }).then((result) => { if (result.isConfirmed) { router.push("/subscription-plan"); // Redirect to the subscription page } }); } }; const handleLogout = () => { handleClose(); Swal.fire({ title: "Are you sure?", text: "You won't be able to revert this!", icon: "warning", showCancelButton: true, customClass: { confirmButton: 'Swal-confirm-buttons', cancelButton: "Swal-cancel-buttons" }, confirmButtonText: "Yes! Logout", }).then((result) => { if (result.isConfirmed) { // Clear the recaptchaVerifier by setting it to null window.recaptchaVerifier = null; // Perform the logout action logoutSuccess(); signOut() toast.success(translate("logoutSuccess")); } else { toast.error(translate("logoutcancel")); } }); }; const CheckActiveUserAccount = () => { if (settingData?.is_active === false) { Swal.fire({ title: "Opps!", text: "Your account has been deactivated by the admin. Please contact them.", icon: "warning", allowOutsideClick: false, showCancelButton: false, customClass: { confirmButton: 'Swal-confirm-buttons', cancelButton: "Swal-cancel-buttons" }, confirmButtonText: "Logout", }).then((result) => { if (result.isConfirmed) { logoutSuccess(); signOut() router.push("/contact-us"); } }); } } useEffect(() => { CheckActiveUserAccount() }, [settingData?.is_active]) return ( <>
headerTop || (isHomePage && (!sliderdata || sliderdata.length === 0)) ? "is-sticky" : ""}`}>
{translate("home")}
{translate("properties")}
{translate("allProperties")}
{translate("featuredProp")}
{" "}
{translate("mostViewedProp")}
{" "}
{translate("nearbyCities")}
{translate("mostFavProp")}
{/*
{translate("listByAgents")}
*/}
{translate("pages")}
{translate("subscriptionPlan")}
{" "}
{translate("articles")}
{translate("areaConverter")}
{translate("terms&condition")}
{" "}
{translate("privacyPolicy")}
{translate("contactUs")}
{translate("aboutUs")}
{selectedLanguage ? selectedLanguage : defaultlang}
{LanguageList && LanguageList.map((ele, index) => (
handleLanguageChange(ele.code)}> {ele.name}
))}
{ // Check if signupData.data is null signupData?.data === null ? (
{translate("login&Regiser")}
) : // Check if mobile and firebase_id are present signupData?.data?.data.mobile && signupData?.data?.data.firebase_id && signupData?.data?.data.name === "" ? ( <>
{translate("welcmGuest")}
> ) : signupData?.data?.data.name ? (
{signupData.data.data.name}
{translate("dashboard")}
{translate("logout")}
) : null }
{signupData?.data?.data.name && settingData && (
{translate("addProp")}
)}
{settingData?.company_name}
{translate("home")}
{translate("properties")}
{translate("allProperties")}
{translate("featuredProp")}
{" "}
{translate("mostViewedProp")}
{" "}
{translate("nearbyCities")}
{translate("mostFavProp")}
{/*
{translate("listByAgents")}
*/}
{translate("pages")}
{translate("subscriptionPlan")}
{" "}
{translate("articles")}
{translate("areaConverter")}
{translate("terms&condition")}
{" "}
{translate("privacyPolicy")}
{translate("contactUs")}
{translate("aboutUs")}
{selectedLanguage ? selectedLanguage : defaultlang}
{LanguageList && LanguageList.map((ele, index) => (
handleLanguageChange(ele.code)}> {ele.name}
))}
{ // Check if signupData.data is null signupData?.data === null ? (
{translate("login&Regiser")}
) : // Check if mobile and firebase_id are present signupData?.data?.data.mobile && signupData?.data?.data.firebase_id && signupData?.data?.data.name === "" ? (
{translate("welcmGuest")}
) : // If name is present, show "Welcome, {name}" signupData?.data?.data.name ? (
{/*
*/} {signupData.data.data.name}
{translate("dashboard")}
{translate("logout")}
) : null // Handle any other cases or conditions here }
{signupData?.data?.data.name && settingData && (
{translate("addProp")}
)}
> ); }; export default Nav;