This repository has been archived by the owner on Dec 14, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Mike Murray <hellomikemurray@gmail.com>
- Loading branch information
1 parent
67eb8d8
commit 29f471a
Showing
2 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import React, { Fragment, useState } from "react"; | ||
import PropTypes from "prop-types"; | ||
import { useHistory } from "react-router-dom"; | ||
import i18next from "i18next"; | ||
import ButtonBase from "@material-ui/core/ButtonBase"; | ||
import Menu from "@material-ui/core/Menu"; | ||
import MenuItem from "@material-ui/core/MenuItem"; | ||
import { | ||
Avatar | ||
} from "@material-ui/core"; | ||
import useAuth from "../hooks/useAuth"; | ||
|
||
/** | ||
* @summary ProfileMenu React component | ||
* @param {Object} props React props | ||
* @return {React.Node} React node | ||
*/ | ||
function ProfileMenu(props) { | ||
const { logout, viewer } = useAuth(); | ||
const history = useHistory(); | ||
const [menuAnchorEl, setMenuAnchorEl] = useState(null); | ||
|
||
if (!viewer) return null; | ||
|
||
return ( | ||
<Fragment> | ||
<ButtonBase | ||
centerRipple | ||
onClick={(event) => { | ||
setMenuAnchorEl(event.currentTarget); | ||
}} | ||
> | ||
<Avatar {...props} /> | ||
</ButtonBase> | ||
|
||
<Menu | ||
id="profile-actions-menu" | ||
anchorEl={menuAnchorEl} | ||
open={Boolean(menuAnchorEl)} | ||
onClose={() => setMenuAnchorEl(null)} | ||
> | ||
<MenuItem | ||
onClick={() => { | ||
setMenuAnchorEl(null); // close menu | ||
history.push("/profile"); | ||
}} | ||
> | ||
{i18next.t("profileLabel")} | ||
</MenuItem> | ||
<MenuItem onClick={logout}>{i18next.t("signOut")}</MenuItem> | ||
</Menu> | ||
</Fragment> | ||
); | ||
} | ||
|
||
ProfileMenu.propTypes = { | ||
logout: PropTypes.func, | ||
viewer: PropTypes.object | ||
}; | ||
|
||
export default ProfileMenu; |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from "./ProfileMenu"; |