Wire testimonials CMS collection and Payload Live Preview

Testimonials on /todo-cards, /newsletter, /challenge now come from the new
Payload testimonials collection via a shared TestimonialsGrid component,
instead of 3 separately hardcoded arrays.

Adds Next.js Draft Mode (/api/preview) plus Live-Preview-aware client
wrappers (LiveRichText, LiveTestimonialsGrid, LivePostContent) for posts,
legal pages, and testimonials — mounted only while Draft Mode is enabled,
so ordinary visitors keep getting the plain static components.
This commit is contained in:
Marco
2026-07-21 19:02:20 +00:00
parent 2d6cff9f40
commit 26ae4a15f4
18 changed files with 420 additions and 305 deletions
+28
View File
@@ -0,0 +1,28 @@
import { draftMode } from "next/headers";
import { redirect } from "next/navigation";
import { NextRequest } from "next/server";
// Entered only via the `livePreview.url` link Payload puts in its admin
// (posts/legal-pages/testimonials, see payload.config.ts and those
// collections' own `admin.livePreview.url` resolvers) — enables Draft Mode
// so the target page renders its Live-Preview-aware components (see the
// `isPreview` checks in those pages' page.tsx), then redirects into the
// actual page. `path` is never redirected to as-is (open-redirect risk);
// it's validated to be an internal path first.
export async function GET(request: NextRequest) {
const { searchParams } = request.nextUrl;
const secret = searchParams.get("secret");
const path = searchParams.get("path");
if (!secret || secret !== process.env.PAYLOAD_PREVIEW_SECRET) {
return new Response("Invalid secret", { status: 401 });
}
if (!path || !path.startsWith("/") || path.startsWith("//")) {
return new Response("Invalid path", { status: 400 });
}
const draft = await draftMode();
draft.enable();
redirect(path);
}