"use client"; import { useRouter } from "next/navigation"; import { useState } from "react"; import { searchActiveEmployees, type EmployeeSearchResult } from "@/actions/employees"; import { staffPositionInternally } from "@/actions/positions"; import { Lookup } from "@/components/ui/Lookup"; import { Modal } from "@/components/ui/Modal"; import { useToast } from "@/components/ui/Toast"; type StaffInternallyModalProps = { open: boolean; onClose: () => void; positionId: string; positionTitle: string; isLead: boolean; }; export function StaffInternallyModal({ open, onClose, positionId, positionTitle, isLead }: StaffInternallyModalProps) { const { showToast } = useToast(); const router = useRouter(); const [employee, setEmployee] = useState(null); const [pending, setPending] = useState(false); async function handleSubmit() { if (!employee) return; setPending(true); const result = await staffPositionInternally({ position_id: positionId, employee_id: employee.id }); setPending(false); if (result.success) { showToast(`${employee.first_name} ${employee.last_name} wurde intern besetzt.`); router.refresh(); onClose(); setEmployee(null); } else { showToast(result.error ?? "Fehler beim Besetzen.", "error"); } } return ( } >

Position: {positionTitle}

{isLead && (
Dies ist eine Führungsposition: Das gesamte Team wird der ausgewählten Person unterstellt.
)}
{!employee ? ( placeholder="Name oder Titel…" onSearch={searchActiveEmployees} onSelect={setEmployee} renderResult={(e) => (
{e.first_name} {e.last_name}
{e.job_title}
)} /> ) : (
{employee.first_name} {employee.last_name}
{employee.job_title}
)}
); }