From 0863d5d9b9fe6df26652990bf11c31abff3b2639 Mon Sep 17 00:00:00 2001 From: Jonny Date: Thu, 20 Aug 2026 20:00:16 +0200 Subject: [PATCH] feat: Zeitplanung-Auswahl beim Anlegen eines Auftrags Neuer ZeitplanungFeld-Client-Komponente zeigt Datum/Uhrzeit-Feld nur fuer die Zeitplanungstypen "am"/"ab" an und wird auf der Auftrag- Neu-Seite eingebunden. createAuftrag validiert und speichert zeitplanung_typ/zeitplanung_zeitpunkt, mit serverseitiger Pruefung vor dem Insert. --- web/app/auftraege/neu/actions.ts | 18 +++++++ web/app/auftraege/neu/page.tsx | 5 ++ web/components/auftraege/ZeitplanungFeld.tsx | 51 ++++++++++++++++++++ 3 files changed, 74 insertions(+) create mode 100644 web/components/auftraege/ZeitplanungFeld.tsx diff --git a/web/app/auftraege/neu/actions.ts b/web/app/auftraege/neu/actions.ts index 598cf81..0c7bbeb 100644 --- a/web/app/auftraege/neu/actions.ts +++ b/web/app/auftraege/neu/actions.ts @@ -6,6 +6,7 @@ import { validateOrt } from "@/lib/orte-fahrzeuge/validate-ort"; import { validateFahrzeug } from "@/lib/orte-fahrzeuge/validate-fahrzeug"; import { insertOrt, insertFahrzeug } from "@/lib/orte-fahrzeuge/mutations"; import { loadProfile } from "@/lib/auth/profile"; +import { ZEITPLANUNG_TYPEN, type ZeitplanungTyp } from "@/lib/auftraege/zeitplanung"; export async function createAuftrag(formData: FormData): Promise { const abholortId = formData.get("abholort_id"); @@ -16,6 +17,21 @@ export async function createAuftrag(formData: FormData): Promise { const auftragsnummer = typeof auftragsnummerRaw === "string" && auftragsnummerRaw.trim() ? auftragsnummerRaw.trim() : null; + const zeitplanungTypRaw = formData.get("zeitplanung_typ"); + const zeitplanungTyp = (ZEITPLANUNG_TYPEN as readonly string[]).includes(zeitplanungTypRaw as string) + ? (zeitplanungTypRaw as ZeitplanungTyp) + : "ab_sofort"; + + let zeitplanungZeitpunkt: string | null = null; + if (zeitplanungTyp === "am" || zeitplanungTyp === "ab") { + const zeitpunktRaw = formData.get("zeitplanung_zeitpunkt"); + const geparst = typeof zeitpunktRaw === "string" && zeitpunktRaw ? new Date(zeitpunktRaw) : null; + if (!geparst || Number.isNaN(geparst.getTime())) { + redirect(`/auftraege/neu?error=${encodeURIComponent("Bitte Datum und Uhrzeit fuer die Zeitplanung angeben.")}`); + } + zeitplanungZeitpunkt = geparst.toISOString(); + } + if (typeof abholortId !== "string" || !abholortId) { redirect(`/auftraege/neu?error=${encodeURIComponent("Bitte einen Abholort auswaehlen.")}`); } @@ -41,6 +57,8 @@ export async function createAuftrag(formData: FormData): Promise { fahrzeug_id: fahrzeugId, erstellt_von: user.id, auftragsnummer, + zeitplanung_typ: zeitplanungTyp, + zeitplanung_zeitpunkt: zeitplanungZeitpunkt, vorgaenger_auftrag_id: typeof vorgaengerAuftragId === "string" && vorgaengerAuftragId ? vorgaengerAuftragId : null, }); diff --git a/web/app/auftraege/neu/page.tsx b/web/app/auftraege/neu/page.tsx index 75791c5..ecb509f 100644 --- a/web/app/auftraege/neu/page.tsx +++ b/web/app/auftraege/neu/page.tsx @@ -7,6 +7,8 @@ import { Card } from "@/components/ui/Card"; import { Button } from "@/components/ui/Button"; import { Alert } from "@/components/ui/Alert"; import { FormField, FIELD_CLASSES } from "@/components/ui/FormField"; +import { ZeitplanungFeld } from "@/components/auftraege/ZeitplanungFeld"; +import { berechneVorbefuelltenZeitpunkt } from "@/lib/auftraege/zeitplanung"; function buildOrtFormularUrl( ziel: "abholort" | "zielort", @@ -66,6 +68,7 @@ export default async function NeuerAuftragPage({ const createOrtFuerAbholortAction = createOrtUndAuswaehlen.bind(null, "abholort"); const createOrtFuerZielortAction = createOrtUndAuswaehlen.bind(null, "zielort"); + const vorbefuelltesDatum = berechneVorbefuelltenZeitpunkt(); return (
@@ -261,6 +264,8 @@ export default async function NeuerAuftragPage({ + Neues Fahrzeug + + diff --git a/web/components/auftraege/ZeitplanungFeld.tsx b/web/components/auftraege/ZeitplanungFeld.tsx new file mode 100644 index 0000000..898de29 --- /dev/null +++ b/web/components/auftraege/ZeitplanungFeld.tsx @@ -0,0 +1,51 @@ +"use client"; + +import { useState } from "react"; +import { FormField, FIELD_CLASSES } from "@/components/ui/FormField"; +import { ZEITPLANUNG_TYPEN, type ZeitplanungTyp } from "@/lib/auftraege/zeitplanung"; + +const LABELS: Record = { + ab_sofort: "Ab sofort", + am: "Am (fester Termin)", + ab: "Ab (frühestens ab)", + diese_woche: "Diese Woche", + sobald_moeglich: "Sobald als möglich", +}; + +export function ZeitplanungFeld({ vorbefuelltesDatum }: { vorbefuelltesDatum: string }) { + const [typ, setTyp] = useState("ab_sofort"); + const zeigeZeitpunkt = typ === "am" || typ === "ab"; + + return ( + <> + + + + {zeigeZeitpunkt && ( + + + + )} + + ); +}