import Link from "next/link"; import { db } from "@/lib/db"; import { requireAdmin } from "@/lib/auth"; import { dateFmt } from "@/lib/status"; import { formatPrice } from "@/lib/money"; import { SALE_STATES as STATE, SCOPE_LABELS, saleState, type SaleScope, type SaleState } from "@/lib/sales"; import { ConfirmButton } from "@/components/admin/AdminForm"; import { Card, Empty, PageHead, Pill } from "@/components/admin/ui"; import { toggleSale } from "./actions"; export default async function SalesPage() { await requireAdmin("coupons.edit"); const [sales, categories] = await Promise.all([db.sale.findMany({ orderBy: { createdAt: "desc" } }), db.category.findMany({ select: { id: true, name: true } })]); const catName = new Map(categories.map((c) => [c.id, c.name])); const order: SaleState[] = ["running", "planned", "off", "ended"]; const sorted = [...sales].sort((a, b) => order.indexOf(saleState(a)) - order.indexOf(saleState(b))); return (
| Sale | Rabatt | Gilt für | Zeitraum | Status | |
|---|---|---|---|---|---|
| {s.name} | {s.type === "percent" ? `−${s.value} %` : `−${formatPrice(s.value)}`} | {SCOPE_LABELS[s.scope as SaleScope] && s.scope !== "shop" ? `${SCOPE_LABELS[s.scope as SaleScope]}: ` : ""}{target} | {s.startsAt ? dateFmt.format(s.startsAt) : "sofort"} – {s.endsAt ? dateFmt.format(s.endsAt) : "offen"} |
{st !== "ended" && (
|
Gelten mehrere Sales für ein Produkt, zählt der günstigste. Gutscheine lassen sich zusätzlich einlösen.