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.
The_Tip_Top/components/NavBar.tsx

89 lines
2.9 KiB

import React, { useRef } 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';
const NavBar = () => {
const navRef = useRef<HTMLInputElement>();
const router = useRouter();
const { data: session, status } = useSession();
console.log('role', session)
const closeNav = () => {
navRef.current.style.height = "0%";
}
const openNav = () => {
navRef.current.style.height = "100%";
}
const logout = () => {
signOut()
}
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} >Accueil </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></>}
{session && <><Link href="#" legacyBehavior><a onClick={() => logout()} className={style.link} >Se déconnecter</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}>&#9776;</span>
</div>
<div className="d-flex justify-content-center">
</div>
<div ref={navRef} className={style.overlay} onClick={closeNav}>
<a className={style.closebtn} onClick={closeNav}>&times;</a>
<div className="overlay-content">
<Link href="/contact" legacyBehavior><a className={style.link} >Accueil</a></Link> |
<Link href="/tout-savoir" legacyBehavior><a className={style.link} >Tout savoir</a></Link> |
<Link href="/" legacyBehavior><a className={style.link} >Contactez-nous</a></Link> |
<Link href="/connexion" legacyBehavior><a className={style.link} >Connexion</a></Link>
{session && <span className={`${style.connexion} badge rounded-pill bg-light text-dark`}><FiArrowRight />{session.user.email}</span>}
</div>
</div>
</nav>
)
return (<>
{visitor}
</>)
};
export default NavBar;