sanamare/src/app/admin/(panel)/gutscheine/page.tsx
Claude dc45fae81b Gutscheine: Neuer Gutschein als Popup über „Gutschein erstellen“
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SvuGvHpbAQ4syfuLuRvutL
2026-10-20 18:46:14 +02:00

41 lines
1.9 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { db } from "@/lib/db";
import { requireAdmin } from "@/lib/auth";
import { formatPrice } from "@/lib/money";
import { AdminForm, ConfirmButton } from "@/components/admin/AdminForm";
import { CouponFields } from "@/components/admin/CouponFields";
import { NewCouponDialog } from "@/components/admin/NewCouponDialog";
import { Empty, PageHead, Pill } from "@/components/admin/ui";
import { deleteCoupon, saveCoupon } from "./actions";
export default async function CouponsPage() {
await requireAdmin("coupons.edit");
const coupons = await db.coupon.findMany({ orderBy: { createdAt: "desc" } });
return (
<div className="ad-wrap ad-wrap--narrow">
<PageHead title="Gutscheine" lead="Rabattcodes, die Kunden im Warenkorb einlösen. Klick auf einen Gutschein, um ihn zu bearbeiten.">
<NewCouponDialog />
</PageHead>
{coupons.length === 0 && (
<section className="ad-card">
<Empty title="Noch keine Gutscheine" text="Lege z. B. SOMMER15 für 15 % Rabatt an." />
</section>
)}
{coupons.map((c) => (
<details className="ad-card" key={c.id} style={{ marginBottom: "var(--space-3)" }}>
<summary className="ad-card__head" style={{ cursor: "pointer", listStyle: "none" }}>
<div>
<h2>{c.code}</h2>
<p>{c.type === "percent" ? `${c.value} %` : formatPrice(c.value)} · {c.usedCount}× eingelöst{c.maxUses ? ` von ${c.maxUses}` : ""}</p>
</div>
<Pill tone={c.active ? "success" : "neutral"}>{c.active ? "Aktiv" : "Aus"}</Pill>
</summary>
<div className="ad-card__body">
<AdminForm action={saveCoupon} extraActions={<ConfirmButton inForm action={deleteCoupon} confirm="Gutschein löschen?">Löschen</ConfirmButton>}>
<CouponFields c={c} />
</AdminForm>
</div>
</details>
))}
</div>
);
}