"use client"; import { zodResolver } from "@hookform/resolvers/zod"; import { useForm } from "react-hook-form"; import { z } from "zod"; import { Button } from "@/components/ui/button"; import { Form, FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage, } from "@/components/ui/form"; import { format } from "date-fns"; import { CalendarIcon } from "lucide-react"; import { Input } from "@/components/ui/input"; import { Calendar } from "@/components/ui/calendar"; import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover"; import { cn } from "@/lib/utils"; import { signupFormSubmit } from "@/lib/actions"; import { useState } from "react"; export const signupFormSchema = z.object({ name: z.string().min(2, { message: "Name is required" }).max(50, { message: "Name is too long" }), email: z.string().email({ message: "Email is invalid" }), dob: z.date({ required_error: "Birthday is required" }), }); export const youngestDate = new Date(new Date().setFullYear(new Date().getFullYear() - 21)); export const oldestDate = new Date(new Date().setFullYear(new Date().getFullYear() - 100)); export default function SignUp() { const [submitted, setSubmitted] = useState(false); const [response, setResponse] = useState(null); const form = useForm>({ resolver: zodResolver(signupFormSchema), defaultValues: { name: "", email: "", dob: youngestDate, }, }); async function onSubmit(values: z.infer) { setSubmitted(true); setResponse(await signupFormSubmit(values)); } function SignupForm() { return (
( Email We will contact you here with information about events. )} /> ( Name Please enter your full name. )} /> ( Date of birth date > youngestDate} defaultMonth={field.value} fromDate={oldestDate} toDate={youngestDate} captionLayout="dropdown" /> You must be over 21 to sign up. )} /> ); } return response ?? SignupForm(); }