Adding validation for name and email (#2612)
This commit is contained in:
parent
6535d654d7
commit
73e3e4e226
1 changed files with 9 additions and 1 deletions
|
@ -5,6 +5,7 @@ import {
|
||||||
ExclamationIcon,
|
ExclamationIcon,
|
||||||
InformationCircleIcon,
|
InformationCircleIcon,
|
||||||
} from "@heroicons/react/solid";
|
} from "@heroicons/react/solid";
|
||||||
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
import { EventTypeCustomInputType } from "@prisma/client";
|
import { EventTypeCustomInputType } from "@prisma/client";
|
||||||
import { useContracts } from "contexts/contractsContext";
|
import { useContracts } from "contexts/contractsContext";
|
||||||
import dayjs from "dayjs";
|
import dayjs from "dayjs";
|
||||||
|
@ -17,6 +18,7 @@ import { Controller, useForm, useWatch } from "react-hook-form";
|
||||||
import { FormattedNumber, IntlProvider } from "react-intl";
|
import { FormattedNumber, IntlProvider } from "react-intl";
|
||||||
import { ReactMultiEmail } from "react-multi-email";
|
import { ReactMultiEmail } from "react-multi-email";
|
||||||
import { useMutation } from "react-query";
|
import { useMutation } from "react-query";
|
||||||
|
import { z } from "zod";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
useIsEmbed,
|
useIsEmbed,
|
||||||
|
@ -195,8 +197,14 @@ const BookingPage = ({
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const bookingFormSchema = z.object({
|
||||||
|
name: z.string().min(1),
|
||||||
|
email: z.string().email(),
|
||||||
|
});
|
||||||
|
|
||||||
const bookingForm = useForm<BookingFormValues>({
|
const bookingForm = useForm<BookingFormValues>({
|
||||||
defaultValues: defaultValues(),
|
defaultValues: defaultValues(),
|
||||||
|
resolver: zodResolver(bookingFormSchema), // Since this isnt set to strict we only validate the fields in the schema
|
||||||
});
|
});
|
||||||
|
|
||||||
const selectedLocation = useWatch({
|
const selectedLocation = useWatch({
|
||||||
|
@ -389,7 +397,7 @@ const BookingPage = ({
|
||||||
</label>
|
</label>
|
||||||
<div className="mt-1">
|
<div className="mt-1">
|
||||||
<input
|
<input
|
||||||
{...bookingForm.register("name")}
|
{...bookingForm.register("name", { required: true })}
|
||||||
type="text"
|
type="text"
|
||||||
name="name"
|
name="name"
|
||||||
id="name"
|
id="name"
|
||||||
|
|
Loading…
Reference in a new issue