import { useState } from 'react'
import { Field, Form, Formik } from 'formik'
import {
Link,
Navigate,
useLocation,
useNavigate,
useSearchParams,
} from 'react-router-dom'
import { Helmet } from 'react-helmet-async'
import { inferMutationInput, trpc } from '~/utils/trpc'
import IVInputField from '~/components/IVInputField'
import IVButton from '~/components/IVButton'
import { tryLogin } from '~/utils/auth'
import useHasSession from '~/utils/useHasSession'
import IVSpinner from '~/components/IVSpinner'
import classNames from 'classnames'
import { ReferralInfo, referralInfoSchema } from '~/utils/referralSchema'
import GoogleIcon from '~/icons/compiled/Google'
import { DateTime } from 'luxon'
import AuthPageHeader from '~/components/AuthPageHeader'
import { REFERRAL_LOCAL_STORAGE_KEY } from '~/utils/isomorphicConsts'
export default function SignupPage() {
const [hasLoginError, setHasLoginError] = useState(false)
const [hasPromoCode, setHasPromoCode] = useState(false)
const createUser = trpc.useMutation('auth.signup')
const checkEmail = trpc.useMutation('auth.signup.check-email')
const [searchParams] = useSearchParams()
const invitationId = searchParams.get('token')
const exampleSlug = searchParams.get('example') || undefined
const intendedPlanName = searchParams.get('plan') || undefined
const integrations = trpc.useQuery(['dashboard.integrations'])
const signupCheck = trpc.useQuery(['auth.signup.check', { invitationId }])
const { hasSession } = useHasSession()
const navigate = useNavigate()
const location = useLocation()
const isEmailValidated =
location.state === 'confirm' || !!signupCheck.data?.invitation
const mutation = isEmailValidated ? createUser : checkEmail
if (hasSession) {
return
Sorry, we were unable to sign you in because the account with that email address has been disabled.
Please reach out to help@interval.com with any questions or if you think this is a mistake.
Sorry, we are not currently accepting new user registrations.
We've added your information to our waitlist and will reach out as soon as registrations are available again. Thank you for your interest!