Complete remaining product gaps: credit-based shop purchases, guild thread replies, help ticket detail/reply/close, offline message compose, sign-out-everywhere via JWT version, ads delete confirm, soft-fail feedback, rate limits, loading states, and single auth() in site layout. Co-authored-by: Cursor <[email protected]>
69 lines
1.7 KiB
TypeScript
69 lines
1.7 KiB
TypeScript
import Link from "next/link";
|
|
import { getTranslations } from "next-intl/server";
|
|
import { StatusCard } from "@/components/admin/dashboard";
|
|
import { prisma } from "@/lib/prisma";
|
|
import { redirect } from "next/navigation";
|
|
import { canAccess, getAdminContext, PERMS } from "@/lib/permissions";
|
|
import { AdsTable } from "./ads-table";
|
|
|
|
export const dynamic = "force-dynamic";
|
|
|
|
export default async function AdminAds() {
|
|
const { session, permissions } = await getAdminContext();
|
|
if (!canAccess(permissions, PERMS.PAGES_VIEW, session.user.rank)) {
|
|
redirect("/admin");
|
|
}
|
|
|
|
const t = await getTranslations("pages.admin.ads");
|
|
let ads: Awaited<ReturnType<typeof prisma.websiteAds.findMany>>;
|
|
try {
|
|
ads = await prisma.websiteAds.findMany({
|
|
orderBy: { id: "desc" },
|
|
take: 500,
|
|
});
|
|
} catch {
|
|
ads = [];
|
|
}
|
|
|
|
const latest = ads[0]?.createdAt
|
|
? ads[0].createdAt.toISOString().slice(0, 10)
|
|
: "—";
|
|
|
|
return (
|
|
<main>
|
|
<div className="flex justify-end mb-6">
|
|
<Link href="/admin/ads/new" className="btn btn-primary">
|
|
+ {t("newAd")}
|
|
</Link>
|
|
</div>
|
|
|
|
<div className="grid grid-cols-[repeat(auto-fit,minmax(180px,1fr))] gap-3.5 mb-6">
|
|
<StatusCard label={t("adsCount")} value={ads.length} icon="🖼️" />
|
|
<StatusCard
|
|
label={t("latest")}
|
|
value={latest}
|
|
hint={t("mostRecentAd")}
|
|
icon="🕒"
|
|
/>
|
|
</div>
|
|
|
|
<section className="mt-6">
|
|
<h2 className="admin-section-title">{t("allAds")}</h2>
|
|
{ads.length === 0 ? (
|
|
<div className="admin-empty">{t("noAds")}</div>
|
|
) : (
|
|
<AdsTable
|
|
ads={ads.map((ad) => ({
|
|
id: String(ad.id),
|
|
image: ad.image,
|
|
createdAt: ad.createdAt
|
|
? ad.createdAt.toISOString().slice(0, 10)
|
|
: null,
|
|
}))}
|
|
/>
|
|
)}
|
|
</section>
|
|
</main>
|
|
);
|
|
}
|