import { Suspense, lazy, useEffect } from "react"; import { BrowserRouter as Router, Routes, Route, Navigate } from "react-router-dom"; import { HelmetProvider } from "react-helmet-async"; import AppLayout from "./layout/AppLayout"; import { ScrollToTop } from "./components/common/ScrollToTop"; import ProtectedRoute from "./components/auth/ProtectedRoute"; import ModuleGuard from "./components/common/ModuleGuard"; import GlobalErrorDisplay from "./components/common/GlobalErrorDisplay"; import LoadingStateMonitor from "./components/common/LoadingStateMonitor"; import { useAuthStore } from "./store/authStore"; // Auth pages - loaded immediately (needed for login) import SignIn from "./pages/AuthPages/SignIn"; import SignUp from "./pages/AuthPages/SignUp"; import NotFound from "./pages/OtherPage/NotFound"; // Lazy load all other pages - only loads when navigated to const Home = lazy(() => import("./pages/Dashboard/Home")); // Planner Module - Lazy loaded const PlannerDashboard = lazy(() => import("./pages/Planner/Dashboard")); const Keywords = lazy(() => import("./pages/Planner/Keywords")); const Clusters = lazy(() => import("./pages/Planner/Clusters")); const ClusterDetail = lazy(() => import("./pages/Planner/ClusterDetail")); const Ideas = lazy(() => import("./pages/Planner/Ideas")); const KeywordOpportunities = lazy(() => import("./pages/Planner/KeywordOpportunities")); // Writer Module - Lazy loaded const WriterDashboard = lazy(() => import("./pages/Writer/Dashboard")); const Tasks = lazy(() => import("./pages/Writer/Tasks")); const Content = lazy(() => import("./pages/Writer/Content")); const ContentView = lazy(() => import("./pages/Writer/ContentView")); const Drafts = lazy(() => import("./pages/Writer/Drafts")); const Images = lazy(() => import("./pages/Writer/Images")); const Review = lazy(() => import("./pages/Writer/Review")); const Published = lazy(() => import("./pages/Writer/Published")); // Automation Module - Lazy loaded const AutomationPage = lazy(() => import("./pages/Automation/AutomationPage")); // Linker Module - Lazy loaded const LinkerDashboard = lazy(() => import("./pages/Linker/Dashboard")); const LinkerContentList = lazy(() => import("./pages/Linker/ContentList")); // Optimizer Module - Lazy loaded const OptimizerDashboard = lazy(() => import("./pages/Optimizer/Dashboard")); const OptimizerContentSelector = lazy(() => import("./pages/Optimizer/ContentSelector")); const AnalysisPreview = lazy(() => import("./pages/Optimizer/AnalysisPreview")); // Thinker Module - Lazy loaded const ThinkerDashboard = lazy(() => import("./pages/Thinker/Dashboard")); const Prompts = lazy(() => import("./pages/Thinker/Prompts")); const AuthorProfiles = lazy(() => import("./pages/Thinker/AuthorProfiles")); const ThinkerProfile = lazy(() => import("./pages/Thinker/Profile")); const Strategies = lazy(() => import("./pages/Thinker/Strategies")); const ImageTesting = lazy(() => import("./pages/Thinker/ImageTesting")); // Billing Module - Lazy loaded const Credits = lazy(() => import("./pages/Billing/Credits")); const Transactions = lazy(() => import("./pages/Billing/Transactions")); const Usage = lazy(() => import("./pages/Billing/Usage")); const CreditsAndBilling = lazy(() => import("./pages/Settings/CreditsAndBilling")); // Admin Module - Lazy loaded const AdminBilling = lazy(() => import("./pages/Admin/AdminBilling")); // Reference Data - Lazy loaded const SeedKeywords = lazy(() => import("./pages/Reference/SeedKeywords")); const ReferenceIndustries = lazy(() => import("./pages/Reference/Industries")); // Setup Pages - Lazy loaded const IndustriesSectorsKeywords = lazy(() => import("./pages/Setup/IndustriesSectorsKeywords")); // Settings - Lazy loaded const GeneralSettings = lazy(() => import("./pages/Settings/General")); const Users = lazy(() => import("./pages/Settings/Users")); const Subscriptions = lazy(() => import("./pages/Settings/Subscriptions")); const SystemSettings = lazy(() => import("./pages/Settings/System")); const AccountSettings = lazy(() => import("./pages/Settings/Account")); const ModuleSettings = lazy(() => import("./pages/Settings/Modules")); const AISettings = lazy(() => import("./pages/Settings/AI")); const Plans = lazy(() => import("./pages/Settings/Plans")); const Industries = lazy(() => import("./pages/Settings/Industries")); const MasterStatus = lazy(() => import("./pages/Settings/MasterStatus")); const ApiMonitor = lazy(() => import("./pages/Settings/ApiMonitor")); const DebugStatus = lazy(() => import("./pages/Settings/DebugStatus")); const Integration = lazy(() => import("./pages/Settings/Integration")); const Publishing = lazy(() => import("./pages/Settings/Publishing")); const Sites = lazy(() => import("./pages/Settings/Sites")); const ImportExport = lazy(() => import("./pages/Settings/ImportExport")); // Sites - Lazy loaded const SiteList = lazy(() => import("./pages/Sites/List")); const SiteManage = lazy(() => import("./pages/Sites/Manage")); const SiteDashboard = lazy(() => import("./pages/Sites/Dashboard")); const SiteContent = lazy(() => import("./pages/Sites/Content")); const PageManager = lazy(() => import("./pages/Sites/PageManager")); const PostEditor = lazy(() => import("./pages/Sites/PostEditor")); const SiteSettings = lazy(() => import("./pages/Sites/Settings")); const SyncDashboard = lazy(() => import("./pages/Sites/SyncDashboard")); const DeploymentPanel = lazy(() => import("./pages/Sites/DeploymentPanel")); // Help - Lazy loaded const Help = lazy(() => import("./pages/Help/Help")); const Docs = lazy(() => import("./pages/Help/Docs")); const SystemTesting = lazy(() => import("./pages/Help/SystemTesting")); const FunctionTesting = lazy(() => import("./pages/Help/FunctionTesting")); // Components - Lazy loaded const Components = lazy(() => import("./pages/Components")); // UI Elements - Lazy loaded (rarely used) const Alerts = lazy(() => import("./pages/Settings/UiElements/Alerts")); const Avatars = lazy(() => import("./pages/Settings/UiElements/Avatars")); const Badges = lazy(() => import("./pages/Settings/UiElements/Badges")); const Breadcrumb = lazy(() => import("./pages/Settings/UiElements/Breadcrumb")); const Buttons = lazy(() => import("./pages/Settings/UiElements/Buttons")); const ButtonsGroup = lazy(() => import("./pages/Settings/UiElements/ButtonsGroup")); const Cards = lazy(() => import("./pages/Settings/UiElements/Cards")); const Carousel = lazy(() => import("./pages/Settings/UiElements/Carousel")); const Dropdowns = lazy(() => import("./pages/Settings/UiElements/Dropdowns")); const ImagesUI = lazy(() => import("./pages/Settings/UiElements/Images")); const Links = lazy(() => import("./pages/Settings/UiElements/Links")); const List = lazy(() => import("./pages/Settings/UiElements/List")); const Modals = lazy(() => import("./pages/Settings/UiElements/Modals")); const Notifications = lazy(() => import("./pages/Settings/UiElements/Notifications")); const Pagination = lazy(() => import("./pages/Settings/UiElements/Pagination")); const Popovers = lazy(() => import("./pages/Settings/UiElements/Popovers")); const PricingTable = lazy(() => import("./pages/Settings/UiElements/PricingTable")); const Progressbar = lazy(() => import("./pages/Settings/UiElements/Progressbar")); const Ribbons = lazy(() => import("./pages/Settings/UiElements/Ribbons")); const Spinners = lazy(() => import("./pages/Settings/UiElements/Spinners")); const Tabs = lazy(() => import("./pages/Settings/UiElements/Tabs")); const Tooltips = lazy(() => import("./pages/Settings/UiElements/Tooltips")); const Videos = lazy(() => import("./pages/Settings/UiElements/Videos")); export default function App() { const isAuthenticated = useAuthStore((state) => state.isAuthenticated); const refreshUser = useAuthStore((state) => state.refreshUser); const logout = useAuthStore((state) => state.logout); useEffect(() => { if (!isAuthenticated) { return; } refreshUser().catch((error) => { console.warn('Session validation failed:', error); logout(); }); }, [isAuthenticated, refreshUser, logout]); return ( <> {/* Auth Routes - Public */} } /> } /> {/* Protected Routes - Require Authentication */} } > {/* Dashboard */} } /> {/* Planner Module - Redirect dashboard to keywords */} } /> } /> } /> } /> } /> {/* Writer Module - Redirect dashboard to tasks */} } /> } /> {/* Writer Content Routes - Order matters: list route must come before detail route */} } /> {/* Content detail view - matches /writer/content/:id (e.g., /writer/content/10) */} } /> } /> } /> } /> } /> {/* Automation Module */} } /> {/* Linker Module - Redirect dashboard to content */} } /> } /> {/* Optimizer Module - Redirect dashboard to content */} } /> } /> } /> {/* Thinker Module */} {/* Thinker Module - Redirect dashboard to prompts */} } /> } /> } /> } /> } /> } /> {/* Billing Module */} } /> } /> } /> } /> } /> {/* Admin Routes */} } /> {/* Reference Data */} } /> } /> } /> {/* Setup Pages */} } /> {/* Legacy redirect */} } /> {/* Settings */} } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> {/* Sites Management */} } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> {/* Help */} } /> } /> } /> } /> {/* UI Elements */} } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> {/* Components (Showcase Page) */} } /> {/* Redirect old notification route */} } /> {/* Fallback Route */} } /> ); }