1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-26 05:16:41 +07:00
vault-frontend/src/components/main/UserButton/index.tsx
2022-01-19 12:30:04 +07:00

48 lines
1.3 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 React, { FC, useCallback } from 'react';
import { Group } from '~/components/containers/Group';
import { Icon } from '~/components/input/Icon';
import { PRESETS } from '~/constants/urls';
import { IUser } from '~/types/auth';
import { getURL } from '~/utils/dom';
import styles from './styles.module.scss';
interface IProps {
user: Partial<IUser>;
onLogout: () => void;
authOpenProfile: () => void;
}
const UserButton: FC<IProps> = ({ user: { username, photo }, authOpenProfile, onLogout }) => {
const onProfileOpen = useCallback(() => {
authOpenProfile();
}, [authOpenProfile]);
const onSettingsOpen = useCallback(() => {
authOpenProfile();
}, [authOpenProfile]);
return (
<div className={styles.wrap}>
<Group horizontal className={styles.user_button}>
<div className={styles.username}>{username}</div>
<div
className={styles.user_avatar}
style={{ backgroundImage: `url('${getURL(photo, PRESETS.avatar)}')` }}
>
{(!photo || !photo.id) && <Icon icon="profile" />}
</div>
</Group>
<div className={styles.menu}>
<div onClick={onProfileOpen}>Профиль</div>
<div onClick={onSettingsOpen}>Настройки</div>
<div onClick={onLogout}>Выдох</div>
</div>
</div>
);
};
export { UserButton };