diff --git a/components/home/join-form.js b/components/home/join-form.js index 6410821c..747d09a9 100644 --- a/components/home/join-form.js +++ b/components/home/join-form.js @@ -1,24 +1,9 @@ -import { useState, useEffect } from 'react' -import { Card, Label, Input, Button, Checkbox, Textarea } from 'theme-ui' -import fetch from 'isomorphic-unfetch' +import { Card, Label, Input, Checkbox, Textarea } from 'theme-ui' +import useForm from '../../lib/use-form' +import Submit from '../submit' const JoinForm = () => { - const [name, setName] = useState('') - const [email, setEmail] = useState('') - const [teen, setTeen] = useState(false) - const [reason, setReason] = useState('') - - const [status, setStatus] = useState('') - - useEffect(() => { - setTimeout(() => { - setName('') - setEmail('') - setTeen(false) - setReason('') - setStatus('') - }, 1500) - }, [status]) + const { status, formProps, useField } = useForm('/api/join') return ( { } }} > -
{ - e.preventDefault() - fetch('https://v3.hackclub.com/api/join', { - method: 'POST', - body: JSON.stringify({ name, email, teen, reason }) - }) - .then((r) => r.json()) - .then((r) => setStatus(r.status)) - .catch((e) => console.error(e)) - }} - > -