diff --git a/src/app/e/[code]/g/[token]/page.tsx b/src/app/e/[code]/g/[token]/page.tsx
index d82a311..4de20d7 100644
--- a/src/app/e/[code]/g/[token]/page.tsx
+++ b/src/app/e/[code]/g/[token]/page.tsx
@@ -1,9 +1,12 @@
import type { Metadata } from "next";
import Link from "next/link";
import { notFound } from "next/navigation";
+import { CancelledEventNotice } from "@/components/CancelledEventNotice";
+import { EventUnavailable } from "@/components/EventUnavailable";
import { RsvpForm } from "@/components/RsvpForm";
import { getDb } from "@/db/client";
import type { RsvpStatus } from "@/domain/headcount";
+import { eventState } from "@/lib/event-state";
import { formatWhen } from "@/lib/format";
import { NotFoundError } from "@/services/errors";
import { getGuestByToken, getPublicEvent } from "@/services/rsvp";
@@ -40,6 +43,24 @@ export default async function GuestEditPage({ params }: PageProps<"/e/[code]/g/[
throw error;
}
+ const state = eventState(event);
+ if (state === "deleted") return ;
+ const cancelled = state === "cancelled";
+
+ const personalNote = (
+
+ This is your personal link — don't share it.{" "}
+ {cancelled ? null : (
+
+ Not you? Answer as someone else
+
+ )}
+
+ );
+
return (
-
- {CONFIRMATION[guest.status]}
-
- Need to change something? Update your answer below.
-
-
-
- This is your personal link — don't share it.{" "}
-
- Not you? Answer as someone else
-
-
+ {cancelled ? (
+
+ ) : (
+
+ {CONFIRMATION[guest.status]}
+
+ Need to change something? Update your answer below.
+
+
+ )}
+ {personalNote}
}
/>
diff --git a/src/app/e/[code]/page.tsx b/src/app/e/[code]/page.tsx
index b9cfaa0..2df16d1 100644
--- a/src/app/e/[code]/page.tsx
+++ b/src/app/e/[code]/page.tsx
@@ -1,8 +1,11 @@
import type { Metadata } from "next";
import { cookies } from "next/headers";
import { notFound, redirect } from "next/navigation";
+import { CancelledEventNotice } from "@/components/CancelledEventNotice";
+import { EventUnavailable } from "@/components/EventUnavailable";
import { RsvpForm } from "@/components/RsvpForm";
import { getDb } from "@/db/client";
+import { eventState } from "@/lib/event-state";
import { formatWhen } from "@/lib/format";
import { guestCookieName } from "@/lib/guest-cookie";
import { eventPreview, wantsBlankForm } from "@/lib/guest-page";
@@ -22,7 +25,8 @@ export async function generateMetadata({ params }: PageProps<"/e/[code]">): Prom
if (error instanceof NotFoundError) return null;
throw error;
});
- const { title, description } = eventPreview(event);
+ // A deleted event must not keep advertising its title in link previews.
+ const { title, description } = eventPreview(event && !event.deletedAt ? event : null);
return { title, description, openGraph: { title, description } };
}
@@ -39,6 +43,10 @@ export default async function GuestPage({ params, searchParams }: PageProps<"/e/
throw error;
}
+ const state = eventState(event);
+ if (state === "deleted") return ;
+ const cancelled = state === "cancelled";
+
// 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;
@@ -71,29 +79,33 @@ export default async function GuestPage({ params, searchParams }: PageProps<"/e/
goingCount: event.goingCount,
}}
action={submitGuestRsvp.bind(null, code)}
+ readOnly={cancelled}
+ notice={cancelled ? : undefined}
/>
-
);
diff --git a/src/components/CancelEventSection.test.tsx b/src/components/CancelEventSection.test.tsx
new file mode 100644
index 0000000..8b8c0a5
--- /dev/null
+++ b/src/components/CancelEventSection.test.tsx
@@ -0,0 +1,30 @@
+import { fireEvent, render, screen, waitFor } from "@testing-library/react";
+import { describe, expect, it, vi } from "vitest";
+import { CancelEventSection } from "./CancelEventSection";
+
+describe("CancelEventSection", () => {
+ it("offers Cancel event for a live event and posts the bound action", async () => {
+ const action = vi.fn();
+ render();
+
+ expect(screen.getByRole("heading", { name: "Cancel event" })).toBeInTheDocument();
+ expect(screen.getByText(/Guests keep the link/)).toBeInTheDocument();
+ expect(screen.queryByRole("button", { name: "Reinstate event" })).not.toBeInTheDocument();
+
+ fireEvent.click(screen.getByRole("button", { name: "Cancel event" }));
+ await waitFor(() => expect(action).toHaveBeenCalledTimes(1));
+ expect(action.mock.calls[0][0]).toBeInstanceOf(FormData);
+ });
+
+ it("offers Reinstate event once cancelled", async () => {
+ const action = vi.fn();
+ render();
+
+ expect(screen.getByRole("heading", { name: "Event cancelled" })).toBeInTheDocument();
+ expect(screen.getByText(/can't RSVP/)).toBeInTheDocument();
+ expect(screen.queryByRole("button", { name: "Cancel event" })).not.toBeInTheDocument();
+
+ fireEvent.click(screen.getByRole("button", { name: "Reinstate event" }));
+ await waitFor(() => expect(action).toHaveBeenCalledTimes(1));
+ });
+});
diff --git a/src/components/CancelEventSection.tsx b/src/components/CancelEventSection.tsx
new file mode 100644
index 0000000..7652b15
--- /dev/null
+++ b/src/components/CancelEventSection.tsx
@@ -0,0 +1,41 @@
+"use client";
+
+import { Card } from "./ui/Card";
+import { SubmitButton } from "./ui/SubmitButton";
+
+/** A server action already bound to the event id (see cancelEventAction). */
+export type CancelEventAction = (formData: FormData) => void | Promise;
+
+/**
+ * Cancel or reinstate an event without deleting it. Cancelling keeps the guest
+ * link working (with RSVPs closed) and everything on the event in place.
+ */
+export function CancelEventSection({
+ cancelled,
+ action,
+}: {
+ cancelled: boolean;
+ action: CancelEventAction;
+}) {
+ return (
+
+
{cancelled ? "Event cancelled" : "Cancel event"}
+
+ {cancelled
+ ? "Guests see the cancellation notice and can't RSVP. Everything is still here, so you can reinstate it if plans change."
+ : "Call it off without deleting anything. Guests keep the link, see that it's cancelled, and can't RSVP."}
+
+
+
+ );
+}
diff --git a/src/components/CancelledEventNotice.tsx b/src/components/CancelledEventNotice.tsx
new file mode 100644
index 0000000..0f2cf48
--- /dev/null
+++ b/src/components/CancelledEventNotice.tsx
@@ -0,0 +1,30 @@
+import type { ReactNode } from "react";
+
+/**
+ * The cancellation notice shared by the guest slip and the host masthead.
+ * Ketchup marks it as the one thing to read first; nothing here takes actions.
+ */
+export function CancelledEventNotice({
+ hostName,
+ children,
+}: {
+ /** Guests see "Cancelled by "; the host's own screens leave it off. */
+ hostName?: string;
+ children?: ReactNode;
+}) {
+ return (
+
+
+ {hostName ? <>Cancelled by {hostName}> : "Cancelled"}
+
+ {children ?? (
+
+ This event was called off, so RSVPs are closed.
+
+ )}
+
+ );
+}
diff --git a/src/components/CopyCancellationButton.test.tsx b/src/components/CopyCancellationButton.test.tsx
new file mode 100644
index 0000000..bd8727d
--- /dev/null
+++ b/src/components/CopyCancellationButton.test.tsx
@@ -0,0 +1,34 @@
+import { fireEvent, render, screen } from "@testing-library/react";
+import { describe, expect, it, vi } from "vitest";
+import { CopyCancellationButton } from "./CopyCancellationButton";
+
+describe("CopyCancellationButton", () => {
+ it("copies a cancellation message with the event title and when", async () => {
+ const writeText = vi.fn().mockResolvedValue(undefined);
+ Object.defineProperty(navigator, "clipboard", { configurable: true, value: { writeText } });
+ render();
+
+ fireEvent.click(screen.getByRole("button", { name: "Copy cancellation message" }));
+
+ expect(await screen.findByRole("status")).toHaveTextContent("Cancellation copied");
+ expect(writeText).toHaveBeenCalledWith(
+ "Sorry everyone, Burger Night on Sat, Nov 14 · 7pm is cancelled. Hope to see you at the next one.",
+ );
+ });
+
+ it("keeps the complete message available when clipboard access fails", async () => {
+ Object.defineProperty(navigator, "clipboard", {
+ configurable: true,
+ value: { writeText: vi.fn().mockRejectedValue(new Error("denied")) },
+ });
+ render();
+
+ fireEvent.click(screen.getByRole("button", { name: "Copy cancellation message" }));
+
+ const message = await screen.findByLabelText("Cancellation message");
+ expect(message).toHaveValue(
+ "Sorry everyone, Sunday lunch on Sun, Nov 15 · noon is cancelled. Hope to see you at the next one.",
+ );
+ expect(screen.getByRole("status")).toHaveTextContent("Select the message below");
+ });
+});
diff --git a/src/components/CopyCancellationButton.tsx b/src/components/CopyCancellationButton.tsx
new file mode 100644
index 0000000..aed100d
--- /dev/null
+++ b/src/components/CopyCancellationButton.tsx
@@ -0,0 +1,54 @@
+"use client";
+
+import { useState } from "react";
+import { Button } from "./ui/Button";
+
+/** The host copies this into their group chat; Spread never sends it. */
+export function cancellationMessage(title: string, when: string): string {
+ return `Sorry everyone, ${title} on ${when} is cancelled. Hope to see you at the next one.`;
+}
+
+/** Prepares a cancellation message for the host to send; never sends a message itself. */
+export function CopyCancellationButton({ title, when }: { title: string; when: string }) {
+ const [state, setState] = useState<"idle" | "copied" | "failed">("idle");
+ const message = cancellationMessage(title, when);
+
+ async function copy() {
+ try {
+ await navigator.clipboard.writeText(message);
+ setState("copied");
+ } catch {
+ setState("failed");
+ }
+ }
+
+ return (
+
+
+ {state !== "idle" ? (
+
+ {state === "copied"
+ ? "Cancellation copied. Paste it into your group chat."
+ : "Couldn't copy. Select the message below and copy it manually."}
+
+ ) : null}
+ {state === "failed" ? (
+
+ );
+}
diff --git a/src/components/DeleteEventSection.test.tsx b/src/components/DeleteEventSection.test.tsx
index e13dba1..09230cd 100644
--- a/src/components/DeleteEventSection.test.tsx
+++ b/src/components/DeleteEventSection.test.tsx
@@ -6,42 +6,43 @@ const renderSection = () =>
render();
describe("DeleteEventSection", () => {
- it("shows only the Delete event button until it is clicked", () => {
+ it("explains that deleting is reversible for 30 days", () => {
renderSection();
expect(screen.getByRole("button", { name: "Delete event" })).toBeInTheDocument();
- expect(screen.queryByRole("button", { name: "Yes, delete it" })).not.toBeInTheDocument();
- expect(screen.queryByText(/permanently removes/)).not.toBeInTheDocument();
- });
-
- it("reveals a confirmation naming the event, with focus on the confirm button", () => {
- renderSection();
- fireEvent.click(screen.getByRole("button", { name: "Delete event" }));
-
expect(
- screen.getByText(/permanently removes all RSVPs, the menu, shopping and split data/),
+ screen.getByText(/You can undo this from your events list for 30 days\./),
).toBeInTheDocument();
expect(screen.getByText("Burger Night")).toBeInTheDocument();
- expect(screen.getByRole("button", { name: "Yes, delete it" })).toHaveFocus();
- expect(screen.queryByRole("button", { name: "Delete event" })).not.toBeInTheDocument();
- });
-
- it("hides the confirmation again when Cancel is pressed", () => {
- renderSection();
- fireEvent.click(screen.getByRole("button", { name: "Delete event" }));
- fireEvent.click(screen.getByRole("button", { name: "Cancel" }));
-
- expect(screen.queryByRole("button", { name: "Yes, delete it" })).not.toBeInTheDocument();
expect(screen.queryByText(/permanently removes/)).not.toBeInTheDocument();
- expect(screen.getByRole("button", { name: "Delete event" })).toBeInTheDocument();
});
- it("submits the bound delete action from the confirmation", async () => {
+ it("submits the bound delete action straight away, with no confirm step", async () => {
const action = vi.fn();
render();
+
fireEvent.click(screen.getByRole("button", { name: "Delete event" }));
- fireEvent.click(screen.getByRole("button", { name: "Yes, delete it" }));
await waitFor(() => expect(action).toHaveBeenCalledTimes(1));
expect(action.mock.calls[0][0]).toBeInstanceOf(FormData);
+ expect(screen.queryByRole("button", { name: /Yes, delete it/ })).not.toBeInTheDocument();
+ });
+
+ it("shows a pending label while the delete is in flight", async () => {
+ let release: (() => void) | undefined;
+ const action = vi.fn(
+ () =>
+ new Promise((resolve) => {
+ release = resolve;
+ }),
+ );
+ render();
+
+ fireEvent.click(screen.getByRole("button", { name: "Delete event" }));
+
+ expect(await screen.findByRole("button", { name: "Deleting..." })).toBeDisabled();
+ release?.();
+ await waitFor(() =>
+ expect(screen.getByRole("button", { name: "Delete event" })).toBeEnabled(),
+ );
});
});
diff --git a/src/components/DeleteEventSection.tsx b/src/components/DeleteEventSection.tsx
index 735ef66..d332a10 100644
--- a/src/components/DeleteEventSection.tsx
+++ b/src/components/DeleteEventSection.tsx
@@ -1,77 +1,28 @@
"use client";
-import { useEffect, useId, useRef, useState, type RefObject } from "react";
-import { useFormStatus } from "react-dom";
-import { Button } from "./ui/Button";
import { Card } from "./ui/Card";
+import { SubmitButton } from "./ui/SubmitButton";
/** A server action already bound to the event id (see deleteEventAction). */
export type DeleteEventAction = (formData: FormData) => void | Promise;
-/** The two confirm buttons; inside the form so useFormStatus sees its pending state. */
-function DeleteActions({
- confirmRef,
- describedBy,
- onCancel,
-}: {
- confirmRef: RefObject;
- describedBy: string;
- onCancel: () => void;
-}) {
- const { pending } = useFormStatus();
- return (
-
-
-
-
- );
-}
-
-/** "Danger zone": Delete event reveals an inline confirmation, then submits the action. */
+/**
+ * "Danger zone": Delete event submits straight away (no confirm step), because
+ * deleting is reversible from the dashboard for 30 days.
+ */
export function DeleteEventSection({ title, action }: { title: string; action: DeleteEventAction }) {
- const [confirming, setConfirming] = useState(false);
- const confirmRef = useRef(null);
- const questionId = useId();
-
- // The confirm step replaces the button that was pressed, so put focus on its first action.
- useEffect(() => {
- if (confirming) confirmRef.current?.focus();
- }, [confirming]);
-
return (
Danger zone
- Deleting an event can’t be undone.
+ Deletes {title} and its RSVPs, menu,
+ shopping and split data. You can undo this from your events list for 30 days.
-
- {confirming ? (
-
- ) : (
-
- )}
+
+
);
}
diff --git a/src/components/EventUnavailable.tsx b/src/components/EventUnavailable.tsx
new file mode 100644
index 0000000..6f61357
--- /dev/null
+++ b/src/components/EventUnavailable.tsx
@@ -0,0 +1,25 @@
+import { Wordmark } from "./ui/Wordmark";
+
+/**
+ * What a guest sees for an event the host has deleted: a friendly slip, not a
+ * 404, so a stale link doesn't look like a broken site. No event details beyond
+ * the host's name, since the event is on its way out.
+ */
+export function EventUnavailable({ hostName }: { hostName: string }) {
+ return (
+
+
+
+
+
+
+
This event is no longer available
+
+ {hostName} took this event down. Ask them
+ for a new link if you think you should still have one.
+
+
+
+
+ );
+}
diff --git a/src/components/RsvpForm.test.tsx b/src/components/RsvpForm.test.tsx
index 15044ce..cf573a0 100644
--- a/src/components/RsvpForm.test.tsx
+++ b/src/components/RsvpForm.test.tsx
@@ -155,4 +155,36 @@ describe("RsvpForm", () => {
"Please use a shorter name.",
);
});
+
+ it("read-only mode shows the event and the guest's answer, with nothing to submit", () => {
+ render(
+ ,
+ );
+ expect(screen.getByRole("heading", { name: "Burger Night 🍔" })).toBeInTheDocument();
+ expect(screen.getByText("Dana · Maybe")).toBeInTheDocument();
+ expect(screen.getByText(/Sam, Alex/)).toBeInTheDocument();
+ expect(screen.getByText(/no peanuts/)).toBeInTheDocument();
+ expect(screen.getByText(/RSVPs are closed/)).toBeInTheDocument();
+ expect(screen.queryByLabelText("Your name")).not.toBeInTheDocument();
+ expect(screen.queryByRole("button", { name: /Count me in|Update my answer/ })).not.toBeInTheDocument();
+ });
+
+ it("read-only mode without a saved answer says nothing is needed", () => {
+ render();
+ expect(
+ screen.getByText("You can close this page. Nothing else is needed from you."),
+ ).toBeInTheDocument();
+ expect(screen.queryByRole("button", { name: "Count me in" })).not.toBeInTheDocument();
+ });
});
diff --git a/src/components/RsvpForm.tsx b/src/components/RsvpForm.tsx
index 0a977c3..391e6d4 100644
--- a/src/components/RsvpForm.tsx
+++ b/src/components/RsvpForm.tsx
@@ -32,17 +32,81 @@ const ANSWERS: { status: RsvpStatus; label: string }[] = [
{ status: "no", label: "Can't" },
];
+const ANSWER_LABELS: Record = {
+ yes: "Going",
+ maybe: "Maybe",
+ no: "Can't make it",
+};
+
+function SlipHead({ event, readOnly }: { event: RsvpFormEvent; readOnly: boolean }) {
+ return (
+
+
+ {event.hostName} is hosting
+
+
{event.title}
+
{event.when}
+
+ {readOnly
+ ? `${event.goingCount} going so far.`
+ : `${event.goingCount} going so far. A quick answer helps the host plan the food. No account needed.`}
+
+
+ );
+}
+
+/** What a guest's own answer looks like once RSVPs are closed: text, no controls. */
+function ReadOnlyReply({ initial }: { initial?: GuestView }) {
+ if (!initial) {
+ return (
+
+ You can close this page. Nothing else is needed from you.
+