From bcd3de94b44624bbc2a80072c10fc25f6d64c26e Mon Sep 17 00:00:00 2001 From: joshua Date: Thu, 22 Oct 2026 13:48:22 +0200 Subject: [PATCH] Show an early-bird ribbon on event cards Event cards on the home page and events list get a diagonal "Early bird" ribbon in the top-right corner while an early-bird tier is running and registration is open. GET /api/events returns earlyBirdEndsAt per event. Co-Authored-By: Claude Opus 5.5 --- apps/events/CHANGELOG.md | 4 ++ apps/events/FEATURES.md | 4 +- .../src/controllers/eventController.js | 46 ++++++++++++++++++- .../src/components/events/EventCard.tsx | 25 +++++++++- .../content/help/supervisor-event-options.tsx | 2 +- 5 files changed, 76 insertions(+), 5 deletions(-) diff --git a/apps/events/CHANGELOG.md b/apps/events/CHANGELOG.md index d37f907..567d69a 100644 --- a/apps/events/CHANGELOG.md +++ b/apps/events/CHANGELOG.md @@ -7,6 +7,10 @@ and this project follows [Semantic Versioning](https://semver.org/). ## [Unreleased] +### Added + +- Event cards on the home page and events list show a diagonal "Early bird" ribbon in the top-right corner while the event has an early-bird tier running (deadline not passed and places left on that tier). It isn't shown when the event is sold out, registration is closed or not open yet, or the event is contact-only. + ## [1.31.1] - 2026-10-22 ### Added diff --git a/apps/events/FEATURES.md b/apps/events/FEATURES.md index 7d6a85b..927db14 100644 --- a/apps/events/FEATURES.md +++ b/apps/events/FEATURES.md @@ -56,7 +56,9 @@ Four roles, each including everything the roles below it can do: and in-progress events, and a "Join Us" button (becomes "My Dashboard" when logged in). - **Events list** (`/events`) — event cards with picture, dates, location, - price, and a Register / Sold Out / Contact us button. + price, and a Register / Sold Out / Contact us button. A diagonal "Early bird" + ribbon in the top-right corner while an early-bird tier is running and + registration is open. - **Event detail** (`/events/[id]`) — description, ticket options with variant and early-bird pricing, low-stock and sold-out badges, downloadable attachments, embedded Google Map with "Directions" link, and an diff --git a/apps/events/backend/src/controllers/eventController.js b/apps/events/backend/src/controllers/eventController.js index fc639df..b7bc3d1 100644 --- a/apps/events/backend/src/controllers/eventController.js +++ b/apps/events/backend/src/controllers/eventController.js @@ -190,6 +190,45 @@ const createEvent = async (req, res) => { } }; +// Map of eventId → when its early bird ends, for events with at least one early-bird +// tier still running: deadline not passed and (no stock limit, or places left, counted +// across tranches the same way as utils/pricing.js). The date is the latest deadline +// among the running tiers. +async function earlyBirdEndsByEvent(events) { + const now = new Date(); + const running = []; + for (const ev of events) { + for (const opt of ev.eventOptions || []) { + for (const tier of opt.earlyBirdTiers || []) { + if (new Date(tier.deadline) > now) running.push({ eventId: ev.id, tier }); + } + } + } + + const limitedIds = running.filter(r => r.tier.stockLimit > 0).map(r => r.tier.id); + const sold = new Map(); + if (limitedIds.length > 0) { + const totals = await prisma.registrationOptionTranche.groupBy({ + by: ['appliedTierId'], + where: { + appliedTierId: { in: limitedIds }, + registrationOption: { registration: { status: { not: 'cancelled' } } } + }, + _sum: { quantity: true } + }); + for (const t of totals) sold.set(t.appliedTierId, t._sum?.quantity || 0); + } + + const ends = new Map(); + for (const { eventId, tier } of running) { + if (tier.stockLimit > 0 && (sold.get(tier.id) || 0) >= tier.stockLimit) continue; + const deadline = new Date(tier.deadline); + const current = ends.get(eventId); + if (!current || deadline > current) ends.set(eventId, deadline); + } + return ends; +} + // @desc Get all events // @route GET /api/events // @access Public @@ -220,9 +259,12 @@ const getEvents = async (req, res) => { }); } + const earlyBirdEnds = await earlyBirdEndsByEvent(events).catch(() => new Map()); + // Compute isSoldOut per event: true when every option that has a stock limit // is fully sold out. Events with no limited options are never sold out. const withStock = await Promise.all(events.map(async ev => { + const earlyBirdEndsAt = earlyBirdEnds.get(ev.id) || null; try { const limitedOpts = (ev.eventOptions || []).filter(o => (o.stockLimit || 0) > 0); let isSoldOut = false; @@ -231,9 +273,9 @@ const getEvents = async (req, res) => { const soldCounts = await Promise.all(limitedOpts.map(opt => takenCount({ eventOptionId: opt.id }))); isSoldOut = limitedOpts.every((opt, i) => soldCounts[i] >= opt.stockLimit); } - return { ...ev, picture: toAbsoluteUrl(req, ev.picture), isSoldOut }; + return { ...ev, picture: toAbsoluteUrl(req, ev.picture), isSoldOut, earlyBirdEndsAt }; } catch { - return { ...ev, picture: toAbsoluteUrl(req, ev.picture), isSoldOut: false }; + return { ...ev, picture: toAbsoluteUrl(req, ev.picture), isSoldOut: false, earlyBirdEndsAt }; } })); diff --git a/apps/events/frontend/src/components/events/EventCard.tsx b/apps/events/frontend/src/components/events/EventCard.tsx index 5e5f35f..7f0e19f 100644 --- a/apps/events/frontend/src/components/events/EventCard.tsx +++ b/apps/events/frontend/src/components/events/EventCard.tsx @@ -19,6 +19,8 @@ import { ContactButton } from "@/components/events/ContactButton"; contactPhone?: string | null; contactEmail?: string | null; location?: string | null; + // Set by GET /api/events while an early-bird tier is still running. + earlyBirdEndsAt?: string | null; }; import { formatDateTimeRange } from "@/lib/date"; @@ -26,9 +28,30 @@ import { formatDateTimeRange } from "@/lib/date"; export const EventCard = ({ event }: { event: Event }) => { const dateRange = formatDateTimeRange(event.startDate, event.endDate); + const now = new Date(); + const deadline = event.registrationDeadline ? new Date(event.registrationDeadline) : null; + const goLive = event.goLiveAt ? new Date(event.goLiveAt) : null; + const registrationOpen = event.requiresRegistration !== false + && !(goLive && now < goLive) + && !(deadline && now >= deadline) + && now < new Date(event.endDate); + const showEarlyBird = !!event.earlyBirdEndsAt && registrationOpen && !event.isSoldOut; + return ( -
+
+ {showEarlyBird && ( + + )} + {showEarlyBird && ( + + Early bird pricing until {new Date(event.earlyBirdEndsAt!).toLocaleDateString("en-GB", { day: "numeric", month: "long" })}. + + )} {event.picture ? ( ) : ( diff --git a/apps/events/frontend/src/content/help/supervisor-event-options.tsx b/apps/events/frontend/src/content/help/supervisor-event-options.tsx index 3d39c4b..9dd2a94 100644 --- a/apps/events/frontend/src/content/help/supervisor-event-options.tsx +++ b/apps/events/frontend/src/content/help/supervisor-event-options.tsx @@ -20,7 +20,7 @@ export const supervisorEventOptionsHelpContent: HelpContent = {

Pick an event, then edit each option's name, price, and "Main ticket" flag directly in the list — changes save when you click away from the field. Use the form below the list to add a new option.

- Expand "Manage early-bird tiers" on an option to add deadline-and-price rows that apply automatically before the cutoff. + Expand "Manage early-bird tiers" on an option to add deadline-and-price rows that apply automatically before the cutoff. While a tier is running (before its deadline, with places left), the event's card on the home page and events list shows an "Early bird" ribbon in the top-right corner.