import router, { useRouter } from 'next/router' import { useEffect, useState } from 'react' import clsx from 'clsx' import dayjs from 'dayjs' import Textarea from 'react-expanding-textarea' import { Spacer } from 'web/components/layout/spacer' import { useUser } from 'web/hooks/use-user' import { Contract, contractPath } from 'web/lib/firebase/contracts' import { createMarket } from 'web/lib/firebase/api' import { FIXED_ANTE } from 'common/antes' import { InfoTooltip } from 'web/components/info-tooltip' import { Page } from 'web/components/page' import { Row } from 'web/components/layout/row' import { MAX_DESCRIPTION_LENGTH, MAX_QUESTION_LENGTH, outcomeType, } from 'common/contract' import { formatMoney } from 'common/util/format' import { removeUndefinedProps } from 'common/util/object' import { ChoicesToggleGroup } from 'web/components/choices-toggle-group' import { setContractGroupSlugs, getGroup } from 'web/lib/firebase/groups' import { Group } from 'common/group' import { useTracking } from 'web/hooks/use-tracking' import { useWarnUnsavedChanges } from 'web/hooks/use-warn-unsaved-changes' import { track } from 'web/lib/service/analytics' import { GroupSelector } from 'web/components/groups/group-selector' import { User } from 'common/user' import { TextEditor, useTextEditor } from 'web/components/editor' import { Checkbox } from 'web/components/checkbox' type NewQuestionParams = { groupId?: string q: string type: string description: string closeTime: string outcomeType: string // Params for PSEUDO_NUMERIC outcomeType min?: string max?: string isLogScale?: string initValue?: string } export default function Create() { useTracking('view create page') const router = useRouter() const params = router.query as NewQuestionParams // TODO: Not sure why Question is pulled out as its own component; // Maybe merge into newContract and then we don't need useEffect here. const [question, setQuestion] = useState('') useEffect(() => { setQuestion(params.q ?? '') }, [params.q]) const creator = useUser() useEffect(() => { if (creator === null) router.push('/') if (creator?.username !== 'RichardHanania') router.push('/') }, [creator, router]) if (!router.isReady || !creator) return
return (