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:
Verifying access...
Manage your homepage content dynamically