2021-12-10 17:54:16 +00:00
|
|
|
import Link from 'next/link'
|
2021-12-14 01:07:28 +00:00
|
|
|
import { useEffect, useState } from 'react'
|
|
|
|
import { useUser } from '../hooks/use-user'
|
|
|
|
import { Contract, deleteContract, listContracts } from '../lib/firebase/contracts'
|
2021-12-10 17:54:16 +00:00
|
|
|
|
|
|
|
function ContractCard(props: { contract: Contract }) {
|
|
|
|
const { contract } = props
|
|
|
|
return (
|
|
|
|
<li>
|
|
|
|
<Link href={`/contract/${contract.id}`}>
|
2021-12-11 03:35:21 +00:00
|
|
|
<a className="block hover:bg-gray-300">
|
2021-12-10 17:54:16 +00:00
|
|
|
<div className="px-4 py-4 sm:px-6">
|
|
|
|
<div className="flex items-center justify-between">
|
2021-12-11 03:35:21 +00:00
|
|
|
<p className="text-sm font-medium text-indigo-700 truncate">
|
2021-12-10 17:54:16 +00:00
|
|
|
{contract.question}
|
|
|
|
</p>
|
|
|
|
<div className="ml-2 flex-shrink-0 flex">
|
|
|
|
<p className="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-green-100 text-green-800">
|
|
|
|
{contract.outcomeType}
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="mt-2 sm:flex sm:justify-between">
|
|
|
|
<div className="sm:flex">
|
|
|
|
<p className="flex items-center text-sm">{contract.id}</p>
|
|
|
|
<p className="mt-2 flex items-center text-sm sm:mt-0 sm:ml-6">
|
|
|
|
{contract.description}
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
<div className="mt-2 flex items-center text-sm sm:mt-0">
|
|
|
|
<p>
|
|
|
|
Created on{' '}
|
|
|
|
<time dateTime={`${contract.createdTime}`}>
|
|
|
|
{new Date(contract.createdTime).toLocaleString()}
|
|
|
|
</time>
|
|
|
|
</p>
|
|
|
|
<button
|
2021-12-10 18:07:38 +00:00
|
|
|
className="btn btn-sm btn-error btn-outline ml-2"
|
2021-12-10 17:54:16 +00:00
|
|
|
onClick={() => {
|
|
|
|
deleteContract(contract.id)
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
Delete
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</a>
|
|
|
|
</Link>
|
|
|
|
</li>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-12-14 01:07:28 +00:00
|
|
|
export function ContractsList(props: {}) {
|
|
|
|
const creator = useUser()
|
|
|
|
|
|
|
|
const [contracts, setContracts] = useState<Contract[]>([])
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (creator?.id) {
|
|
|
|
listContracts(creator.id).then(setContracts)
|
|
|
|
}
|
|
|
|
}, [creator])
|
|
|
|
|
2021-12-10 17:54:16 +00:00
|
|
|
return (
|
2021-12-11 03:35:21 +00:00
|
|
|
<div className="bg-gray-200 shadow-xl overflow-hidden sm:rounded-md max-w-4xl w-full">
|
|
|
|
<ul role="list" className="divide-y divide-gray-300">
|
2021-12-10 17:54:16 +00:00
|
|
|
{contracts.map((contract) => (
|
|
|
|
<ContractCard contract={contract} key={contract.id} />
|
|
|
|
))}
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|