import { redirect } from "next/navigation"; import { desc, eq, inArray } from "drizzle-orm"; import { auth } from "@/auth"; import { db } from "@/db"; import { members, promotions } from "@/db/schema"; import { can } from "@/lib/rbac"; import { moderatePromo } from "../actions"; export const dynamic = "force-dynamic"; const STRIPE_WARM = "repeating-linear-gradient(45deg,#efe9da,#efe9da 11px,#e6ddc9 11px,#e6ddc9 22px)"; const STRIPE_COOL = "repeating-linear-gradient(45deg,#eef0ec,#eef0ec 11px,#e2e8e6 11px,#e2e8e6 22px)"; export default async function PromotionsPage() { const session = await auth(); if (!can(session?.user.role, "moderatePromos")) { redirect("/backend"); } const rows = await db .select({ id: promotions.id, title: promotions.title, text: promotions.text, category: promotions.category, status: promotions.status, imageUrl: promotions.imageUrl, memberName: members.name, }) .from(promotions) .leftJoin(members, eq(promotions.memberId, members.id)) .where(inArray(promotions.status, ["pending", "live"])) .orderBy(desc(promotions.status), desc(promotions.createdAt)); const pending = rows.filter((r) => r.status === "pending"); const live = rows.filter((r) => r.status === "live"); // pending first, then live const ordered = [...pending, ...live]; return (
En attente · {pending.length} En ligne · {live.length}
{ordered.length === 0 && (
Aucune promotion pour le moment.
)}
{ordered.map((p) => { const isPending = p.status === "pending"; return (
{p.category && ( {p.category} )} {isPending ? "En attente" : "En ligne"}

{p.title}

{p.memberName}

{p.text}

{isPending ? (
) : (
● En ligne
)}
); })}
); }