-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix responsive burger menu to show name, account & logout
- Loading branch information
1 parent
8699fcd
commit e2ef836
Showing
1 changed file
with
64 additions
and
40 deletions.
There are no files selected for viewing
104 changes: 64 additions & 40 deletions
104
src/client/src/components/DropDownLogout/DropDownLogout.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
</> | ||
)} | ||
</> | ||
); | ||
} |