ConceptPortal-public/rsconcept/frontend/src/components/Navigation/UserMenu.tsx
2023-07-20 17:11:03 +03:00

36 lines
903 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { UserIcon } from '../Icons';
import { useAuth } from '../../context/AuthContext';
import UserDropdown from './UserDropdown';
import NavigationButton from './NavigationButton';
import { Link } from 'react-router-dom';
import useDropdown from '../../hooks/useDropdown';
function LoginRef() {
return (
<Link to='login' className='inline-block text-sm font-bold hover:underline'>
Войти...
</Link>
);
}
function UserMenu() {
const {user} = useAuth();
const menu = useDropdown();
return (
<div ref={menu.ref}>
{ !user && <LoginRef />}
{ user &&
<NavigationButton
icon={<UserIcon />}
description={`Пользователь ${user?.username}`}
onClick={menu.toggle}
/>}
{ user && menu.isActive &&
<UserDropdown
hideDropdown={() => menu.hide()}
/>}
</div>
);
}
export default UserMenu;