diff --git a/components/header/Navbar.tsx b/components/header/Navbar.tsx index 43c3dbb..ac5dc7a 100644 --- a/components/header/Navbar.tsx +++ b/components/header/Navbar.tsx @@ -8,6 +8,8 @@ import Image from "next/image"; // import { useState } from "react"; import { usePathname } from "next/navigation"; import { Button } from "../ui/button"; +import { useEffect, useRef, useState } from "react"; +import NotificationDropdown from "../notifications/NotificationDropdown"; // const navItems = ["Dashboard", "Convert"]; @@ -20,11 +22,26 @@ const pageNames: Record = { }; export default function Navbar() { + const [notifOpen, setNotifOpen] = useState(false); + const notifRef = useRef(null); const pathname = usePathname(); - const currentPageName = pageNames[pathname] || "Dashboard"; const { toggleMobile, isCollapsed, isMobileOpen } = useSidebarStore(); + useEffect(() => { + function handleClickOutside(event: MouseEvent) { + if ( + notifRef.current && + !notifRef.current.contains(event.target as Node) + ) { + setNotifOpen(false); + } + } + + document.addEventListener("mousedown", handleClickOutside); + return () => document.removeEventListener("mousedown", handleClickOutside); + }, []); + return (