You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
83 lines
3.6 KiB
83 lines
3.6 KiB
import React, { useEffect, useRef, useState } from "react";
|
|
import logo from '../public/images/thetiptop_logo.webp';
|
|
import Link from "next/link";
|
|
import { useRouter } from "next/router";
|
|
import { signOut, useSession } from "next-auth/react";
|
|
import style from '../styles/NavBar.module.css';
|
|
import Image from 'next/image';
|
|
|
|
import { FiArrowRight } from 'react-icons/fi';
|
|
import { MdAdminPanelSettings } from 'react-icons/md';
|
|
import { BiExit } from 'react-icons/bi'
|
|
|
|
const NavBar = () => {
|
|
const navRef = useRef<HTMLInputElement>();
|
|
const [isAdmin, setIsAdmin] = useState<boolean>(false)
|
|
const { data: session } = useSession();
|
|
|
|
const closeNav = () => {
|
|
navRef.current.style.height = "0%";
|
|
}
|
|
|
|
const openNav = () => {
|
|
navRef.current.style.height = "100%";
|
|
}
|
|
|
|
const logout = () => {
|
|
signOut()
|
|
}
|
|
|
|
const checkRole = () => {
|
|
const isAdmin = ['SELLER', 'ADMIN', 'SUPERADMIN'].includes(session?.user['role']);
|
|
return isAdmin ? setIsAdmin(true) : setIsAdmin(false);
|
|
}
|
|
|
|
useEffect(() => {
|
|
checkRole();
|
|
}, [session?.user['role']])
|
|
|
|
let visitor = (
|
|
<nav className={`${style['navbar']}`}>
|
|
<div className="d-flex justify-content-center">
|
|
<Image
|
|
src={logo}
|
|
alt="thetiptop navigation logo big"
|
|
width={250}
|
|
height={100}
|
|
/>
|
|
</div>
|
|
<div className={`justify-content-center text-center ${style['hidden-mobile']}`}>
|
|
<Link href="/" legacyBehavior><a className={style.link} >Accueillllll</a></Link><p>|</p>
|
|
<Link href="/tout-savoir" legacyBehavior><a className={style.link} >Tout savoir</a></Link><p>|</p>
|
|
<Link href="/contact" legacyBehavior><a className={style.link} >Contactez-nous</a></Link><p>|</p>
|
|
{!session && <><Link href="/connexion" legacyBehavior><a className={style.link} >Connexion</a></Link></>}
|
|
{session && <><Link href="/mon-compte" legacyBehavior><a className={style.link} >Mon compte</a></Link><p>|</p></>}
|
|
{isAdmin && <><Link href="/admin" legacyBehavior><a className={style.link} >Administration <MdAdminPanelSettings /></a></Link><p>|</p></>}
|
|
{session && <><Link href="#" legacyBehavior><a onClick={() => logout()} className={style.link} >Se déconnecter <BiExit /></a></Link></>}
|
|
{session && <span className={`${style.connexion} badge rounded-pill bg-light text-dark`}>Vous-êtes connecté <FiArrowRight /> {session.user.email}</span>}
|
|
</div>
|
|
<div className={`justify-content-center text-center ${style['show-mobile']}`}>
|
|
<span className={`${style.burgerButton}`} onClick={openNav}>☰</span>
|
|
</div>
|
|
<div className="d-flex justify-content-center">
|
|
</div>
|
|
<div ref={navRef} className={style.overlay} onClick={closeNav}>
|
|
<a className={style.closebtn} onClick={closeNav}>×</a>
|
|
<div className={style['overlay-content']}>
|
|
<Link href="/" legacyBehavior><a className={style.link} >Accueil</a></Link> |
|
|
<Link href="/tout-savoir" legacyBehavior><a className={style.link} >Tout savoir</a></Link> |
|
|
<Link href="/contact" legacyBehavior><a className={style.link} >Contactez-nous</a></Link> |
|
|
{!session && <Link href="/connexion" legacyBehavior><a className={style.link} >Connexion</a></Link>} |
|
|
{session && <Link href="/mon-compte" legacyBehavior><a className={style.link} >Mon compte</a></Link>} |
|
|
{session && <Link href="#" legacyBehavior><a onClick={() => logout()} className={style.link} >Se déconnecter</a></Link>}
|
|
</div>
|
|
</div>
|
|
</nav>
|
|
)
|
|
return (<>
|
|
{visitor}
|
|
</>)
|
|
};
|
|
|
|
export default NavBar;
|