"use client"; import { useQuery } from "@tanstack/react-query"; import { api } from "@/lib/api"; import type { Case } from "@/lib/types"; import Link from "next/link"; import { useSearchParams, useRouter } from "next/navigation"; import { Breadcrumb } from "@/components/layout/Breadcrumb"; import { Plus, Search, FolderOpen } from "lucide-react"; import { useState } from "react"; import { SkeletonTable } from "@/components/ui/Skeleton"; import { EmptyState } from "@/components/ui/EmptyState"; import { usePermissions } from "@/lib/hooks/usePermissions"; const STATUS_OPTIONS = [ { value: "", label: "Alle Status" }, { value: "active", label: "Aktiv" }, { value: "pending", label: "Anhängig" }, { value: "closed", label: "Geschlossen" }, { value: "archived", label: "Archiviert" }, ]; const TYPE_OPTIONS = [ { value: "", label: "Alle Typen" }, { value: "INF", label: "Verletzungsklage" }, { value: "REV", label: "Widerruf" }, { value: "CCR", label: "Einstweilige Verfügung" }, { value: "APP", label: "Berufung" }, { value: "PI", label: "Vorläufiger Rechtsschutz" }, { value: "ZPO_CIVIL", label: "ZPO Zivilverfahren" }, ]; const STATUS_BADGE: Record = { active: "bg-emerald-50 text-emerald-700", pending: "bg-amber-50 text-amber-700", closed: "bg-neutral-100 text-neutral-600", archived: "bg-neutral-100 text-neutral-400", }; const STATUS_LABEL: Record = { active: "Aktiv", pending: "Anhängig", closed: "Geschlossen", archived: "Archiviert", }; const inputClass = "rounded-md border border-neutral-200 bg-white px-2.5 py-1.5 text-sm outline-none transition-colors focus:border-neutral-400 focus:ring-1 focus:ring-neutral-400"; export default function CasesPage() { const router = useRouter(); const searchParams = useSearchParams(); const { can } = usePermissions(); const canCreateCase = can("create_case"); const [search, setSearch] = useState(searchParams.get("search") ?? ""); const [status, setStatus] = useState(searchParams.get("status") ?? ""); const [type, setType] = useState(searchParams.get("type") ?? ""); const { data, isLoading } = useQuery({ queryKey: ["cases", { search, status, type }], queryFn: () => { const params = new URLSearchParams(); if (search) params.set("search", search); if (status) params.set("status", status); if (type) params.set("type", type); params.set("limit", "50"); const qs = params.toString(); return api.get<{ cases: Case[]; total: number }>( `/cases${qs ? `?${qs}` : ""}`, ); }, }); const cases = Array.isArray(data?.cases) ? data.cases : []; return (

Akten

{data ? `${data.total} Akten` : "\u00A0"}

{canCreateCase && ( Neue Akte )}
setSearch(e.target.value)} className={`w-full pl-9 pr-3 ${inputClass}`} />
{isLoading ? ( ) : cases.length === 0 ? ( Neue Akte anlegen ) : undefined } /> ) : (
{cases.map((c) => ( router.push(`/cases/${c.id}`)} className="cursor-pointer transition-colors hover:bg-neutral-50" > ))}
Aktenzeichen Titel Typ Gericht Status Erstellt
{c.case_number} {c.title} {c.case_type ?? "-"} {c.court ?? "-"} {STATUS_LABEL[c.status] ?? c.status} {new Date(c.created_at).toLocaleDateString("de-DE")}
)}
); }