Files
anouma/app/(frontend)/termine/[slug]/page.tsx
T
maroandClaude Sonnet 5 1cd15aff25 Add email verification, personal calendar feed, and full SEO implementation
- Customer accounts now require email verification (hashed, single-use,
  time-limited tokens) before they can request/confirm bookings, with
  resend flows on login/account/booking widget and rate limiting.
- Admins get a private, rotatable iCalendar (ICS) subscription feed of
  their confirmed bookings and public events, timezone-correct for
  Europe/Berlin including DST, never exposing meeting passwords.
- Adds a full SEO layer: per-page canonical/OG/Twitter metadata with
  CMS-editable overrides and content-derived fallbacks, a dynamic
  sitemap.xml and robots.txt driven by real published content, JSON-LD
  (Organization/LocalBusiness, WebSite, WebPage, BreadcrumbList, Service,
  Event, BlogPosting) that never fabricates data, and a CMS-managed
  redirect table for changed slugs.
- Global ANOUMA-naming audit: the brand name is never used to label
  personal account/calendar areas anywhere in the app, CMS, or emails.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-25 22:57:31 +02:00

198 lines
7.8 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import type { Metadata } from "next";
import { notFound, permanentRedirect, redirect } from "next/navigation";
import Link from "next/link";
import { headers } from "next/headers";
import { getPayload } from "payload";
import config from "@payload-config";
import { PageHeader } from "@/components/PageHeader";
import { Section } from "@/components/Section";
import { ImagePlaceholder } from "@/components/ImagePlaceholder";
import { RichText } from "@/components/RichText";
import { CTA } from "@/components/CTA";
import { RegisterForm } from "@/components/meeting/RegisterForm";
import { getEventBySlug } from "@/lib/payload/content";
import { getBookingSettingsGlobal, getSEOSettingsGlobal } from "@/lib/payload/globals";
import { mediaAlt, mediaUrl } from "@/lib/payload/media";
import { formatFullDate, formatTimeRange } from "@/lib/format";
import { EVENT_CATEGORIES } from "@/collections/Events";
import { canJoinMeeting, combineDateAndTime, getMeetingStatus, statusLabel } from "@/lib/meeting/status";
import { resolveSeo } from "@/lib/seo/resolve";
import { buildMetadata } from "@/lib/seo/metadata";
import { getSiteUrl } from "@/lib/seo/config";
import { excerptFromRichText } from "@/lib/seo/textExcerpt";
import { JsonLd, eventJsonLd } from "@/lib/seo/jsonld";
import { resolveRedirect } from "@/lib/seo/redirects";
import { siteConfig } from "@/lib/site";
export const dynamic = "force-dynamic";
type Args = { params: Promise<{ slug: string }> };
async function resolveEventOrRedirect(slug: string) {
const event = await getEventBySlug(slug);
if (event) return event;
const match = await resolveRedirect(`/termine/${slug}`);
if (match) {
if (match.permanent) permanentRedirect(match.to);
redirect(match.to);
}
return null;
}
export async function generateMetadata({ params }: Args): Promise<Metadata> {
const { slug } = await params;
const [event, seoSettings] = await Promise.all([getEventBySlug(slug), getSEOSettingsGlobal()]);
if (!event) return {};
const resolved = resolveSeo({
seo: event.seo,
fallbackTitle: `${event.title} ${siteConfig.name}`,
fallbackDescription: () => excerptFromRichText(event.description) || `${event.title} bei ${siteConfig.name}.`,
fallbackImage: event.image,
defaultOgImage: seoSettings.defaultOgImage,
});
return buildMetadata({
title: resolved.title,
description: resolved.description,
path: `/termine/${event.slug}`,
ogImageUrl: resolved.ogImageUrl,
keywords: resolved.keywords,
});
}
export default async function EventDetailPage({ params }: Args) {
const { slug } = await params;
const event = await resolveEventOrRedirect(slug);
if (!event) notFound();
const categoryLabel = EVENT_CATEGORIES.find((c) => c.value === event.category)?.label;
const time = formatTimeRange(event.startTime, event.endTime);
const [siteUrl, bookingSettings] = await Promise.all([getSiteUrl(), getBookingSettingsGlobal()]);
let meetingCard = null;
if (event.isOnline) {
const payload = await getPayload({ config });
const { user } = await payload.auth({ headers: await headers() });
// Must check the collection, not just presence — a logged-in customer
// (collection "customers") must never be treated as host.
const isHost = user?.collection === "users";
const settings = await payload.findGlobal({ slug: "meeting-settings" });
const start = combineDateAndTime(event.date, event.startTime);
const end = event.endTime
? combineDateAndTime(event.date, event.endTime)
: new Date(start.getTime() + 60 * 60_000);
const status = getMeetingStatus({
start,
end,
joinWindowMinutes: isHost ? settings.hostJoinWindowMinutes : settings.participantJoinWindowMinutes,
closeAfterMinutes: settings.meetingCloseAfterMinutes,
});
const joinable = canJoinMeeting(status);
meetingCard = (
<div className="rounded-3xl bg-anouma-plum p-6 text-center text-anouma-cream-light">
<p className="text-xs font-medium uppercase tracking-[0.18em] text-anouma-cream-light/80">
Online-Termin
</p>
{joinable ? (
<Link
href={`/termine/${slug}/beitreten`}
className="mt-4 inline-flex w-full items-center justify-center rounded-full bg-white px-6 py-3 text-sm font-medium text-anouma-plum hover:bg-anouma-cream-light"
>
{statusLabel[status]}
</Link>
) : (
<p className="mt-4 text-base">{statusLabel[status]}</p>
)}
</div>
);
}
return (
<>
<JsonLd
data={eventJsonLd({
event,
description: event.seo?.description || excerptFromRichText(event.description) || `${event.title} bei ${siteConfig.name}.`,
imageUrl: mediaUrl(event.image, "hero"),
joinUrl: event.isOnline ? `${siteUrl}/termine/${slug}/beitreten` : undefined,
siteUrl,
providerName: siteConfig.name,
booking: bookingSettings,
})}
/>
<PageHeader
eyebrow={categoryLabel}
title={event.title}
crumbs={[{ title: "Termine", href: "/termine" }, { title: event.title }]}
/>
<Section tone="plain">
<div className="grid gap-14 lg:grid-cols-[1fr_0.8fr]">
<div className="order-2 lg:order-1 space-y-10">
{event.description && <RichText data={event.description} />}
{event.registrationRequired && (
<div>
<h2 className="font-serif text-2xl font-medium text-anouma-plum">Anmeldung</h2>
<div className="mt-4 max-w-sm">
<RegisterForm slug={slug} />
</div>
</div>
)}
</div>
<div className="order-1 space-y-6 lg:order-2">
{meetingCard}
<div className="relative aspect-[4/3] w-full">
<ImagePlaceholder
mood="rose"
label={event.title}
src={mediaUrl(event.image, "card")}
alt={mediaAlt(event.image) ?? event.title}
className="h-full w-full"
/>
</div>
<dl className="space-y-3 rounded-3xl bg-anouma-cream-light p-6 text-sm">
<div>
<dt className="font-medium uppercase tracking-wide text-anouma-plum/70">Datum</dt>
<dd className="text-base text-anouma-plum">{formatFullDate(event.date)}</dd>
</div>
{time && (
<div>
<dt className="font-medium uppercase tracking-wide text-anouma-plum/70">Uhrzeit</dt>
<dd className="text-base text-anouma-plum">{time}</dd>
</div>
)}
{event.location && (
<div>
<dt className="font-medium uppercase tracking-wide text-anouma-plum/70">Ort</dt>
<dd className="text-base text-anouma-plum">{event.location}</dd>
</div>
)}
{event.maxParticipants && (
<div>
<dt className="font-medium uppercase tracking-wide text-anouma-plum/70">
Teilnehmerzahl
</dt>
<dd className="text-base text-anouma-plum">max. {event.maxParticipants}</dd>
</div>
)}
{event.registrationRequired && event.registrationInfo && (
<div>
<dt className="font-medium uppercase tracking-wide text-anouma-plum/70">
Anmeldung
</dt>
<dd className="text-base text-anouma-plum">{event.registrationInfo}</dd>
</div>
)}
</dl>
</div>
</div>
</Section>
<CTA
title="Dabei sein?"
lead={`Melde dich gerne für „${event.title}“ an oder frag nach freien Plätzen.`}
/>
</>
);
}