summaryrefslogtreecommitdiff
path: root/src/components/Header.js
diff options
context:
space:
mode:
authorRafi Zadanly <rafizadanly@gmail.com>2022-12-22 15:29:18 +0700
committerRafi Zadanly <rafizadanly@gmail.com>2022-12-22 15:29:18 +0700
commit31d6352ab8855754ef18c01763d3c1b5a68de857 (patch)
treee9b7e67a994574b5b1ccc7c8ef805a899f561d3d /src/components/Header.js
parent7ca4c68e3c509004a84d05ebd6d66019c7e92b72 (diff)
Appbar component and auth hook (useAuth)
Diffstat (limited to 'src/components/Header.js')
-rw-r--r--src/components/Header.js31
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">