({
event,
}: {
event?: {
id: string
name: string
description?: string
durationInMinutes: number
isActive: boolean
}
})
| 33 | import { useState, useTransition } from "react" |
| 34 | |
| 35 | export function EventForm({ |
| 36 | event, |
| 37 | }: { |
| 38 | event?: { |
| 39 | id: string |
| 40 | name: string |
| 41 | description?: string |
| 42 | durationInMinutes: number |
| 43 | isActive: boolean |
| 44 | } |
| 45 | }) { |
| 46 | const [isDeletePending, startDeleteTransition] = useTransition() |
| 47 | const form = useForm<z.infer<typeof eventFormSchema>>({ |
| 48 | resolver: zodResolver(eventFormSchema), |
| 49 | defaultValues: event ?? { |
| 50 | isActive: true, |
| 51 | durationInMinutes: 30, |
| 52 | }, |
| 53 | }) |
| 54 | |
| 55 | async function onSubmit(values: z.infer<typeof eventFormSchema>) { |
| 56 | const action = |
| 57 | event == null ? createEvent : updateEvent.bind(null, event.id) |
| 58 | const data = await action(values) |
| 59 | |
| 60 | if (data?.error) { |
| 61 | form.setError("root", { |
| 62 | message: "There was an error saving your event", |
| 63 | }) |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | return ( |
| 68 | <Form {...form}> |
| 69 | <form |
| 70 | onSubmit={form.handleSubmit(onSubmit)} |
| 71 | className="flex gap-6 flex-col" |
| 72 | > |
| 73 | {form.formState.errors.root && ( |
| 74 | <div className="text-destructive text-sm"> |
| 75 | {form.formState.errors.root.message} |
| 76 | </div> |
| 77 | )} |
| 78 | <FormField |
| 79 | control={form.control} |
| 80 | name="name" |
| 81 | render={({ field }) => ( |
| 82 | <FormItem> |
| 83 | <FormLabel>Event Name</FormLabel> |
| 84 | <FormControl> |
| 85 | <Input {...field} /> |
| 86 | </FormControl> |
| 87 | <FormDescription> |
| 88 | The name users will see when booking |
| 89 | </FormDescription> |
| 90 | <FormMessage /> |
| 91 | </FormItem> |
| 92 | )} |
nothing calls this directly
no test coverage detected