diff --git a/apps/web/src/components/DashboardLayout.tsx b/apps/web/src/components/DashboardLayout.tsx index df81ad7..d3ed629 100644 --- a/apps/web/src/components/DashboardLayout.tsx +++ b/apps/web/src/components/DashboardLayout.tsx @@ -67,16 +67,30 @@ export function DashboardLayout({children}: DashboardLayoutProps) { const [showProjectMenu, setShowProjectMenu] = useState(false); const [showUserMenu, setShowUserMenu] = useState(false); const [showMobileMenu, setShowMobileMenu] = useState(false); - const projectMenuRef = useRef(null); - const userMenuRef = useRef(null); + const desktopProjectMenuRef = useRef(null); + const desktopUserMenuRef = useRef(null); + const mobileProjectMenuRef = useRef(null); + const mobileUserMenuRef = useRef(null); // Handle click outside for project menu useEffect(() => { function handleClickOutside(event: MouseEvent) { - if (projectMenuRef.current && !projectMenuRef.current.contains(event.target as Node)) { + const isClickOutsideProjectMenu = + desktopProjectMenuRef.current && + !desktopProjectMenuRef.current.contains(event.target as Node) && + mobileProjectMenuRef.current && + !mobileProjectMenuRef.current.contains(event.target as Node); + + const isClickOutsideUserMenu = + desktopUserMenuRef.current && + !desktopUserMenuRef.current.contains(event.target as Node) && + mobileUserMenuRef.current && + !mobileUserMenuRef.current.contains(event.target as Node); + + if (isClickOutsideProjectMenu) { setShowProjectMenu(false); } - if (userMenuRef.current && !userMenuRef.current.contains(event.target as Node)) { + if (isClickOutsideUserMenu) { setShowUserMenu(false); } } @@ -134,7 +148,10 @@ export function DashboardLayout({children}: DashboardLayoutProps) { ); // Sidebar content (reusable for both desktop and mobile) - const sidebarContent = ( + const getSidebarContent = ( + projectMenuRef: React.RefObject, + userMenuRef: React.RefObject, + ) => ( <> {/* Logo */}
@@ -164,7 +181,9 @@ export function DashboardLayout({children}: DashboardLayoutProps) { {availableProjects.map(project => (