diff --git a/src/App.tsx b/src/App.tsx index e8b0307..d24671a 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -28,7 +28,7 @@ import { Toaster } from "./components/ui/sonner"; import { Settings } from "lucide-react"; export default function App() { - const [isAuthenticated, setIsAuthenticated] = useState(false); + const [isAuthenticated, setIsAuthenticated] = useState(null); // null = loading const [user, setUser] = useState({ name: "Admin User", email: "admin@klc.edu", @@ -41,9 +41,7 @@ export default function App() { useEffect(() => { const authToken = localStorage.getItem("klc_auth_token"); - if (authToken) { - setIsAuthenticated(true); - } + setIsAuthenticated(!!authToken); // true if token exists, false otherwise }, []); const login = () => { @@ -58,6 +56,11 @@ export default function App() { navigate("/login"); }; + if (isAuthenticated === null) { + // while checking localStorage + return
Loading...
; + } + return (
diff --git a/src/components/layout/AuthenticatedLayout.tsx b/src/components/layout/AuthenticatedLayout.tsx index c9579f2..800d12b 100644 --- a/src/components/layout/AuthenticatedLayout.tsx +++ b/src/components/layout/AuthenticatedLayout.tsx @@ -1,15 +1,15 @@ import React, { useState } from 'react'; import { Button } from '../ui/button'; -import { - Home, - FileText, - GraduationCap, - Users, - Calendar, - Globe, - BarChart3, - Settings, - Menu, +import { + Home, + FileText, + GraduationCap, + Users, + Calendar, + Globe, + BarChart3, + Settings, + Menu, ChevronLeft, LogOut, User, @@ -20,7 +20,7 @@ import { ClipboardList, Target } from 'lucide-react'; -import { +import { Breadcrumb, BreadcrumbItem, BreadcrumbLink, @@ -29,7 +29,7 @@ import { BreadcrumbSeparator, } from '../ui/breadcrumb'; import { Avatar, AvatarFallback } from '../ui/avatar'; -import { +import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, @@ -171,19 +171,19 @@ const navigationItems: NavigationItem[] = [ } ]; -export function AuthenticatedLayout({ - children, - currentRoute, - // onNavigate, - onLogout, - user, - breadcrumbs = [] +export function AuthenticatedLayout({ + children, + currentRoute, + onLogout, + user, + breadcrumbs = [] }: AuthenticatedLayoutProps) { const [sidebarCollapsed, setSidebarCollapsed] = useState(false); + const navigate = useNavigate(); // Move useNavigate to the top level const isActiveRoute = (route: string) => { - return currentRoute === route || - (route === '/users/individual' && currentRoute.startsWith('/users/')); + return currentRoute === route || + (route === '/users/individual' && currentRoute.startsWith('/users/')); }; const getActiveParent = (items: NavigationItem[]): string | null => { @@ -205,27 +205,24 @@ export function AuthenticatedLayout({ const isParentActive = activeParent === item.id; const Icon = item.icon; - const navigate = useNavigate(); - return (
- + {/* Render children if parent is active and not collapsed */} {item.children && isParentActive && !sidebarCollapsed && (
@@ -235,11 +232,10 @@ export function AuthenticatedLayout({
); }; - const navigate = useNavigate(); return (
{/* Left Sidebar */} -
{!sidebarCollapsed && ( - Kautilya Leadership Centre )} @@ -275,7 +271,6 @@ export function AuthenticatedLayout({ {/* User Section */}
navigate('/profile')} > @@ -324,7 +319,7 @@ export function AuthenticatedLayout({ - navigate('/dashboard')} className="cursor-pointer" > @@ -336,7 +331,7 @@ export function AuthenticatedLayout({ {crumb.route && index < breadcrumbs.length - 1 ? ( - navigate(crumb.route!)} className="cursor-pointer" > diff --git a/src/components/ui/dropdown-menu.tsx b/src/components/ui/dropdown-menu.tsx index 4a6042f..d287f98 100644 --- a/src/components/ui/dropdown-menu.tsx +++ b/src/components/ui/dropdown-menu.tsx @@ -1,8 +1,8 @@ "use client"; import * as React from "react"; -import * as DropdownMenuPrimitive from "@radix-ui/react-dropdown-menu@2.1.6"; -import { CheckIcon, ChevronRightIcon, CircleIcon } from "lucide-react@0.487.0"; +import * as DropdownMenuPrimitive from "@radix-ui/react-dropdown-menu"; +import { CheckIcon, ChevronRightIcon, CircleIcon } from "lucide-react"; import { cn } from "./utils";