import React from 'react'; import { FormattedMessage } from 'react-intl'; import { useRouter } from 'next/router'; import MenuButton from 'components/common/MenuButton'; import Icon from 'components/common/Icon'; import User from 'assets/user.svg'; import Chevron from 'assets/chevron-down.svg'; import styles from './UserButton.module.css'; import { removeItem } from 'lib/web'; import { AUTH_TOKEN } from 'lib/constants'; import useUser from 'hooks/useUser'; export default function UserButton() { const { user } = useUser(); const router = useRouter(); const menuOptions = [ { label: ( {user.username} }} /> ), value: 'username', className: styles.username, }, { label: , value: 'profile' }, { label: , value: 'logout' }, ]; function handleSelect(value) { if (value === 'logout') { removeItem(AUTH_TOKEN); router.push('/login'); } else if (value === 'profile') { router.push('/settings/profile'); } } return ( } size="large" />} value={} size="small" />} buttonVariant="light" options={menuOptions} onSelect={handleSelect} /> ); }