'use client'; import { useState, useEffect, useRef } from 'react'; import Link from 'next/link'; import Image from 'next/image'; import { useSession, signOut } from 'next-auth/react'; const navLinks = [ { label: 'Education', href: '/education' }, { label: 'About Us', href: '/about' }, { label: "FAQ's", href: '/faq' }, ]; export function CommonHeader() { const { data: session } = useSession(); const [showProfileMenu, setShowProfileMenu] = useState(false); const profileMenuRef = useRef(null); // Close dropdown when clicking outside useEffect(() => { function handleClickOutside(event: MouseEvent) { if (profileMenuRef.current && !profileMenuRef.current.contains(event.target as Node)) { setShowProfileMenu(false); } } if (showProfileMenu) { document.addEventListener('mousedown', handleClickOutside); } return () => { document.removeEventListener('mousedown', handleClickOutside); }; }, [showProfileMenu]); const userName = session?.user?.name; const userEmail = session?.user?.email; const userRole = (session?.user as any)?.role; // Determine dashboard link based on user role const dashboardLink = userRole === 'AGENT' ? '/agent/dashboard' : '/user/dashboard'; return (
{/* Logo */} RE-QuestN {/* Navigation */} {/* Right Side Icons */}
{session ? ( <> {/* Notification Bell */} {/* Profile Section with Greeting - Entire area clickable */}
{/* Profile Dropdown Menu */} {showProfileMenu && (
{/* Arrow/Triangle at top */}
{/* User Profile Section */}
Profile

{userName?.split(' ')[0] || 'User'}

{userEmail}

{/* Account Settings */} setShowProfileMenu(false)} > Settings

Account Settings

Profile, Security

{/* Notification Settings */} setShowProfileMenu(false)} > Notifications

Notification Settings

{/* Log Out */}
)}
) : (
Login Sign Up
)} {/* Mobile Menu Button */}
); }