"use client"; import { useEffect, useState } from "react"; import { CalendarPlus, Pencil, X } from "lucide-react"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Textarea } from "@/components/ui/textarea"; export interface AuditFormValues { id: string; type: "INTERNAL" | "EXTERNAL"; title: string; plannedDate: string | null; scope: string | null; assessmentLevel: string | null; provider: string | null; auditorUserId: string | null; interval: string | null; } /** * Popup zum Anlegen bzw. Bearbeiten eines Audits (V5A). Overlay-/Karten-Optik bewusst * identisch zum bestehenden `Modal`/`Popup`. Der Typ (intern/extern) schaltet lokal die * jeweils passenden Felder frei: extern → Assessment-Level + Prüfdienstleister, * intern → Auditor + Turnus. Gespeichert wird über die als `action` übergebene * Server-Action (`createAudit` bzw. `updateAudit.bind(null, id)`), die anschließend * navigiert (Redirect) — daher kein manuelles Schließen nach dem Submit nötig. */ export function AuditDialog({ action, users, audit, mode, }: { action: (formData: FormData) => void | Promise; users: { id: string; name: string | null }[]; audit?: AuditFormValues; mode: "create" | "edit"; }) { const [open, setOpen] = useState(false); const [type, setType] = useState<"INTERNAL" | "EXTERNAL">(audit?.type ?? "EXTERNAL"); const initialInterval = audit?.interval ?? ""; useEffect(() => { if (!open) return; const onKey = (e: KeyboardEvent) => { if (e.key === "Escape") setOpen(false); }; document.addEventListener("keydown", onKey); const prev = document.body.style.overflow; document.body.style.overflow = "hidden"; return () => { document.removeEventListener("keydown", onKey); document.body.style.overflow = prev; }; }, [open]); const isExternal = type === "EXTERNAL"; const selectCls = "h-8 w-full rounded-md border border-input bg-background px-2 text-[12.5px]"; const labelCls = "mb-1 block text-[12px] font-medium text-muted-foreground"; return ( <> {mode === "create" ? ( ) : ( )} {open && (
{ if (e.target === e.currentTarget) setOpen(false); }} >

{mode === "create" ? "Neues Audit planen" : "Audit bearbeiten"}

Intern = anlegen & terminieren. Extern = Vorbereitung im Wizard.

{/* Typ */}
Audit-Typ
{(["INTERNAL", "EXTERNAL"] as const).map((v) => ( ))}
{isExternal ? (
) : (
)}
{isExternal ? (
) : (
)}