feat: Wabenhain Honig-Shop Anwendung

Vollstaendige Next.js/Prisma-E-Commerce-Anwendung fuer eine Imkerei:
Shop, Warenkorb, Stripe-Checkout, Kundenkonto mit 2FA, Admin-Bereich
(Produkte, Ernten, Chargen, Bestellungen, Gutscheine, admin-editierbare
Website-Inhalte), i18n (DE/EN), Rate-Limiting/CSP/Audit-Log-Haertung,
PostgreSQL- und MySQL-Unterstuetzung ueber austauschbare Prisma-
Treiber-Adapter, Unit-/Komponenten-/E2E-Tests.
This commit is contained in:
Nick Szaunig committed 2026-08-17 14:30:28 +02:00
1 parent 5c76fcc266
commit c7927f2883
240 files changed
+26096 -137

No files matched your search

+123
View File
@@ -0,0 +1,123 @@
import { notFound } from "next/navigation";
import { prisma } from "@/lib/prisma";
import { BackLink } from "@/components/back-link";
import { updateDiscountCodeAction } from "../../actions";
import { getLocale } from "@/i18n/locale";
import { getDictionary } from "@/i18n/get-dictionary";
function toDateInputValue(date: Date | null): string {
if (!date) return "";
return date.toISOString().slice(0, 10);
}
export default async function AdminGutscheinEditPage(props: PageProps<"/admin/gutscheine/[id]">) {
const t = getDictionary(await getLocale());
const { id } = await props.params;
const { error } = await props.searchParams;
const code = await prisma.discountCode.findUnique({ where: { id } });
if (!code) notFound();
return (
<div className="max-w-md">
<BackLink href="/admin/gutscheine" label={t.adminVoucherEditPage.backToVouchers} />
<h1 className="text-2xl text-forest mb-8">{t.adminVoucherEditPage.title}</h1>
{error ? (
<p className="mb-6 text-sm text-red-700 bg-red-50 border border-red-200 px-4 py-3">{error}</p>
) : null}
<form action={updateDiscountCodeAction} className="space-y-4 bg-background border border-ink/10 p-6">
<input type="hidden" name="id" value={code.id} />
<Field name="code" label={t.adminVoucherEditPage.codeLabel} defaultValue={code.code} required />
<div className="grid grid-cols-2 gap-4">
<label className="block text-sm">
<span className="text-ink/70">{t.adminVoucherEditPage.typeLabel}</span>
<select
name="type"
defaultValue={code.type}
className="mt-1 w-full border border-ink/20 bg-background px-3 py-2"
>
<option value="PERCENT">{t.adminVoucherEditPage.typePercent}</option>
<option value="FIXED">{t.adminVoucherEditPage.typeFixed}</option>
</select>
</label>
<Field name="value" label={t.adminVoucherEditPage.valueLabel} type="number" defaultValue={String(code.value)} required />
</div>
<Field
name="minOrderCents"
label={t.adminVoucherEditPage.minOrderLabel}
type="number"
defaultValue={String(code.minOrderCents)}
/>
<Field
name="minQuantity"
label={t.adminVoucherEditPage.minQuantityLabel}
type="number"
defaultValue={code.minQuantity !== null ? String(code.minQuantity) : ""}
/>
<Field
name="maxUses"
label={t.adminVoucherEditPage.maxUsesLabel}
type="number"
defaultValue={code.maxUses !== null ? String(code.maxUses) : ""}
/>
<div className="grid grid-cols-2 gap-4">
<Field
name="validFrom"
label={t.adminVoucherEditPage.validFromLabel}
type="date"
defaultValue={toDateInputValue(code.validFrom)}
/>
<Field
name="validUntil"
label={t.adminVoucherEditPage.validUntilLabel}
type="date"
defaultValue={toDateInputValue(code.validUntil)}
/>
</div>
<label className="flex items-center gap-2 text-sm text-ink/70">
<input type="checkbox" name="isActive" defaultChecked={code.isActive} />
{t.adminVoucherEditPage.activeLabel}
</label>
<p className="text-xs text-ink/65">{t.adminVoucherEditPage.redeemedSoFar(code.usedCount, code.maxUses)}</p>
<button type="submit" className="bg-forest text-cream px-6 py-2 text-sm">
{t.adminVoucherEditPage.save}
</button>
</form>
</div>
);
}
function Field({
name,
label,
type = "text",
defaultValue,
required = false,
}: {
name: string;
label: string;
type?: string;
defaultValue?: string;
required?: boolean;
}) {
return (
<label className="block text-sm">
<span className="text-ink/70">{label}</span>
<input
name={name}
type={type}
defaultValue={defaultValue}
required={required}
min={0}
className="mt-1 w-full border border-ink/20 bg-background px-3 py-2"
/>
</label>
);
}
+81
View File
@@ -0,0 +1,81 @@
import { BackLink } from "@/components/back-link";
import { createDiscountCodeAction } from "../../actions";
import { getLocale } from "@/i18n/locale";
import { getDictionary } from "@/i18n/get-dictionary";
export default async function AdminGutscheinNewPage(props: PageProps<"/admin/gutscheine/neu">) {
const t = getDictionary(await getLocale());
const { error } = await props.searchParams;
return (
<div className="max-w-md">
<BackLink href="/admin/gutscheine" label={t.adminVoucherNewPage.backToVouchers} />
<h1 className="text-2xl text-forest mb-8">{t.adminVoucherNewPage.title}</h1>
{error ? (
<p className="mb-6 text-sm text-red-700 bg-red-50 border border-red-200 px-4 py-3">{error}</p>
) : null}
<form action={createDiscountCodeAction} className="space-y-4 bg-background border border-ink/10 p-6">
<Field name="code" label={t.adminVoucherNewPage.codeLabel} placeholder={t.adminVoucherNewPage.codePlaceholder} required />
<div className="grid grid-cols-2 gap-4">
<label className="block text-sm">
<span className="text-ink/70">{t.adminVoucherNewPage.typeLabel}</span>
<select name="type" className="mt-1 w-full border border-ink/20 bg-background px-3 py-2">
<option value="PERCENT">{t.adminVoucherNewPage.typePercent}</option>
<option value="FIXED">{t.adminVoucherNewPage.typeFixed}</option>
</select>
</label>
<Field name="value" label={t.adminVoucherNewPage.valueLabel} type="number" placeholder="10" required />
</div>
<Field name="minOrderCents" label={t.adminVoucherNewPage.minOrderLabel} type="number" placeholder="0" />
<Field name="minQuantity" label={t.adminVoucherNewPage.minQuantityLabel} type="number" placeholder="3" />
<Field name="maxUses" label={t.adminVoucherNewPage.maxUsesLabel} type="number" />
<div className="grid grid-cols-2 gap-4">
<Field name="validFrom" label={t.adminVoucherNewPage.validFromLabel} type="date" />
<Field name="validUntil" label={t.adminVoucherNewPage.validUntilLabel} type="date" />
</div>
<label className="flex items-center gap-2 text-sm text-ink/70">
<input type="checkbox" name="isActive" defaultChecked />
{t.adminVoucherNewPage.activeLabel}
</label>
<button type="submit" className="bg-forest text-cream px-6 py-2 text-sm">
{t.adminVoucherNewPage.create}
</button>
</form>
</div>
);
}
function Field({
name,
label,
type = "text",
placeholder,
required = false,
}: {
name: string;
label: string;
type?: string;
placeholder?: string;
required?: boolean;
}) {
return (
<label className="block text-sm">
<span className="text-ink/70">{label}</span>
<input
name={name}
type={type}
placeholder={placeholder}
required={required}
min={0}
className="mt-1 w-full border border-ink/20 bg-background px-3 py-2"
/>
</label>
);
}
+91
View File
@@ -0,0 +1,91 @@
import Link from "next/link";
import { prisma } from "@/lib/prisma";
import { BackLink } from "@/components/back-link";
import { ConfirmForm } from "@/components/confirm-form";
import { formatPrice, formatDate } from "@/lib/format";
import { deleteDiscountCodeAction } from "../actions";
import { getLocale } from "@/i18n/locale";
import { getDictionary } from "@/i18n/get-dictionary";
export default async function AdminGutscheinePage(props: PageProps<"/admin/gutscheine">) {
const t = getDictionary(await getLocale());
const { error } = await props.searchParams;
const codes = await prisma.discountCode.findMany({ orderBy: { createdAt: "desc" } });
return (
<div>
<BackLink href="/admin" label={t.adminVouchersPage.backToDashboard} />
<div className="flex items-center justify-between mb-8">
<h1 className="text-2xl text-forest">{t.adminVouchersPage.title}</h1>
<Link href="/admin/gutscheine/neu" className="bg-forest text-cream px-5 py-2 text-sm">
{t.adminVouchersPage.newVoucher}
</Link>
</div>
{error ? (
<p className="mb-6 text-sm text-red-700 bg-red-50 border border-red-200 px-4 py-3">{error}</p>
) : null}
<div className="overflow-x-auto bg-background border border-ink/10">
<table className="w-full text-sm">
<thead className="text-left text-ink/65 border-b border-ink/10">
<tr>
<th className="p-4">{t.adminVouchersPage.colCode}</th>
<th className="p-4">{t.adminVouchersPage.colDiscount}</th>
<th className="p-4">{t.adminVouchersPage.colMinOrder}</th>
<th className="p-4">{t.adminVouchersPage.colMinQuantity}</th>
<th className="p-4">{t.adminVouchersPage.colUsage}</th>
<th className="p-4">{t.adminVouchersPage.colValidity}</th>
<th className="p-4">{t.adminVouchersPage.colStatus}</th>
<th className="p-4" />
</tr>
</thead>
<tbody className="divide-y divide-ink/10">
{codes.map((code) => (
<tr key={code.id} className="transition-colors hover:bg-ink/[0.03]">
<td className="p-4 text-forest font-mono">{code.code}</td>
<td className="p-4">
{code.type === "PERCENT" ? `${code.value} %` : formatPrice(code.value)}
</td>
<td className="p-4">{code.minOrderCents > 0 ? formatPrice(code.minOrderCents) : "—"}</td>
<td className="p-4">{code.minQuantity !== null ? code.minQuantity : "—"}</td>
<td className="p-4">
{code.usedCount}
{code.maxUses !== null ? ` / ${code.maxUses}` : ""}
</td>
<td className="p-4 whitespace-nowrap">
{code.validFrom ? formatDate(code.validFrom) : t.adminVouchersPage.immediately} –{" "}
{code.validUntil ? formatDate(code.validUntil) : t.adminVouchersPage.unlimited}
</td>
<td className="p-4">
{code.isActive ? (
<span className="text-forest">{t.adminVouchersPage.statusActive}</span>
) : (
<span className="text-ink/65">{t.adminVouchersPage.statusInactive}</span>
)}
</td>
<td className="p-4">
<div className="flex items-center gap-3 whitespace-nowrap">
<Link href={`/admin/gutscheine/${code.id}`} className="text-forest underline">
{t.adminVouchersPage.edit}
</Link>
<ConfirmForm
action={deleteDiscountCodeAction}
confirmMessage={t.adminVouchersPage.deleteConfirm(code.code)}
>
<input type="hidden" name="id" value={code.id} />
<button type="submit" className="text-red-700 underline">
{t.adminVouchersPage.delete}
</button>
</ConfirmForm>
</div>
</td>
</tr>
))}
</tbody>
</table>
{codes.length === 0 ? <p className="p-6 text-ink/65">{t.adminVouchersPage.noVouchersYet}</p> : null}
</div>
</div>
);
}