1
0
Fork 0
fahrPool/web/components/auftraege/ZeitplanungFeld.tsx

52 lines
1.5 KiB
TypeScript

"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<ZeitplanungTyp, string> = {
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<ZeitplanungTyp>("ab_sofort");
const zeigeZeitpunkt = typ === "am" || typ === "ab";
return (
<>
<FormField label="Zeitplanung" htmlFor="zeitplanung_typ">
<select
id="zeitplanung_typ"
name="zeitplanung_typ"
required
value={typ}
onChange={(event) => setTyp(event.target.value as ZeitplanungTyp)}
className={FIELD_CLASSES}
>
{ZEITPLANUNG_TYPEN.map((wert) => (
<option key={wert} value={wert}>
{LABELS[wert]}
</option>
))}
</select>
</FormField>
{zeigeZeitpunkt && (
<FormField label="Datum und Uhrzeit" htmlFor="zeitplanung_zeitpunkt">
<input
id="zeitplanung_zeitpunkt"
name="zeitplanung_zeitpunkt"
type="datetime-local"
required
defaultValue={vorbefuelltesDatum}
className={FIELD_CLASSES}
/>
</FormField>
)}
</>
);
}