Skip to content
Open
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
8 changes: 8 additions & 0 deletions peopleportal/server/src/controllers/EventController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,14 @@ export class EventController extends Controller {
throw new CustomValidationError(404, `No event with id ${eventId}`);
}

// RSVPs close when the event starts.
if (event.startTime.getTime() <= Date.now()) {
throw new CustomValidationError(
400,
"RSVPs are closed because this event has already started.",
);
}

// Ensure email is available through session or tempsession
const email =
req.session.authorizedUser?.email ??
Expand Down
29 changes: 27 additions & 2 deletions peopleportal/webui/src/components/fabric/EventAttendance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,10 @@ export const EventAttendance = () => {
setDialogOpen(true);
};

// RSVPs close when the event starts (the server enforces this too).
const rsvpClosed =
event !== null && new Date(event.startTime).getTime() <= Date.now();

const submitRsvp = async (acceptRsvp: boolean) => {
const res = await fetch(
`${PEOPLEPORTAL_SERVER_ENDPOINT}/api/events/${eventId}/rsvp`,
Expand All @@ -468,7 +472,10 @@ export const EventAttendance = () => {
);

if (!res.ok) {
toast.error(`Failed to RSVP to event: ${res.statusText}`);
const body = await res.json().catch(() => null);
toast.error(
`Failed to RSVP to event: ${body?.message ?? res.statusText}`,
);
return;
}

Expand Down Expand Up @@ -700,6 +707,18 @@ export const EventAttendance = () => {
<h2 className="text-xl font-semibold">RSVP</h2>
{loading ? (
<Skeleton className="h-18" />
) : rsvp === null && rsvpClosed ? (
<Card>
<CardHeader>
<CardTitle className="text-base">
RSVPs are closed
</CardTitle>
<CardDescription>
This event has already started, so RSVPs are
no longer accepted.
</CardDescription>
</CardHeader>
</Card>
) : rsvp === null ? (
<Card>
<CardHeader>
Expand Down Expand Up @@ -762,7 +781,13 @@ export const EventAttendance = () => {
: "Declined"}
</Badge>
</CardHeader>
{updating ? (
{rsvpClosed ? (
<CardFooter>
<p className="text-sm text-muted-foreground">
RSVPs closed when this event started.
</p>
</CardFooter>
) : updating ? (
<>
<CardContent>
<p className="text-sm text-muted-foreground mb-3">
Expand Down