ConceptPortal-public/rsconcept/frontend/src/components/Navigation/UserMenu.tsx
2023-07-15 17:46:19 +03:00

35 lines
1.1 KiB
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 { useRef, useState } from 'react';
import UserDropdown from './UserDropdown';
import { useClickedOutside } from '../../hooks/useClickedOutside';
import NavigationButton from './NavigationButton';
import { Link } from 'react-router-dom';
function LoginRef() {
return (
<Link to='login' className='inline-block text-sm font-bold hover:underline'>
Войти...
</Link>
);
}
function UserMenu() {
const {user} = useAuth();
const [showUserDropdown, setShowUserDropdown] = useState(false);
const dropdownRef = useRef(null);
const toggleUserDropdown = () => setShowUserDropdown(!showUserDropdown);
const hideDropdown = () => setShowUserDropdown(false);
useClickedOutside({ref: dropdownRef, callback: hideDropdown})
return (
<div ref={dropdownRef}>
{ !user && <LoginRef />}
{ user && <NavigationButton icon={<UserIcon />} description='Пользователь' onClick={toggleUserDropdown} /> }
{ user && showUserDropdown && <UserDropdown hideDropdown={hideDropdown} /> }
</div>
);
}
export default UserMenu;