forked from fahrPool/fahrPool
110 lines
3.4 KiB
TypeScript
110 lines
3.4 KiB
TypeScript
import Link from "next/link";
|
|
import type { Fahrzeug, Ort } from "@/lib/auftraege/queries";
|
|
import type { ZeitplanungTyp } from "@/lib/auftraege/zeitplanung";
|
|
import { fahrzeugBezeichnung } from "@/lib/orte-fahrzeuge/fahrzeug-bezeichnung";
|
|
import { FormField, FIELD_CLASSES } from "@/components/ui/FormField";
|
|
import { ZeitplanungFeld } from "@/components/auftraege/ZeitplanungFeld";
|
|
|
|
export type AuftragStammWerte = {
|
|
abholortId?: string;
|
|
zielortId?: string;
|
|
fahrzeugId?: string;
|
|
auftragsnummer?: string;
|
|
zeitplanungTyp?: ZeitplanungTyp;
|
|
zeitplanungZeitpunkt?: string;
|
|
};
|
|
|
|
const LINK_CLASSES = "mb-4 inline-flex min-h-11 items-center text-sm text-performance-blue hover:underline";
|
|
|
|
// Gemeinsame Felder fuer "Auftrag anlegen" und "Auftrag bearbeiten". Formular
|
|
// und Absende-Knopf bleiben in der jeweiligen Seite.
|
|
export function AuftragStammFelder({
|
|
orte,
|
|
fahrzeuge,
|
|
werte,
|
|
vorbefuelltesDatum,
|
|
neuLinks,
|
|
nummerLabel,
|
|
}: {
|
|
orte: Ort[];
|
|
fahrzeuge: Fahrzeug[];
|
|
werte: AuftragStammWerte;
|
|
vorbefuelltesDatum: string;
|
|
neuLinks: { abholort: string; zielort: string; fahrzeug: string } | null;
|
|
nummerLabel: string;
|
|
}) {
|
|
return (
|
|
<>
|
|
<FormField label="Abholort" htmlFor="abholort_id">
|
|
<select id="abholort_id" name="abholort_id" required defaultValue={werte.abholortId ?? ""} className={FIELD_CLASSES}>
|
|
<option value="" disabled>
|
|
Bitte waehlen
|
|
</option>
|
|
{orte.map((ort) => (
|
|
<option key={ort.id} value={ort.id}>
|
|
{ort.adresse} ({ort.ansprechpartner})
|
|
</option>
|
|
))}
|
|
</select>
|
|
</FormField>
|
|
{neuLinks && (
|
|
<Link href={neuLinks.abholort} className={LINK_CLASSES}>
|
|
+ Neuer Abholort
|
|
</Link>
|
|
)}
|
|
|
|
<FormField label="Zielort" htmlFor="zielort_id">
|
|
<select id="zielort_id" name="zielort_id" required defaultValue={werte.zielortId ?? ""} className={FIELD_CLASSES}>
|
|
<option value="" disabled>
|
|
Bitte waehlen
|
|
</option>
|
|
{orte.map((ort) => (
|
|
<option key={ort.id} value={ort.id}>
|
|
{ort.adresse} ({ort.ansprechpartner})
|
|
</option>
|
|
))}
|
|
</select>
|
|
</FormField>
|
|
{neuLinks && (
|
|
<Link href={neuLinks.zielort} className={LINK_CLASSES}>
|
|
+ Neuer Zielort
|
|
</Link>
|
|
)}
|
|
|
|
<FormField label="Fahrzeug" htmlFor="fahrzeug_id">
|
|
<select id="fahrzeug_id" name="fahrzeug_id" required defaultValue={werte.fahrzeugId ?? ""} className={FIELD_CLASSES}>
|
|
<option value="" disabled>
|
|
Bitte waehlen
|
|
</option>
|
|
{fahrzeuge.map((fahrzeug) => (
|
|
<option key={fahrzeug.id} value={fahrzeug.id}>
|
|
{fahrzeugBezeichnung(fahrzeug)}
|
|
</option>
|
|
))}
|
|
</select>
|
|
</FormField>
|
|
{neuLinks && (
|
|
<Link href={neuLinks.fahrzeug} className={LINK_CLASSES}>
|
|
+ Neues Fahrzeug
|
|
</Link>
|
|
)}
|
|
|
|
<ZeitplanungFeld
|
|
vorbefuelltesDatum={vorbefuelltesDatum}
|
|
startTyp={werte.zeitplanungTyp}
|
|
startZeitpunkt={werte.zeitplanungZeitpunkt}
|
|
/>
|
|
|
|
<FormField label={nummerLabel} htmlFor="auftragsnummer">
|
|
<input
|
|
id="auftragsnummer"
|
|
name="auftragsnummer"
|
|
type="text"
|
|
defaultValue={werte.auftragsnummer ?? ""}
|
|
className={FIELD_CLASSES}
|
|
/>
|
|
</FormField>
|
|
</>
|
|
);
|
|
}
|