Alle Anlege- und Bearbeiten-Formulare nutzen jetzt die Bausteine aus components/admin-form.tsx wie das Produktformular: Rahmen mit fester Speicherleiste, Abschnitte mit Serif-Ueberschrift (Gutschein: Code und Rabatt / Bedingungen / Zeitraum und Status; Ernte: Angaben / Bilder / Sichtbarkeit; Charge: Abfuellung und Bestand / Bilder), Schalter statt Checkbox, buendige Eingabefelder in Rastern. Benutzer bearbeiten: Sicherheitsbereich mit Status-Badges, Passwort-Reset als Sekundaerknopf, Sperren/Loeschen in eigenem abgesetzten Bereich. AdminField/AdminSelect koennen jetzt min und einen Hinweistext. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
81 lines
3.3 KiB
TypeScript
81 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 { Button } from "@/components/ui";
|
|
import { AdminImageField } from "@/components/admin-image-field";
|
|
import { AdminField, AdminFieldset, AdminFormPanel } from "@/components/admin-form";
|
|
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 tb = t.adminBatchEditPage;
|
|
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-2xl">
|
|
<BackLink href="/admin/chargen" label={tb.backToBatches} />
|
|
<h1 className="text-2xl text-forest mb-2">{tb.title}</h1>
|
|
<p className="text-sm text-ink/65 mb-8">
|
|
{batch.code} · {batch.harvest.type} {batch.harvest.year}
|
|
</p>
|
|
|
|
<AdminFormPanel action={updateBatchAction} actions={<Button type="submit">{tb.save}</Button>}>
|
|
<input type="hidden" name="id" value={batch.id} />
|
|
<AdminFieldset legend={tb.sectionDetails}>
|
|
<div className="grid grid-cols-2 items-end gap-4">
|
|
<AdminField
|
|
name="fillDate"
|
|
label={tb.fillDateLabel}
|
|
type="date"
|
|
defaultValue={batch.fillDate.toISOString().slice(0, 10)}
|
|
required
|
|
/>
|
|
<AdminField
|
|
name="bestBeforeDate"
|
|
label={tb.bestBeforeDateLabel}
|
|
type="date"
|
|
defaultValue={batch.bestBeforeDate.toISOString().slice(0, 10)}
|
|
required
|
|
/>
|
|
</div>
|
|
<div className="grid grid-cols-2 items-end gap-4">
|
|
<AdminField
|
|
name="glassCount"
|
|
label={tb.glassCountLabel}
|
|
type="number"
|
|
min={0}
|
|
defaultValue={String(batch.glassCount)}
|
|
required
|
|
/>
|
|
<AdminField
|
|
name="remainingGlasses"
|
|
label={tb.remainingGlassesLabel}
|
|
type="number"
|
|
min={0}
|
|
defaultValue={String(batch.remainingGlasses)}
|
|
required
|
|
/>
|
|
</div>
|
|
</AdminFieldset>
|
|
|
|
{/* Zwei einzeln setzbare Slots statt einer Liste: die Position
|
|
entscheidet, welche Kachel auf /charge/[code] gefuellt wird.
|
|
Beide tragen denselben Feldnamen "images" und werden in dieser
|
|
Reihenfolge uebermittelt (siehe imageSlots() in
|
|
admin/actions/harvests-batches.ts). Ein leerer Slot faellt auf
|
|
das entsprechende Erntebild zurueck. */}
|
|
<AdminFieldset legend={tb.imagesLabel} last>
|
|
<AdminImageField name="images" label={tb.image1Label} initialValue={batch.images[0] ?? ""} />
|
|
<AdminImageField name="images" label={tb.image2Label} initialValue={batch.images[1] ?? ""} />
|
|
</AdminFieldset>
|
|
</AdminFormPanel>
|
|
</div>
|
|
);
|
|
}
|