From 20980d8a804c91178c82977deb2426e413dcabdc Mon Sep 17 00:00:00 2001 From: Tiago Yamamoto Date: Tue, 23 Dec 2025 08:12:54 -0300 Subject: [PATCH] Add profile dropdown to marketplace header --- marketplace/src/layouts/Shell.tsx | 70 ++++++++++++++++++++++++++----- 1 file changed, 60 insertions(+), 10 deletions(-) diff --git a/marketplace/src/layouts/Shell.tsx b/marketplace/src/layouts/Shell.tsx index 0fc4353..6910a91 100644 --- a/marketplace/src/layouts/Shell.tsx +++ b/marketplace/src/layouts/Shell.tsx @@ -1,12 +1,28 @@ +import { useEffect, useRef, useState } from 'react' import { Link } from 'react-router-dom' import { useAuth } from '../context/AuthContext' export function Shell({ children }: { children: React.ReactNode }) { const { user, logout } = useAuth() + const [isProfileOpen, setIsProfileOpen] = useState(false) + const profileMenuRef = useRef(null) const isOwner = user?.role === 'owner' || user?.role === 'seller' const isAdmin = user?.role === 'admin' + useEffect(() => { + const handleClickOutside = (event: MouseEvent) => { + if (profileMenuRef.current && !profileMenuRef.current.contains(event.target as Node)) { + setIsProfileOpen(false) + } + } + + document.addEventListener('mousedown', handleClickOutside) + return () => { + document.removeEventListener('mousedown', handleClickOutside) + } + }, []) + return (
@@ -44,17 +60,51 @@ export function Shell({ children }: { children: React.ReactNode }) { Checkout - - Perfil da Empresa - {user && ( - +
+ + {isProfileOpen && ( +
+ {isOwner && ( + setIsProfileOpen(false)} + > + Perfil da Empresa + + )} + {isAdmin && ( + setIsProfileOpen(false)} + > + Meu Perfil + + )} + +
+ )} +
)}