import Link from "next/link"; import { notFound } from "next/navigation"; import { prisma } from "@/lib/prisma"; import { Calendar } from "lucide-react"; export const dynamic = "force-dynamic"; type Campaign = { id: number; name: string; image: string; startTimestamp: number; totalDays: number; lockExpired: string; enabled: string; }; type Reward = { id: number; campaignId: number; productName: string; customImage: string; credits: number; pixels: number; points: number; pointsType: number; badge: string; itemId: number; subscriptionType: string | null; subscriptionDays: number; }; function fmtDate(ts: number): string { if (!ts) return "—"; return new Date(ts * 1000).toISOString().slice(0, 10); } export default async function AdminCalendarCampaign({ params, }: { params: Promise<{ id: string }>; }) { const { id } = await params; const campaignId = Number(id); if (!Number.isInteger(campaignId)) notFound(); let campaign: Campaign | null = null; try { campaign = await prisma.calendarCampaigns.findUnique({ where: { id: campaignId }, select: { id: true, name: true, image: true, startTimestamp: true, totalDays: true, lockExpired: true, enabled: true, }, }); } catch { campaign = null; } if (!campaign) notFound(); let rewards: Reward[] = []; try { rewards = await prisma.calendarRewards.findMany({ where: { campaignId }, select: { id: true, campaignId: true, productName: true, customImage: true, credits: true, pixels: true, points: true, pointsType: true, badge: true, itemId: true, subscriptionType: true, subscriptionDays: true, }, orderBy: { id: "asc" }, take: 500, }); } catch { rewards = []; } const disabled = campaign.enabled !== "1"; return (

← Calendar campaigns

{campaign.image ? ( // eslint-disable-next-line @next/next/no-img-element {campaign.name} ) : null}

{campaign.name || `Campaign #${campaign.id}`}

#{campaign.id} · {campaign.totalDays} day{campaign.totalDays === 1 ? "" : "s"} · starts{" "} {fmtDate(campaign.startTimestamp)} {disabled ? " · Disabled" : " · Enabled"} {campaign.lockExpired === "1" ? " · Locks expired days" : ""}

Rewards

{rewards.length === 0 ? (
No rewards configured for this campaign.
) : ( {rewards.map((r) => ( ))}
ID Product Item Credits Pixels Points Badge Subscription
{r.id} {r.productName || —} {r.itemId > 0 ? r.itemId : "—"} {r.credits > 0 ? r.credits : —} {r.pixels > 0 ? r.pixels : —} {r.points > 0 ? ( `${r.points} (type ${r.pointsType})` ) : ( — )} {r.badge || "—"} {r.subscriptionType ? `${r.subscriptionType} · ${r.subscriptionDays}d` : "—"}
)}

{rewards.length} reward{rewards.length === 1 ? "" : "s"}

); }