manifold/web/pages/account.tsx

79 lines
2.3 KiB
TypeScript
Raw Normal View History

import { firebaseLogin, firebaseLogout, User } from '../lib/firebase/users'
import { Header } from '../components/header'
2021-12-09 23:37:26 +00:00
import { useUser } from '../hooks/use-user'
import { ContractsList } from '../components/contracts-list'
import { Title } from '../components/title'
2021-12-14 01:29:02 +00:00
import { Row } from '../components/layout/row'
function UserCard(props: { user: User }) {
const { user } = props
return (
2021-12-14 01:29:02 +00:00
<Row className="card glass lg:card-side shadow-xl hover:shadow-xl text-neutral-content bg-green-600 hover:bg-green-600 transition-all max-w-sm mx-auto my-12">
<div className="p-4">
{user?.avatarUrl && (
2021-12-14 01:29:02 +00:00
<img src={user.avatarUrl} className="rounded-lg shadow-lg" width={96} height={96} />
)}
2021-12-14 01:29:02 +00:00
</div>
<div className="max-w-md card-body">
<h2 className="card-title font-major-mono">{user?.name}</h2>
<p>{user?.email}</p>
<p>M$ {user?.balance}</p>
<div className="card-actions">
<button
className="btn glass rounded-full hover:bg-green-500"
onClick={firebaseLogout}
>
Sign Out
</button>
</div>
</div>
2021-12-14 01:29:02 +00:00
</Row>
)
}
function SignInCard() {
return (
<div className="card glass lg:card-side shadow-xl hover:shadow-xl text-neutral-content bg-green-600 hover:bg-green-600 transition-all max-w-sm mx-auto my-12">
2021-12-14 01:29:02 +00:00
<div className="p-4">
<img
src="/logo-icon-white-bg.png"
className="rounded-lg shadow-lg w-20 h-20"
/>
2021-12-14 01:29:02 +00:00
</div>
<div className="max-w-md card-body">
<h2 className="card-title font-major-mono">Welcome!</h2>
<p>Sign in to get started</p>
<div className="card-actions">
<button
className="btn glass rounded-full hover:bg-green-500"
onClick={firebaseLogin}
>
Sign in with Google
</button>
</div>
</div>
</div>
)
}
export default function Account() {
2021-12-09 23:37:26 +00:00
const user = useUser()
return (
2021-12-10 18:07:38 +00:00
<div>
<Header />
2021-12-14 01:29:02 +00:00
<div className="max-w-4xl pt-8 pb-0 sm:pb-8 mx-auto">
{user ? (
<div>
<UserCard user={user} />
2021-12-14 01:29:02 +00:00
<Title className="px-2" text="Your markets" />
2021-12-14 07:05:33 +00:00
<ContractsList />
</div>
) : (
<SignInCard />
)}
</div>
</div>
)
}