Skip to content

Commit

Permalink
fix responsive burger menu to show name, account & logout
Browse files Browse the repository at this point in the history
  • Loading branch information
rebeccadumazert committed Oct 22, 2024
1 parent 8699fcd commit e2ef836
Showing 1 changed file with 64 additions and 40 deletions.
104 changes: 64 additions & 40 deletions src/client/src/components/DropDownLogout/DropDownLogout.tsx
Original file line number Diff line number Diff line change
@@ -1,47 +1,71 @@
import { useEffect, useState } from "react";
import { getUserInfos } from "../../lib/authentication";

export function DropDownLogout() {
const [width, setWidth] = useState(window.innerWidth);

useEffect(() => {
const handleResize = () => setWidth(window.innerWidth);
window.addEventListener("resize", handleResize);
return () => window.removeEventListener("resize", handleResize);
}, []);

const { lastName, firstName } = getUserInfos();
return (
<nav role="navigation" className="fr-translate fr-nav">
<div className="fr-nav__item">
<button
className="fr-btn--icon-left fr-icon-account-circle-line fr-btn fr-btn--tertiary"
aria-controls="translate-1177"
aria-expanded="false"
title="Sélectionner une langue"
>
{`${firstName} ${lastName}`}
</button>
<div
className="fr-collapse fr-translate__menu fr-menu"
id="translate-1177"
>
<ul className="fr-menu__list">
<li>
<a
className="fr-translate__language fr-nav__link"
lang="fr"
href="/mon-compte"
aria-current={
window.location.pathname === "/mon-compte" ? true : false
}
>
Mon compte
</a>
</li>
<li>
<a
className="fr-translate__language fr-nav__link"
lang="en"
href="/openid/logout"
>
Se déconnecter
</a>
</li>
</ul>
</div>
</div>
</nav>
<>
{width >= 991 ? (
<nav role="navigation" className="fr-translate fr-nav">
<div className="fr-nav__item">
<button
className="fr-btn--icon-left fr-icon-account-circle-line fr-btn fr-btn--tertiary"
aria-controls="name-account"
aria-expanded="false"
title="Nom de la personne connectée"
>
{`${firstName} ${lastName}`}
</button>
<div
className="fr-collapse fr-translate__menu fr-menu"
id="name-account"
>
<ul className="fr-menu__list">
<li>
<a
className="fr-translate__language fr-nav__link"
href="/mon-compte"
aria-current={
window.location.pathname === "/mon-compte" ? true : false
}
>
Mon compte
</a>
</li>
<li>
<a
className="fr-translate__language fr-nav__link"
href="/openid/logout"
>
Se déconnecter
</a>
</li>
</ul>
</div>
</div>
</nav>
) : (
<>
<a
href="/mon-compte"
rel="noreferrer"
className="fr-btn fr-icon-account-line"
>
Mon compte {`(${firstName} ${lastName})`}
</a>
<a className="fr-btn fr-icon-logout-box-r-line" href="/openid/logout">
Se déconnecter
</a>
</>
)}
</>
);
}

0 comments on commit e2ef836

Please sign in to comment.