"use client"; import { Plus, Trash2 } from "lucide-react"; import { useRouter } from "next/navigation"; import { useState } from "react"; import { deletePosition } from "@/actions/positions"; import { Button } from "@/components/ui/Button"; import { useToast } from "@/components/ui/Toast"; import { fmtDate, todayIso } from "@/lib/format"; import type { OpenPositionResolved } from "@/lib/positions"; import { CreatePositionModal, type UnitOption } from "./CreatePositionModal"; type OpenPositionWithDays = OpenPositionResolved & { daysOpen: number }; type PositionsPageClientProps = { openPositions: OpenPositionWithDays[]; units: UnitOption[]; }; export function PositionsPageClient({ openPositions, units }: PositionsPageClientProps) { const { showToast } = useToast(); const router = useRouter(); const [createOpen, setCreateOpen] = useState(false); const [deletingId, setDeletingId] = useState(null); const today = todayIso(); async function handleDelete(id: string) { setDeletingId(id); const result = await deletePosition(id); setDeletingId(null); if (result.success) { showToast("Planstelle entfernt."); router.refresh(); } else { showToast(result.error ?? "Fehler beim Löschen.", "error"); } } return (

Unbesetzte Planstellen ({openPositions.length})

{openPositions.length === 0 ? (

Derzeit ist jede Planstelle besetzt.

) : (
{openPositions.map((p) => { const notYetValid = p.valid_from > today; return (
{p.title}
{p.position_number} · {p.orgLabel}
{p.is_chief ? "Leitungsplanstelle · " : ""} seit {p.daysOpen} Tagen unbesetzt
{p.managerName &&
berichtet an {p.managerName}
} {notYetValid &&
Gültig ab {fmtDate(p.valid_from)}
}
); })}
)}
setCreateOpen(false)} units={units} />
); }