2020-04-06 16:46:03 +02:00
|
|
|
import { Fragment, useState, useContext } from 'react';
|
|
|
|
import { UserContext } from '../../contexts/UserContext';
|
2020-03-18 16:26:18 +01:00
|
|
|
import Link from 'next/link';
|
2020-04-07 13:56:56 +02:00
|
|
|
import { useRouter } from 'next/router';
|
2020-03-17 15:34:26 +01:00
|
|
|
import NavigationLink from './NavigationLink';
|
|
|
|
import './Header.css';
|
|
|
|
|
|
|
|
export default function Header() {
|
|
|
|
|
2020-04-06 23:06:21 +02:00
|
|
|
const { isAuth, logoutUser, user } = useContext(UserContext);
|
|
|
|
const [isActive, setIsActive] = useState(false);
|
2020-04-07 13:56:56 +02:00
|
|
|
const { pathname } = useRouter();
|
2020-03-17 15:34:26 +01:00
|
|
|
|
|
|
|
const toggleNavbar = () => {
|
2020-03-25 18:22:03 +01:00
|
|
|
setIsActive(!isActive);
|
2020-03-17 15:34:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<header className="Header">
|
|
|
|
<div className="container">
|
|
|
|
|
|
|
|
{/* Brand */}
|
2020-03-18 16:26:18 +01:00
|
|
|
<Link href={"/"}>
|
|
|
|
<a className="Header__brand-link">
|
|
|
|
<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" />
|
|
|
|
</a>
|
2020-03-17 15:34:26 +01:00
|
|
|
</Link>
|
|
|
|
|
|
|
|
{/* Hamburger icon on Mobile */}
|
2020-03-25 18:22:03 +01:00
|
|
|
<div onClick={toggleNavbar} className={`Header__hamburger ${(isActive) ? "Header__hamburger-active" : ""}`}>
|
2020-03-17 15:34:26 +01:00
|
|
|
<span></span>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
{/* Navigation */}
|
|
|
|
<nav className="Header__navbar">
|
2020-03-25 18:22:03 +01:00
|
|
|
<ul className={`navbar__list ${(isActive) ? "navbar__list-active" : ""}`}>
|
2020-03-17 15:34:26 +01:00
|
|
|
<NavigationLink name="Accueil" path="/" />
|
2020-03-19 16:13:51 +01:00
|
|
|
<NavigationLink name="Fonctions" path="/functions" />
|
2020-05-04 12:58:36 +02:00
|
|
|
<NavigationLink name="Utilisateurs" path="/users" />
|
2020-04-06 16:46:03 +02:00
|
|
|
{
|
|
|
|
(!isAuth) ?
|
|
|
|
<Fragment>
|
2020-04-23 17:45:21 +02:00
|
|
|
<NavigationLink name="S'inscrire" path="/users/register" />
|
|
|
|
<NavigationLink name="Connexion" path="/users/login" />
|
2020-04-06 16:46:03 +02:00
|
|
|
</Fragment>
|
|
|
|
:
|
|
|
|
<Fragment>
|
2020-04-06 23:06:21 +02:00
|
|
|
<li className="navbar-item">
|
2020-04-23 17:45:21 +02:00
|
|
|
<Link href={"/users/[name]"} as={`/users/${user.name}`}>
|
|
|
|
<a className={`navbar-link ${pathname === "/users/[name]" ? "navbar-link-active" : null}`}>Mon Profil</a>
|
2020-04-06 23:06:21 +02:00
|
|
|
</Link>
|
|
|
|
</li>
|
2020-04-06 16:46:03 +02:00
|
|
|
<li className="navbar-item">
|
|
|
|
<Link href={"/"}>
|
|
|
|
<a onClick={logoutUser} className="navbar-link">Se déconnecter</a>
|
|
|
|
</Link>
|
|
|
|
</li>
|
|
|
|
</Fragment>
|
|
|
|
}
|
2020-04-11 21:07:13 +02:00
|
|
|
{
|
|
|
|
(isAuth && user.isAdmin) &&
|
|
|
|
<NavigationLink name="Admin" path="/admin" />
|
|
|
|
}
|
2020-03-17 15:34:26 +01:00
|
|
|
</ul>
|
|
|
|
</nav>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
</header>
|
|
|
|
);
|
|
|
|
}
|