Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.
TypeScript i18nextnext-authnextjspostgresqlprismareact-emailt3-stacktailwindcsstrpcturborepotypescriptzod
✨ Add event types list page and nav entry (#2381)
Luke Vellab9f8e4a570c7
diff --git a/apps/landing/public/locales/en/common.json b/apps/landing/public/locales/en/common.jsonindex a5d92589f..c0153cd72 100644--- a/apps/landing/public/locales/en/common.json+++ b/apps/landing/public/locales/en/common.json@@ -6,7 +6,6 @@"footerCredit": "Made by <a>@imlukevella</a>","footerSponsor": "This project is user-funded. Please consider supporting it by <a>donating</a>.","language": "Language",- "poweredBy": "Powered by","privacyPolicy": "Privacy Policy","support": "Support","cookiePolicy": "Cookie Policy",diff --git a/apps/web/public/locales/en/app.json b/apps/web/public/locales/en/app.jsonindex c1d73da61..70f604a25 100644--- a/apps/web/public/locales/en/app.json+++ b/apps/web/public/locales/en/app.json@@ -628,5 +628,9 @@"customBrandingPromptCta": "Set Up Now","dismiss": "Dismiss","new": "New",- "updateAvailable": "Update available"+ "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"}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.tsxnew file mode 100644index 000000000..be1935ad8--- /dev/null+++ b/apps/web/src/app/[locale]/(space)/(dashboard)/event-types/event-types-page.tsx@@ -0,0 +1,150 @@+"use client";++import { Badge } from "@rallly/ui/badge";+import { CardTitle } from "@rallly/ui/card";+import {+ ArmchairIcon,+ CalendarRangeIcon,+ ClockIcon,+ Link2Icon,+ MapPinIcon,+} from "lucide-react";+import {+ PageContainer,+ PageContent,+ PageHeader,+ PageHeaderContent,+ PageTitle,+} from "@/app/components/page-layout";+import {+ EmptyState,+ EmptyStateDescription,+ EmptyStateIcon,+ EmptyStateTitle,+} from "@/components/empty-state";+import { OptimizedAvatarImage } from "@/components/optimized-avatar-image";+import { RandomGradientBar } from "@/components/random-gradient-bar";+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() {+ return (+ <EmptyState className="p-8">+ <EmptyStateIcon>+ <CalendarRangeIcon />+ </EmptyStateIcon>+ <EmptyStateTitle>+ <Trans i18nKey="eventTypesEmptyTitle" defaults="No event types yet" />+ </EmptyStateTitle>+ <EmptyStateDescription>+ <Trans+ i18nKey="eventTypesEmptyDescription"+ defaults="Create reusable event types that people can book with you."+ />+ </EmptyStateDescription>+ </EmptyState>+ );+}++function EventTypeCard({+ name,+ duration,+ capacity,+ hostName,+ hostImage,+ locationType,+ locationLabel,+}: {+ name: string;+ duration: number;+ capacity: number | null;+ hostName: string;+ hostImage?: string;+ locationType: LocationType | null;+ locationLabel: string | null;+}) {+ const { locale } = useLocale();+ return (+ <div className="flex flex-col overflow-hidden rounded-2xl border border-card-border bg-card">+ <RandomGradientBar />+ <div className="p-3">+ <OptimizedAvatarImage size="lg" src={hostImage} name={hostName} />+ <p className="mt-2 font-medium text-muted-foreground text-sm">+ {hostName}+ </p>+ <CardTitle className="mt-2 truncate">{name}</CardTitle>+ </div>+ <div className="mt-auto p-3">+ <div className="flex flex-wrap gap-1">+ <Badge>+ <ClockIcon className="mr-1 -ml-0.5 size-4" />+ <span>{formatDuration(duration, locale)}</span>+ </Badge>+ {capacity !== null ? (+ <Badge>+ <ArmchairIcon className="mr-1 -ml-0.5 size-4" />+ <span>{capacity}</span>+ </Badge>+ ) : null}+ {locationType && locationLabel ? (+ <Badge>+ {locationType === "in_person" ? (+ <MapPinIcon className="mr-1 -ml-0.5 size-4" />+ ) : (+ <Link2Icon className="mr-1 -ml-0.5 size-4" />+ )}+ <span className="truncate">{locationLabel}</span>+ </Badge>+ ) : null}+ </div>+ </div>+ </div>+ );+}++export function EventTypesPage() {+ const [{ eventTypes }] = trpc.eventTypes.list.useSuspenseQuery();++ return (+ <PageContainer>+ <PageHeader>+ <PageHeaderContent>+ <PageTitle>+ <Trans i18nKey="eventTypes" defaults="Event Types" />+ </PageTitle>+ </PageHeaderContent>+ </PageHeader>+ <PageContent>+ {eventTypes.length === 0 ? (+ <EventTypesEmptyState />+ ) : (+ <div className="@container">+ <div className="grid @4xl:grid-cols-3 @md:grid-cols-2 grid-cols-1 gap-4">+ {eventTypes.map((eventType) => (+ <EventTypeCard+ key={eventType.id}+ name={eventType.name}+ duration={eventType.duration}+ capacity={eventType.capacity}+ hostName={eventType.host.name}+ hostImage={eventType.host.image ?? undefined}+ locationType={eventType.location?.type ?? null}+ locationLabel={+ eventType.location+ ? eventType.location.type === "in_person"+ ? eventType.location.address+ : (eventType.location.text ?? eventType.location.url)+ : null+ }+ />+ ))}+ </div>+ </div>+ )}+ </PageContent>+ </PageContainer>+ );+}diff --git a/apps/web/src/app/[locale]/(space)/(dashboard)/event-types/page.tsx b/apps/web/src/app/[locale]/(space)/(dashboard)/event-types/page.tsxnew file mode 100644index 000000000..713f36c67--- /dev/null+++ b/apps/web/src/app/[locale]/(space)/(dashboard)/event-types/page.tsx@@ -0,0 +1,31 @@+import { dehydrate, HydrationBoundary } from "@tanstack/react-query";+import type { Metadata } from "next";+import { notFound } from "next/navigation";+import { getTranslation } from "@/i18n/server";+import { isFeatureEnabled } from "@/lib/feature-flags/server";+import { createPrivateSSRHelper } from "@/trpc/server/create-ssr-helper";+import { EventTypesPage } from "./event-types-page";++export default async function Page() {+ if (!isFeatureEnabled("eventTypes")) {+ notFound();+ }++ const helpers = await createPrivateSSRHelper();+ await helpers.eventTypes.list.prefetch();++ return (+ <HydrationBoundary state={dehydrate(helpers.queryClient)}>+ <EventTypesPage />+ </HydrationBoundary>+ );+}++export async function generateMetadata(): Promise<Metadata> {+ const { t } = await getTranslation();+ return {+ title: t("eventTypes", {+ defaultValue: "Event Types",+ }),+ };+}diff --git a/apps/web/src/features/event-types/data.ts b/apps/web/src/features/event-types/data.tsindex d06575500..aa51bea70 100644--- a/apps/web/src/features/event-types/data.ts+++ b/apps/web/src/features/event-types/data.ts@@ -1,4 +1,4 @@-import type { EventType } from "@rallly/database";+import type { EventType, User } from "@rallly/database";import { prisma } from "@rallly/database";import { createLogger } from "@rallly/logger";import type { EventTypeDTO } from "@/features/event-types/types";@@ -7,7 +7,9 @@ import { locationSchema } from "@/lib/location";const logger = createLogger("event-types/data");-export function createEventTypeDTO(eventType: EventType): EventTypeDTO {+export function createEventTypeDTO(+ eventType: EventType & { host: Pick<User, "id" | "name" | "image"> },+): EventTypeDTO {let location: Location | null = null;if (eventType.location !== null) {try {@@ -27,6 +29,11 @@ export function createEventTypeDTO(eventType: EventType): EventTypeDTO {description: eventType.description,location,hostId: eventType.hostId,+ host: {+ id: eventType.host.id,+ name: eventType.host.name,+ image: eventType.host.image,+ },spaceId: eventType.spaceId,createdAt: eventType.createdAt,updatedAt: eventType.updatedAt,@@ -40,6 +47,11 @@ export async function getEventTypes(spaceId: string): Promise<EventTypeDTO[]> {deleted: false,},orderBy: { updatedAt: "desc" },+ include: {+ host: {+ select: { id: true, name: true, image: true },+ },+ },});return rows.map(createEventTypeDTO);diff --git a/apps/web/src/features/event-types/types.ts b/apps/web/src/features/event-types/types.tsindex 8d4fd4da5..7368e4349 100644--- a/apps/web/src/features/event-types/types.ts+++ b/apps/web/src/features/event-types/types.ts@@ -1,5 +1,11 @@import type { Location } from "@/lib/location";+export type EventTypeHost = {+ id: string;+ name: string;+ image: string | null;+};+export type EventTypeDTO = {id: string;name: string;@@ -8,6 +14,7 @@ export type EventTypeDTO = {description: string | null;location: Location | null;hostId: string;+ host: EventTypeHost;spaceId: string;createdAt: Date;updatedAt: Date;diff --git a/apps/web/src/features/navigation/config.tsx b/apps/web/src/features/navigation/config.tsxindex 57b12c55e..6e7c05f8e 100644--- a/apps/web/src/features/navigation/config.tsx+++ b/apps/web/src/features/navigation/config.tsx@@ -6,6 +6,7 @@ import {CalendarDaysIcon,CalendarIcon,HomeIcon,+ ShapesIcon,} from "lucide-react";import { usePathname } from "next/navigation";import React from "react";@@ -37,6 +38,7 @@ export const useSpaceMenu = () => {const { t } = useTranslation();const pathname = usePathname();const isCalendarsEnabled = useFeatureFlag("calendars");+ const isEventTypesEnabled = useFeatureFlag("eventTypes");const config = React.useMemo<NavigationConfig>(() => ({sections: [@@ -81,11 +83,24 @@ export const useSpaceMenu = () => {},]: []),+ ...(isEventTypesEnabled+ ? [+ {+ id: "event-types",+ label: t("eventTypes", { defaultValue: "Event Types" }),+ href: "/event-types",+ icon: ShapesIcon,+ isActive:+ pathname === "/event-types" ||+ pathname.startsWith("/event-types/"),+ },+ ]+ : []),],},],}),- [pathname, t, isCalendarsEnabled],+ [pathname, t, isCalendarsEnabled, isEventTypesEnabled],);return React.useMemo(diff --git a/apps/web/src/trpc/routers/event-types.ts b/apps/web/src/trpc/routers/event-types.tsindex 77805a289..c8435c5ba 100644--- a/apps/web/src/trpc/routers/event-types.ts+++ b/apps/web/src/trpc/routers/event-types.ts@@ -40,6 +40,11 @@ export const eventTypes = router({description: input.description,location: input.location,},+ include: {+ host: {+ select: { id: true, name: true, image: true },+ },+ },});return createEventTypeDTO(created);}),@@ -60,6 +65,11 @@ export const eventTypes = router({description: input.description,location: input.location,},+ include: {+ host: {+ select: { id: true, name: true, image: true },+ },+ },});return createEventTypeDTO(updated);diff --git a/apps/web/src/utils/date-time-utils.ts b/apps/web/src/utils/date-time-utils.tsindex 58700ef4e..348b4117f 100644--- a/apps/web/src/utils/date-time-utils.ts+++ b/apps/web/src/utils/date-time-utils.ts@@ -38,20 +38,33 @@ export interface ParsedTimeSlotOption {export type ParsedDateTimeOpton = ParsedDateOption | ParsedTimeSlotOption;-export const getDuration = (startTime: dayjs.Dayjs, endTime: dayjs.Dayjs) => {- const hours = Math.floor(endTime.diff(startTime, "hours"));- const minutes = Math.floor(endTime.diff(startTime, "minute") - hours * 60);- let res = "";- if (hours) {- res += `${hours}h`;+type DurationFormatCtor = new (+ locale: string | undefined,+ options: { style: "narrow" },+) => { format(duration: { hours?: number; minutes?: number }): string };++export const formatDuration = (minutes: number, locale?: string) => {+ const hours = Math.floor(minutes / 60);+ const mins = minutes % 60;+ const DurationFormat = (Intl as { DurationFormat?: DurationFormatCtor })+ .DurationFormat;+ if (DurationFormat) {+ return new DurationFormat(locale, { style: "narrow" }).format({+ hours,+ minutes: mins,+ });}- if (hours && minutes) {- res += " ";+ if (hours && mins) {+ return `${hours}h ${mins}m`;}- if (minutes) {- res += `${minutes}m`;+ if (hours) {+ return `${hours}h`;}- return res;+ return `${mins}m`;+};++export const getDuration = (startTime: dayjs.Dayjs, endTime: dayjs.Dayjs) => {+ return formatDuration(endTime.diff(startTime, "minute"));};export const removeAllOptionsForDay = (diff --git a/packages/database/prisma/seed.ts b/packages/database/prisma/seed.tsindex 793f04204..24ec18ba8 100644--- a/packages/database/prisma/seed.ts+++ b/packages/database/prisma/seed.ts@@ -1,6 +1,7 @@import { PrismaPg } from "@prisma/adapter-pg";import { PrismaClient } from "../generated/prisma/client";import {+ eventTypes,polls,scheduledEvents,spaceMembers,@@ -168,6 +169,23 @@ async function main() {console.info(`✓ ${polls.length} polls, ${optionCount} options, ${participantCount} participants, ${voteCount} votes, ${commentCount} comments`,);++ // 6. Event types+ const now = Date.now();+ await prisma.eventType.createMany({+ data: eventTypes.map((et, i) => ({+ id: et.id,+ spaceId: et.spaceId,+ hostId: et.hostId,+ name: et.name,+ duration: et.duration,+ capacity: et.capacity,+ description: et.description,+ location: et.location ?? undefined,+ updatedAt: new Date(now - i * 60_000),+ })),+ });+ console.info(`✓ ${eventTypes.length} event types`);}main()diff --git a/packages/database/prisma/seed/data.ts b/packages/database/prisma/seed/data.tsindex 78a6fffcf..2cc94940b 100644--- a/packages/database/prisma/seed/data.ts+++ b/packages/database/prisma/seed/data.ts@@ -1003,6 +1003,106 @@ const acmePolls: PollDef[] = [export const polls: PollDef[] = [...personalPolls, ...acmePolls];+// ─── Event Types ─────────────────────────────────────────────────────────────++type EventTypeLocation =+ | { type: "in_person"; address: string; placeId?: string }+ | { type: "custom_link"; url: string; text?: string };++export type EventTypeDef = {+ id: string;+ spaceId: string;+ hostId: string;+ name: string;+ duration: number;+ capacity: number | null;+ description: string | null;+ location: EventTypeLocation | null;+};++export const eventTypes: EventTypeDef[] = [+ // ── Personal space (space-1) ─────────────────────────────────────────────+ {+ id: "et-1",+ spaceId: "space-1",+ hostId: "user-1",+ name: "30 Minute Meeting",+ duration: 30,+ capacity: null,+ description: "Quick catch-up or intro.",+ location: {+ type: "custom_link",+ url: "https://zoom.us/j/1234567890",+ text: "Zoom",+ },+ },+ {+ id: "et-2",+ spaceId: "space-1",+ hostId: "user-1",+ name: "Coffee Chat",+ duration: 45,+ capacity: 1,+ description: null,+ location: {+ type: "in_person",+ address: "Café on 5th Ave, New York",+ },+ },++ // ── Acme Inc (space-2) ───────────────────────────────────────────────────+ {+ id: "et-3",+ spaceId: "space-2",+ hostId: "user-1",+ name: "Intro Call",+ duration: 15,+ capacity: null,+ description: "Brief intro to see if we're a fit.",+ location: {+ type: "custom_link",+ url: "https://meet.google.com/abc-defg-hij",+ text: "Google Meet",+ },+ },+ {+ id: "et-4",+ spaceId: "space-2",+ hostId: "user-2",+ name: "Product Demo",+ duration: 45,+ capacity: null,+ description: "Live walkthrough of the product.",+ location: {+ type: "custom_link",+ url: "https://zoom.us/j/9876543210",+ },+ },+ {+ id: "et-5",+ spaceId: "space-2",+ hostId: "user-3",+ name: "Office Hours",+ duration: 60,+ capacity: 5,+ description: "Drop-in time for engineering questions.",+ location: {+ type: "in_person",+ address: "Acme HQ, Conference Room B",+ },+ },+ {+ id: "et-6",+ spaceId: "space-2",+ hostId: "user-1",+ name: "Team Workshop",+ duration: 90,+ capacity: null,+ description: "Hands-on working session.",+ location: null,+ },+];+// ─── Scheduled Events ────────────────────────────────────────────────────────export type ScheduledEventDef = {diff --git a/packages/ui/src/badge.tsx b/packages/ui/src/badge.tsxindex 5c6001f22..8fbcee4eb 100644--- a/packages/ui/src/badge.tsx+++ b/packages/ui/src/badge.tsx@@ -5,12 +5,12 @@ import type * as React from "react";import { cn } from "./lib/utils";const badgeVariants = cva(- "group inline-flex items-center justify-center whitespace-nowrap rounded-full transition-colors focus:outline-hidden focus:ring-2 focus:ring-ring focus:ring-offset-2",+ "group inline-flex items-center justify-center whitespace-nowrap rounded-lg transition-colors focus:outline-hidden focus:ring-2 focus:ring-ring focus:ring-offset-2",{variants: {variant: {primary: "bg-primary text-primary-foreground",- default: "bg-muted",+ default: "border border-card-border bg-card text-muted-foreground",destructive:"bg-rose-600/10 text-rose-600 dark:bg-rose-500/10 dark:text-rose-500",outline: "text-foreground",