fix final backend and styling
This commit is contained in:
@ -9,8 +9,9 @@ export default function Page() {
|
||||
alt="Bangers and Mash GBG"
|
||||
width={200}
|
||||
height={200}
|
||||
className="mx-auto"
|
||||
className="mx-auto my-8"
|
||||
/>
|
||||
<h1 className="mb-4 text-xl">Sign up to our guest list here</h1>
|
||||
<SignUp />
|
||||
</div>
|
||||
);
|
||||
|
@ -21,17 +21,19 @@ 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<string | null>(null);
|
||||
const form = useForm<z.infer<typeof signupFormSchema>>({
|
||||
resolver: zodResolver(signupFormSchema),
|
||||
defaultValues: {
|
||||
@ -40,85 +42,91 @@ export default function SignUp() {
|
||||
dob: youngestDate,
|
||||
},
|
||||
});
|
||||
function onSubmit(values: z.infer<typeof signupFormSchema>) {
|
||||
signupFormSubmit(values);
|
||||
async function onSubmit(values: z.infer<typeof signupFormSchema>) {
|
||||
setSubmitted(true);
|
||||
setResponse(await signupFormSubmit(values));
|
||||
}
|
||||
return (
|
||||
<Form {...form}>
|
||||
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-8">
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="email"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Email</FormLabel>
|
||||
<FormControl>
|
||||
<Input placeholder="name@example.com" {...field} />
|
||||
</FormControl>
|
||||
<FormDescription>
|
||||
We will contact you here with information about events.
|
||||
</FormDescription>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="name"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Name</FormLabel>
|
||||
<FormControl>
|
||||
<Input placeholder="Firstname Lastname" {...field} />
|
||||
</FormControl>
|
||||
<FormDescription>Please enter your full name.</FormDescription>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="dob"
|
||||
render={({ field }) => (
|
||||
<FormItem className="flex flex-col">
|
||||
<FormLabel>Date of birth</FormLabel>
|
||||
<Popover>
|
||||
<PopoverTrigger asChild>
|
||||
<FormControl>
|
||||
<Button
|
||||
variant={"outline"}
|
||||
className={cn(
|
||||
"w-[240px] pl-3 text-left font-normal",
|
||||
!field.value && "text-muted-foreground"
|
||||
)}
|
||||
>
|
||||
{field.value ? format(field.value, "PPP") : <span>Pick a date</span>}
|
||||
<CalendarIcon className="ml-auto h-4 w-4 opacity-50" />
|
||||
</Button>
|
||||
</FormControl>
|
||||
</PopoverTrigger>
|
||||
<PopoverContent className="w-auto p-0" align="start">
|
||||
<Calendar
|
||||
required
|
||||
mode="single"
|
||||
showOutsideDays={false}
|
||||
selected={field.value}
|
||||
onSelect={field.onChange}
|
||||
disabled={(date) => date > youngestDate}
|
||||
defaultMonth={field.value}
|
||||
fromDate={oldestDate}
|
||||
toDate={youngestDate}
|
||||
captionLayout="dropdown"
|
||||
/>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
<FormDescription>You must be over 21 to sign up.</FormDescription>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<Button type="submit">Submit</Button>
|
||||
</form>
|
||||
</Form>
|
||||
);
|
||||
function SignupForm() {
|
||||
return (
|
||||
<Form {...form}>
|
||||
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-8">
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="email"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Email</FormLabel>
|
||||
<FormControl>
|
||||
<Input placeholder="name@example.com" {...field} />
|
||||
</FormControl>
|
||||
<FormDescription>
|
||||
We will contact you here with information about events.
|
||||
</FormDescription>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="name"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Name</FormLabel>
|
||||
<FormControl>
|
||||
<Input placeholder="Firstname Lastname" {...field} />
|
||||
</FormControl>
|
||||
<FormDescription>Please enter your full name.</FormDescription>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="dob"
|
||||
render={({ field }) => (
|
||||
<FormItem className="flex flex-col">
|
||||
<FormLabel>Date of birth</FormLabel>
|
||||
<Popover>
|
||||
<PopoverTrigger asChild>
|
||||
<FormControl>
|
||||
<Button
|
||||
variant={"outline"}
|
||||
className={cn(
|
||||
"w-[240px] pl-3 text-left font-normal",
|
||||
!field.value && "text-muted-foreground"
|
||||
)}
|
||||
>
|
||||
{field.value ? format(field.value, "PPP") : <span>Pick a date</span>}
|
||||
<CalendarIcon className="ml-auto h-4 w-4 opacity-50" />
|
||||
</Button>
|
||||
</FormControl>
|
||||
</PopoverTrigger>
|
||||
<PopoverContent className="w-auto p-0" align="start">
|
||||
<Calendar
|
||||
required
|
||||
mode="single"
|
||||
showOutsideDays={false}
|
||||
selected={field.value}
|
||||
onSelect={field.onChange}
|
||||
disabled={(date) => date > youngestDate}
|
||||
defaultMonth={field.value}
|
||||
fromDate={oldestDate}
|
||||
toDate={youngestDate}
|
||||
captionLayout="dropdown"
|
||||
/>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
<FormDescription>You must be over 21 to sign up.</FormDescription>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<Button type="submit" disabled={submitted}>
|
||||
Submit
|
||||
</Button>
|
||||
</form>
|
||||
</Form>
|
||||
);
|
||||
}
|
||||
return response ?? SignupForm();
|
||||
}
|
||||
|
Reference in New Issue
Block a user