@@ -22,21 +22,21 @@ export const NavBar = () => {
2222 logout ( ) ;
2323 router . push ( "/" ) ;
2424 } ;
25- const handleSubmit = async ( e : React . FormEvent ) => {
25+
26+ const handleSubmit = async ( e : React . FormEvent ) => {
2627 e . preventDefault ( ) ;
2728 try {
2829 console . log ( "Buscando produto:" , findItem ) ;
2930 const response = await api . get < productType > ( `/product/name/${ findItem } ` ) ;
3031 console . log ( "Resposta da API:" , response . data ) ;
3132 const product = response . data ;
3233 console . log ( "Produto encontrado:" , product ) ;
33- // Redireciona para a rota de resultados com o ID do produto como query parameter
3434 setFindItem ( "" ) ;
3535 router . push ( `/search?productId=${ product . id } ` ) ;
36- } catch ( error ) {
36+ } catch ( error ) {
3737 console . error ( "Erro ao buscar produto:" , error ) ;
38- }
39- }
38+ }
39+ } ;
4040
4141 // Fecha dropdowns ao clicar fora
4242 const userMenuRef = useRef < HTMLDivElement > ( null ) ;
@@ -74,44 +74,45 @@ export const NavBar = () => {
7474
7575 < div className = "flex items-center w-80" >
7676 < form action = "" onSubmit = { handleSubmit } className = "flex w-full" >
77- < input
78- type = "text"
79- className = "rounded-md w-80 text-black"
80- placeholder = " what is your desire today?"
81- value = { findItem }
82- onChange = { ( e ) => setFindItem ( e . target . value ) }
83- />
84- < button className = "rounded-md text-white text-lg w-12 flex items-center justify-center" >
85- < CiSearch />
86- </ button >
77+ < input
78+ type = "text"
79+ className = "rounded-md w-80 text-black"
80+ placeholder = " what is your desire today?"
81+ value = { findItem }
82+ onChange = { ( e ) => setFindItem ( e . target . value ) }
83+ />
84+ < button className = "rounded-md text-white text-lg w-12 flex items-center justify-center" >
85+ < CiSearch />
86+ </ button >
8787 </ form >
88-
8988 </ div >
9089
9190 < div className = "flex gap-4" >
9291 { user ? (
9392 < div className = "flex gap-4 items-center" >
9493 { /* Dropdown Management */ }
95- < div className = "relative" ref = { managementMenuRef } >
96- < button
97- onClick = { ( ) => setOpenManagementMenu ( ! openManagementMenu ) }
98- className = "uppercase font-bold text-sm h-12 flex items-center"
99- >
100- Management
101- </ button >
102- { openManagementMenu && (
103- < div className = "absolute right-0 mt-2 w-40 rounded-xl shadow-lg bg-white text-black ring-1 ring-black/5 z-50" >
104- < ul className = "py-2 text-sm" >
105- < li className = "px-4 py-2 hover:bg-gray-100 cursor-pointer" >
106- < Link href = "/admin/newProduct" > New Product</ Link >
107- </ li >
108- < li className = "px-4 py-2 hover:bg-gray-100 cursor-pointer" >
109- < Link href = "/admin/stocks" > Stocks</ Link >
110- </ li >
111- </ ul >
112- </ div >
113- ) }
114- </ div >
94+ { user . role === "admin" && (
95+ < div className = "relative" ref = { managementMenuRef } >
96+ < button
97+ onClick = { ( ) => setOpenManagementMenu ( ! openManagementMenu ) }
98+ className = "uppercase font-bold text-sm h-12 flex items-center"
99+ >
100+ Management
101+ </ button >
102+ { openManagementMenu && (
103+ < div className = "absolute right-0 mt-2 w-40 rounded-xl shadow-lg bg-white text-black ring-1 ring-black/5 z-50" >
104+ < ul className = "py-2 text-sm" >
105+ < li className = "px-4 py-2 hover:bg-gray-100 cursor-pointer" >
106+ < Link href = "/admin/newProduct" > New Product</ Link >
107+ </ li >
108+ < li className = "px-4 py-2 hover:bg-gray-100 cursor-pointer" >
109+ < Link href = "/admin/stocks" > Stocks</ Link >
110+ </ li >
111+ </ ul >
112+ </ div >
113+ ) }
114+ </ div >
115+ ) }
115116
116117 { /* Dropdown User */ }
117118 < div className = "relative" ref = { userMenuRef } >
@@ -156,4 +157,4 @@ export const NavBar = () => {
156157 </ div >
157158 </ nav >
158159 ) ;
159- } ;
160+ } ;
0 commit comments