Skip to content

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

🚧 Public event page (#2441)

Luke Vella60b4d4a97fb0
diff --git a/apps/web/public/locales/en/app.json b/apps/web/public/locales/en/app.json
index e2fe9db97..6fdb1f4ba 100644
--- a/apps/web/public/locales/en/app.json
+++ b/apps/web/public/locales/en/app.json
@@ -51,11 +51,6 @@
"applyToAllDates": "Apply to all dates",
"areYouSure": "Are you sure?",
"attendeeCount": "{count, plural, =0 {No attendees} one {1 attendee} other {# attendees}}",
- "attendees": "Attendees",
- "attendeeStatusDeclined": "Declined",
- "attendeeStatusGoing": "Going",
- "attendeeStatusMaybe": "Maybe",
- "attendeeStatusPending": "Pending",
"attribution": "Attribution",
"attributionDescription": "Control the visibility of the attribution text",
"authenticationAndSecurity": "Authentication & Security",
@@ -116,10 +111,8 @@
"commentPlaceholder": "Leave a comment on this poll (visible to everyone)",
"comments": "Comments",
"common_language": "Language",
- "conferencing": "Conferencing",
"configuredByEnvironmentVariable": "This setting has been configured by environment variable.",
"confirm": "Confirm",
- "confirmResponse": "Confirm response",
"confirmSpaceName": "Please type the space name to confirm:",
"connectCalendar": "Connect Calendar",
"connectGoogleCalendar": "Google Calendar",
@@ -256,7 +249,12 @@
"errorUploadPictureDescription": "There was an issue uploading your picture. Please try again later.",
"event": "Event",
"eventHostDescription": "You are the creator of this poll",
- "eventOrganizedBy": "Organized by {name}",
+ "eventPageAbout": "About",
+ "eventPageGoingCount": "{count, plural, one {# going} other {# going}}",
+ "eventPageHostedBy": "Hosted by {name}",
+ "eventRegisterAlreadyResponded": "This email has already been used to respond",
+ "eventRegisterSuccessTitle": "You're registered",
+ "eventRegisterYourDetails": "Your details",
"events": "Events",
"eventStatusCanceled": "Canceled",
"eventStatusPast": "Past",
@@ -315,7 +313,6 @@
"invalidName": "Please enter a valid name, not a URL, email, or phone number",
"inviteCanceledError": "Failed to cancel invite",
"inviteCanceledSuccess": "Invite canceled successfully",
- "invited": "Invited",
"inviteFailed": "Failed to send invitation",
"inviteLink": "Invite Link",
"inviteMember": "Invite member",
@@ -398,7 +395,6 @@
"muteNotifications": "Mute notifications",
"name": "Name",
"namePlaceholder": "Jessie Smith",
- "nameRequired": "Please enter your name",
"neverUsed": "Never used",
"new": "New",
"newEventType": "New Event Type",
@@ -548,11 +544,20 @@
"roleChangedError": "Failed to change role",
"roleChangedSuccess": "Role changed successfully",
"rolePlaceholder": "Select role...",
- "rsvpAlreadyResponded": "It looks like you've already responded with this email",
- "rsvpChange": "Change",
- "rsvpDecline": "Decline",
- "rsvpResponseHeadingDeclining": "You're declining",
- "rsvpResponseHeadingGoing": "You're going",
+ "rsvpCardDescription": "To join this event, please register below.",
+ "rsvpCardTitle": "Registration",
+ "rsvpNoticeCanceled": "Event canceled",
+ "rsvpNoticeEnded": "Event ended",
+ "rsvpNoticeFull": "Event full",
+ "rsvpNoticeInProgress": "Event in progress",
+ "rsvpOneClickRegister": "One-click register",
+ "rsvpStatusCancelDescription": "Can't make it? <a>Cancel your registration</a>",
+ "rsvpStatusRegistered": "You're going!",
+ "rsvpVerifyCta": "Verify your email",
+ "rsvpVerifyDialogDescription": "Enter the 6-digit code we sent to {email}.",
+ "rsvpVerifyError": "We couldn't verify your email. Please try again.",
+ "rsvpVerifyPrompt": "Verify your email to manage your registration from any device.",
+ "rsvpVerifyTitle": "Verify your email",
"save": "Save",
"saved": "Saved",
"saveInstruction": "Select your availability and click <b>{action}</b>",
@@ -589,6 +594,7 @@
"sheetUpdatedRelative": "Updated {relativeTime}",
"showBrandingDescription": "Show your brand identity on your public pages and emails",
"shrink": "Shrink",
+ "signIn": "Sign in",
"signOut": "Sign Out",
"signUp": "Sign Up",
"signupSheets": "Sign-up Sheets",
diff --git a/apps/web/src/app/[locale]/e/[id]/attendee-rows.tsx b/apps/web/src/app/[locale]/e/[id]/attendee-rows.tsx
deleted file mode 100644
index c7dfdba05..000000000
--- a/apps/web/src/app/[locale]/e/[id]/attendee-rows.tsx
+++ /dev/null
@@ -1,51 +0,0 @@
-"use client";
-
-import { OptimizedAvatarImage } from "@/components/optimized-avatar-image";
-import { Trans } from "@/i18n/client";
-import { SectionItem, SectionItemValue } from "./section";
-
-type AttendeeStatus = "accepted" | "tentative" | "declined" | "pending";
-
-export type Attendee = {
- id: string;
- name: string;
- image?: string;
- status: AttendeeStatus;
-};
-
-function StatusLabel({ status }: { status: AttendeeStatus }) {
- switch (status) {
- case "accepted":
- return <Trans i18nKey="attendeeStatusGoing" defaults="Going" />;
- case "tentative":
- return <Trans i18nKey="attendeeStatusMaybe" defaults="Maybe" />;
- case "declined":
- return <Trans i18nKey="attendeeStatusDeclined" defaults="Declined" />;
- case "pending":
- return <Trans i18nKey="attendeeStatusPending" defaults="Pending" />;
- }
-}
-
-const STATUS_ORDER: AttendeeStatus[] = ["accepted", "tentative", "declined"];
-
-export function AttendeeRows({ attendees }: { attendees: Attendee[] }) {
- const sorted = [...attendees]
- .filter((a) => a.status !== "pending")
- .sort(
- (a, b) => STATUS_ORDER.indexOf(a.status) - STATUS_ORDER.indexOf(b.status),
- );
-
- return (
- <>
- {sorted.map((a) => (
- <SectionItem key={a.id}>
- <OptimizedAvatarImage size="md" name={a.name} src={a.image} />
- <p className="min-w-0 truncate text-foreground text-sm">{a.name}</p>
- <SectionItemValue>
- <StatusLabel status={a.status} />
- </SectionItemValue>
- </SectionItem>
- ))}
- </>
- );
-}
diff --git a/apps/web/src/app/[locale]/e/[id]/components/calendar-card.tsx b/apps/web/src/app/[locale]/e/[id]/components/calendar-card.tsx
new file mode 100644
index 000000000..38da387e8
--- /dev/null
+++ b/apps/web/src/app/[locale]/e/[id]/components/calendar-card.tsx
@@ -0,0 +1,58 @@
+import { cn } from "@rallly/ui";
+
+export function CalendarCard({
+ children,
+ className,
+}: {
+ children: React.ReactNode;
+ className?: string;
+}) {
+ return (
+ <div
+ className={cn(
+ "inline-flex size-12 flex-col overflow-hidden rounded-xl border bg-muted text-center text-card-foreground",
+ className,
+ )}
+ >
+ {children}
+ </div>
+ );
+}
+
+export function CalendarCardMonth({
+ children,
+ className,
+}: {
+ children: React.ReactNode;
+ className?: string;
+}) {
+ return (
+ <div
+ className={cn(
+ "bg-muted font-normal text-[10px] text-muted-foreground uppercase leading-4",
+ className,
+ )}
+ >
+ {children}
+ </div>
+ );
+}
+
+export function CalendarCardDay({
+ children,
+ className,
+}: {
+ children: React.ReactNode;
+ className?: string;
+}) {
+ return (
+ <div
+ className={cn(
+ "flex grow items-center justify-center bg-card font-semibold text-base text-foreground leading-none tracking-tight",
+ className,
+ )}
+ >
+ {children}
+ </div>
+ );
+}
diff --git a/apps/web/src/app/[locale]/e/[id]/components/event-detail.tsx b/apps/web/src/app/[locale]/e/[id]/components/event-detail.tsx
new file mode 100644
index 000000000..342e0e2f7
--- /dev/null
+++ b/apps/web/src/app/[locale]/e/[id]/components/event-detail.tsx
@@ -0,0 +1,86 @@
+import { cn } from "@rallly/ui";
+
+export function EventDetail({
+ children,
+ className,
+}: {
+ children: React.ReactNode;
+ className?: string;
+}) {
+ return (
+ <div className={cn("flex items-center gap-4", className)}>{children}</div>
+ );
+}
+
+export function EventDetailTile({
+ children,
+ className,
+}: {
+ children: React.ReactNode;
+ className?: string;
+}) {
+ return (
+ <div
+ className={cn(
+ "inline-flex size-12 flex-col overflow-hidden rounded-xl border bg-card text-center text-card-foreground",
+ className,
+ )}
+ >
+ {children}
+ </div>
+ );
+}
+
+export function EventDetailIcon({
+ children,
+ className,
+}: {
+ children: React.ReactNode;
+ className?: string;
+}) {
+ return (
+ <EventDetailTile
+ className={cn("items-center justify-center [&>svg]:size-5", className)}
+ >
+ {children}
+ </EventDetailTile>
+ );
+}
+
+export function EventDetailContent({
+ children,
+ className,
+}: {
+ children: React.ReactNode;
+ className?: string;
+}) {
+ return <div className={cn(className)}>{children}</div>;
+}
+
+export function EventDetailTitle({
+ children,
+ className,
+}: {
+ children: React.ReactNode;
+ className?: string;
+}) {
+ return (
+ <div className={cn("font-medium text-base text-foreground", className)}>
+ {children}
+ </div>
+ );
+}
+
+export function EventDetailDescription({
+ children,
+ className,
+}: {
+ children: React.ReactNode;
+ className?: string;
+}) {
+ return (
+ <div className={cn("text-muted-foreground text-sm", className)}>
+ {children}
+ </div>
+ );
+}
diff --git a/apps/web/src/app/[locale]/e/[id]/event-header.tsx b/apps/web/src/app/[locale]/e/[id]/components/event-header.tsx
similarity index 95%
rename from apps/web/src/app/[locale]/e/[id]/event-header.tsx
rename to apps/web/src/app/[locale]/e/[id]/components/event-header.tsx
index c96a150c3..91c8d97e0 100644
--- a/apps/web/src/app/[locale]/e/[id]/event-header.tsx
+++ b/apps/web/src/app/[locale]/e/[id]/components/event-header.tsx
@@ -12,7 +12,7 @@ export function EventHeader({
children: React.ReactNode;
className?: string;
}) {
- return <header className={cn("px-4 pb-6", className)}>{children}</header>;
+ return <header className={cn(className)}>{children}</header>;
}
export function EventTitle({
@@ -25,7 +25,7 @@ export function EventTitle({
return (
<h1
className={cn(
- "text-balance font-semibold text-foreground text-xl leading-tight tracking-tight",
+ "text-balance font-semibold text-foreground text-xl leading-tight tracking-tight md:text-2xl",
className,
)}
>
diff --git a/apps/web/src/app/[locale]/e/[id]/components/event-section.tsx b/apps/web/src/app/[locale]/e/[id]/components/event-section.tsx
new file mode 100644
index 000000000..66db3c10d
--- /dev/null
+++ b/apps/web/src/app/[locale]/e/[id]/components/event-section.tsx
@@ -0,0 +1,25 @@
+import { cn } from "@rallly/ui";
+
+export function EventSection({
+ children,
+ className,
+}: {
+ children: React.ReactNode;
+ className?: string;
+}) {
+ return <section className={cn("grid gap-2", className)}>{children}</section>;
+}
+
+export function EventSectionTitle({
+ children,
+ className,
+}: {
+ children: React.ReactNode;
+ className?: string;
+}) {
+ return (
+ <h2 className={cn("text-muted-foreground text-sm", className)}>
+ {children}
+ </h2>
+ );
+}
diff --git a/apps/web/src/app/[locale]/e/[id]/components/registration-dialog.tsx b/apps/web/src/app/[locale]/e/[id]/components/registration-dialog.tsx
new file mode 100644
index 000000000..7eb6e40a7
--- /dev/null
+++ b/apps/web/src/app/[locale]/e/[id]/components/registration-dialog.tsx
@@ -0,0 +1,73 @@
+"use client";
+
+import {
+ Dialog,
+ DialogContent,
+ DialogDescription,
+ DialogHeader,
+ DialogTitle,
+} from "@rallly/ui/dialog";
+import { CircleCheckIcon } from "lucide-react";
+import { useRouter } from "next/navigation";
+import * as React from "react";
+import { Trans } from "@/i18n/client";
+import { RegistrationForm } from "./registration-form";
+
+export function RegistrationDialog({
+ eventId,
+ ...dialogProps
+}: { eventId: string } & React.ComponentProps<typeof Dialog>) {
+ const router = useRouter();
+ const [registration, setRegistration] = React.useState<{
+ name: string;
+ email: string;
+ } | null>(null);
+
+ return (
+ <Dialog
+ {...dialogProps}
+ onOpenChange={(open) => {
+ dialogProps.onOpenChange?.(open);
+ if (!open) {
+ // Reflect the new registration (e.g. the going count) once the
+ // dialog is dismissed, then reset for the next time it opens.
+ if (registration) {
+ router.refresh();
+ }
+ setRegistration(null);
+ }
+ }}
+ >
+ <DialogContent>
+ {registration ? (
+ <div className="flex flex-col items-center gap-3 py-4 text-center">
+ <CircleCheckIcon className="size-10 text-green-600" />
+ <DialogHeader>
+ <DialogTitle>
+ <Trans
+ i18nKey="eventRegisterSuccessTitle"
+ defaults="You're registered"
+ />
+ </DialogTitle>
+ <DialogDescription>
+ {registration.name} · {registration.email}
+ </DialogDescription>
+ </DialogHeader>
+ </div>
+ ) : (
+ <>
+ <DialogHeader>
+ <DialogTitle>
+ <Trans
+ i18nKey="eventRegisterYourDetails"
+ defaults="Your details"
+ />
+ </DialogTitle>
+ </DialogHeader>
+ <RegistrationForm eventId={eventId} onSuccess={setRegistration} />
+ </>
+ )}
+ </DialogContent>
+ </Dialog>
+ );
+}
diff --git a/apps/web/src/app/[locale]/e/[id]/components/registration-form.tsx b/apps/web/src/app/[locale]/e/[id]/components/registration-form.tsx
new file mode 100644
index 000000000..f52a943cc
--- /dev/null
+++ b/apps/web/src/app/[locale]/e/[id]/components/registration-form.tsx
@@ -0,0 +1,121 @@
+"use client";
+
+import { zodResolver } from "@hookform/resolvers/zod";
+import { Button } from "@rallly/ui/button";
+import {
+ Form,
+ FormControl,
+ FormField,
+ FormItem,
+ FormLabel,
+ FormMessage,
+} from "@rallly/ui/form";
+import { Input } from "@rallly/ui/input";
+import { useForm } from "react-hook-form";
+import * as z from "zod";
+import { submitRsvpAction } from "@/features/scheduled-event/actions";
+import { Trans, useTranslation } from "@/i18n/client";
+import { useSafeAction } from "@/lib/safe-action/client";
+
+const formSchema = z.object({
+ name: z.string().trim().min(1).max(100),
+ email: z.email(),
+});
+
+export function RegistrationForm({
+ eventId,
+ onSuccess,
+}: {
+ eventId: string;
+ onSuccess: (registration: { name: string; email: string }) => void;
+}) {
+ const { t } = useTranslation();
+ const submitRsvp = useSafeAction(submitRsvpAction);
+ const form = useForm({
+ defaultValues: {
+ name: "",
+ email: "",
+ },
+ resolver: zodResolver(formSchema),
+ });
+
+ return (
+ <Form {...form}>
+ <form
+ className="grid gap-4"
+ onSubmit={form.handleSubmit(async (data) => {
+ const result = await submitRsvp.executeAsync({
+ eventId,
+ name: data.name,
+ email: data.email,
+ status: "accepted",
+ });
+
+ if (result.data?.ok === false) {
+ form.setError("email", {
+ message: t("eventRegisterAlreadyResponded", {
+ defaultValue: "This email has already been used to respond",
+ }),
+ });
+ return;
+ }
+
+ if (result.data?.ok) {
+ onSuccess({ name: data.name, email: data.email });
+ }
+ })}
+ >
+ <FormField
+ name="name"
+ render={({ field }) => (
+ <FormItem>
+ <FormLabel>
+ <Trans i18nKey="name" defaults="Name" />
+ </FormLabel>
+ <FormControl>
+ <Input
+ autoFocus
+ disabled={form.formState.isSubmitting}
+ placeholder={t("namePlaceholder", {
+ defaultValue: "Jessie Smith",
+ })}
+ {...field}
+ />
+ </FormControl>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ <FormField
+ name="email"
+ render={({ field }) => (
+ <FormItem>
+ <FormLabel>
+ <Trans i18nKey="email" defaults="Email" />
+ </FormLabel>
+ <FormControl>
+ <Input
+ type="email"
+ disabled={form.formState.isSubmitting}
+ placeholder={t("emailPlaceholder", {
+ defaultValue: "[email protected]",
+ })}
+ {...field}
+ />
+ </FormControl>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ <Button
+ size="lg"
+ variant="primary"
+ type="submit"
+ loading={form.formState.isSubmitting}
+ >
+ <Trans i18nKey="register" defaults="Register" />
+ </Button>
+ </form>
+ </Form>
+ );
+}
diff --git a/apps/web/src/app/[locale]/e/[id]/components/rsvp-area.tsx b/apps/web/src/app/[locale]/e/[id]/components/rsvp-area.tsx
new file mode 100644
index 000000000..85f888ddb
--- /dev/null
+++ b/apps/web/src/app/[locale]/e/[id]/components/rsvp-area.tsx
@@ -0,0 +1,121 @@
+import type { ScheduledEventStatus } from "@rallly/database";
+import { getEventRegistration } from "@/features/scheduled-event/data";
+import {
+ getEventPhase,
+ isEventFull,
+} from "@/features/scheduled-event/registration";
+import { getSession } from "@/lib/auth";
+import { RsvpCancel } from "./rsvp-cancel";
+import { RsvpNotice } from "./rsvp-notice";
+import { RsvpOneClickRegister } from "./rsvp-one-click-register";
+import { RsvpRegister } from "./rsvp-register";
+import { RsvpRegistered } from "./rsvp-registered";
+import { RsvpVerifyEmail } from "./rsvp-verify-email";
+
+function Separator() {
+ return <hr className="border-card-border" />;
+}
+
+/**
+ * Server component that owns the RSVP card's dynamic content. It reads the
+ * session, runs a dedicated query for the viewer's registration, and resolves
+ * the event phase + capacity to decide which sections to render.
+ */
+export async function RSVPArea({
+ eventId,
+ status,
+ start,
+ end,
+ capacity,
+ acceptedCount,
+}: {
+ eventId: string;
+ status: ScheduledEventStatus;
+ start: Date;
+ end: Date;
+ capacity: number | null;
+ acceptedCount: number;
+}) {
+ const session = await getSession();
+ // The invite is tied to a user (real or anonymous), so any session can have
+ // a registration. Only real accounts, though, get the one-click CTA — guests
+ // without a registration are treated as logged out.
+ const user = session?.user ?? null;
+ const realUser = user && !user.isGuest ? user : null;
+
+ const registration = user
+ ? await getEventRegistration({ eventId, userId: user.id })
+ : null;
+
+ const phase = getEventPhase({ status, start, end, now: new Date() });
+
+ // A canceled event overrides everything else.
+ if (phase === "canceled") {
+ return <RsvpNotice variant="canceled" />;
+ }
+
+ // Registered: show the status, layering a notice for started/ended events
+ // and offering cancellation only while the event is still upcoming.
+ if (registration) {
+ const notice =
+ phase === "ended" ? (
+ <RsvpNotice variant="ended" />
+ ) : phase === "inProgress" ? (
+ <RsvpNotice variant="inProgress" />
+ ) : null;
+
+ return (
+ <div className="flex flex-col gap-3">
+ {notice ? (
+ <>
+ {notice}
+ <Separator />
+ </>
+ ) : null}
+ <RsvpRegistered
+ name={registration.inviteeName}
+ email={registration.inviteeEmail}
+ />
+ {phase === "upcoming" && !realUser ? (
+ <>
+ <Separator />
+ <RsvpVerifyEmail
+ email={registration.inviteeEmail}
+ name={registration.inviteeName}
+ />
+ </>
+ ) : null}
+ {phase === "upcoming" ? (
+ <>
+ <Separator />
+ <RsvpCancel inviteUid={registration.uid} />
+ </>
+ ) : null}
+ </div>
+ );
+ }
+
+ // Not registered: surface why registration is unavailable, otherwise the CTA.
+ if (phase === "ended") {
+ return <RsvpNotice variant="ended" />;
+ }
+ if (phase === "inProgress") {
+ return <RsvpNotice variant="inProgress" />;
+ }
+ if (isEventFull({ capacity, acceptedCount })) {
+ return <RsvpNotice variant="full" />;
+ }
+
+ if (realUser) {
+ return (
+ <RsvpOneClickRegister
+ eventId={eventId}
+ name={realUser.name}
+ email={realUser.email}
+ image={realUser.image ?? undefined}
+ />
+ );
+ }
+
+ return <RsvpRegister eventId={eventId} />;
+}
diff --git a/apps/web/src/app/[locale]/e/[id]/components/rsvp-cancel.tsx b/apps/web/src/app/[locale]/e/[id]/components/rsvp-cancel.tsx
new file mode 100644
index 000000000..e511f3960
--- /dev/null
+++ b/apps/web/src/app/[locale]/e/[id]/components/rsvp-cancel.tsx
@@ -0,0 +1,36 @@
+"use client";
+
+import { useRouter } from "next/navigation";
+import { cancelRsvpAction } from "@/features/scheduled-event/actions";
+import { Trans } from "@/i18n/client";
+import { useSafeAction } from "@/lib/safe-action/client";
+
+export function RsvpCancel({ inviteUid }: { inviteUid: string }) {
+ const router = useRouter();
+ const cancelRsvp = useSafeAction(cancelRsvpAction);
+
+ return (
+ <p className="text-muted-foreground text-sm">
+ <Trans
+ i18nKey="rsvpStatusCancelDescription"
+ defaults="Can't make it? <a>Cancel your registration</a>"
+ components={{
+ a: (
+ <button
+ type="button"
+ disabled={cancelRsvp.isExecuting}
+ className="underline hover:text-foreground"
+ onClick={async () => {
+ await cancelRsvp.executeAsync({ inviteUid });
+ // Re-run the server query so the card reflects the
+ // cancellation (a not_found result means it's already gone
+ // server-side, so refreshing is correct either way).
+ router.refresh();
+ }}
+ />
+ ),
+ }}
+ />
+ </p>
+ );
+}
diff --git a/apps/web/src/app/[locale]/e/[id]/components/rsvp-card.tsx b/apps/web/src/app/[locale]/e/[id]/components/rsvp-card.tsx
new file mode 100644
index 000000000..d57187853
--- /dev/null
+++ b/apps/web/src/app/[locale]/e/[id]/components/rsvp-card.tsx
@@ -0,0 +1,41 @@
+import { cn } from "@rallly/ui";
+
+export function RsvpCard({
+ children,
+ className,
+}: {
+ children: React.ReactNode;
+ className?: string;
+}) {
+ return (
+ <div
+ className={cn("rounded-2xl border border-card-border bg-card", className)}
+ >
+ {children}
+ </div>
+ );
+}
+
+export function RsvpCardTitle({
+ children,
+ className,
+}: {
+ children: React.ReactNode;
+ className?: string;
+}) {
+ return (
+ <p className={cn("border-b p-3 font-medium text-sm", className)}>
+ {children}
+ </p>
+ );
+}
+
+export function RsvpCardContent({
+ children,
+ className,
+}: {
+ children: React.ReactNode;
+ className?: string;
+}) {
+ return <div className={cn("grid gap-4 p-3", className)}>{children}</div>;
+}
diff --git a/apps/web/src/app/[locale]/e/[id]/components/rsvp-notice.tsx b/apps/web/src/app/[locale]/e/[id]/components/rsvp-notice.tsx
new file mode 100644
index 000000000..18acce73b
--- /dev/null
+++ b/apps/web/src/app/[locale]/e/[id]/components/rsvp-notice.tsx
@@ -0,0 +1,56 @@
+import { BanIcon, CircleCheckIcon, ClockIcon, UsersIcon } from "lucide-react";
+import { Trans } from "@/i18n/client";
+
+function Notice({
+ icon,
+ children,
+}: {
+ icon: React.ReactNode;
+ children: React.ReactNode;
+}) {
+ return (
+ <div className="flex items-center gap-3">
+ <span className="shrink-0 text-muted-foreground">{icon}</span>
+ <p className="font-medium text-foreground text-sm">{children}</p>
+ </div>
+ );
+}
+
+export function RsvpNotice({
+ variant,
+}: {
+ variant: "canceled" | "ended" | "inProgress" | "full";
+}) {
+ switch (variant) {
+ case "canceled":
+ return (
+ <Notice icon={<BanIcon className="size-5" />}>
+ <Trans
+ i18nKey="rsvpNoticeCanceled"
+ defaults="This event has been canceled"
+ />
+ </Notice>
+ );
+ case "ended":
+ return (
+ <Notice icon={<CircleCheckIcon className="size-5" />}>
+ <Trans i18nKey="rsvpNoticeEnded" defaults="This event has ended" />
+ </Notice>
+ );
+ case "inProgress":
+ return (
+ <Notice icon={<ClockIcon className="size-5" />}>
+ <Trans
+ i18nKey="rsvpNoticeInProgress"
+ defaults="This event is in progress"
+ />
+ </Notice>
+ );
+ case "full":
+ return (
+ <Notice icon={<UsersIcon className="size-5" />}>
+ <Trans i18nKey="rsvpNoticeFull" defaults="This event is full" />
+ </Notice>
+ );
+ }
+}
diff --git a/apps/web/src/app/[locale]/e/[id]/components/rsvp-one-click-register.tsx b/apps/web/src/app/[locale]/e/[id]/components/rsvp-one-click-register.tsx
new file mode 100644
index 000000000..045180f4d
--- /dev/null
+++ b/apps/web/src/app/[locale]/e/[id]/components/rsvp-one-click-register.tsx
@@ -0,0 +1,43 @@
+"use client";
+
+import { Button } from "@rallly/ui/button";
+import { OptimizedAvatarImage } from "@/components/optimized-avatar-image";
+import { registerForEventAction } from "@/features/scheduled-event/actions";
+import { Trans } from "@/i18n/client";
+import { useSafeAction } from "@/lib/safe-action/client";
+
+export function RsvpOneClickRegister({
+ eventId,
+ name,
+ email,
+ image,
+}: {
+ eventId: string;
+ name: string;
+ email: string;
+ image?: string;
+}) {
+ const register = useSafeAction(registerForEventAction);
+
+ return (
+ <div className="flex flex-col gap-3">
+ <div className="flex items-center gap-3">
+ <OptimizedAvatarImage src={image} name={name} size="md" />
+ <div className="min-w-0">
+ <p className="truncate font-medium text-foreground text-sm">{name}</p>
+ <p className="truncate text-muted-foreground text-sm">{email}</p>
+ </div>
+ </div>
+ <Button
+ size="lg"
+ variant="primary"
+ loading={register.isExecuting}
+ onClick={async () => {
+ await register.executeAsync({ eventId });
+ }}
+ >
+ <Trans i18nKey="rsvpOneClickRegister" defaults="One-click register" />
+ </Button>
+ </div>
+ );
+}
diff --git a/apps/web/src/app/[locale]/e/[id]/components/rsvp-register.tsx b/apps/web/src/app/[locale]/e/[id]/components/rsvp-register.tsx
new file mode 100644
index 000000000..8d2c5bb56
--- /dev/null
+++ b/apps/web/src/app/[locale]/e/[id]/components/rsvp-register.tsx
@@ -0,0 +1,25 @@
+"use client";
+
+import { Button } from "@rallly/ui/button";
+import { useDialog } from "@rallly/ui/dialog";
+import { Trans } from "@/i18n/client";
+import { RegistrationDialog } from "./registration-dialog";
+
+export function RsvpRegister({ eventId }: { eventId: string }) {
+ const dialog = useDialog();
+
+ return (
+ <div className="flex flex-col gap-3">
+ <p className="text-muted-foreground text-sm">
+ <Trans
+ i18nKey="rsvpCardDescription"
+ defaults="To join this event, please register below."
+ />
+ </p>
+ <Button size="lg" variant="primary" {...dialog.triggerProps}>
+ <Trans i18nKey="register" defaults="Register" />
+ </Button>
+ <RegistrationDialog eventId={eventId} {...dialog.dialogProps} />
+ </div>
+ );
+}
diff --git a/apps/web/src/app/[locale]/e/[id]/components/rsvp-registered.tsx b/apps/web/src/app/[locale]/e/[id]/components/rsvp-registered.tsx
new file mode 100644
index 000000000..58e19f601
--- /dev/null
+++ b/apps/web/src/app/[locale]/e/[id]/components/rsvp-registered.tsx
@@ -0,0 +1,24 @@
+import { CircleCheckIcon } from "lucide-react";
+import { Trans } from "@/i18n/client";
+
+export function RsvpRegistered({
+ name,
+ email,
+}: {
+ name: string;
+ email: string;
+}) {
+ return (
+ <div className="flex items-center gap-3">
+ <CircleCheckIcon className="size-9 shrink-0 text-green-600" />
+ <div>
+ <p className="font-medium text-foreground text-sm">
+ <Trans i18nKey="rsvpStatusRegistered" defaults="You're going!" />
+ </p>
+ <p className="text-muted-foreground text-sm">
+ {name} · {email}
+ </p>
+ </div>
+ </div>
+ );
+}
diff --git a/apps/web/src/app/[locale]/e/[id]/components/rsvp-verify-email.tsx b/apps/web/src/app/[locale]/e/[id]/components/rsvp-verify-email.tsx
new file mode 100644
index 000000000..92c38704b
--- /dev/null
+++ b/apps/web/src/app/[locale]/e/[id]/components/rsvp-verify-email.tsx
@@ -0,0 +1,163 @@
+"use client";
+
+import { zodResolver } from "@hookform/resolvers/zod";
+import { Button } from "@rallly/ui/button";
+import {
+ Dialog,
+ DialogContent,
+ DialogDescription,
+ DialogHeader,
+ DialogTitle,
+ useDialog,
+} from "@rallly/ui/dialog";
+import {
+ Form,
+ FormControl,
+ FormField,
+ FormItem,
+ FormMessage,
+} from "@rallly/ui/form";
+import { useRouter } from "next/navigation";
+import { useForm } from "react-hook-form";
+import * as z from "zod";
+import { InputOTP } from "@/components/input-otp";
+import { Trans, useTranslation } from "@/i18n/client";
+import { authClient } from "@/lib/auth-client";
+
+const otpSchema = z.object({ otp: z.string().regex(/^\d{6}$/) });
+
+export function RsvpVerifyEmail({
+ email,
+ name,
+}: {
+ email: string;
+ name: string;
+}) {
+ const { t } = useTranslation();
+ const router = useRouter();
+ const dialog = useDialog();
+ const form = useForm({
+ defaultValues: { otp: "" },
+ resolver: zodResolver(otpSchema),
+ });
+
+ const handleSubmit = form.handleSubmit(async (data) => {
+ // Verifying signs the guest in: into their existing account if the email
+ // is already in use, otherwise into a freshly created one. The anonymous
+ // session is linked, migrating their registration to the real account.
+ // `name` is only applied when a new account is created.
+ const res = await authClient.signIn.emailOtp({
+ email,
+ otp: data.otp,
+ name,
+ });
+
+ if (res.error) {
+ switch (res.error.code) {
+ case "INVALID_OTP":
+ form.setError("otp", {
+ message: t("wrongVerificationCode", {
+ defaultValue: "Your verification code is incorrect",
+ }),
+ });
+ return;
+ case "OTP_EXPIRED":
+ form.setError("otp", {
+ message: t("expiredVerificationCode", {
+ defaultValue:
+ "This code has expired. Request a new one to continue.",
+ }),
+ });
+ return;
+ case "TOO_MANY_ATTEMPTS":
+ form.setError("otp", {
+ message: t("tooManyVerificationAttempts", {
+ defaultValue:
+ "Too many incorrect attempts. Request a new code to continue.",
+ }),
+ });
+ return;
+ default:
+ form.setError("otp", {
+ message: t("rsvpVerifyError", {
+ defaultValue: "We couldn't verify your email. Please try again.",
+ }),
+ });
+ return;
+ }
+ }
+
+ // A newly created account may come back without a name; set it from the
+ // registration. Existing accounts keep their own name (we only fill a
+ // missing one). updateUser also refreshes the session so the name shows
+ // immediately.
+ if (!res.data?.user?.name) {
+ await authClient.updateUser({ name });
+ }
+
+ dialog.dismiss();
+ router.refresh();
+ });
+
+ return (
+ <div className="flex flex-col gap-2">
+ <p className="text-muted-foreground text-sm">
+ <Trans
+ i18nKey="rsvpVerifyPrompt"
+ defaults="Verify your email to manage your registration from any device."
+ />
+ </p>
+ <Button
+ className="self-start"
+ onClick={() => {
+ form.reset();
+ dialog.trigger();
+ void authClient.emailOtp.sendVerificationOtp({
+ email,
+ type: "sign-in",
+ });
+ }}
+ >
+ <Trans i18nKey="rsvpVerifyCta" defaults="Verify your email" />
+ </Button>
+ <Dialog {...dialog.dialogProps}>
+ <DialogContent>
+ <DialogHeader>
+ <DialogTitle>
+ <Trans i18nKey="rsvpVerifyTitle" defaults="Verify your email" />
+ </DialogTitle>
+ <DialogDescription>
+ <Trans
+ i18nKey="rsvpVerifyDialogDescription"
+ defaults="Enter the 6-digit code we sent to {email}."
+ values={{ email }}
+ />
+ </DialogDescription>
+ </DialogHeader>
+ <Form {...form}>
+ <form onSubmit={handleSubmit}>
+ <FormField
+ control={form.control}
+ name="otp"
+ render={({ field }) => (
+ <FormItem>
+ <FormControl>
+ <InputOTP
+ autoFocus
+ placeholder={t("verificationCodePlaceholder")}
+ disabled={form.formState.isSubmitting}
+ onValidCode={() => handleSubmit()}
+ {...field}
+ />
+ </FormControl>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ </form>
+ </Form>
+ </DialogContent>
+ </Dialog>
+ </div>
+ );
+}
diff --git a/apps/web/src/app/[locale]/e/[id]/components/space-branding.tsx b/apps/web/src/app/[locale]/e/[id]/components/space-branding.tsx
new file mode 100644
index 000000000..0795f9137
--- /dev/null
+++ b/apps/web/src/app/[locale]/e/[id]/components/space-branding.tsx
@@ -0,0 +1,19 @@
+import { cn } from "@rallly/ui";
+import { SpaceIcon } from "@/features/space/components/space-icon";
+
+export function SpaceBranding({
+ name,
+ image,
+ className,
+}: {
+ name: string;
+ image?: string;
+ className?: string;
+}) {
+ return (
+ <div className={cn("flex flex-col gap-2", className)}>
+ <SpaceIcon name={name} src={image} size="lg" />
+ <p className="font-medium text-muted-foreground text-sm">{name}</p>
+ </div>
+ );
+}
diff --git a/apps/web/src/app/[locale]/e/[id]/components/user-dropdown.tsx b/apps/web/src/app/[locale]/e/[id]/components/user-dropdown.tsx
new file mode 100644
index 000000000..3bbb81186
--- /dev/null
+++ b/apps/web/src/app/[locale]/e/[id]/components/user-dropdown.tsx
@@ -0,0 +1,82 @@
+"use client";
+
+import { cn } from "@rallly/ui";
+import { Button } from "@rallly/ui/button";
+import {
+ DropdownMenu,
+ DropdownMenuContent,
+ DropdownMenuItem,
+ DropdownMenuLabel,
+ DropdownMenuSeparator,
+ DropdownMenuTrigger,
+} from "@rallly/ui/dropdown-menu";
+import { LogOutIcon, Settings2Icon, UserIcon } from "lucide-react";
+import Link from "next/link";
+import { useRouter } from "next/navigation";
+import { OptimizedAvatarImage } from "@/components/optimized-avatar-image";
+import { Trans } from "@/i18n/client";
+import { authClient } from "@/lib/auth-client";
+
+export function UserDropdown({
+ name,
+ email,
+ image,
+ className,
+}: {
+ name: string;
+ email: string;
+ image?: string;
+ className?: string;
+}) {
+ const router = useRouter();
+
+ return (
+ <DropdownMenu modal={false}>
+ <DropdownMenuTrigger asChild className={cn("group min-w-0", className)}>
+ <Button variant="ghost" className="rounded-full" size="icon">
+ <OptimizedAvatarImage src={image} name={name} size="sm" />
+ </Button>
+ </DropdownMenuTrigger>
+ <DropdownMenuContent align="end" className="min-w-48">
+ <DropdownMenuLabel className="flex items-center gap-2">
+ <OptimizedAvatarImage src={image} name={name} size="md" />
+ <div className="grow">
+ <div className="font-medium text-foreground text-sm">{name}</div>
+ {email ? (
+ <div className="font-normal text-muted-foreground text-xs">
+ {email}
+ </div>
+ ) : null}
+ </div>
+ </DropdownMenuLabel>
+ <DropdownMenuSeparator />
+ <DropdownMenuItem asChild>
+ <Link href="/settings/profile" className="flex items-center gap-x-2">
+ <UserIcon className="size-4 text-muted-foreground" />
+ <Trans i18nKey="profile" defaults="Profile" />
+ </Link>
+ </DropdownMenuItem>
+ <DropdownMenuItem asChild>
+ <Link
+ href="/settings/preferences"
+ className="flex items-center gap-x-2"
+ >
+ <Settings2Icon className="size-4 text-muted-foreground" />
+ <Trans i18nKey="preferences" defaults="Preferences" />
+ </Link>
+ </DropdownMenuItem>
+ <DropdownMenuSeparator />
+ <DropdownMenuItem
+ className="flex items-center gap-x-2"
+ onClick={async () => {
+ await authClient.signOut();
+ router.refresh();
+ }}
+ >
+ <LogOutIcon className="size-4 text-muted-foreground" />
+ <Trans i18nKey="logout" defaults="Logout" />
+ </DropdownMenuItem>
+ </DropdownMenuContent>
+ </DropdownMenu>
+ );
+}
diff --git a/apps/web/src/app/[locale]/e/[id]/event-wizard.tsx b/apps/web/src/app/[locale]/e/[id]/event-wizard.tsx
deleted file mode 100644
index 8559ca565..000000000
--- a/apps/web/src/app/[locale]/e/[id]/event-wizard.tsx
+++ /dev/null
@@ -1,322 +0,0 @@
-"use client";
-
-import { zodResolver } from "@hookform/resolvers/zod";
-import { cn } from "@rallly/ui";
-import {
- ActionBar,
- ActionBarButton,
- ActionBarOffset,
-} from "@rallly/ui/action-bar";
-import { Field, FieldError, FieldGroup, FieldLabel } from "@rallly/ui/field";
-import { Input } from "@rallly/ui/input";
-import { CheckIcon, MapPinIcon, VideoIcon, XIcon } from "lucide-react";
-import React from "react";
-import { Controller, useForm } from "react-hook-form";
-import * as z from "zod";
-import TruncatedLinkify from "@/components/poll/truncated-linkify";
-import { ConferencingLink } from "@/features/conferencing/components/conferencing-link";
-import type { Conferencing } from "@/features/conferencing/schema";
-import { submitRsvpAction } from "@/features/scheduled-event/actions";
-import { Trans, useTranslation } from "@/i18n/client";
-import { useSafeAction } from "@/lib/safe-action/client";
-import type { Attendee } from "./attendee-rows";
-import { AttendeeRows } from "./attendee-rows";
-import {
- Section,
- SectionGroup,
- SectionItem,
- SectionItemLabel,
- SectionItemValue,
-} from "./section";
-
-type RsvpStatus = "accepted" | "declined";
-
-export function EventWizard({
- eventId,
- description,
- locationText,
- conferencing,
- attendees,
-}: {
- eventId: string;
- description: string | null;
- locationText: string | null;
- conferencing: Conferencing | null;
- attendees: Attendee[];
-}) {
- const [response, setResponse] = React.useState<RsvpStatus | null>(null);
-
- if (response !== null) {
- return (
- <div className="space-y-6 px-3">
- <RsvpResponseBanner
- response={response}
- onChange={() => setResponse(null)}
- />
- <RsvpForm eventId={eventId} status={response} />
- </div>
- );
- }
-
- return (
- <>
- <EventBody
- description={description}
- locationText={locationText}
- conferencing={conferencing}
- attendees={attendees}
- />
- <ActionBarOffset />
- <RsvpActions onPick={setResponse} />
- </>
- );
-}
-
-function EventBody({
- description,
- locationText,
- conferencing,
- attendees,
-}: {
- description: string | null;
- locationText: string | null;
- conferencing: Conferencing | null;
- attendees: Attendee[];
-}) {
- return (
- <div className="px-3 pb-3">
- <SectionGroup>
- {locationText || conferencing ? (
- <Section>
- {locationText ? (
- <SectionItem>
- <SectionItemLabel>
- <MapPinIcon />
- <Trans i18nKey="location" defaults="Location" />
- </SectionItemLabel>
- <SectionItemValue className="text-foreground">
- {locationText}
- </SectionItemValue>
- </SectionItem>
- ) : null}
- {conferencing ? (
- <SectionItem>
- <SectionItemLabel>
- <VideoIcon />
- <Trans i18nKey="conferencing" defaults="Conferencing" />
- </SectionItemLabel>
- <SectionItemValue className="overflow-hidden">
- <ConferencingLink conferencing={conferencing} />
- </SectionItemValue>
- </SectionItem>
- ) : null}
- </Section>
- ) : null}
-
- {description ? (
- <Section
- title={<Trans i18nKey="description" defaults="Description" />}
- >
- <SectionItem className="py-3">
- <p className="whitespace-pre-wrap text-pretty text-foreground text-sm leading-relaxed">
- <TruncatedLinkify>{description}</TruncatedLinkify>
- </p>
- </SectionItem>
- </Section>
- ) : null}
-
- {attendees.length > 0 ? (
- <Section title={<Trans i18nKey="attendees" defaults="Attendees" />}>
- <SectionItem>
- <SectionItemLabel>
- <Trans i18nKey="invited" defaults="Invited" />
- </SectionItemLabel>
- <SectionItemValue className="tabular-nums">
- {attendees.length}
- </SectionItemValue>
- </SectionItem>
- <AttendeeRows attendees={attendees} />
- </Section>
- ) : null}
- </SectionGroup>
- </div>
- );
-}
-
-function RsvpActions({ onPick }: { onPick: (status: RsvpStatus) => void }) {
- return (
- <ActionBar>
- <ActionBarButton
- variant="default"
- className="flex-1"
- onClick={() => onPick("declined")}
- >
- <XIcon />
- <Trans i18nKey="rsvpDecline" defaults="Decline" />
- </ActionBarButton>
- <ActionBarButton
- variant="primary"
- className="flex-1"
- onClick={() => onPick("accepted")}
- >
- <CheckIcon />
- <Trans i18nKey="attendeeStatusGoing" defaults="Going" />
- </ActionBarButton>
- </ActionBar>
- );
-}
-
-function RsvpResponseBanner({
- response,
- onChange,
-}: {
- response: RsvpStatus;
- onChange: () => void;
-}) {
- const isAccepted = response === "accepted";
- return (
- <div
- className={cn(
- "flex items-center gap-3 rounded-xl border p-3",
- isAccepted
- ? "border-green-400/20 bg-green-400/10 dark:bg-green-950/30"
- : "border-red-400/20 bg-red-400/10 dark:bg-red-950/30",
- )}
- >
- {isAccepted ? (
- <CheckIcon className="size-4 shrink-0 text-green-600 dark:text-green-400" />
- ) : (
- <XIcon className="size-4 shrink-0 text-red-600 dark:text-red-400" />
- )}
- <p className="flex-1 text-foreground text-sm">
- {isAccepted ? (
- <Trans i18nKey="rsvpResponseHeadingGoing" defaults="You're going" />
- ) : (
- <Trans
- i18nKey="rsvpResponseHeadingDeclining"
- defaults="You're declining"
- />
- )}
- </p>
- <button
- type="button"
- onClick={onChange}
- className="font-medium text-muted-foreground text-sm hover:text-foreground hover:underline"
- >
- <Trans i18nKey="rsvpChange" defaults="Change" />
- </button>
- </div>
- );
-}
-
-function useRsvpFormSchema() {
- const { t } = useTranslation();
- return z.object({
- name: z
- .string()
- .trim()
- .min(1, t("nameRequired", { defaultValue: "Please enter your name" })),
- email: z.email(
- t("invalidEmail", {
- defaultValue: "Please enter a valid email address",
- }),
- ),
- });
-}
-
-function RsvpForm({
- eventId,
- status,
-}: {
- eventId: string;
- status: RsvpStatus;
-}) {
- const { t } = useTranslation();
- const schema = useRsvpFormSchema();
- const submitRsvp = useSafeAction(submitRsvpAction);
- const form = useForm({
- resolver: zodResolver(schema),
- defaultValues: {
- name: "",
- email: "",
- },
- });
-
- return (
- <form
- onSubmit={form.handleSubmit(async (data) => {
- const result = await submitRsvp.executeAsync({
- eventId,
- status,
- name: data.name,
- email: data.email,
- });
-
- if (result.data?.ok === false) {
- if (result.data.reason === "already_responded") {
- form.setError("email", {
- message: t("rsvpAlreadyResponded", {
- defaultValue:
- "It looks like you've already responded with this email",
- }),
- });
- }
- }
- })}
- >
- <FieldGroup>
- <Controller
- control={form.control}
- name="name"
- render={({ field, fieldState }) => (
- <Field data-invalid={fieldState.invalid}>
- <FieldLabel htmlFor={field.name}>
- <Trans i18nKey="name" defaults="Name" />
- </FieldLabel>
- <Input
- {...field}
- id={field.name}
- placeholder={t("namePlaceholder")}
- autoFocus={true}
- autoComplete="name"
- disabled={form.formState.isSubmitting}
- aria-invalid={fieldState.invalid}
- />
- {fieldState.invalid && <FieldError errors={[fieldState.error]} />}
- </Field>
- )}
- />
- <Controller
- control={form.control}
- name="email"
- render={({ field, fieldState }) => (
- <Field data-invalid={fieldState.invalid}>
- <FieldLabel htmlFor={field.name}>
- <Trans i18nKey="email" defaults="Email" />
- </FieldLabel>
- <Input
- {...field}
- id={field.name}
- placeholder={t("emailPlaceholder")}
- autoComplete="email"
- disabled={form.formState.isSubmitting}
- aria-invalid={fieldState.invalid}
- />
- {fieldState.invalid && <FieldError errors={[fieldState.error]} />}
- </Field>
- )}
- />
- </FieldGroup>
- <ActionBar>
- <ActionBarButton
- variant="primary"
- className="flex-1"
- type="submit"
- loading={form.formState.isSubmitting}
- >
- <Trans i18nKey="confirmResponse" defaults="Confirm response" />
- </ActionBarButton>
- </ActionBar>
- </form>
- );
-}
diff --git a/apps/web/src/app/[locale]/e/[id]/page.tsx b/apps/web/src/app/[locale]/e/[id]/page.tsx
index b8fe506ad..e32d2c11f 100644
--- a/apps/web/src/app/[locale]/e/[id]/page.tsx
+++ b/apps/web/src/app/[locale]/e/[id]/page.tsx
@@ -1,31 +1,59 @@
import { buttonVariants } from "@rallly/ui";
+import { AvatarGroup, AvatarGroupCount } from "@rallly/ui/avatar";
import { absoluteUrl } from "@rallly/utils/absolute-url";
-import { ArrowLeftIcon } from "lucide-react";
+import { MapPinIcon } from "lucide-react";
import type { Metadata } from "next";
import Link from "next/link";
import { notFound } from "next/navigation";
-import { cache, Suspense } from "react";
-import { getCurrentUser } from "@/auth/data";
+import { cache } from "react";
+import { SpaceBranding } from "@/app/[locale]/e/[id]/components/space-branding";
+import { UserDropdown } from "@/app/[locale]/e/[id]/components/user-dropdown";
+import LogoMarkGray from "@/assets/logo-mark-gray.svg";
+import { OptimizedAvatarImage } from "@/components/optimized-avatar-image";
+import TruncatedLinkify from "@/components/poll/truncated-linkify";
import { BrandingStyle } from "@/features/branding/branding-style";
import { formatLocationText } from "@/features/location/utils";
import { isScheduledEventEnabled } from "@/features/scheduled-event/constants";
import {
createScheduledEventDTO,
- getCachedPublicScheduledEvent,
+ getEventAcceptedCount,
+ getEventAttendeePreview,
+ getPublicScheduledEvent,
} from "@/features/scheduled-event/data";
-import { SpaceIcon } from "@/features/space/components/space-icon";
-import { Trans } from "@/i18n/client";
+import { getSpaceBranding } from "@/features/space/data";
+import { getUserProfile } from "@/features/user/data";
+import { getTranslation } from "@/i18n/server";
+import { getSession } from "@/lib/auth";
+import { dayjs } from "@/lib/dayjs";
+import {
+ CalendarCard,
+ CalendarCardDay,
+ CalendarCardMonth,
+} from "./components/calendar-card";
+import {
+ EventDetail,
+ EventDetailContent,
+ EventDetailDescription,
+ EventDetailIcon,
+ EventDetailTitle,
+} from "./components/event-detail";
import {
- EventDate,
EventHeader,
- EventStatus,
EventSubtitle,
EventTitle,
-} from "./event-header";
-import { EventWizard } from "./event-wizard";
+} from "./components/event-header";
+import { EventSection, EventSectionTitle } from "./components/event-section";
+import { RSVPArea } from "./components/rsvp-area";
+import {
+ RsvpCard,
+ RsvpCardContent,
+ RsvpCardTitle,
+} from "./components/rsvp-card";
+
+const ATTENDEE_PREVIEW_LIMIT = 5;
const getScheduledEvent = cache(async (id: string) => {
- const event = await getCachedPublicScheduledEvent(id);
+ const event = await getPublicScheduledEvent(id);
if (!event || event.deletedAt) {
notFound();
@@ -37,31 +65,6 @@ const getScheduledEvent = cache(async (id: string) => {
};
});
-async function EventsBackLink() {
- const user = await getCurrentUser();
- if (!user) {
- return null;
- }
- return (
- <Link
- href="/events"
- className={buttonVariants({ variant: "ghost", size: "sm" })}
- >
- <ArrowLeftIcon data-icon="inline-start" />
- <Trans i18nKey="events" defaults="Events" />
- </Link>
- );
-}
-
-function SpaceBranding({ name, image }: { name: string; image?: string }) {
- return (
- <div className="mb-4 flex flex-col gap-2 px-4">
- <SpaceIcon name={name} src={image} size="lg" />
- <p className="font-medium text-muted-foreground text-sm">{name}</p>
- </div>
- );
-}
-
export default async function EventPage({
params,
}: {
@@ -72,73 +75,162 @@ export default async function EventPage({
}
const { id } = await params;
const event = await getScheduledEvent(id);
+ const [branding, host, acceptedCount, visibleAttendees] = await Promise.all([
+ getSpaceBranding(event.spaceId),
+ getUserProfile(event.userId),
+ getEventAcceptedCount({ eventId: id }),
+ event.hideAttendees
+ ? Promise.resolve([])
+ : getEventAttendeePreview({ eventId: id, take: ATTENDEE_PREVIEW_LIMIT }),
+ ]);
- const isBranded = event.space.showBranding && !!event.space.image;
+ if (!host) {
+ // The host relation cascades on delete, so a missing host means the
+ // cached event is stale and the event no longer exists.
+ notFound();
+ }
+
+ const isBranded = !!branding?.showBranding && !!branding.image;
const brandingColor =
- event.space.showBranding && event.space.primaryColor
- ? event.space.primaryColor
+ branding?.showBranding && branding.primaryColor
+ ? branding.primaryColor
: null;
- const hasEnded = event.end < new Date();
- const visibleAttendees = event.hideAttendees
- ? []
- : event.invites
- .filter((i) => i.status !== "pending")
- .map((invite) => ({
- id: invite.id,
- name: invite.inviteeName,
- image: invite.user?.image ?? undefined,
- status: invite.status,
- }));
+
+ const session = await getSession();
+ const { t } = await getTranslation();
return (
- <div className="min- flex h-dvh flex-col antialiased dark:bg-gray-900">
+ <div className="page-bg-gray-50 absolute inset-0 h-dvh overflow-auto md:h-dvh md:items-center md:justify-center md:p-5 dark:bg-gray-900">
{brandingColor ? <BrandingStyle primaryColor={brandingColor} /> : null}
-
- <div className="pointer-events-none fixed inset-x-0 top-0 z-40 bg-linear-to-b from-25% from-white to-transparent dark:from-gray-900">
- <div className="pointer-events-auto flex items-center gap-4 px-3 pt-[max(--spacing(3),env(safe-area-inset-top))] pb-12">
- <Suspense fallback={null}>
- <EventsBackLink />
- </Suspense>
- </div>
- </div>
-
- <div className="mx-auto mt-12 w-full max-w-xl flex-1 py-4 sm:py-8">
- {isBranded ? (
- <SpaceBranding
- name={event.space.name}
- image={event.space.image ?? undefined}
- />
- ) : null}
-
- <EventHeader>
- <EventTitle>{event.title}</EventTitle>
- <EventSubtitle>
- <Trans
- i18nKey="eventOrganizedBy"
- defaults="Organized by {name}"
- values={{ name: event.user.name }}
- />
- </EventSubtitle>
- <div className="flex items-center justify-between gap-3">
- <EventDate
- start={event.start}
- end={event.end}
- allDay={event.allDay}
- timezone={event.displayTimeZone}
+ <header className="fixed top-0 right-0 left-0 z-10 flex justify-between p-4">
+ <Link href="/">
+ <LogoMarkGray className="size-8 text-muted-foreground" />
+ </Link>
+ <div className="flex items-center gap-2">
+ {session?.user.isGuest === false ? (
+ <UserDropdown
+ name={session.user.name}
+ email={session.user.email}
+ image={session.user.image ?? undefined}
/>
- <EventStatus status={event.status} hasEnded={hasEnded} />
- </div>
- </EventHeader>
-
- <EventWizard
- eventId={event.id}
- description={event.description}
- locationText={
- event.location ? formatLocationText(event.location) : null
- }
- conferencing={event.conferencing}
- attendees={visibleAttendees}
- />
+ ) : (
+ <Link
+ href="/login"
+ className={buttonVariants({ variant: "ghost", size: "sm" })}
+ >
+ {t("signIn", { defaultValue: "Sign in" })}
+ </Link>
+ )}
+ </div>
+ </header>
+ <div className="mx-auto max-w-lg pt-16">
+ <div className="flex flex-col justify-between gap-6 p-4">
+ <EventHeader>
+ {isBranded && branding ? (
+ <SpaceBranding
+ className="mb-4"
+ name={branding.name}
+ image={branding.image ?? undefined}
+ />
+ ) : null}
+ <EventTitle>{event.title}</EventTitle>
+ <EventSubtitle className="flex items-center gap-2">
+ <OptimizedAvatarImage
+ name={host.name}
+ src={host.image ?? undefined}
+ size="sm"
+ />
+ {t("eventPageHostedBy", {
+ defaultValue: "Hosted by {name}",
+ name: host.name,
+ })}
+ </EventSubtitle>
+ <div className="mt-4 grid gap-4">
+ <EventDetail>
+ <CalendarCard>
+ <CalendarCardMonth>
+ {dayjs(event.start).format("MMM")}
+ </CalendarCardMonth>
+ <CalendarCardDay>
+ {dayjs(event.start).format("D")}
+ </CalendarCardDay>
+ </CalendarCard>
+ <EventDetailContent>
+ <EventDetailTitle>
+ {dayjs(event.start).format("dddd, D MMMM")}
+ </EventDetailTitle>
+ <EventDetailDescription>
+ {dayjs(event.start).format("LT")} -{" "}
+ {dayjs(event.end).format("LT z")}
+ </EventDetailDescription>
+ </EventDetailContent>
+ </EventDetail>
+ {event.location ? (
+ <EventDetail>
+ <EventDetailIcon>
+ <MapPinIcon />
+ </EventDetailIcon>
+ <EventDetailContent>
+ <EventDetailTitle>
+ {formatLocationText(event.location)}
+ </EventDetailTitle>
+ </EventDetailContent>
+ </EventDetail>
+ ) : null}
+ </div>
+ </EventHeader>
+ <RsvpCard>
+ <RsvpCardTitle>
+ {t("rsvpCardTitle", { defaultValue: "Registration" })}
+ </RsvpCardTitle>
+ <RsvpCardContent>
+ <RSVPArea
+ eventId={event.id}
+ status={event.status}
+ start={event.start}
+ end={event.end}
+ capacity={event.capacity}
+ acceptedCount={acceptedCount}
+ />
+ </RsvpCardContent>
+ </RsvpCard>
+ {event.description ? (
+ <EventSection>
+ <EventSectionTitle>
+ {t("eventPageAbout", { defaultValue: "About" })}
+ </EventSectionTitle>
+ <p className="whitespace-pre-wrap text-pretty text-foreground text-sm leading-relaxed">
+ <TruncatedLinkify>{event.description}</TruncatedLinkify>
+ </p>
+ </EventSection>
+ ) : null}
+ {visibleAttendees.length > 0 ? (
+ <EventSection>
+ <EventSectionTitle>
+ {t("eventPageGoingCount", {
+ defaultValue:
+ "{count, plural, one {# going} other {# going}}",
+ count: acceptedCount,
+ })}
+ </EventSectionTitle>
+ <AvatarGroup>
+ {visibleAttendees.map((attendee) => (
+ <OptimizedAvatarImage
+ key={attendee.id}
+ name={attendee.name}
+ src={attendee.image}
+ size="md"
+ />
+ ))}
+ {acceptedCount > visibleAttendees.length ? (
+ <AvatarGroupCount>
+ +{acceptedCount - visibleAttendees.length}
+ </AvatarGroupCount>
+ ) : null}
+ </AvatarGroup>
+ </EventSection>
+ ) : null}
+ </div>
</div>
</div>
);
diff --git a/apps/web/src/app/[locale]/e/[id]/section.tsx b/apps/web/src/app/[locale]/e/[id]/section.tsx
deleted file mode 100644
index b54ae623c..000000000
--- a/apps/web/src/app/[locale]/e/[id]/section.tsx
+++ /dev/null
@@ -1,93 +0,0 @@
-import { cn } from "@rallly/ui";
-
-export function SectionGroup({
- children,
- className,
-}: {
- children: React.ReactNode;
- className?: string;
-}) {
- return <div className={cn("space-y-6", className)}>{children}</div>;
-}
-
-export function Section({
- children,
- title,
- className,
-}: {
- children: React.ReactNode;
- title?: React.ReactNode;
- className?: string;
-}) {
- return (
- <section className="space-y-2">
- {title ? (
- <h2 className="px-4 font-medium text-muted-foreground text-xs uppercase tracking-wide">
- {title}
- </h2>
- ) : null}
- <div
- className={cn(
- "divide-y divide-gray-950/5 overflow-hidden rounded-2xl bg-gray-100 dark:divide-foreground/5 dark:bg-foreground/5",
- className,
- )}
- >
- {children}
- </div>
- </section>
- );
-}
-
-export function SectionItem({
- children,
- className,
-}: {
- children: React.ReactNode;
- className?: string;
-}) {
- return (
- <div
- className={cn("flex min-h-12 items-center gap-3 px-4 py-2.5", className)}
- >
- {children}
- </div>
- );
-}
-
-export function SectionItemLabel({
- children,
- className,
-}: {
- children: React.ReactNode;
- className?: string;
-}) {
- return (
- <div
- className={cn(
- "flex min-w-0 items-center gap-2.5 font-medium text-foreground text-sm [&>svg]:size-4 [&>svg]:shrink-0 [&>svg]:text-muted-foreground",
- className,
- )}
- >
- {children}
- </div>
- );
-}
-
-export function SectionItemValue({
- children,
- className,
-}: {
- children: React.ReactNode;
- className?: string;
-}) {
- return (
- <div
- className={cn(
- "ml-auto min-w-0 truncate text-right text-muted-foreground text-sm",
- className,
- )}
- >
- {children}
- </div>
- );
-}
diff --git a/apps/web/src/assets/logo-mark-gray.svg b/apps/web/src/assets/logo-mark-gray.svg
new file mode 100644
index 000000000..c615a6765
--- /dev/null
+++ b/apps/web/src/assets/logo-mark-gray.svg
@@ -0,0 +1,3 @@
+<svg width="30" height="30" viewBox="0 0 30 30" fill="none" xmlns="http://www.w3.org/2000/svg">
+<path fill-rule="evenodd" clip-rule="evenodd" d="M4.26056 2C3.01256 2 2 3.01111 2 4.26056V25.7394C2 26.9874 3.01111 28 4.26056 28H25.7394C26.9874 28 28 26.9889 28 25.7394V4.26056C28 3.01256 26.9889 2 25.7394 2H4.26056ZM25.6369 7.90778H4.36311V25.6369H25.6369V7.90778ZM22.3479 5.39156C22.3533 5.54339 22.3281 5.69475 22.2737 5.83662C22.2194 5.97849 22.137 6.10796 22.0315 6.21729C21.926 6.32662 21.7996 6.41358 21.6597 6.47297C21.5199 6.53236 21.3695 6.56297 21.2176 6.56297C21.0657 6.56297 20.9153 6.53236 20.7755 6.47297C20.6356 6.41358 20.5092 6.32662 20.4037 6.21729C20.2982 6.10796 20.2158 5.97849 20.1615 5.83662C20.1071 5.69475 20.0819 5.54339 20.0873 5.39156C20.0978 5.09878 20.2215 4.82149 20.4323 4.61807C20.6431 4.41465 20.9246 4.30097 21.2176 4.30097C21.5106 4.30097 21.7921 4.41465 22.0029 4.61807C22.2138 4.82149 22.3374 5.09878 22.3479 5.39156ZM7.65211 6.52111C7.80394 6.52654 7.95531 6.50132 8.09718 6.44697C8.23905 6.39261 8.36851 6.31023 8.47784 6.20473C8.58717 6.09924 8.67413 5.9728 8.73352 5.83297C8.79291 5.69313 8.82352 5.54276 8.82352 5.39083C8.82352 5.23891 8.79291 5.08854 8.73352 4.9487C8.67413 4.80886 8.58717 4.68242 8.47784 4.57693C8.36851 4.47144 8.23905 4.38906 8.09718 4.3347C7.95531 4.28034 7.80394 4.25513 7.65211 4.26056C7.35934 4.27102 7.08204 4.39469 6.87862 4.60551C6.6752 4.81634 6.56152 5.09787 6.56152 5.39083C6.56152 5.6838 6.6752 5.96533 6.87862 6.17615C7.08204 6.38698 7.35934 6.51064 7.65211 6.52111ZM9.18322 17.0944C9.13077 17.042 9.08916 16.9797 9.06077 16.9112C9.03238 16.8427 9.01777 16.7692 9.01777 16.6951C9.01777 16.6209 9.03238 16.5474 9.06077 16.4789C9.08916 16.4104 9.13077 16.3481 9.18322 16.2957L9.982 15.4969C10.0344 15.4444 10.0967 15.4028 10.1652 15.3744C10.2338 15.346 10.3072 15.3314 10.3814 15.3314C10.4556 15.3314 10.529 15.346 10.5975 15.3744C10.6661 15.4028 10.7283 15.4444 10.7808 15.4969L13.6321 18.3468L19.8736 12.1053C19.926 12.0529 19.9883 12.0113 20.0568 11.9829C20.1253 11.9545 20.1988 11.9399 20.2729 11.9399C20.3471 11.9399 20.4206 11.9545 20.4891 11.9829C20.5576 12.0113 20.6199 12.0529 20.6723 12.1053L21.4726 12.9041C21.6936 13.1251 21.6936 13.4833 21.4726 13.7043L14.0351 21.1389C13.9827 21.1913 13.9204 21.233 13.8519 21.2613C13.7833 21.2897 13.7099 21.3043 13.6357 21.3043C13.5615 21.3043 13.4881 21.2897 13.4196 21.2613C13.351 21.233 13.2888 21.1913 13.2363 21.1389L9.18322 17.0944Z" fill="currentColor"/>
+</svg>
diff --git a/apps/web/src/auth/helpers/merge-user.ts b/apps/web/src/auth/helpers/merge-user.ts
index 829bc0e85..a9799b04c 100644
--- a/apps/web/src/auth/helpers/merge-user.ts
+++ b/apps/web/src/auth/helpers/merge-user.ts
@@ -25,50 +25,77 @@ export const linkAnonymousUser = async (
authenticatedUserId: string,
anonymousUserId: string,
) => {
- const spaceId = await getActiveSpaceForUser({ userId: authenticatedUserId });
-
- if (!spaceId) {
- logger.error({ userId: authenticatedUserId }, "User has no active space");
- return;
- }
-
try {
- await prisma.$transaction(async (tx) => {
- // Transfer all data from anonymous user to authenticated user
- await Promise.all([
- // Transfer polls
- tx.poll.updateMany({
- where: {
- userId: anonymousUserId,
- },
- data: {
- userId: authenticatedUserId,
- spaceId,
- },
- }),
+ // Claim event registrations made with the account's own email. A
+ // registration's email is its identity (the host's record), so it must
+ // not be reassigned to an account that doesn't control that address —
+ // only the ones whose email matches follow the user. This is scoped
+ // independently of the space because a freshly created account may not
+ // have its space provisioned yet.
+ const authenticatedUser = await prisma.user.findUnique({
+ where: { id: authenticatedUserId },
+ select: { email: true },
+ });
- // Transfer participants
- tx.participant.updateMany({
- where: {
- userId: anonymousUserId,
- },
- data: {
- userId: authenticatedUserId,
- },
- }),
+ if (authenticatedUser?.email) {
+ await prisma.scheduledEventInvite.updateMany({
+ where: {
+ inviteeId: anonymousUserId,
+ inviteeEmail: authenticatedUser.email,
+ },
+ data: {
+ inviteeId: authenticatedUserId,
+ },
+ });
+ }
- // Transfer comments
- tx.comment.updateMany({
- where: {
- userId: anonymousUserId,
- },
- data: {
- userId: authenticatedUserId,
- },
- }),
- ]);
+ const spaceId = await getActiveSpaceForUser({
+ userId: authenticatedUserId,
});
+ if (spaceId) {
+ await prisma.$transaction(async (tx) => {
+ // Transfer space-scoped data from anonymous user to authenticated user
+ await Promise.all([
+ // Transfer polls
+ tx.poll.updateMany({
+ where: {
+ userId: anonymousUserId,
+ },
+ data: {
+ userId: authenticatedUserId,
+ spaceId,
+ },
+ }),
+
+ // Transfer participants
+ tx.participant.updateMany({
+ where: {
+ userId: anonymousUserId,
+ },
+ data: {
+ userId: authenticatedUserId,
+ },
+ }),
+
+ // Transfer comments
+ tx.comment.updateMany({
+ where: {
+ userId: anonymousUserId,
+ },
+ data: {
+ userId: authenticatedUserId,
+ },
+ }),
+ ]);
+ });
+ } else {
+ logger.error(
+ { userId: authenticatedUserId },
+ "User has no active space; skipped poll/participant/comment migration",
+ );
+ }
+
// Merge user identities in PostHog
posthog()?.capture({
distinctId: authenticatedUserId,
diff --git a/apps/web/src/features/scheduled-event/actions.ts b/apps/web/src/features/scheduled-event/actions.ts
index e48cbd30c..774a45127 100644
--- a/apps/web/src/features/scheduled-event/actions.ts
+++ b/apps/web/src/features/scheduled-event/actions.ts
@@ -1,12 +1,49 @@
"use server";
-import { prisma } from "@rallly/database";
-import { nanoid } from "@rallly/utils/nanoid";
-import { updateTag } from "next/cache";
+import { headers } from "next/headers";
import * as z from "zod";
-import { scheduledEventTag } from "@/features/scheduled-event/constants";
+import {
+ getEventAcceptedCount,
+ getPublicScheduledEvent,
+} from "@/features/scheduled-event/data";
+import { cancelRsvp, createRsvp } from "@/features/scheduled-event/mutations";
+import {
+ getEventPhase,
+ isEventFull,
+} from "@/features/scheduled-event/registration";
+import { authLib, getSession } from "@/lib/auth";
import { AppError } from "@/lib/errors";
-import { actionClient } from "@/lib/safe-action/server";
+import { actionClient, authActionClient } from "@/lib/safe-action/server";
+
+// Re-validates the registration gate server-side — never trust that the client
+// only offered registration when the event was actually open.
+async function assertRegistrationOpen(eventId: string) {
+ const event = await getPublicScheduledEvent(eventId);
+
+ if (!event || event.deletedAt) {
+ throw new AppError({ code: "NOT_FOUND", message: "Event not found" });
+ }
+
+ const phase = getEventPhase({
+ status: event.status,
+ start: event.start,
+ end: event.end,
+ now: new Date(),
+ });
+
+ if (phase !== "upcoming") {
+ throw new AppError({
+ code: "FORBIDDEN",
+ message: "Registration is closed for this event",
+ });
+ }
+
+ const acceptedCount = await getEventAcceptedCount({ eventId });
+
+ if (isEventFull({ capacity: event.capacity, acceptedCount })) {
+ throw new AppError({ code: "FORBIDDEN", message: "Event is full" });
+ }
+}
export const submitRsvpAction = actionClient
.metadata({ actionName: "submit_rsvp" })
@@ -21,38 +58,51 @@ export const submitRsvpAction = actionClient
.action(async ({ parsedInput }) => {
const { eventId, name, email, status } = parsedInput;
- const event = await prisma.scheduledEvent.findUnique({
- where: { id: eventId },
- select: { id: true, deletedAt: true },
- });
+ await assertRegistrationOpen(eventId);
- if (!event || event.deletedAt) {
- throw new AppError({
- code: "NOT_FOUND",
- message: "Event not found",
+ // Tie the registration to a session so guests can manage it (e.g. cancel)
+ // without an account. Reuse an existing session — anonymous or real —
+ // otherwise create a fresh anonymous one.
+ const session = await getSession();
+ let inviteeId: string;
+ if (session?.user) {
+ inviteeId = session.user.id;
+ } else {
+ const { user } = await authLib.api.signInAnonymous({
+ headers: await headers(),
});
+ inviteeId = user.id;
}
- const existing = await prisma.scheduledEventInvite.findFirst({
- where: { scheduledEventId: eventId, inviteeEmail: email },
- select: { id: true },
- });
+ return await createRsvp({ eventId, name, email, status, inviteeId });
+ });
- if (existing) {
- return { ok: false, reason: "already_responded" } as const;
- }
+export const registerForEventAction = authActionClient
+ .metadata({ actionName: "register_for_event" })
+ .inputSchema(z.object({ eventId: z.string() }))
+ .action(async ({ ctx, parsedInput }) => {
+ const { eventId } = parsedInput;
- await prisma.scheduledEventInvite.create({
- data: {
- uid: nanoid(),
- scheduledEventId: eventId,
- inviteeName: name,
- inviteeEmail: email,
- status,
- },
- });
+ await assertRegistrationOpen(eventId);
- updateTag(scheduledEventTag(eventId));
+ return await createRsvp({
+ eventId,
+ name: ctx.user.name,
+ email: ctx.user.email,
+ status: "accepted",
+ inviteeId: ctx.user.id,
+ });
+ });
- return { ok: true } as const;
+export const cancelRsvpAction = actionClient
+ .metadata({ actionName: "cancel_rsvp" })
+ .inputSchema(
+ z.object({
+ // The invite uid is an unguessable token that acts as proof of
+ // ownership, so the registrant can cancel without re-authenticating.
+ inviteUid: z.string().min(1).max(255),
+ }),
+ )
+ .action(async ({ parsedInput }) => {
+ return await cancelRsvp({ inviteUid: parsedInput.inviteUid });
});
diff --git a/apps/web/src/features/scheduled-event/data.ts b/apps/web/src/features/scheduled-event/data.ts
index b1e62fdbd..115f9ea6c 100644
--- a/apps/web/src/features/scheduled-event/data.ts
+++ b/apps/web/src/features/scheduled-event/data.ts
@@ -1,63 +1,93 @@
import type { Prisma, ScheduledEventStatus } from "@rallly/database";
import { prisma } from "@rallly/database";
-import { unstable_cache } from "next/cache";
import { parseConferencing } from "@/features/conferencing/data";
import type { Conferencing } from "@/features/conferencing/schema";
import { parseLocation } from "@/features/location/data";
import type { Location } from "@/features/location/schema";
import { dayjs } from "@/lib/dayjs";
-import { scheduledEventTag } from "./constants";
import type { Status } from "./schema";
-export function getCachedPublicScheduledEvent(id: string) {
- return unstable_cache(
- async () => {
- return prisma.scheduledEvent.findUnique({
- where: { id },
- select: {
- id: true,
- title: true,
- description: true,
- location: true,
- conferencing: true,
- start: true,
- end: true,
- allDay: true,
- timeZone: true,
- status: true,
- deletedAt: true,
- hideAttendees: true,
- user: {
- select: {
- name: true,
- },
- },
- space: {
- select: {
- name: true,
- image: true,
- showBranding: true,
- primaryColor: true,
- },
- },
- invites: {
- select: {
- id: true,
- inviteeName: true,
- status: true,
- user: {
- select: {
- image: true,
- },
- },
- },
- },
- },
- });
+export function getPublicScheduledEvent(id: string) {
+ return prisma.scheduledEvent.findUnique({
+ where: { id },
+ select: {
+ id: true,
+ title: true,
+ description: true,
+ location: true,
+ conferencing: true,
+ start: true,
+ end: true,
+ allDay: true,
+ timeZone: true,
+ status: true,
+ deletedAt: true,
+ capacity: true,
+ hideAttendees: true,
+ userId: true,
+ spaceId: true,
+ },
+ });
+}
+
+// Live count of accepted registrations. Kept separate from the event read so
+// the (stable) event can be cached while this churns on every RSVP, and so the
+// capacity gate always sees a fresh count.
+export function getEventAcceptedCount({ eventId }: { eventId: string }) {
+ return prisma.scheduledEventInvite.count({
+ where: { scheduledEventId: eventId, status: "accepted" },
+ });
+}
+
+// A capped slice of accepted attendees for the avatar preview — never the full
+// list, which is unbounded. Pair with getEventAcceptedCount for the total.
+export async function getEventAttendeePreview({
+ eventId,
+ take,
+}: {
+ eventId: string;
+ take: number;
+}) {
+ const invites = await prisma.scheduledEventInvite.findMany({
+ where: { scheduledEventId: eventId, status: "accepted" },
+ select: {
+ id: true,
+ inviteeName: true,
+ user: { select: { image: true } },
},
- [`public-scheduled-event-${id}`],
- { tags: [scheduledEventTag(id)] },
- )();
+ orderBy: { createdAt: "asc" },
+ take,
+ });
+
+ return invites.map((invite) => ({
+ id: invite.id,
+ name: invite.inviteeName,
+ image: invite.user?.image ?? undefined,
+ }));
+}
+
+// Looks up the current user's registration for an event, keyed by the user
+// (real or anonymous) the invite is tied to. Returns the invite the public
+// event page needs to render the "you're going" state, or null.
+export function getEventRegistration({
+ eventId,
+ userId,
+}: {
+ eventId: string;
+ userId: string;
+}) {
+ return prisma.scheduledEventInvite.findFirst({
+ where: {
+ scheduledEventId: eventId,
+ inviteeId: userId,
+ status: { not: "pending" },
+ },
+ select: {
+ uid: true,
+ inviteeName: true,
+ inviteeEmail: true,
+ },
+ });
}
// Legacy fallback used when neither location nor conferencing is populated.
diff --git a/apps/web/src/features/scheduled-event/mutations.ts b/apps/web/src/features/scheduled-event/mutations.ts
new file mode 100644
index 000000000..58c65eb99
--- /dev/null
+++ b/apps/web/src/features/scheduled-event/mutations.ts
@@ -0,0 +1,62 @@
+import type { ScheduledEventInviteStatus } from "@rallly/database";
+import { prisma } from "@rallly/database";
+import { nanoid } from "@rallly/utils/nanoid";
+import { updateTag } from "next/cache";
+import { scheduledEventTag } from "@/features/scheduled-event/constants";
+
+export async function createRsvp({
+ eventId,
+ name,
+ email,
+ status,
+ inviteeId,
+}: {
+ eventId: string;
+ name: string;
+ email: string;
+ status: Extract<ScheduledEventInviteStatus, "accepted" | "declined">;
+ // Links the registration to a user account when the registrant is logged in.
+ inviteeId?: string;
+}) {
+ const existing = await prisma.scheduledEventInvite.findFirst({
+ where: { scheduledEventId: eventId, inviteeEmail: email },
+ select: { id: true },
+ });
+
+ if (existing) {
+ return { ok: false, reason: "already_responded" } as const;
+ }
+
+ const invite = await prisma.scheduledEventInvite.create({
+ data: {
+ uid: nanoid(),
+ scheduledEventId: eventId,
+ inviteeName: name,
+ inviteeEmail: email,
+ inviteeId,
+ status,
+ },
+ select: { uid: true },
+ });
+
+ updateTag(scheduledEventTag(eventId));
+
+ return { ok: true, inviteUid: invite.uid } as const;
+}
+
+export async function cancelRsvp({ inviteUid }: { inviteUid: string }) {
+ const invite = await prisma.scheduledEventInvite.findUnique({
+ where: { uid: inviteUid },
+ select: { id: true, scheduledEventId: true },
+ });
+
+ if (!invite) {
+ return { ok: false, reason: "not_found" } as const;
+ }
+
+ await prisma.scheduledEventInvite.delete({ where: { id: invite.id } });
+
+ updateTag(scheduledEventTag(invite.scheduledEventId));
+
+ return { ok: true } as const;
+}
diff --git a/apps/web/src/features/scheduled-event/registration.ts b/apps/web/src/features/scheduled-event/registration.ts
new file mode 100644
index 000000000..f17116790
--- /dev/null
+++ b/apps/web/src/features/scheduled-event/registration.ts
@@ -0,0 +1,40 @@
+import type { ScheduledEventStatus } from "@rallly/database";
+
+export type EventPhase = "canceled" | "ended" | "inProgress" | "upcoming";
+
+/**
+ * Resolves the registration-relevant phase of an event. Registration is only
+ * open while the event is "upcoming"; every other phase blocks it.
+ */
+export function getEventPhase({
+ status,
+ start,
+ end,
+ now,
+}: {
+ status: ScheduledEventStatus;
+ start: Date;
+ end: Date;
+ now: Date;
+}): EventPhase {
+ if (status === "canceled") {
+ return "canceled";
+ }
+ if (now > end) {
+ return "ended";
+ }
+ if (now >= start) {
+ return "inProgress";
+ }
+ return "upcoming";
+}
+
+export function isEventFull({
+ capacity,
+ acceptedCount,
+}: {
+ capacity: number | null;
+ acceptedCount: number;
+}) {
+ return capacity !== null && acceptedCount >= capacity;
+}
diff --git a/apps/web/src/features/space/data.ts b/apps/web/src/features/space/data.ts
index 7b455dc92..ae5211460 100644
--- a/apps/web/src/features/space/data.ts
+++ b/apps/web/src/features/space/data.ts
@@ -97,6 +97,18 @@ export const getMember = async (id: string) => {
return createMemberDTO(member);
};
+export function getSpaceBranding(spaceId: string) {
+ return prisma.space.findUnique({
+ where: { id: spaceId },
+ select: {
+ name: true,
+ image: true,
+ showBranding: true,
+ primaryColor: true,
+ },
+ });
+}
+
export const getActiveSpaceForUser = async (userId: string) => {
const spaceMember = await prisma.spaceMember.findFirst({
where: {
diff --git a/apps/web/src/features/user/data.ts b/apps/web/src/features/user/data.ts
index 0a014d4f4..14479b9e6 100644
--- a/apps/web/src/features/user/data.ts
+++ b/apps/web/src/features/user/data.ts
@@ -51,6 +51,16 @@ export const getUser = async (id: string) => {
return createUserDTO(user);
};
+export function getUserProfile(userId: string) {
+ return prisma.user.findUnique({
+ where: { id: userId },
+ select: {
+ name: true,
+ image: true,
+ },
+ });
+}
+
export const getUserSession = async () => {
const session = await getSession();
diff --git a/apps/web/src/lib/auth.ts b/apps/web/src/lib/auth.ts
index 3d5241a9c..52e758327 100644
--- a/apps/web/src/lib/auth.ts
+++ b/apps/web/src/lib/auth.ts
@@ -150,7 +150,11 @@ export const authLib = betterAuth({
storeInDatabase: true,
}),
emailOTP({
- disableSignUp: true,
+ // Sign-up via OTP is allowed so that registering for an event can either
+ // log a guest into their existing account or create one for a new email.
+ // The login page is unaffected: it sends "email-verification" OTPs and
+ // verifies with verifyEmail, neither of which is gated by this flag.
+ disableSignUp: false,
expiresIn: 15 * 60,
resendStrategy: "reuse",
overrideDefaultEmailVerification: true,