manifold/web/components/profile-menu.tsx
Austin Chen da4ce99755
Merge Manifold for Teams infra into main codebase (#61)
* Add dev target for TheoremOne

* Restrict signups to theoremone.co emails

* Add new indices

* Forbid reads from unauthenticated users

* Client-side render pages that need auth

These pages are now client-side rendered:
- /home
- /leaderboards
- /market/...
- /fold/...

* Hide 404 for private Manifolds

* Brand instance for TheoremOne

* Hide "Add Funds" and "Personalize your feed"

* "M$" =>  "T$"

* Hide Discord & About Page too

* Update placeholders for teams

* Update firestore.indexes.json

* Switch /analytics to propz

* Migrate per-env code into common/

* More migrations to PROJECT_ID

* Conditionally use SSG depending on public vs private instance

* Fix props to be empty object

* Move more logic into access

* Spin out config files for each environment

* Generify most of the customizable brand stuff

* Move IS_PRIVATE_MANIFOLD to access.ts

* Rename access.ts to envs/constants.ts

* Add "dev:dev" alias

* Rever firestore rules to existing settings

* Fixes according to James's review
2022-03-08 18:43:30 -08:00

107 lines
2.5 KiB
TypeScript

import { firebaseLogout, User } from '../lib/firebase/users'
import { formatMoney } from '../../common/util/format'
import { Avatar } from './avatar'
import { Col } from './layout/col'
import { MenuButton } from './menu'
import { IS_PRIVATE_MANIFOLD } from '../../common/envs/constants'
export function ProfileMenu(props: { user: User | undefined }) {
const { user } = props
return (
<>
<MenuButton
className="hidden md:block"
menuItems={getNavigationOptions(user, { mobile: false })}
buttonContent={<ProfileSummary user={user} />}
/>
<MenuButton
className="mr-2 md:hidden"
menuItems={getNavigationOptions(user, { mobile: true })}
buttonContent={<ProfileSummary user={user} />}
/>
</>
)
}
function getNavigationOptions(
user: User | undefined,
options: { mobile: boolean }
) {
const { mobile } = options
return [
{
name: 'Home',
href: user ? '/home' : '/',
},
...(mobile
? [
{
name: 'Markets',
href: '/markets',
},
{
name: 'Communities',
href: '/folds',
},
]
: []),
{
name: `Your profile`,
href: `/${user?.username}`,
},
{
name: 'Your trades',
href: '/trades',
},
// Disable irrelevant menu options for teams.
...(IS_PRIVATE_MANIFOLD
? [
{
name: 'Leaderboards',
href: '/leaderboards',
},
]
: [
{
name: 'Add funds',
href: '/add-funds',
},
{
name: 'Leaderboards',
href: '/leaderboards',
},
{
name: 'Discord',
href: 'https://discord.gg/eHQBNBqXuh',
},
{
name: 'About',
href: '/about',
},
]),
{
name: 'Sign out',
href: '#',
onClick: () => firebaseLogout(),
},
]
}
function ProfileSummary(props: { user: User | undefined }) {
const { user } = props
return (
<Col className="avatar items-center gap-2 sm:flex-row sm:gap-4">
<Avatar avatarUrl={user?.avatarUrl} username={user?.username} noLink />
<div className="truncate text-left sm:w-32">
<div className="hidden sm:flex">{user?.name}</div>
<div className="text-sm text-gray-700">
{user ? formatMoney(Math.floor(user.balance)) : ' '}
</div>
</div>
</Col>
)
}