Fix import on useForm + validate e-mail

This commit is contained in:
Francesco Manzali
2021-10-19 10:43:42 +02:00
parent 617b60adca
commit eaeb432fe6

View File

@@ -6,10 +6,10 @@ import {
FieldError, FieldError,
Label, Label,
FormError, FormError,
useForm,
} from '@redwoodjs/forms' } from '@redwoodjs/forms'
import { useMutation } from '@redwoodjs/web' import { useMutation } from '@redwoodjs/web'
import { toast, Toaster } from '@redwoodjs/web/toast' import { toast, Toaster } from '@redwoodjs/web/toast'
import { useForm } from 'react-hook-form'
const CREATE_CONTACT = gql` const CREATE_CONTACT = gql`
mutation CreateContactMutation($input: CreateContactInput!) { mutation CreateContactMutation($input: CreateContactInput!) {
@@ -34,7 +34,8 @@ const ContactPage = () => {
console.log(data) console.log(data)
} }
return <> return (
<>
<Toaster /> <Toaster />
<Form <Form
onSubmit={onSubmit} onSubmit={onSubmit}
@@ -74,6 +75,10 @@ const ContactPage = () => {
name="email" name="email"
validation={{ validation={{
required: true, required: true,
pattern: {
value: /[^@]+@[^.]+\..+/,
message: 'Please enter a valid email address',
},
}} }}
className="border rounded-sm px-2 py-1" className="border rounded-sm px-2 py-1"
errorClassName="border rounded-sm px-2 py-1 border-red-700 outline-none" errorClassName="border rounded-sm px-2 py-1 border-red-700 outline-none"
@@ -102,7 +107,8 @@ const ContactPage = () => {
Save Save
</Submit> </Submit>
</Form> </Form>
</>; </>
)
} }
export default ContactPage export default ContactPage