import router from 'next/router' import { useEffect, useState } from 'react' import { ContractsList } from '../components/contracts-list' import { Header } from '../components/header' import { Spacer } from '../components/layout/spacer' import { Title } from '../components/title' import { useUser } from '../hooks/use-user' import { path } from '../lib/firebase/contracts' import { createContract } from '../lib/service/create-contract' // Allow user to create a new contract export default function NewContract() { const creator = useUser() useEffect(() => { if (creator === null) router.push('/') }) const [initialProb, setInitialProb] = useState(50) const [question, setQuestion] = useState('') const [description, setDescription] = useState('') const [isSubmitting, setIsSubmitting] = useState(false) async function submit() { // TODO: add more rigorous error handling for question if (!creator || !question) return setIsSubmitting(true) const contract = await createContract( question, description, initialProb, creator ) await router.push(path(contract)) } const descriptionPlaceholder = `e.g. This market will resolve to “Yes” if, by June 2, 2021, 11:59:59 PM ET, Paxlovid (also known under PF-07321332)...` if (!creator) return <>> return (