Files
Wabenhain/src/app/admin/chargen/[id]/page.tsx
T
Nick SzaunigandClaude Sonnet 5 7d5c172487
Docker Image bauen und veroeffentlichen / build-and-push (push) Successful in 2m21s
feat: eigene Bilder pro Charge
Chargen hatten bisher kein eigenes Bild-Feld (nur Ernten und Produkte) —
neue Migration ergaenzt Batch.images (Json-Array, gleiches Muster wie
Harvest.images/Product.images). Admin kann Chargenfotos jetzt unter
/admin/chargen/[id] hochladen (AdminImageListField, identisch zum
Ernten-Formular). Die oeffentliche Chargen-Seite (/charge/[code]) zeigt
diese Fotos jetzt bevorzugt, faellt ohne eigene Chargenbilder weiterhin
auf die Erntebilder zurueck.

Hinweis fuer den naechsten Live-Deploy: die generierte Migration hat
nebenbei eine bereits laenger bestehende Schema-Abweichung mitkorrigiert
(harvests.images und products.images/tasteTags werden jetzt als NOT NULL
erzwungen, wie im Schema schon laenger deklariert) - "prisma migrate
deploy" schlaegt fehl, falls dort noch echte NULL-Werte stehen sollten.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
2026-09-12 04:08:39 +02:00

82 lines
3.3 KiB
TypeScript

import { notFound } from "next/navigation";
import { prisma } from "@/lib/prisma";
import { asStringArray } from "@/lib/json-array";
import { BackLink } from "@/components/back-link";
import { AdminImageListField } from "@/components/admin-image-list-field";
import { updateBatchAction } from "../../actions";
import { getLocale } from "@/i18n/locale";
import { getDictionary } from "@/i18n/get-dictionary";
export default async function AdminBatchEditPage(props: PageProps<"/admin/chargen/[id]">) {
const t = getDictionary(await getLocale());
const { id } = await props.params;
const rawBatch = await prisma.batch.findUnique({ where: { id }, include: { harvest: true } });
if (!rawBatch) notFound();
const batch = { ...rawBatch, images: asStringArray(rawBatch.images) };
return (
<div className="max-w-xl">
<BackLink href="/admin/chargen" label={t.adminBatchEditPage.backToBatches} />
<h1 className="text-2xl text-forest mb-2">{t.adminBatchEditPage.title}</h1>
<p className="text-sm text-ink/65 mb-8">
{batch.code} · {batch.harvest.type} {batch.harvest.year}
</p>
<form action={updateBatchAction} className="space-y-4 bg-background border border-ink/10 p-6">
<input type="hidden" name="id" value={batch.id} />
<div className="grid grid-cols-2 gap-4">
<label className="block text-sm">
<span className="text-ink/70">{t.adminBatchEditPage.fillDateLabel}</span>
<input
name="fillDate"
type="date"
defaultValue={batch.fillDate.toISOString().slice(0, 10)}
required
className="mt-1 w-full border border-ink/20 bg-background px-3 py-2"
/>
</label>
<label className="block text-sm">
<span className="text-ink/70">{t.adminBatchEditPage.bestBeforeDateLabel}</span>
<input
name="bestBeforeDate"
type="date"
defaultValue={batch.bestBeforeDate.toISOString().slice(0, 10)}
required
className="mt-1 w-full border border-ink/20 bg-background px-3 py-2"
/>
</label>
</div>
<div className="grid grid-cols-2 gap-4">
<label className="block text-sm">
<span className="text-ink/70">{t.adminBatchEditPage.glassCountLabel}</span>
<input
name="glassCount"
type="number"
defaultValue={batch.glassCount}
required
className="mt-1 w-full border border-ink/20 bg-background px-3 py-2"
/>
</label>
<label className="block text-sm">
<span className="text-ink/70">{t.adminBatchEditPage.remainingGlassesLabel}</span>
<input
name="remainingGlasses"
type="number"
defaultValue={batch.remainingGlasses}
required
className="mt-1 w-full border border-ink/20 bg-background px-3 py-2"
/>
</label>
</div>
<AdminImageListField
name="images"
label={t.adminBatchEditPage.imagesLabel}
initialValues={batch.images}
/>
<button type="submit" className="bg-forest text-cream px-6 py-2 text-sm">
{t.adminBatchEditPage.save}
</button>
</form>
</div>
);
}