2023-07-15 17:46:19 +03:00
|
|
|
import { useNavigate } from 'react-router-dom';
|
|
|
|
import { useAuth } from '../../context/AuthContext';
|
|
|
|
import NavigationTextItem from './NavigationTextItem';
|
|
|
|
import { useTheme } from '../../context/ThemeContext';
|
|
|
|
|
|
|
|
interface UserDropdownProps {
|
|
|
|
hideDropdown: Function
|
|
|
|
}
|
|
|
|
|
|
|
|
function UserDropdown({hideDropdown}: UserDropdownProps) {
|
|
|
|
const {darkMode, toggleDarkMode} = useTheme();
|
|
|
|
const navigate = useNavigate();
|
|
|
|
const {user, logout} = useAuth();
|
|
|
|
|
|
|
|
const navigateProfile = () => {
|
|
|
|
hideDropdown()
|
|
|
|
navigate('/profile');
|
|
|
|
};
|
|
|
|
|
|
|
|
const logoutAndRedirect = () => {
|
|
|
|
hideDropdown()
|
|
|
|
logout(() => {navigate('/login/');})
|
|
|
|
};
|
2023-07-16 22:53:22 +03:00
|
|
|
|
|
|
|
const navigateMyWork = () => {
|
|
|
|
hideDropdown()
|
|
|
|
navigate('/rsforms?filter=personal');
|
|
|
|
};
|
|
|
|
|
2023-07-15 17:46:19 +03:00
|
|
|
return (
|
|
|
|
<div className='relative'>
|
|
|
|
<div className='absolute right-0 z-10 flex flex-col items-stretch justify-start p-2 mt-4 text-sm origin-top-right bg-white border border-gray-100 divide-y rounded-md shadow-lg dark:border-gray-500 dark:bg-gray-900 w-36'>
|
2023-07-16 22:53:22 +03:00
|
|
|
<NavigationTextItem description='Профиль пользователя'
|
2023-07-15 17:46:19 +03:00
|
|
|
text={user?.username}
|
|
|
|
onClick={navigateProfile}
|
|
|
|
/>
|
2023-07-16 22:53:22 +03:00
|
|
|
<NavigationTextItem description='Переключение темы оформления'
|
2023-07-15 17:46:19 +03:00
|
|
|
text={darkMode ? 'Светлая тема' : 'Темная тема'}
|
|
|
|
onClick={toggleDarkMode}
|
|
|
|
/>
|
2023-07-16 22:53:22 +03:00
|
|
|
<NavigationTextItem text={'Мои схемы'} onClick={navigateMyWork} />
|
|
|
|
<NavigationTextItem text={'Выйти...'} bold onClick={logoutAndRedirect} />
|
2023-07-15 17:46:19 +03:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default UserDropdown;
|