jam-cloud/jam-ui/src/components/navbar/JKProfileDropdown.js

71 lines
2.6 KiB
JavaScript
Raw Normal View History

//import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
2021-10-18 12:25:31 +00:00
import React, { useState } from 'react';
import { DropdownItem, DropdownMenu, DropdownToggle, Dropdown } from 'reactstrap';
import { useAuth } from '../../context/UserAuth';
2021-10-13 10:55:02 +00:00
import JKProfileAvatar from '../profile/JKProfileAvatar';
2021-10-18 12:25:31 +00:00
import { useCookies } from 'react-cookie';
2024-08-29 11:38:19 +00:00
import { useHistory } from 'react-router-dom';
import { useTranslation } from 'react-i18next';
2024-08-29 11:38:19 +00:00
// import useUserProfile from '../../hooks/useUserProfile';
import { useAppData } from '../../context/AppDataContext';
const ProfileDropdown = () => {
const { t } = useTranslation();
const [dropdownOpen, setDropdownOpen] = useState(false);
const toggle = () => setDropdownOpen(prevState => !prevState);
2024-08-29 11:38:19 +00:00
const { isAuthenticated, currentUser, setCurrentUser, logout, currentUserProfile } = useAuth();
2021-10-18 12:25:31 +00:00
const [cookies, setCookie, removeCookie] = useCookies(['remember_token']);
const history = useHistory();
2024-08-29 11:38:19 +00:00
// const { photoUrl } = useUserProfile(currentUser);
const { appData } = useAppData();
const { currentUserPhotoUrl } = appData;
const handleLogout = async event => {
2021-10-18 12:25:31 +00:00
event.preventDefault();
removeCookie('remember_token', {
domain: `.${process.env.REACT_APP_ORIGIN}`
});
setCurrentUser(null);
2024-08-29 11:38:19 +00:00
await logout();
window.location.href = "/auth/login";
2021-10-18 12:25:31 +00:00
};
return (
2021-10-13 10:55:02 +00:00
<>
2024-08-29 11:38:19 +00:00
{isAuthenticated && (
<Dropdown
nav
inNavbar
data-testid="navbarTopProfileDropdown"
isOpen={dropdownOpen}
toggle={toggle}
// onMouseOver={() => {
// let windowWidth = window.innerWidth;
// windowWidth > 992 && setDropdownOpen(true);
// }}
// onMouseLeave={() => {
// let windowWidth = window.innerWidth;
// windowWidth > 992 && setDropdownOpen(false);
// }}
>
<DropdownToggle nav className="pr-0">
{<JKProfileAvatar src={currentUserPhotoUrl} className="d-none d-lg-block d-xl-block" />}
{/* <span className="d-none d-lg-block">{currentUser && currentUser.name}</span> */}
</DropdownToggle>
<DropdownMenu right className="dropdown-menu-card">
<div className="bg-white rounded-soft py-2">
{/* <DropdownItem tag={Link} to="/pages/settings">
2021-10-18 12:25:31 +00:00
My Profile
2021-10-18 13:25:54 +00:00
</DropdownItem> */}
2024-08-29 11:38:19 +00:00
<DropdownItem onClick={handleLogout}>{t('signout', { ns: 'auth' })}</DropdownItem>
</div>
</DropdownMenu>
</Dropdown>
)}
2021-10-13 10:55:02 +00:00
</>
);
};
export default ProfileDropdown;