forked from fahrPool/fahrPool
feat: add Fahrer-Auswaehler dialog for Disponent/Admin assignment
This commit is contained in:
parent
3f77f10520
commit
d873d6d97b
|
|
@ -0,0 +1,44 @@
|
|||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { Card } from "@/components/ui/Card";
|
||||
import { Button } from "@/components/ui/Button";
|
||||
import { FIELD_CLASSES } from "@/components/ui/FormField";
|
||||
|
||||
export function FahrerAuswaehler({
|
||||
fahrerListe,
|
||||
onBestaetigen,
|
||||
onAbbrechen,
|
||||
}: {
|
||||
fahrerListe: { id: string; name: string }[];
|
||||
onBestaetigen: (fahrerId: string) => void;
|
||||
onAbbrechen: () => void;
|
||||
}) {
|
||||
const [ausgewaehlt, setAusgewaehlt] = useState("");
|
||||
|
||||
return (
|
||||
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4">
|
||||
<Card className="w-full max-w-sm">
|
||||
<h2 className="mb-4 text-base font-semibold text-asphalt-grey">Fahrer auswählen</h2>
|
||||
<select value={ausgewaehlt} onChange={(e) => setAusgewaehlt(e.target.value)} className={FIELD_CLASSES}>
|
||||
<option value="" disabled>
|
||||
Bitte waehlen
|
||||
</option>
|
||||
{fahrerListe.map((fahrer) => (
|
||||
<option key={fahrer.id} value={fahrer.id}>
|
||||
{fahrer.name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<div className="mt-4 flex gap-3">
|
||||
<Button type="button" disabled={!ausgewaehlt} onClick={() => ausgewaehlt && onBestaetigen(ausgewaehlt)}>
|
||||
Zuweisen
|
||||
</Button>
|
||||
<Button type="button" variant="secondary" onClick={onAbbrechen}>
|
||||
Abbrechen
|
||||
</Button>
|
||||
</div>
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
@ -15,10 +15,11 @@ import type { AuftragStatus } from "@/lib/auftraege/queries";
|
|||
import type { KanbanAuftrag, KanbanSpalten } from "@/lib/dashboard/queries";
|
||||
import type { Role } from "@/lib/auth/roles";
|
||||
import { istDragErlaubt } from "@/lib/dashboard/kanban-permissions";
|
||||
import { uebernehmenVomBoard, stornierenVomBoard } from "@/app/dashboard/actions";
|
||||
import { uebernehmenVomBoard, stornierenVomBoard, zuweisenAnFahrer } from "@/app/dashboard/actions";
|
||||
import { Card } from "@/components/ui/Card";
|
||||
import { StatusBadge } from "@/components/ui/StatusBadge";
|
||||
import { Alert } from "@/components/ui/Alert";
|
||||
import { FahrerAuswaehler } from "./FahrerAuswaehler";
|
||||
|
||||
const SPALTEN_REIHENFOLGE: AuftragStatus[] = ["offen", "zugewiesen", "unterwegs", "abgeschlossen", "storniert"];
|
||||
|
||||
|
|
@ -84,6 +85,7 @@ export type ZuweisenDialogState = { auftragId: string; quelle: AuftragStatus } |
|
|||
|
||||
export function KanbanBoard({
|
||||
initialSpalten,
|
||||
fahrerListe,
|
||||
rolle,
|
||||
}: {
|
||||
initialSpalten: KanbanSpalten;
|
||||
|
|
@ -136,6 +138,19 @@ export function KanbanBoard({
|
|||
}
|
||||
}
|
||||
|
||||
async function bestaetigeZuweisung(fahrerId: string) {
|
||||
if (!zuweisenDialog) return;
|
||||
const { auftragId, quelle } = zuweisenDialog;
|
||||
setZuweisenDialog(null);
|
||||
verschiebeKarteLokal(auftragId, quelle, "zugewiesen");
|
||||
|
||||
const ergebnis = await zuweisenAnFahrer(auftragId, fahrerId);
|
||||
if (!ergebnis.success) {
|
||||
macheRueckgaengig(auftragId, quelle, "zugewiesen");
|
||||
setFehler(ergebnis.error);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
{fehler && (
|
||||
|
|
@ -150,7 +165,13 @@ export function KanbanBoard({
|
|||
))}
|
||||
</div>
|
||||
</DndContext>
|
||||
{/* Fahrer-Auswaehler-Dialog fuer zuweisenDialog wird in Task 6 ergaenzt. */}
|
||||
{zuweisenDialog && (
|
||||
<FahrerAuswaehler
|
||||
fahrerListe={fahrerListe}
|
||||
onBestaetigen={bestaetigeZuweisung}
|
||||
onAbbrechen={() => setZuweisenDialog(null)}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue