2025-02-12 13:42:21 +03:00
|
|
|
import { useAuthSuspense } from '@/features/auth';
|
2025-02-12 21:36:25 +03:00
|
|
|
|
|
|
|
import { IconLogin, IconUser2 } from '@/components/Icons';
|
2025-01-27 15:03:48 +03:00
|
|
|
import { usePreferencesStore } from '@/stores/preferences';
|
2025-03-07 02:46:19 +03:00
|
|
|
import { globalIDs } from '@/utils/constants';
|
2025-01-27 15:03:48 +03:00
|
|
|
|
2025-02-19 23:30:35 +03:00
|
|
|
import { NavigationButton } from './NavigationButton';
|
2025-01-27 15:03:48 +03:00
|
|
|
|
|
|
|
interface UserButtonProps {
|
|
|
|
onLogin: () => void;
|
|
|
|
onClickUser: () => void;
|
2025-03-06 22:26:44 +03:00
|
|
|
isOpen: boolean;
|
2025-01-27 15:03:48 +03:00
|
|
|
}
|
|
|
|
|
2025-03-06 22:26:44 +03:00
|
|
|
export function UserButton({ onLogin, onClickUser, isOpen }: UserButtonProps) {
|
2025-01-28 19:47:24 +03:00
|
|
|
const { user, isAnonymous } = useAuthSuspense();
|
2025-01-27 15:03:48 +03:00
|
|
|
const adminMode = usePreferencesStore(state => state.adminMode);
|
2025-01-28 19:47:24 +03:00
|
|
|
if (isAnonymous) {
|
2025-01-27 15:03:48 +03:00
|
|
|
return (
|
|
|
|
<NavigationButton
|
|
|
|
className='cc-fade-in'
|
|
|
|
title='Перейти на страницу логина'
|
|
|
|
icon={<IconLogin size='1.5rem' className='icon-primary' />}
|
|
|
|
onClick={onLogin}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return (
|
|
|
|
<NavigationButton
|
|
|
|
className='cc-fade-in'
|
2025-03-06 22:26:44 +03:00
|
|
|
title='Пользователь'
|
2025-03-07 02:46:19 +03:00
|
|
|
hideTitle={isOpen}
|
2025-03-06 22:26:44 +03:00
|
|
|
aria-haspopup='true'
|
|
|
|
aria-expanded={isOpen}
|
2025-03-07 02:46:19 +03:00
|
|
|
aria-controls={globalIDs.user_dropdown}
|
2025-01-27 15:03:48 +03:00
|
|
|
icon={<IconUser2 size='1.5rem' className={adminMode && user.is_staff ? 'icon-primary' : ''} />}
|
|
|
|
onClick={onClickUser}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|