'use client' import { useState } from 'react' import { Escalation, priorityColors, priorityLabels, statusColors, statusLabels, categoryLabels, formatDate } from './types' interface DrawerProps { escalation: Escalation onClose: () => void onUpdated: () => void } export function EscalationDetailDrawer({ escalation, onClose, onUpdated }: DrawerProps) { const [editAssignee, setEditAssignee] = useState(escalation.assignee || '') const [editPriority, setEditPriority] = useState(escalation.priority) const [editDueDate, setEditDueDate] = useState( escalation.due_date ? escalation.due_date.slice(0, 10) : '' ) const [saving, setSaving] = useState(false) const [statusSaving, setStatusSaving] = useState(false) const [isDeleting, setIsDeleting] = useState(false) async function handleDeleteEscalation() { if (!window.confirm(`Eskalation "${escalation.title}" wirklich löschen?`)) return setIsDeleting(true) try { const res = await fetch(`/api/sdk/v1/escalations/${escalation.id}`, { method: 'DELETE' }) if (!res.ok) throw new Error(`Fehler: ${res.status}`) onUpdated() onClose() } catch (err) { console.error('Löschen fehlgeschlagen:', err) alert('Löschen fehlgeschlagen.') } finally { setIsDeleting(false) } } async function handleSaveEdit() { setSaving(true) try { await fetch(`/api/sdk/v1/escalations/${escalation.id}`, { method: 'PUT', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ assignee: editAssignee || null, priority: editPriority, due_date: editDueDate || null, }), }) onUpdated() } finally { setSaving(false) } } async function handleStatusChange(newStatus: string) { setStatusSaving(true) try { await fetch(`/api/sdk/v1/escalations/${escalation.id}/status`, { method: 'PUT', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ status: newStatus }), }) onUpdated() onClose() } finally { setStatusSaving(false) } } return (
{priorityLabels[escalation.priority]} {statusLabels[escalation.status]} {escalation.category && ( {categoryLabels[escalation.category] || escalation.category} )}

{escalation.title}

{escalation.description && (

Beschreibung

{escalation.description}

)}
Erstellt

{formatDate(escalation.created_at)}

{escalation.reporter && (
Gemeldet von

{escalation.reporter}

)} {escalation.source_module && (
Quell-Modul

{escalation.source_module}

)} {escalation.resolved_at && (
Geloest am

{formatDate(escalation.resolved_at)}

)}

Bearbeiten

setEditAssignee(e.target.value)} className="w-full border border-gray-300 rounded-lg px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-purple-500" placeholder="Name oder Team" />
setEditDueDate(e.target.value)} className="w-full border border-gray-300 rounded-lg px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-purple-500" />

Status-Aktionen

{escalation.status === 'open' && ( )} {escalation.status === 'in_progress' && ( )} {(escalation.status === 'escalated' || escalation.status === 'in_progress') && ( )} {escalation.status === 'resolved' && ( )} {escalation.status === 'closed' && (

Eskalation ist geschlossen.

)}
) }