This repository has been archived on 2024-10-29. You can view files and clone it, but cannot push or open issues or pull requests.
FunctionProject/website/components/Header/Header.js

70 lines
3.0 KiB
JavaScript
Raw Normal View History

import { Fragment, useState, useContext } from 'react';
import { UserContext } from '../../contexts/UserContext';
2020-03-18 16:26:18 +01:00
import Link from 'next/link';
import { useRouter } from 'next/router';
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);
const { pathname } = useRouter();
const toggleNavbar = () => {
setIsActive(!isActive);
}
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>
</Link>
{/* Hamburger icon on Mobile */}
<div onClick={toggleNavbar} className={`Header__hamburger ${(isActive) ? "Header__hamburger-active" : ""}`}>
<span></span>
</div>
{/* Navigation */}
<nav className="Header__navbar">
<ul className={`navbar__list ${(isActive) ? "navbar__list-active" : ""}`}>
<NavigationLink name="Accueil" path="/" />
<NavigationLink name="Fonctions" path="/functions" />
{
(!isAuth) ?
<Fragment>
<NavigationLink name="S'inscrire" path="/register" />
<NavigationLink name="Connexion" path="/login" />
</Fragment>
:
<Fragment>
2020-04-06 23:06:21 +02:00
<li className="navbar-item">
<Link href={"/profile/[name]"} as={`/profile/${user.name}`}>
<a className={`navbar-link ${pathname === "/profile/[name]" ? "navbar-link-active" : null}`}>Mon Profil</a>
2020-04-06 23:06:21 +02:00
</Link>
</li>
<li className="navbar-item">
<Link href={"/"}>
<a onClick={logoutUser} className="navbar-link">Se déconnecter</a>
</Link>
</li>
</Fragment>
}
{
(isAuth && user.isAdmin) &&
<NavigationLink name="Admin" path="/admin" />
}
</ul>
</nav>
</div>
</header>
);
}