forked from fahrPool/fahrPool
60 lines
1.6 KiB
TypeScript
60 lines
1.6 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,
|
|
startTyp = "ab_sofort",
|
|
startZeitpunkt,
|
|
}: {
|
|
vorbefuelltesDatum: string;
|
|
startTyp?: ZeitplanungTyp;
|
|
startZeitpunkt?: string;
|
|
}) {
|
|
const [typ, setTyp] = useState<ZeitplanungTyp>(startTyp);
|
|
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={startZeitpunkt ?? vorbefuelltesDatum}
|
|
className={FIELD_CLASSES}
|
|
/>
|
|
</FormField>
|
|
)}
|
|
</>
|
|
);
|
|
}
|