diff --git a/app/admin/support/[id]/page.tsx b/app/admin/support/[id]/page.tsx index 103d1b4e..6589d745 100644 --- a/app/admin/support/[id]/page.tsx +++ b/app/admin/support/[id]/page.tsx @@ -15,7 +15,8 @@ import { User, Calendar, MessageSquare, - Save + Save, + Send } from 'lucide-react' import { toast } from 'sonner' import Link from 'next/link' @@ -47,6 +48,8 @@ export default function TicketDetailPage() { const [loading, setLoading] = useState(true) const [updating, setUpdating] = useState(false) const [notes, setNotes] = useState('') + const [reply, setReply] = useState('') + const [sendingReply, setSendingReply] = useState(false) useEffect(() => { fetchTicket() @@ -94,6 +97,59 @@ export default function TicketDetailPage() { } } + const sendReply = async () => { + if (!reply.trim()) { + toast.error('Please enter a reply message') + return + } + + setSendingReply(true) + try { + const response = await fetch(`/api/admin/support/tickets/${ticketId}/reply`, { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ message: reply }), + }) + + if (response.ok) { + toast.success('Reply sent successfully!') + setReply('') + + // Update status to "in_progress" if it's "open" + if (ticket?.status === 'open') { + try { + const statusResponse = await fetch(`/api/admin/support/tickets/${ticketId}`, { + method: 'PATCH', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ status: 'in_progress' }), + }) + + if (statusResponse.ok) { + toast.success('Status updated to In Progress') + } else { + console.error('Failed to update status') + toast.error('Reply sent, but failed to update status') + } + } catch (statusError) { + console.error('Error updating status:', statusError) + toast.error('Reply sent, but failed to update status') + } + } + + // Refresh ticket data + await fetchTicket() + } else { + const error = await response.json() + toast.error(error.error || 'Failed to send reply') + } + } catch (error) { + console.error('Error sending reply:', error) + toast.error('Failed to send reply') + } finally { + setSendingReply(false) + } + } + const getStatusColor = (status: string) => { switch (status) { case 'open': return 'bg-red-500/10 text-red-400 border-red-500/20' @@ -179,6 +235,56 @@ export default function TicketDetailPage() { + {/* Reply to User */} + + + + + Reply to User + + + Send a response directly to {ticket.user?.email || 'the user'} + + + +