From 8733795c8449f3514369d7b4220934760e386f1b Mon Sep 17 00:00:00 2001 From: Biswa Kalyan Bhuyan Date: Fri, 25 Apr 2025 01:09:30 +0530 Subject: finance/frontend: fix: did some minor changes to the frontend --- frontend/src/app/(main)/layout.tsx | 437 +++++++++++++++++-------------------- 1 file changed, 203 insertions(+), 234 deletions(-) (limited to 'frontend/src/app/(main)') diff --git a/frontend/src/app/(main)/layout.tsx b/frontend/src/app/(main)/layout.tsx index ee1026c..11e557b 100644 --- a/frontend/src/app/(main)/layout.tsx +++ b/frontend/src/app/(main)/layout.tsx @@ -1,12 +1,12 @@ 'use client'; -import { useEffect, useState } from 'react'; -import { useRouter } from 'next/navigation'; +import { useState, useEffect } from 'react'; import Link from 'next/link'; import { Button } from '@/components/ui/button'; -import { authApi, userApi } from '@/lib/api'; import { ThemeToggle } from '@/components/shared/ThemeToggle'; import { PageTransition } from '@/components/shared/PageTransition'; +import ProtectedRoute from '@/components/shared/ProtectedRoute'; +import { useAuth } from '@/components/shared/AuthContext'; import { ChevronLeftIcon, ChevronRightIcon, @@ -25,38 +25,18 @@ export default function MainLayout({ }: Readonly<{ children: React.ReactNode; }>) { - const router = useRouter(); const pathname = usePathname(); - const [userName, setUserName] = useState(''); - const [isLoading, setIsLoading] = useState(true); + const { user, logout } = useAuth(); const [isSidebarCollapsed, setIsSidebarCollapsed] = useState(false); const [isMobileMenuOpen, setIsMobileMenuOpen] = useState(false); useEffect(() => { - // Check if user is authenticated - const token = localStorage.getItem('token'); - if (!token) { - router.push('/login'); - return; - } - - // Fetch user profile - userApi.getProfile() - .then(data => { - setUserName(data.user.Name); - setIsLoading(false); - }) - .catch(() => { - // If error fetching profile, redirect to login - router.push('/login'); - }); - // Load sidebar state from localStorage const savedSidebarState = localStorage.getItem('sidebarCollapsed'); if (savedSidebarState !== null) { setIsSidebarCollapsed(savedSidebarState === 'true'); } - }, [router]); + }, []); // Close mobile menu when changing routes useEffect(() => { @@ -64,7 +44,7 @@ export default function MainLayout({ }, [pathname]); const handleLogout = () => { - authApi.logout(); + logout(); }; const toggleSidebar = () => { @@ -77,227 +57,216 @@ export default function MainLayout({ setIsMobileMenuOpen(!isMobileMenuOpen); }; - if (isLoading) { - return ( -
-
-
-
-
-

Loading...

-
-
- ); - } - return ( -
- {/* Top Navigation */} -
-
-
- {/* Mobile menu button - only visible on small screens */} - -
- - Finance Management - + +
+ {/* Top Navigation */} +
+
+
+ {/* Mobile menu button - only visible on small screens */} + +
+ + Finance Management + +
-
- -
-
- - - - - - {userName} - + +
+
+ + + + + + {user?.Name} + +
+ +
- - -
-
-
- - {/* Mobile Menu - outside the normal flow and only visible when toggled */} -
-
- -
-
-
-
+
- {/* Main Content */} -
- {/* Sidebar - hidden on mobile */} - + + +
+ +
+
+
- {/* Page Content */} -
- - {children} - -
+ {/* Main Content */} +
+ {/* Sidebar - hidden on mobile */} + + + {/* Page Content */} +
+ + {children} + +
+
- + ); } \ No newline at end of file -- cgit v1.2.3-59-g8ed1b