2021-12-09 01:57:59 +00:00
|
|
|
import { useRouter } from 'next/router'
|
2021-12-09 23:37:26 +00:00
|
|
|
import { firebaseLogout } from '../lib/firebase/users'
|
2021-12-09 01:57:59 +00:00
|
|
|
import { Header } from '../components/header'
|
2021-12-09 23:37:26 +00:00
|
|
|
import { useUser } from '../hooks/use-user'
|
2021-12-10 17:54:16 +00:00
|
|
|
import { useState, useEffect } from 'react'
|
|
|
|
import { Contract, listContracts } from '../lib/firebase/contracts'
|
|
|
|
import { ContractsList } from '../components/contracts-list'
|
2021-12-10 23:43:22 +00:00
|
|
|
import Image from 'next/image'
|
2021-12-09 01:57:59 +00:00
|
|
|
|
|
|
|
export default function Account() {
|
2021-12-09 23:37:26 +00:00
|
|
|
const user = useUser()
|
2021-12-09 01:57:59 +00:00
|
|
|
const router = useRouter()
|
2021-12-10 17:54:16 +00:00
|
|
|
const [contracts, setContracts] = useState<Contract[]>([])
|
|
|
|
useEffect(() => {
|
|
|
|
if (user?.id) {
|
|
|
|
listContracts(user?.id).then(setContracts)
|
|
|
|
}
|
|
|
|
}, [user?.id])
|
2021-12-09 01:57:59 +00:00
|
|
|
|
|
|
|
return (
|
2021-12-10 18:07:38 +00:00
|
|
|
<div>
|
2021-12-09 01:57:59 +00:00
|
|
|
<Header />
|
2021-12-11 00:06:51 +00:00
|
|
|
<div className="max-w-4xl py-8 mx-auto">
|
2021-12-10 17:54:16 +00:00
|
|
|
<div>
|
2021-12-11 00:06:51 +00:00
|
|
|
<div className="card glass lg:card-side text-neutral-content bg-green-600 hover:bg-green-600 transition-all max-w-sm mx-auto my-12">
|
2021-12-10 17:54:16 +00:00
|
|
|
<figure className="p-6">
|
2021-12-10 23:43:22 +00:00
|
|
|
{user?.avatarUrl && (
|
|
|
|
<Image
|
|
|
|
src={user.avatarUrl}
|
|
|
|
className="rounded-lg shadow-lg"
|
|
|
|
width={96}
|
|
|
|
height={96}
|
|
|
|
/>
|
|
|
|
)}
|
2021-12-10 17:54:16 +00:00
|
|
|
</figure>
|
|
|
|
<div className="max-w-md card-body">
|
|
|
|
<h2 className="card-title font-major-mono">{user?.name}</h2>
|
|
|
|
<p>{user?.email}</p>
|
|
|
|
<p>${user?.balanceUsd} USD</p>
|
|
|
|
<div className="card-actions">
|
|
|
|
<button
|
2021-12-10 23:43:22 +00:00
|
|
|
className="btn glass rounded-full hover:bg-green-500"
|
2021-12-10 17:54:16 +00:00
|
|
|
onClick={() => {
|
|
|
|
firebaseLogout()
|
|
|
|
router.push('/')
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
Sign Out
|
|
|
|
</button>
|
|
|
|
</div>
|
2021-12-09 01:57:59 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
2021-12-10 23:43:22 +00:00
|
|
|
<h1 className="text-2xl font-major-mono text-green-600 font-bold mt-6 mb-4">
|
2021-12-10 17:54:16 +00:00
|
|
|
Your markets
|
2021-12-09 01:57:59 +00:00
|
|
|
</h1>
|
2021-12-10 17:54:16 +00:00
|
|
|
<ContractsList contracts={contracts} />
|
2021-12-09 01:57:59 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|