1
0
Fork 0

feat: pro Schadensfoto eine optionale Freitext-Beschreibung erfassen und anzeigen

This commit is contained in:
Jonny 2026-09-03 12:42:04 +02:00
parent 002601f1e5
commit 803b726bea
4 changed files with 63 additions and 30 deletions

View File

@ -5,6 +5,7 @@ import { createClient } from "@/lib/supabase/server";
import { validateFahrtBeginn, validateFahrtEnde } from "@/lib/auftraege/validate-fahrt";
import { STANDARD_FOTO_POSITIONEN } from "@/lib/auftraege/foto-positionen";
import { loadProfile } from "@/lib/auth/profile";
import { parseSchadenUploads } from "@/lib/auftraege/schaden-upload";
export async function uebernehmen(auftragId: string): Promise<void> {
const supabase = await createClient();
@ -51,7 +52,7 @@ export async function fahrtBeginnen(auftragId: string, formData: FormData): Prom
uploads.push({ position, file });
}
}
const schadenFiles = formData.getAll("foto_schaden").filter((f): f is File => f instanceof File && f.size > 0);
const schadenUploads = parseSchadenUploads(formData);
const validation = validateFahrtBeginn({
startKm: formData.get("start_km"),
@ -95,9 +96,10 @@ export async function fahrtBeginnen(auftragId: string, formData: FormData): Prom
}
}
for (let i = 0; i < schadenFiles.length; i++) {
for (let i = 0; i < schadenUploads.length; i++) {
const { file, beschreibung } = schadenUploads[i];
const path = `${auftragId}/schaden-${Date.now()}-${i}.jpg`;
const { error: uploadError } = await supabase.storage.from("auftrag-fotos").upload(path, schadenFiles[i]);
const { error: uploadError } = await supabase.storage.from("auftrag-fotos").upload(path, file);
if (uploadError) {
redirect(
`/auftraege/${auftragId}?error=${encodeURIComponent(`Foto-Upload fehlgeschlagen: ${uploadError.message}`)}`
@ -105,7 +107,7 @@ export async function fahrtBeginnen(auftragId: string, formData: FormData): Prom
}
const { error: fotoError } = await supabase
.from("auftrag_fotos")
.insert({ auftrag_id: auftragId, position: "schaden", storage_path: path, uploaded_by: user.id });
.insert({ auftrag_id: auftragId, position: "schaden", storage_path: path, uploaded_by: user.id, beschreibung });
if (fotoError) {
redirect(
`/auftraege/${auftragId}?error=${encodeURIComponent(`Foto-Speichern fehlgeschlagen: ${fotoError.message}`)}`
@ -140,9 +142,9 @@ export async function schadenFotoNachtragen(auftragId: string, formData: FormDat
redirect("/login");
}
const schadenFiles = formData.getAll("foto_schaden").filter((f): f is File => f instanceof File && f.size > 0);
const schadenUploads = parseSchadenUploads(formData);
if (schadenFiles.length === 0) {
if (schadenUploads.length === 0) {
redirect(`/auftraege/${auftragId}?error=${encodeURIComponent("Bitte mindestens ein Schadensfoto auswaehlen.")}`);
}
@ -152,9 +154,10 @@ export async function schadenFotoNachtragen(auftragId: string, formData: FormDat
// geprueft. Kein Statuswechsel und keine Pflichtfoto-Validierung hier --
// diese Aktion darf laut Spec jederzeit waehrend der Fahrt (status =
// 'unterwegs', aber auch weiterhin 'zugewiesen') Schadensfotos nachtragen.
for (let i = 0; i < schadenFiles.length; i++) {
for (let i = 0; i < schadenUploads.length; i++) {
const { file, beschreibung } = schadenUploads[i];
const path = `${auftragId}/schaden-${Date.now()}-${i}.jpg`;
const { error: uploadError } = await supabase.storage.from("auftrag-fotos").upload(path, schadenFiles[i]);
const { error: uploadError } = await supabase.storage.from("auftrag-fotos").upload(path, file);
if (uploadError) {
redirect(
`/auftraege/${auftragId}?error=${encodeURIComponent(`Foto-Upload fehlgeschlagen: ${uploadError.message}`)}`
@ -162,7 +165,7 @@ export async function schadenFotoNachtragen(auftragId: string, formData: FormDat
}
const { error: fotoError } = await supabase
.from("auftrag_fotos")
.insert({ auftrag_id: auftragId, position: "schaden", storage_path: path, uploaded_by: user.id });
.insert({ auftrag_id: auftragId, position: "schaden", storage_path: path, uploaded_by: user.id, beschreibung });
if (fotoError) {
redirect(
`/auftraege/${auftragId}?error=${encodeURIComponent(`Foto-Speichern fehlgeschlagen: ${fotoError.message}`)}`

View File

@ -6,6 +6,7 @@ import { loadProfile } from "@/lib/auth/profile";
import { STANDARD_FOTO_POSITIONEN } from "@/lib/auftraege/foto-positionen";
import { loadAuftragFotos } from "@/lib/auftraege/fotos";
import { FotoGalerie } from "@/components/auftraege/FotoGalerie";
import { SchadenFotoFelder } from "@/components/auftraege/SchadenFotoFelder";
import { uebernehmen, fahrtBeginnen, schadenFotoNachtragen, fahrtBeenden, stornieren } from "./actions";
import { Card } from "@/components/ui/Card";
import { StatusBadge } from "@/components/ui/StatusBadge";
@ -167,16 +168,7 @@ export default async function AuftragDetailPage({
/>
</FormField>
))}
<FormField label="Schadensfotos (optional, mehrere möglich)" htmlFor="foto_schaden">
<input
id="foto_schaden"
name="foto_schaden"
type="file"
accept="image/*"
multiple
className={FIELD_CLASSES}
/>
</FormField>
<SchadenFotoFelder />
<Button type="submit">Fahrt beginnen</Button>
</form>
</Card>
@ -198,17 +190,7 @@ export default async function AuftragDetailPage({
<Card className="mb-6">
<form action={schadenFotoNachtragenAction}>
<h2 className="mb-4 text-lg font-semibold text-asphalt-grey">Schadensfoto nachtragen</h2>
<FormField label="Schadensfotos (mehrere möglich)" htmlFor="foto_schaden_nachtrag">
<input
id="foto_schaden_nachtrag"
name="foto_schaden"
type="file"
accept="image/*"
multiple
required
className={FIELD_CLASSES}
/>
</FormField>
<SchadenFotoFelder />
<Button type="submit">Foto nachtragen</Button>
</form>
</Card>

View File

@ -58,6 +58,11 @@ export function FotoGalerie({ fotos }: { fotos: AuftragFoto[] }) {
className="pointer-events-auto max-h-[80vh] max-w-[90vw] rounded-md object-contain"
/>
<p className="pointer-events-none text-white">{offenesFoto.label}</p>
{offenesFoto.beschreibung && (
<p className="pointer-events-none max-w-[90vw] text-center text-sm text-white/80">
{offenesFoto.beschreibung}
</p>
)}
<a href={offenesFoto.downloadUrl} className={`${buttonClasses("secondary", false)} pointer-events-auto`}>
Download
</a>

View File

@ -0,0 +1,43 @@
"use client";
import { useState } from "react";
import { FormField, FIELD_CLASSES } from "@/components/ui/FormField";
import { buttonClasses } from "@/components/ui/Button";
export function SchadenFotoFelder() {
const [zeilen, setZeilen] = useState<number[]>([0]);
return (
<div className="mb-4 flex flex-col gap-4">
{zeilen.map((index) => (
<div key={index} className="rounded-md border border-aluminium-grey p-3">
<FormField label={`Schadensfoto ${index + 1} (optional)`} htmlFor={`foto_schaden_${index}`}>
<input
id={`foto_schaden_${index}`}
name={`foto_schaden_${index}`}
type="file"
accept="image/*"
className={FIELD_CLASSES}
/>
</FormField>
<FormField label="Beschreibung (optional)" htmlFor={`foto_schaden_${index}_beschreibung`}>
<input
id={`foto_schaden_${index}_beschreibung`}
name={`foto_schaden_${index}_beschreibung`}
type="text"
placeholder="z. B. Kratzer hintere Stoßstange"
className={FIELD_CLASSES}
/>
</FormField>
</div>
))}
<button
type="button"
onClick={() => setZeilen((prev) => [...prev, prev.length])}
className={buttonClasses("secondary", false)}
>
Weiteres Schadensfoto hinzufügen
</button>
</div>
);
}