diff options
Diffstat (limited to 'src/components/Header.js')
| -rw-r--r-- | src/components/Header.js | 31 |
1 files changed, 13 insertions, 18 deletions
diff --git a/src/components/Header.js b/src/components/Header.js index a294c140..d41847ef 100644 --- a/src/components/Header.js +++ b/src/components/Header.js @@ -11,7 +11,7 @@ import { } from "@heroicons/react/24/outline"; // Helpers -import { getAuth } from "../helpers/auth"; +import { getAuth, useAuth } from "../helpers/auth"; // Components import Link from "./Link"; // Images @@ -24,11 +24,7 @@ export default function Header({ title }) { const [suggestions, setSuggestions] = useState([]); const searchQueryRef = useRef(); const [isMenuActive, setIsMenuActive] = useState(false); - const [auth, setAuth] = useState(); - - useEffect(() => { - if (!auth) setAuth(getAuth()); - }, [auth]); + const [auth, setAuth] = useAuth(); useEffect(() => { if (q) { @@ -76,24 +72,23 @@ export default function Header({ title }) { <div className={'menu-wrapper' + (isMenuActive ? ' active ' : '')}> <div className="flex gap-x-2 items-center border-b border-gray_r-6 p-4"> - {auth ? ( - <h1>Hi, {auth.name}</h1> - ) : ( + { auth && ( + <Link href="/my/menu" className="w-full flex text-gray_r-12"> + <h1>Hi, {auth.name}</h1> + <div className="ml-auto"> + <ChevronRightIcon className="w-5" /> + </div> + </Link> + ) } + + { !auth && ( <> <Link href="/login" onClick={closeMenu} className="w-full py-2 btn-light text-gray_r-12">Masuk</Link> <Link href="/register" onClick={closeMenu} className="w-full py-2 btn-yellow text-gray_r-12">Daftar</Link> </> - )} + ) } </div> <div className="flex flex-col"> - {auth && ( - <Link className="flex w-full font-normal text-gray_r-11 border-b border-gray_r-6 p-4 py-3" href="/my/profile" onClick={closeMenu}> - <span>Profil Saya</span> - <div className="ml-auto"> - <ChevronRightIcon className="text-gray_r-12 w-5" /> - </div> - </Link> - )} <Link className="flex w-full font-normal text-gray_r-11 border-b border-gray_r-6 p-4 py-3" href="/shop/brands" onClick={closeMenu}> <span>Semua Brand</span> <div className="ml-auto"> |
