2020-08-03 12:04:07 +02:00
|
|
|
import { useState, useContext } from 'react'
|
|
|
|
import { UserContext } from '../../contexts/UserContext'
|
|
|
|
import Link from 'next/link'
|
|
|
|
import { useRouter } from 'next/router'
|
|
|
|
import NavigationLink from './NavigationLink'
|
|
|
|
import './Header.css'
|
2020-03-17 15:34:26 +01:00
|
|
|
|
2020-08-03 12:04:07 +02:00
|
|
|
export default function Header () {
|
|
|
|
const { isAuth, logoutUser, user } = useContext(UserContext)
|
|
|
|
const [isActive, setIsActive] = useState(false)
|
|
|
|
const { pathname } = useRouter()
|
2020-03-17 15:34:26 +01:00
|
|
|
|
2020-08-03 12:04:07 +02:00
|
|
|
const toggleNavbar = () => {
|
|
|
|
setIsActive(!isActive)
|
|
|
|
}
|
2020-03-17 15:34:26 +01:00
|
|
|
|
2020-08-03 12:04:07 +02:00
|
|
|
return (
|
|
|
|
<header className='Header'>
|
|
|
|
<div className='container'>
|
|
|
|
{/* Brand */}
|
|
|
|
<Link href='/'>
|
|
|
|
<a className='Header__brand-link'>
|
2020-08-03 14:14:45 +02:00
|
|
|
<img
|
|
|
|
id='brand-link__logo'
|
|
|
|
src='/images/FunctionProject_brand-logo.png'
|
|
|
|
alt='FunctionProject'
|
|
|
|
/>
|
|
|
|
<img
|
|
|
|
id='brand-link__logo-small-screen'
|
|
|
|
src='/images/FunctionProject_icon_small.png'
|
|
|
|
alt='FunctionProject'
|
|
|
|
/>
|
2020-08-03 12:04:07 +02:00
|
|
|
</a>
|
|
|
|
</Link>
|
2020-03-17 15:34:26 +01:00
|
|
|
|
2020-08-03 12:04:07 +02:00
|
|
|
{/* Hamburger icon on Mobile */}
|
2020-08-03 14:14:45 +02:00
|
|
|
<div
|
|
|
|
onClick={toggleNavbar}
|
|
|
|
className={`Header__hamburger ${
|
|
|
|
isActive ? 'Header__hamburger-active' : ''
|
|
|
|
}`}
|
|
|
|
>
|
2020-08-03 12:04:07 +02:00
|
|
|
<span />
|
|
|
|
</div>
|
2020-03-17 15:34:26 +01:00
|
|
|
|
2020-08-03 12:04:07 +02:00
|
|
|
{/* Navigation */}
|
|
|
|
<nav className='Header__navbar'>
|
2020-08-03 14:14:45 +02:00
|
|
|
<ul
|
|
|
|
className={`navbar__list ${isActive ? 'navbar__list-active' : ''}`}
|
|
|
|
>
|
2020-08-03 12:04:07 +02:00
|
|
|
<NavigationLink name='Accueil' path='/' />
|
|
|
|
<NavigationLink name='Fonctions' path='/functions' />
|
|
|
|
<NavigationLink name='Utilisateurs' path='/users' />
|
2020-08-03 14:14:45 +02:00
|
|
|
{!isAuth ? (
|
|
|
|
<>
|
|
|
|
<NavigationLink name="S'inscrire" path='/users/register' />
|
|
|
|
<NavigationLink name='Connexion' path='/users/login' />
|
|
|
|
</>
|
|
|
|
) : (
|
|
|
|
<>
|
|
|
|
<li className='navbar-item'>
|
|
|
|
<Link href='/users/[name]' as={`/users/${user.name}`}>
|
|
|
|
<a
|
|
|
|
className={`navbar-link ${
|
|
|
|
pathname === '/users/[name]'
|
|
|
|
? 'navbar-link-active'
|
|
|
|
: null
|
|
|
|
}`}
|
|
|
|
>
|
|
|
|
Mon Profil
|
|
|
|
</a>
|
|
|
|
</Link>
|
|
|
|
</li>
|
|
|
|
<li className='navbar-item'>
|
|
|
|
<Link href='/'>
|
|
|
|
<a onClick={logoutUser} className='navbar-link'>
|
|
|
|
Se déconnecter
|
|
|
|
</a>
|
|
|
|
</Link>
|
|
|
|
</li>
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
{isAuth && user.isAdmin && (
|
|
|
|
<NavigationLink name='Admin' path='/admin' />
|
|
|
|
)}
|
2020-08-03 12:04:07 +02:00
|
|
|
</ul>
|
|
|
|
</nav>
|
|
|
|
</div>
|
|
|
|
</header>
|
|
|
|
)
|
|
|
|
}
|