2021-12-20 03:12:12 +00:00
|
|
|
import { firebaseLogout, User } from '../lib/firebase/users'
|
2022-01-30 21:51:30 +00:00
|
|
|
import { formatMoney } from '../../common/util/format'
|
2022-01-27 23:24:44 +00:00
|
|
|
import { Avatar } from './avatar'
|
2022-01-11 06:16:58 +00:00
|
|
|
import { Col } from './layout/col'
|
2021-12-20 03:12:12 +00:00
|
|
|
import { MenuButton } from './menu'
|
2022-03-02 01:19:20 +00:00
|
|
|
import { IS_PRIVATE_MANIFOLD } from '../lib/firebase/init'
|
2021-12-20 03:12:12 +00:00
|
|
|
|
2022-01-27 23:06:31 +00:00
|
|
|
export function ProfileMenu(props: { user: User | undefined }) {
|
2021-12-20 03:12:12 +00:00
|
|
|
const { user } = props
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<MenuButton
|
|
|
|
className="hidden md:block"
|
|
|
|
menuItems={getNavigationOptions(user, { mobile: false })}
|
|
|
|
buttonContent={<ProfileSummary user={user} />}
|
|
|
|
/>
|
|
|
|
|
|
|
|
<MenuButton
|
2022-02-11 18:40:22 +00:00
|
|
|
className="mr-2 md:hidden"
|
2021-12-20 03:12:12 +00:00
|
|
|
menuItems={getNavigationOptions(user, { mobile: true })}
|
|
|
|
buttonContent={<ProfileSummary user={user} />}
|
|
|
|
/>
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-01-27 23:06:31 +00:00
|
|
|
function getNavigationOptions(
|
|
|
|
user: User | undefined,
|
|
|
|
options: { mobile: boolean }
|
|
|
|
) {
|
2021-12-20 03:12:12 +00:00
|
|
|
const { mobile } = options
|
|
|
|
return [
|
|
|
|
{
|
|
|
|
name: 'Home',
|
2022-01-27 23:33:50 +00:00
|
|
|
href: user ? '/home' : '/',
|
2021-12-20 03:12:12 +00:00
|
|
|
},
|
|
|
|
...(mobile
|
|
|
|
? [
|
2022-01-12 03:56:11 +00:00
|
|
|
{
|
2022-01-27 07:30:51 +00:00
|
|
|
name: 'Markets',
|
2022-01-12 03:56:11 +00:00
|
|
|
href: '/markets',
|
|
|
|
},
|
2022-01-27 07:30:51 +00:00
|
|
|
{
|
2022-02-04 01:55:00 +00:00
|
|
|
name: 'Communities',
|
2022-01-27 07:30:51 +00:00
|
|
|
href: '/folds',
|
|
|
|
},
|
2021-12-20 03:12:12 +00:00
|
|
|
]
|
|
|
|
: []),
|
2022-02-23 08:24:39 +00:00
|
|
|
{
|
|
|
|
name: `Your profile`,
|
|
|
|
href: `/${user?.username}`,
|
|
|
|
},
|
2021-12-20 03:12:12 +00:00
|
|
|
{
|
2021-12-24 21:06:01 +00:00
|
|
|
name: 'Your trades',
|
|
|
|
href: '/trades',
|
2021-12-20 03:12:12 +00:00
|
|
|
},
|
2022-03-02 01:19:20 +00:00
|
|
|
// Disable "Add Funds" for teams
|
|
|
|
...(IS_PRIVATE_MANIFOLD
|
|
|
|
? []
|
|
|
|
: [
|
|
|
|
{
|
|
|
|
name: 'Add funds',
|
|
|
|
href: '/add-funds',
|
|
|
|
},
|
|
|
|
]),
|
2022-01-27 22:43:45 +00:00
|
|
|
{
|
|
|
|
name: 'Leaderboards',
|
|
|
|
href: '/leaderboards',
|
|
|
|
},
|
2021-12-31 20:33:05 +00:00
|
|
|
{
|
|
|
|
name: 'Discord',
|
|
|
|
href: 'https://discord.gg/eHQBNBqXuh',
|
|
|
|
},
|
2022-01-12 07:18:14 +00:00
|
|
|
{
|
|
|
|
name: 'About',
|
|
|
|
href: '/about',
|
|
|
|
},
|
2021-12-20 03:12:12 +00:00
|
|
|
{
|
|
|
|
name: 'Sign out',
|
|
|
|
href: '#',
|
|
|
|
onClick: () => firebaseLogout(),
|
|
|
|
},
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
2022-01-27 23:06:31 +00:00
|
|
|
function ProfileSummary(props: { user: User | undefined }) {
|
2021-12-20 03:12:12 +00:00
|
|
|
const { user } = props
|
|
|
|
return (
|
2022-02-11 18:40:22 +00:00
|
|
|
<Col className="avatar items-center gap-2 sm:flex-row sm:gap-4">
|
2022-01-27 23:24:44 +00:00
|
|
|
<Avatar avatarUrl={user?.avatarUrl} username={user?.username} noLink />
|
|
|
|
|
2022-01-27 23:31:41 +00:00
|
|
|
<div className="truncate text-left sm:w-32">
|
2022-01-27 23:06:31 +00:00
|
|
|
<div className="hidden sm:flex">{user?.name}</div>
|
2022-02-11 18:40:22 +00:00
|
|
|
<div className="text-sm text-gray-700">
|
2022-02-17 03:14:12 +00:00
|
|
|
{user ? formatMoney(Math.floor(user.balance)) : ' '}
|
2022-01-08 18:14:20 +00:00
|
|
|
</div>
|
2021-12-20 03:12:12 +00:00
|
|
|
</div>
|
2022-01-11 06:16:58 +00:00
|
|
|
</Col>
|
2021-12-20 03:12:12 +00:00
|
|
|
)
|
|
|
|
}
|