import {
    useActionData,
    Form,
    redirect,
    json
} from 'remix'

export async function action({ request }) {
    const formData = await request.formData()
    const errors = {}
    
    // Do data validation and add to the errors object if there are any errors
    
    if (Object.keys(errors).length) {
        return json(errors, { status: 422 })
    }
    
    // No errors: send email, store in DB, do whatever you need to do with the form data
    
    return redirect('/contact/thanks')
}

export default function ContactIndex() {
    const errors = useActionData()
    
    return (
        <Form method="post">
        </Form>
    )
}