import React, { useState, useEffect } from "react"; import { useNavigate } from "react-router-dom"; import "./LandingPageCMS.scss"; import { FaHome, FaHeading, FaImage, FaQuestionCircle, FaArrowLeft, FaSave, FaEye, FaLock, FaMoon, FaSun, FaBars, FaTimes } from "react-icons/fa"; import { MdDashboard, MdEdit } from "react-icons/md"; import { useDispatch } from "react-redux"; import { message } from "antd"; import { getAdminPanel, postAdminPanel, putAdminPanel } from "../features/AdminPanel/AdminPanel"; import { getSession } from "../Services/others"; // Section Components import HeroContentEditor from "./Sections/HeroContentEditor"; import OfferingsEditor from "./Sections/OfferingsEditor"; import FeaturesEditor from "./Sections/FeaturesEditor"; import FAQEditor from "./Sections/FAQEditor"; const subDirectory = import.meta.env.ENV_BASE_URL; const LandingPageCMS = () => { const navigate = useNavigate(); const dispatch = useDispatch(); const [activeSection, setActiveSection] = useState("hero"); const [isSaving, setIsSaving] = useState(false); const [hasChanges, setHasChanges] = useState(false); const [isAuthorized, setIsAuthorized] = useState(false); const [isCheckingAuth, setIsCheckingAuth] = useState(true); const [isDarkMode, setIsDarkMode] = useState(true); const [isMobileSidebarOpen, setIsMobileSidebarOpen] = useState(false); // Load theme preference from localStorage useEffect(() => { const savedTheme = localStorage.getItem("landing-cms-theme"); if (savedTheme) { setIsDarkMode(savedTheme === "dark"); } }, []); const toggleTheme = () => { const newTheme = !isDarkMode; setIsDarkMode(newTheme); localStorage.setItem("landing-cms-theme", newTheme ? "dark" : "light"); }; // 📱 Prevent body scroll when mobile sidebar is open useEffect(() => { if (isMobileSidebarOpen && window.innerWidth <= 900) { document.body.style.overflow = "hidden"; } else { document.body.style.overflow = ""; } return () => { document.body.style.overflow = ""; }; }, [isMobileSidebarOpen]); // 🔒 Authentication Check useEffect(() => { const checkAuthentication = () => { const userType = getSession("UserType"); const userId = getSession("UserId"); const authToken = sessionStorage.getItem("auth"); // Allow only Marketing, Super Admin, or Admin const allowedUserTypes = ["Marketing", "Super Admin", "Admin", "Super Admin User"]; if (!authToken || !userId || !allowedUserTypes.includes(userType)) { message.error("Unauthorized access! Please login first."); navigate(`${subDirectory}signin`); return; } setIsAuthorized(true); setIsCheckingAuth(false); }; checkAuthentication(); }, [navigate]); const sections = [ { id: "hero", name: "Hero Section", icon: , description: "Main headline, subtext, and CTA button", component: HeroContentEditor }, { id: "offerings", name: "Offerings", icon: , description: "3 key features (Experience, Innovation, Cost)", component: OfferingsEditor }, { id: "features", name: "Features", icon: , description: "Product features and benefits", component: FeaturesEditor }, { id: "faq", name: "FAQ Section", icon: , description: "Frequently asked questions", component: FAQEditor } ]; const currentSection = sections.find(s => s.id === activeSection); const CurrentComponent = currentSection?.component; const handlePreview = () => { window.open(`${subDirectory}`, '_blank'); }; const handleSaveAll = async () => { setIsSaving(true); try { // Save logic will be implemented in each section component message.success("All changes saved successfully!"); setHasChanges(false); } catch (error) { message.error("Failed to save changes"); } finally { setIsSaving(false); } }; // Show loading while checking auth if (isCheckingAuth) { return (

Verifying access...

); } // Don't render if not authorized (will redirect) if (!isAuthorized) { return null; } return (
{/* Top Header */}

Landing Page CMS

Manage your homepage content dynamically

{/* Mobile Overlay */} {isMobileSidebarOpen && (
setIsMobileSidebarOpen(false)} aria-hidden="true" /> )} {/* Sidebar Navigation */}
Content Sections
{sections.map((section) => ( ))}
{/* Content Area */}
Landing Page / {currentSection?.name}
{hasChanges && (
Unsaved changes
)}
{CurrentComponent && ( setHasChanges(true)} /> )}
); }; export default LandingPageCMS;