// /opt/erp-system/app/tickets/page.tsx 'use client'; import { useState, useEffect } from 'react'; import { useSession } from "next-auth/react"; import { Ticket as TicketIcon, Plus, X } from 'lucide-react'; import { getStatusBadge, getPriorityBadge } from '../components/AppShell'; import { useToast } from '../components/ToastProvider'; export default function TicketsPage() { const { data: session } = useSession(); const [tickets, setTickets] = useState([]); const [customers, setCustomers] = useState([]); const [filter, setFilter] = useState<'ALL' | 'MINE' | 'OPEN'>('ALL'); // States für das Formular const [showForm, setShowForm] = useState(false); const [formData, setFormData] = useState({ title: '', description: '', customerId: '', priority: 'MEDIUM' }); const { toast } = useToast(); useEffect(() => { fetchTickets(); fetchCustomers(); }, []); const fetchTickets = async () => { const res = await fetch('/api/tickets'); if (res.ok) setTickets(await res.json()); }; const fetchCustomers = async () => { const res = await fetch('/api/customers'); if (res.ok) { const data = await res.json(); setCustomers(data); if (data.length > 0) { setFormData(prev => ({ ...prev, customerId: data[0].id.toString() })); } } }; const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); const res = await fetch('/api/tickets', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(formData) }); if (res.ok) { setShowForm(false); setFormData({ title: '', description: '', customerId: customers[0]?.id.toString() || '', priority: 'MEDIUM' }); fetchTickets(); toast('Ticket erfolgreich erstellt', 'success'); } else { toast('Fehler beim Erstellen des Tickets', 'error'); } }; // getStatusBadge is imported from AppShell // Filter-Logik const filteredTickets = tickets.filter(t => { if (filter === 'OPEN') return t.status === 'OPEN' || t.status === 'IN_PROGRESS'; if (filter === 'MINE') return t.assignedToId === parseInt((session?.user as any)?.id); return true; }); return (
{/* Header */}

Ticketsystem

{/* Neues Ticket Formular */} {showForm && (

Neues Ticket erfassen

setFormData({...formData, title: e.target.value})} placeholder="Kurze Beschreibung des Problems..." />