aboutsummaryrefslogtreecommitdiffstats
path: root/pages/register.js
blob: aa6b69ec954f0ae5fef840c22f93072ea8ae21dd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { useState } from 'react'
import useUser from 'hooks/useUser'
import submitForm from 'helpers/submitForm'
import { Layout, Form, Splash } from 'components'

const Register = () => {
  const [errorMsg, setErrorMsg] = useState('')
  const [loading, setLoading] = useState(false)
  const { mutateUser } = useUser({
    redirectToVerify: true
  })

  const handleSubmit = async e => {
    setLoading(true)
    await submitForm(e, '/api/register', mutateUser, setErrorMsg)
    setLoading(false)
  }

  return (
    <Layout>
      {loading
        ? <Splash fixed />
        : (
          <Form
            errorMessage={errorMsg}
            onSubmit={handleSubmit}
          />
          )}
    </Layout>
  )
}

export default Register