MCPcopy Create free account
hub / github.com/WebDevSimplified/calendly-clone / MeetingForm

Function MeetingForm

src/components/forms/MeetingForm.tsx:41–258  ·  view source on GitHub ↗
({
  validTimes,
  eventId,
  clerkUserId,
}: {
  validTimes: Date[]
  eventId: string
  clerkUserId: string
})

Source from the content-addressed store, hash-verified

39import { createMeeting } from "@/server/actions/meetings"
40
41export function MeetingForm({
42 validTimes,
43 eventId,
44 clerkUserId,
45}: {
46 validTimes: Date[]
47 eventId: string
48 clerkUserId: string
49}) {
50 const form = useForm<z.infer<typeof meetingFormSchema>>({
51 resolver: zodResolver(meetingFormSchema),
52 defaultValues: {
53 timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
54 },
55 })
56
57 const timezone = form.watch("timezone")
58 const date = form.watch("date")
59 const validTimesInTimezone = useMemo(() => {
60 return validTimes.map(date => toZonedTime(date, timezone))
61 }, [validTimes, timezone])
62
63 async function onSubmit(values: z.infer<typeof meetingFormSchema>) {
64 const data = await createMeeting({
65 ...values,
66 eventId,
67 clerkUserId,
68 })
69
70 if (data?.error) {
71 form.setError("root", {
72 message: "There was an error saving your event",
73 })
74 }
75 }
76
77 return (
78 <Form {...form}>
79 <form
80 onSubmit={form.handleSubmit(onSubmit)}
81 className="flex gap-6 flex-col"
82 >
83 {form.formState.errors.root && (
84 <div className="text-destructive text-sm">
85 {form.formState.errors.root.message}
86 </div>
87 )}
88 <FormField
89 control={form.control}
90 name="timezone"
91 render={({ field }) => (
92 <FormItem>
93 <FormLabel>Timezone</FormLabel>
94 <Select onValueChange={field.onChange} defaultValue={field.value}>
95 <FormControl>
96 <SelectTrigger>
97 <SelectValue />
98 </SelectTrigger>

Callers

nothing calls this directly

Calls 4

formatTimezoneOffsetFunction · 0.90
cnFunction · 0.90
formatDateFunction · 0.90
formatTimeStringFunction · 0.90

Tested by

no test coverage detected