Skip to content

Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.

✨ Add create event type dialog (RAL-1184) (#2385)

Luke Vella03f2795ab9aa
diff --git a/apps/web/public/locales/en/app.json b/apps/web/public/locales/en/app.json
index 70f604a25..58e0ff032 100644
--- a/apps/web/public/locales/en/app.json
+++ b/apps/web/public/locales/en/app.json
@@ -631,6 +631,27 @@
"updateAvailable": "Update available",
"eventTypesEmptyTitle": "No event types yet",
"eventTypesEmptyDescription": "Create reusable event types that people can book with you.",
- "eventTypeUpdatedRelative": "Updated {relativeTime}",
- "eventTypes": "Event Types"
+ "eventTypes": "Event Types",
+ "newEventType": "New Event Type",
+ "createEventTypeTitle": "Create Event Type",
+ "createEventTypeDescription": "Set up a reusable event type that people can book with you.",
+ "address": "Address",
+ "url": "URL",
+ "locationDisplayText": "Display text",
+ "createEventTypeError": "Failed to create event type",
+ "eventTypeNamePlaceholder": "Discovery call",
+ "eventTypeDescriptionPlaceholder": "What is this event about?",
+ "locationInPerson": "In person",
+ "locationCustomLink": "Custom link",
+ "addressPlaceholder": "123 Main Street",
+ "durationLabel": "Duration",
+ "minutesAbbreviation": "min",
+ "addDescription": "Add description",
+ "remove": "Remove",
+ "maxAttendees": "Max attendees",
+ "setMaxAttendees": "Set max attendees",
+ "maxAttendeesInvalid": "Must be a positive integer",
+ "requiredField": "Required",
+ "urlInvalid": "Must be a valid URL",
+ "locationDisplayTextPlaceholder": "Meeting link"
}
diff --git a/apps/web/src/app/[locale]/(space)/(dashboard)/event-types/event-types-page.tsx b/apps/web/src/app/[locale]/(space)/(dashboard)/event-types/event-types-page.tsx
index be1935ad8..1f559915c 100644
--- a/apps/web/src/app/[locale]/(space)/(dashboard)/event-types/event-types-page.tsx
+++ b/apps/web/src/app/[locale]/(space)/(dashboard)/event-types/event-types-page.tsx
@@ -1,36 +1,42 @@
"use client";
import { Badge } from "@rallly/ui/badge";
+import { Button } from "@rallly/ui/button";
import { CardTitle } from "@rallly/ui/card";
+import { useDialog } from "@rallly/ui/dialog";
import {
ArmchairIcon,
CalendarRangeIcon,
ClockIcon,
Link2Icon,
MapPinIcon,
+ PlusIcon,
} from "lucide-react";
import {
PageContainer,
PageContent,
PageHeader,
+ PageHeaderActions,
PageHeaderContent,
PageTitle,
} from "@/app/components/page-layout";
import {
EmptyState,
EmptyStateDescription,
+ EmptyStateFooter,
EmptyStateIcon,
EmptyStateTitle,
} from "@/components/empty-state";
import { OptimizedAvatarImage } from "@/components/optimized-avatar-image";
import { RandomGradientBar } from "@/components/random-gradient-bar";
+import { CreateEventTypeDialog } from "@/features/event-types/components/create-event-type-dialog";
import { Trans } from "@/i18n/client";
import { useLocale } from "@/lib/locale/client";
import type { LocationType } from "@/lib/location";
import { trpc } from "@/trpc/client";
import { formatDuration } from "@/utils/date-time-utils";
-function EventTypesEmptyState() {
+function EventTypesEmptyState({ onCreate }: { onCreate: () => void }) {
return (
<EmptyState className="p-8">
<EmptyStateIcon>
@@ -45,6 +51,12 @@ function EventTypesEmptyState() {
defaults="Create reusable event types that people can book with you."
/>
</EmptyStateDescription>
+ <EmptyStateFooter>
+ <Button variant="primary" onClick={onCreate}>
+ <PlusIcon data-icon="inline-start" />
+ <Trans i18nKey="newEventType" defaults="New Event Type" />
+ </Button>
+ </EmptyStateFooter>
</EmptyState>
);
}
@@ -107,6 +119,7 @@ function EventTypeCard({
export function EventTypesPage() {
const [{ eventTypes }] = trpc.eventTypes.list.useSuspenseQuery();
+ const dialog = useDialog();
return (
<PageContainer>
@@ -116,10 +129,16 @@ export function EventTypesPage() {
<Trans i18nKey="eventTypes" defaults="Event Types" />
</PageTitle>
</PageHeaderContent>
+ <PageHeaderActions>
+ <Button variant="primary" onClick={() => dialog.trigger()}>
+ <PlusIcon data-icon="inline-start" />
+ <Trans i18nKey="newEventType" defaults="New Event Type" />
+ </Button>
+ </PageHeaderActions>
</PageHeader>
<PageContent>
{eventTypes.length === 0 ? (
- <EventTypesEmptyState />
+ <EventTypesEmptyState onCreate={() => dialog.trigger()} />
) : (
<div className="@container">
<div className="grid @4xl:grid-cols-3 @md:grid-cols-2 grid-cols-1 gap-4">
@@ -145,6 +164,7 @@ export function EventTypesPage() {
</div>
)}
</PageContent>
+ <CreateEventTypeDialog {...dialog.dialogProps} />
</PageContainer>
);
}
diff --git a/apps/web/src/features/event-types/components/create-event-type-dialog.tsx b/apps/web/src/features/event-types/components/create-event-type-dialog.tsx
new file mode 100644
index 000000000..a5641c65c
--- /dev/null
+++ b/apps/web/src/features/event-types/components/create-event-type-dialog.tsx
@@ -0,0 +1,514 @@
+"use client";
+
+import { zodResolver } from "@hookform/resolvers/zod";
+import { usePostHog } from "@rallly/posthog/client";
+import { Button } from "@rallly/ui/button";
+import type { DialogProps } from "@rallly/ui/dialog";
+import {
+ Dialog,
+ DialogClose,
+ DialogContent,
+ DialogDescription,
+ DialogFooter,
+ DialogHeader,
+ DialogTitle,
+} from "@rallly/ui/dialog";
+import {
+ Form,
+ FormControl,
+ FormField,
+ FormItem,
+ FormLabel,
+ FormMessage,
+} from "@rallly/ui/form";
+import { Input } from "@rallly/ui/input";
+import { RadioGroup, RadioGroupItem } from "@rallly/ui/radio-group";
+import { toast } from "@rallly/ui/sonner";
+import { Textarea } from "@rallly/ui/textarea";
+import { Link2Icon, MapPinIcon, PlusIcon } from "lucide-react";
+import React from "react";
+import { useForm } from "react-hook-form";
+import { z } from "zod";
+import { Trans, useTranslation } from "@/i18n/client";
+import { trpc } from "@/trpc/client";
+
+function buildFormSchema(
+ t: (key: string, opts: { defaultValue: string }) => string,
+) {
+ return z
+ .object({
+ name: z.string().min(1).max(255),
+ duration: z.number().int().positive(),
+ maxAttendees: z.string().optional(),
+ description: z.string().max(2000).optional(),
+ locationType: z.enum(["", "in_person", "custom_link"]),
+ locationAddress: z.string().optional(),
+ locationUrl: z.string().optional(),
+ locationText: z.string().optional(),
+ })
+ .superRefine((data, ctx) => {
+ if (data.maxAttendees) {
+ const parsed = Number(data.maxAttendees);
+ if (!Number.isInteger(parsed) || parsed <= 0) {
+ ctx.addIssue({
+ path: ["maxAttendees"],
+ code: "custom",
+ message: t("maxAttendeesInvalid", {
+ defaultValue: "Must be a positive integer",
+ }),
+ });
+ }
+ }
+ if (data.locationType === "in_person") {
+ if (!data.locationAddress?.trim()) {
+ ctx.addIssue({
+ path: ["locationAddress"],
+ code: "custom",
+ message: t("requiredField", { defaultValue: "Required" }),
+ });
+ }
+ } else if (data.locationType === "custom_link") {
+ if (!data.locationUrl?.trim()) {
+ ctx.addIssue({
+ path: ["locationUrl"],
+ code: "custom",
+ message: t("requiredField", { defaultValue: "Required" }),
+ });
+ } else {
+ try {
+ new URL(data.locationUrl);
+ } catch {
+ ctx.addIssue({
+ path: ["locationUrl"],
+ code: "custom",
+ message: t("urlInvalid", {
+ defaultValue: "Must be a valid URL",
+ }),
+ });
+ }
+ }
+ }
+ });
+}
+
+const defaultValues = {
+ name: "",
+ duration: 60,
+ maxAttendees: "",
+ description: "",
+ locationType: "" as "" | "in_person" | "custom_link",
+ locationAddress: "",
+ locationUrl: "",
+ locationText: "",
+};
+
+export function CreateEventTypeDialog({ open, onOpenChange }: DialogProps) {
+ const { t } = useTranslation();
+ const posthog = usePostHog();
+ const createEventType = trpc.eventTypes.create.useMutation();
+ const [showMaxAttendees, setShowMaxAttendees] = React.useState(false);
+ const [showDescription, setShowDescription] = React.useState(false);
+
+ const formSchema = React.useMemo(() => buildFormSchema(t), [t]);
+
+ const form = useForm({
+ resolver: zodResolver(formSchema),
+ defaultValues,
+ });
+
+ const locationType = form.watch("locationType");
+
+ const handleOpenChange = (nextOpen: boolean) => {
+ if (!nextOpen) {
+ form.reset(defaultValues);
+ setShowMaxAttendees(false);
+ setShowDescription(false);
+ }
+ onOpenChange?.(nextOpen);
+ };
+
+ const onSubmit = form.handleSubmit(async (values) => {
+ const capacity = values.maxAttendees ? Number(values.maxAttendees) : null;
+ const description = values.description?.trim() || undefined;
+ const location =
+ values.locationType === "in_person" && values.locationAddress
+ ? {
+ type: "in_person" as const,
+ address: values.locationAddress.trim(),
+ }
+ : values.locationType === "custom_link" && values.locationUrl
+ ? {
+ type: "custom_link" as const,
+ url: values.locationUrl.trim(),
+ text: values.locationText?.trim() || undefined,
+ }
+ : undefined;
+
+ try {
+ await createEventType.mutateAsync({
+ name: values.name.trim(),
+ duration: values.duration,
+ capacity,
+ description,
+ location,
+ });
+ } catch {
+ toast.error(
+ t("createEventTypeError", {
+ defaultValue: "Failed to create event type",
+ }),
+ );
+ return;
+ }
+ posthog?.capture("event_type_creation:form_submit", {
+ duration_minutes: values.duration,
+ location_type: location?.type ?? "none",
+ has_max_attendees: capacity !== null,
+ has_description: description !== undefined,
+ });
+ handleOpenChange(false);
+ });
+
+ const handleRemoveMaxAttendees = () => {
+ setShowMaxAttendees(false);
+ form.setValue("maxAttendees", "");
+ form.clearErrors("maxAttendees");
+ };
+
+ const handleRemoveDescription = () => {
+ setShowDescription(false);
+ form.setValue("description", "");
+ form.clearErrors("description");
+ };
+
+ return (
+ <Dialog open={open} onOpenChange={handleOpenChange}>
+ <DialogContent size="lg">
+ <DialogHeader>
+ <DialogTitle>
+ <Trans
+ i18nKey="createEventTypeTitle"
+ defaults="Create Event Type"
+ />
+ </DialogTitle>
+ <DialogDescription>
+ <Trans
+ i18nKey="createEventTypeDescription"
+ defaults="Set up a reusable event type that people can book with you."
+ />
+ </DialogDescription>
+ </DialogHeader>
+ <Form {...form}>
+ <form onSubmit={onSubmit} className="space-y-5">
+ <div className="grid gap-4 sm:grid-cols-[1fr_8rem]">
+ <FormField
+ control={form.control}
+ name="name"
+ render={({ field }) => (
+ <FormItem>
+ <FormLabel>
+ <Trans i18nKey="name" defaults="Name" />
+ </FormLabel>
+ <FormControl>
+ <Input
+ {...field}
+ autoFocus
+ placeholder={t("eventTypeNamePlaceholder", {
+ defaultValue: "Discovery call",
+ })}
+ />
+ </FormControl>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ <FormField
+ control={form.control}
+ name="duration"
+ render={({ field }) => (
+ <FormItem>
+ <FormLabel>
+ <Trans i18nKey="durationLabel" defaults="Duration" />
+ </FormLabel>
+ <FormControl>
+ <div className="relative">
+ <Input
+ type="number"
+ min={1}
+ step={1}
+ className="pr-10"
+ {...field}
+ onChange={(event) => {
+ const value = event.target.value;
+ field.onChange(value === "" ? "" : Number(value));
+ }}
+ />
+ <span className="pointer-events-none absolute inset-y-0 right-2.5 flex items-center text-muted-foreground text-sm">
+ <Trans i18nKey="minutesAbbreviation" defaults="min" />
+ </span>
+ </div>
+ </FormControl>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ </div>
+
+ <FormField
+ control={form.control}
+ name="locationType"
+ render={({ field }) => (
+ <FormItem>
+ <FormLabel>
+ <Trans i18nKey="location" defaults="Location" />
+ </FormLabel>
+ <FormControl>
+ <RadioGroup
+ value={field.value}
+ onValueChange={(value) => {
+ field.onChange(value);
+ form.clearErrors(["locationAddress", "locationUrl"]);
+ }}
+ className="grid grid-cols-2 gap-2"
+ >
+ <RadioCardOption
+ value="in_person"
+ icon={<MapPinIcon className="size-4" />}
+ label={t("locationInPerson", {
+ defaultValue: "In person",
+ })}
+ />
+ <RadioCardOption
+ value="custom_link"
+ icon={<Link2Icon className="size-4" />}
+ label={t("locationCustomLink", {
+ defaultValue: "Custom link",
+ })}
+ />
+ </RadioGroup>
+ </FormControl>
+ </FormItem>
+ )}
+ />
+
+ {locationType === "in_person" ? (
+ <FormField
+ control={form.control}
+ name="locationAddress"
+ render={({ field }) => (
+ <FormItem>
+ <FormLabel>
+ <Trans i18nKey="address" defaults="Address" />
+ </FormLabel>
+ <FormControl>
+ <Input
+ {...field}
+ placeholder={t("addressPlaceholder", {
+ defaultValue: "123 Main Street",
+ })}
+ />
+ </FormControl>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ ) : null}
+
+ {locationType === "custom_link" ? (
+ <div className="grid gap-3 sm:grid-cols-2">
+ <FormField
+ control={form.control}
+ name="locationUrl"
+ render={({ field }) => (
+ <FormItem>
+ <FormLabel>
+ <Trans i18nKey="url" defaults="URL" />
+ </FormLabel>
+ <FormControl>
+ <Input type="url" {...field} placeholder="https://" />
+ </FormControl>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ <FormField
+ control={form.control}
+ name="locationText"
+ render={({ field }) => (
+ <FormItem>
+ <FormLabel className="flex items-center gap-1.5">
+ <Trans
+ i18nKey="locationDisplayText"
+ defaults="Display text"
+ />
+ <span className="text-muted-foreground">
+ <Trans
+ i18nKey="optionalLabel"
+ defaults="(Optional)"
+ />
+ </span>
+ </FormLabel>
+ <FormControl>
+ <Input
+ {...field}
+ placeholder={t("locationDisplayTextPlaceholder", {
+ defaultValue: "Meeting link",
+ })}
+ />
+ </FormControl>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ </div>
+ ) : null}
+
+ {showMaxAttendees ? (
+ <FormField
+ control={form.control}
+ name="maxAttendees"
+ render={({ field }) => (
+ <FormItem>
+ <div className="flex items-center justify-between">
+ <FormLabel>
+ <Trans
+ i18nKey="maxAttendees"
+ defaults="Max attendees"
+ />
+ </FormLabel>
+ <RemoveOptionalButton
+ onClick={handleRemoveMaxAttendees}
+ />
+ </div>
+ <FormControl>
+ <Input type="number" min={1} step={1} {...field} />
+ </FormControl>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ ) : null}
+
+ {showDescription ? (
+ <FormField
+ control={form.control}
+ name="description"
+ render={({ field }) => (
+ <FormItem>
+ <div className="flex items-center justify-between">
+ <FormLabel>
+ <Trans i18nKey="description" defaults="Description" />
+ </FormLabel>
+ <RemoveOptionalButton onClick={handleRemoveDescription} />
+ </div>
+ <FormControl>
+ <Textarea
+ {...field}
+ rows={3}
+ placeholder={t("eventTypeDescriptionPlaceholder", {
+ defaultValue: "What is this event about?",
+ })}
+ />
+ </FormControl>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ ) : null}
+
+ {!showMaxAttendees || !showDescription ? (
+ <div className="flex flex-wrap items-center gap-1">
+ {!showMaxAttendees ? (
+ <Button
+ type="button"
+ variant="ghost"
+ size="sm"
+ onClick={() => {
+ setShowMaxAttendees(true);
+ form.setValue("maxAttendees", "1");
+ }}
+ className="text-muted-foreground"
+ >
+ <PlusIcon data-icon="inline-start" />
+ <Trans
+ i18nKey="setMaxAttendees"
+ defaults="Set max attendees"
+ />
+ </Button>
+ ) : null}
+ {!showDescription ? (
+ <Button
+ type="button"
+ variant="ghost"
+ size="sm"
+ onClick={() => setShowDescription(true)}
+ className="text-muted-foreground"
+ >
+ <PlusIcon data-icon="inline-start" />
+ <Trans
+ i18nKey="addDescription"
+ defaults="Add description"
+ />
+ </Button>
+ ) : null}
+ </div>
+ ) : null}
+
+ <DialogFooter className="pt-2">
+ <DialogClose asChild>
+ <Button type="button" disabled={createEventType.isPending}>
+ <Trans i18nKey="cancel" defaults="Cancel" />
+ </Button>
+ </DialogClose>
+ <Button
+ type="submit"
+ variant="primary"
+ loading={createEventType.isPending}
+ >
+ <Trans i18nKey="create" defaults="Create" />
+ </Button>
+ </DialogFooter>
+ </form>
+ </Form>
+ </DialogContent>
+ </Dialog>
+ );
+}
+
+function RadioCardOption({
+ value,
+ icon,
+ label,
+}: {
+ value: string;
+ icon: React.ReactNode;
+ label: string;
+}) {
+ const id = React.useId();
+ return (
+ <label
+ htmlFor={id}
+ className="group flex cursor-pointer items-center gap-2.5 rounded-lg border border-input bg-card px-3 py-2.5 text-sm transition-colors hover:bg-accent has-data-[state=checked]:border-primary has-data-[state=checked]:bg-primary/5"
+ >
+ <RadioGroupItem id={id} value={value} />
+ <span className="flex items-center gap-1.5 font-medium text-foreground">
+ <span className="text-muted-foreground group-has-data-[state=checked]:text-primary">
+ {icon}
+ </span>
+ {label}
+ </span>
+ </label>
+ );
+}
+
+function RemoveOptionalButton({ onClick }: { onClick: () => void }) {
+ return (
+ <button
+ type="button"
+ onClick={onClick}
+ className="font-normal text-muted-foreground text-sm underline-offset-2 hover:text-foreground hover:underline"
+ >
+ <Trans i18nKey="remove" defaults="Remove" />
+ </button>
+ );
+}