Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/app/e/[code]/g/[token]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ import { notFound } from "next/navigation";
import { CancelledEventNotice } from "@/components/CancelledEventNotice";
import { EventUnavailable } from "@/components/EventUnavailable";
import { RsvpForm } from "@/components/RsvpForm";
import { UpdatedDetailsNotice } from "@/components/UpdatedDetailsNotice";
import { getDb } from "@/db/client";
import type { RsvpStatus } from "@/domain/headcount";
import { coverFor } from "@/lib/cover";
import { eventState } from "@/lib/event-state";
import { formatWhen } from "@/lib/format";
import { relativeDateLabel } from "@/lib/relative-date";
import { NotFoundError } from "@/services/errors";
import { getGuestByToken, getPublicEvent } from "@/services/rsvp";
import { updateGuestRsvp } from "../../actions";
Expand Down Expand Up @@ -47,6 +50,19 @@ export default async function GuestEditPage({ params }: PageProps<"/e/[code]/g/[
if (state === "deleted") return <EventUnavailable hostName={event.hostName} />;
const cancelled = state === "cancelled";

// A returning guest only needs the notice if the move happened after they
// answered; cancellation has its own banner.
const now = new Date();
const changedAt = cancelled ? null : event.detailsChangedAt;
const updated =
changedAt && changedAt.getTime() > guest.createdAt.getTime()
? {
relative: relativeDateLabel(changedAt, now, event.timezone),
when: formatWhen(event.startsAt, "", event.timezone),
location: event.location,
}
: null;

const personalNote = (
<p className="px-2 text-xs text-ink-muted">
This is your personal link — don&apos;t share it.{" "}
Expand All @@ -69,6 +85,7 @@ export default async function GuestEditPage({ params }: PageProps<"/e/[code]/g/[
when: formatWhen(event.startsAt, event.location, event.timezone),
hostName: event.hostName,
goingCount: event.goingCount,
cover: coverFor(event),
}}
initial={guest}
action={updateGuestRsvp.bind(null, code, token)}
Expand All @@ -88,6 +105,7 @@ export default async function GuestEditPage({ params }: PageProps<"/e/[code]/g/[
</span>
</div>
)}
{updated ? <UpdatedDetailsNotice {...updated} /> : null}
{personalNote}
</div>
}
Expand Down
24 changes: 23 additions & 1 deletion src/app/e/[code]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ import { notFound, redirect } from "next/navigation";
import { CancelledEventNotice } from "@/components/CancelledEventNotice";
import { EventUnavailable } from "@/components/EventUnavailable";
import { RsvpForm } from "@/components/RsvpForm";
import { UpdatedDetailsNotice } from "@/components/UpdatedDetailsNotice";
import { getDb } from "@/db/client";
import { coverFor } from "@/lib/cover";
import { eventState } from "@/lib/event-state";
import { formatWhen } from "@/lib/format";
import { guestCookieName } from "@/lib/guest-cookie";
import { eventPreview, wantsBlankForm } from "@/lib/guest-page";
import { calendarDetails, googleCalendarUrl } from "@/lib/ics";
import { changedRecently, relativeDateLabel } from "@/lib/relative-date";
import { getBaseUrl, shareUrl } from "@/server/base-url";
import { NotFoundError } from "@/services/errors";
import { getGuestByToken, getPublicEvent } from "@/services/rsvp";
Expand Down Expand Up @@ -47,6 +50,18 @@ export default async function GuestPage({ params, searchParams }: PageProps<"/e/
if (state === "deleted") return <EventUnavailable hostName={event.hostName} />;
const cancelled = state === "cancelled";

// Anonymous visitors have no RSVP date to compare with, so a recent move
// shows for two weeks. Cancelled events keep the cancellation banner instead.
const now = new Date();
const changedAt = cancelled ? null : event.detailsChangedAt;
const updated = changedAt && changedRecently(changedAt, now)
? {
relative: relativeDateLabel(changedAt, now, event.timezone),
when: formatWhen(event.startsAt, "", event.timezone),
location: event.location,
}
: null;

// A returning guest goes straight to their edit page. A missing, invalid or
// stale cookie is ignored. `?new=1` ("Not you?") skips this and shows a blank form.
const token = blank ? undefined : (await cookies()).get(guestCookieName(code))?.value;
Expand Down Expand Up @@ -77,10 +92,17 @@ export default async function GuestPage({ params, searchParams }: PageProps<"/e/
when: formatWhen(event.startsAt, event.location, event.timezone),
hostName: event.hostName,
goingCount: event.goingCount,
cover: coverFor(event),
}}
action={submitGuestRsvp.bind(null, code)}
readOnly={cancelled}
notice={cancelled ? <CancelledEventNotice hostName={event.hostName} /> : undefined}
notice={
cancelled ? (
<CancelledEventNotice hostName={event.hostName} />
) : updated ? (
<UpdatedDetailsNotice {...updated} />
) : undefined
}
/>

