import { createVoucher, deleteVoucher } from "@/actions/admin-vouchers"; import { prisma } from "@/lib/prisma"; export const dynamic = "force-dynamic"; type VoucherRow = { id: bigint; code: string; amount: number; maxUses: number; useCount: number; expiresAt: Date | null; createdAt: Date | null; }; function fmtDate(d: Date | null): string { if (!d) return "—"; return d.toISOString().slice(0, 16).replace("T", " "); } export default async function AdminVouchers() { const now = Date.now(); let vouchers: VoucherRow[] = []; try { vouchers = await prisma.websiteShopVouchers.findMany({ select: { id: true, code: true, amount: true, maxUses: true, useCount: true, expiresAt: true, createdAt: true, }, orderBy: { id: "desc" }, take: 200, }); } catch { vouchers = []; } return (

Shop Vouchers

Codes redeemable on the website shop for a balance top-up. Each user can use a given voucher once, up to its max uses.

New voucher

{vouchers.map((v) => { const expired = v.expiresAt ? v.expiresAt.getTime() <= now : false; const usedUp = v.maxUses > 0 && v.useCount >= v.maxUses; return ( ); })}
Code Amount Uses Expires Created
{v.code} {expired ? ( · expired ) : usedUp ? ( · used up ) : null} {v.amount} {v.useCount} / {v.maxUses} {fmtDate(v.expiresAt)} {fmtDate(v.createdAt)}
{vouchers.length === 0 ?

No vouchers yet.

: null}
); }