"use client" import { useEffect, useState } from "react" import { useNavigate } from "react-router-dom" import { LogOut, Menu, Settings, UserCircle2 } from "lucide-react" import { Avatar, AvatarFallback, AvatarImage } from "../ui/avatar" import * as DropdownMenu from "@radix-ui/react-dropdown-menu" import { cn } from "../../lib/utils" import { NotificationDropdown } from "./NotificationDropdown" type TopbarProps = { onMenuClick: () => void } export function Topbar({ onMenuClick }: TopbarProps) { const navigate = useNavigate() const [shortName, setShortName] = useState("AA") useEffect(() => { const updateShortName = () => { const first = localStorage.getItem("user_first_name") ?? "A" const last = localStorage.getItem("user_last_name") ?? "A" setShortName(first.charAt(0).toUpperCase() + last.charAt(0).toUpperCase()) } updateShortName() window.addEventListener("user-profile-updated", updateShortName) return () => window.removeEventListener("user-profile-updated", updateShortName) }, []) const handleOptionClick = (option: string) => { switch (option) { case "profile": navigate("/profile") break case "settings": navigate("/settings") break case "logout": localStorage.clear() window.location.href = "/login" break } } return (
{/* Mobile hamburger */}
{/* Notifications */} {/* Separator */}
{/* Avatar + Radix Dropdown */} handleOptionClick("profile")} > Profile handleOptionClick("settings")} > Settings handleOptionClick("logout")} > Logout
) }