{cancelled ? null : (
Expand Down
20 changes: 17 additions & 3 deletions src/app/host/events/[id]/edit/actions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,29 @@ function form(over: Record<string, string> = {}) {

describe("updateEventAction", () => {
it("saves and redirects back to the Guests tab", async () => {
await expect(updateEventAction(eventId, { error: null }, form())).rejects.toThrow(
// Same time, zone and place: a title-only edit sends no change alert.
const titleOnly = form({
title: "Cookout 2",
startsAt: "2026-07-04T18:00",
location: "Backyard",
timezone: "UTC",
});
await expect(updateEventAction(eventId, { error: null }, titleOnly)).rejects.toThrow(
`NEXT_REDIRECT:/host/events/${eventId}`,
);
expect(await getHostEvent(db, "host-1", eventId)).toMatchObject({
title: "Burger Night",
location: "The patio",
title: "Cookout 2",
location: "Backyard",
});
});

it("redirects with changed=1 when the time or place moved", async () => {
await expect(updateEventAction(eventId, { error: null }, form())).rejects.toThrow(
`NEXT_REDIRECT:/host/events/${eventId}?changed=1`,
);
expect((await getHostEvent(db, "host-1", eventId)).detailsChangedAt).toBeInstanceOf(Date);
});

it("returns a friendly error for bad input and saves nothing", async () => {
expect(await updateEventAction(eventId, { error: null }, form({ location: " " }))).toEqual({
error: "Where is it?",
Expand Down
9 changes: 7 additions & 2 deletions src/app/host/events/[id]/edit/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,15 @@ export async function updateEventAction(
formData: FormData,
): Promise<EditEventState> {
const host = await requireHost();
let result: { detailsChanged: boolean };
try {
await updateEvent(await getDb(), host.id, eventId, {
result = await updateEvent(await getDb(), host.id, eventId, {
title: text(formData, "title"),
startsAt: text(formData, "startsAt"),
location: text(formData, "location"),
timezone: text(formData, "timezone") || undefined,
coverEmoji: text(formData, "coverEmoji") || null,
coverColor: text(formData, "coverColor") || null,
});
} catch (error) {
if (error instanceof ValidationError) return { error: error.message };
Expand All @@ -43,7 +46,9 @@ export async function updateEventAction(
// The title and time show in the layout header and on the dashboard.
revalidatePath(`/host/events/${encodeURIComponent(eventId)}`, "layout");
revalidatePath("/host");
redirect(`/host/events/${encodeURIComponent(eventId)}`);
// A moved time or place lands on the Guests tab with a copyable heads-up.
const query = result.detailsChanged ? "?changed=1" : "";
redirect(`/host/events/${encodeURIComponent(eventId)}${query}`);
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/app/host/events/[id]/edit/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export default async function EditEventPage({ params }: PageProps<"/host/events/
startsAt: dateToZonedLocal(event.startsAt, event.timezone),
location: event.location,
timezone: event.timezone,
coverEmoji: event.coverEmoji,
coverColor: event.coverColor,
}}
action={updateEventAction.bind(null, event.id)}
backHref={`/host/events/${encodeURIComponent(event.id)}`}
Expand Down
39 changes: 22 additions & 17 deletions src/app/host/events/[id]/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ import type { ReactNode } from "react";
import { CancelledEventNotice } from "@/components/CancelledEventNotice";
import { CopyCancellationButton } from "@/components/CopyCancellationButton";
import { CopyLinkButton } from "@/components/CopyLinkButton";
import { CoverChip } from "@/components/CoverChip";
import { EventTabs } from "@/components/EventTabs";
import { Wordmark } from "@/components/ui/Wordmark";
import { coverFor } from "@/lib/cover";
import { formatWhen } from "@/lib/format";
import { getBaseUrl, shareUrl } from "@/server/base-url";
import { loadHostEvent } from "@/server/host-event";
Expand Down Expand Up @@ -57,23 +59,26 @@ export default async function EventLayout({

<div className="ticket event-ticket">
<div className="event-heading">
<div className="min-w-0">
<h1 className="event-title">{event.title}</h1>
<p className="event-meta">
{formatWhen(event.startsAt, event.location, event.timezone)}
</p>
<div className="mt-2 flex flex-wrap items-center gap-x-5">
<Link
href={`/host/events/${encodeURIComponent(event.id)}/edit`}
className="quiet-link"
>
Edit details
</Link>
<form action={duplicateEventAction.bind(null, event.id)}>
<button type="submit" className="quiet-link">
Plan this again
</button>
</form>
<div className="flex min-w-0 items-start gap-3">
<CoverChip cover={coverFor(event)} size="lg" className="mt-1" />
<div className="min-w-0">
<h1 className="event-title">{event.title}</h1>
<p className="event-meta">
{formatWhen(event.startsAt, event.location, event.timezone)}
</p>
<div className="mt-2 flex flex-wrap items-center gap-x-5">
<Link
href={`/host/events/${encodeURIComponent(event.id)}/edit`}
className="quiet-link"
>
Edit details
</Link>
<form action={duplicateEventAction.bind(null, event.id)}>
<button type="submit" className="quiet-link">
Plan this again
</button>
</form>
</div>
</div>
</div>
<div className="ticket-count">
Expand Down
19 changes: 18 additions & 1 deletion src/app/host/events/[id]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import Link from "next/link";
import { ChangeNotice } from "@/components/ChangeNotice";
import { GuestsPanel } from "@/components/GuestsPanel";
import { DevGuestTools } from "@/components/dev/DevGuestTools";
import { getDb } from "@/db/client";
import { formatWhen } from "@/lib/format";
import { devToolsEnabled } from "@/server/dev-tools";
import { requireHost } from "@/server/auth";
import { loadHostEvent } from "@/server/host-event";
Expand All @@ -17,9 +20,11 @@ import { addInviteesAction, removeGuestAction, setMaybePercentAction } from "./a

export const dynamic = "force-dynamic";

export default async function GuestsTab({ params }: PageProps<"/host/events/[id]">) {
export default async function GuestsTab({ params, searchParams }: PageProps<"/host/events/[id]">) {
// Layouts and pages are authorised independently: check ownership here too.
const { event } = await loadHostEvent((await params).id);
// Set by updateEventAction when the time, zone or place moved.
const changed = (await searchParams).changed === "1";
const host = await requireHost();
const db = await getDb();
const overview = await getGuestsOverview(db, host.id, event.id);
Expand All @@ -30,6 +35,18 @@ export default async function GuestsTab({ params }: PageProps<"/host/events/[id]

return (
<>
{changed && !event.cancelledAt ? (
<div className="ticket-surface mb-6 flex flex-wrap items-start justify-between gap-4 rounded-2xl bg-stub px-4 py-3">
<ChangeNotice
title={event.title}
when={formatWhen(event.startsAt, "", event.timezone)}
location={event.location}
/>
<Link href={`/host/events/${encodeURIComponent(event.id)}`} className="quiet-link">
Dismiss
</Link>
</div>
) : null}
<GuestsPanel
overview={overview}
invitation={{ title: event.title, url: shareUrl(baseUrl, event.shareCode) }}
Expand Down
2 changes: 2 additions & 0 deletions src/app/host/new/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ export async function createEventAction(
hostName: host.name,
startsAt,
timezone: text(formData, "timezone"),
coverEmoji: text(formData, "coverEmoji") || null,
coverColor: text(formData, "coverColor") || null,
}));
} catch (error) {
if (error instanceof ValidationError) return { error: error.message };
Expand Down
Loading
Loading