-
-
- {isCreator && user && (
+ {allowTrade && }
+ {allowResolve && (
)}
diff --git a/web/pages/create.tsx b/web/pages/create.tsx
index 5806f9ec..6ad2bcb1 100644
--- a/web/pages/create.tsx
+++ b/web/pages/create.tsx
@@ -8,6 +8,9 @@ import { useUser } from '../hooks/use-user'
import { path } from '../lib/firebase/contracts'
import { createContract } from '../lib/service/create-contract'
import { Page } from '../components/page'
+import { Row } from '../components/layout/row'
+import clsx from 'clsx'
+import dayjs from 'dayjs'
// Allow user to create a new contract
export default function NewContract() {
@@ -20,11 +23,33 @@ export default function NewContract() {
const [initialProb, setInitialProb] = useState(50)
const [question, setQuestion] = useState('')
const [description, setDescription] = useState('')
+ const [closeDate, setCloseDate] = useState('')
const [isSubmitting, setIsSubmitting] = useState(false)
+ const [collapsed, setCollapsed] = useState(true)
+
+ // Given a date string like '2022-04-02',
+ // return the time just before midnight on that date (in the user's local time), as millis since epoch
+ function dateToMillis(date: string) {
+ return dayjs(date)
+ .set('hour', 23)
+ .set('minute', 59)
+ .set('second', 59)
+ .valueOf()
+ }
+ const closeTime = dateToMillis(closeDate)
+ // We'd like this to look like "Apr 2, 2022, 23:59:59 PM PT" but timezones are hard with dayjs
+ const formattedCloseTime = new Date(closeTime).toString()
+
+ const isValid =
+ initialProb > 0 &&
+ initialProb < 100 &&
+ question.length > 0 &&
+ // If set, closeTime must be in the future
+ (!closeDate || closeTime > Date.now())
async function submit() {
- // TODO: add more rigorous error handling for question
- if (!creator || !question) return
+ // TODO: Tell users why their contract is invalid
+ if (!creator || !isValid) return
setIsSubmitting(true)
@@ -32,7 +57,8 @@ export default function NewContract() {
question,
description,
initialProb,
- creator
+ creator,
+ closeTime
)
await router.push(path(contract))
}
@@ -49,52 +75,94 @@ export default function NewContract() {
{/* Create a Tailwind form that takes in all the fields needed for a new contract */}
{/* When the form is submitted, create a new contract in the database */}