Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 | 'use client'; /** * TicketDetail - Full ticket view with messages */ import React, { useState } from 'react'; import Link from 'next/link'; import { SupportTicketWithRelations } from '@/types/support'; import { TICKET_STATUS_CONFIG, TICKET_PRIORITY_CONFIG, TICKET_CATEGORY_CONFIG } from '@/constants/support'; import MessageThread from './MessageThread'; import SurveyForm from './SurveyForm'; import { Icon } from '@/components/ui/icons'; export interface TicketDetailProps { /** The ticket to display */ ticket: SupportTicketWithRelations; /** Handler for sending new messages */ onSendMessage: (content: string) => Promise<void>; /** Handler for closing the ticket */ onCloseTicket: () => Promise<void>; /** Whether actions are loading */ isLoading?: boolean; /** Show survey prompt */ showSurvey?: boolean; } export default function TicketDetail({ ticket, onSendMessage, onCloseTicket, isLoading = false, showSurvey = false}: TicketDetailProps) { const [showCloseConfirm, setShowCloseConfirm] = useState(false); const statusConfig = TICKET_STATUS_CONFIG[ticket.status]; const priorityConfig = TICKET_PRIORITY_CONFIG[ticket.priority]; const categoryConfig = TICKET_CATEGORY_CONFIG[ticket.category]; const canClose = ['OPEN', 'IN_PROGRESS', 'AWAITING_CUSTOMER', 'AWAITING_AGENT', 'RESOLVED'].includes( ticket.status ); const canMessage = !['CLOSED', 'CANCELLED'].includes(ticket.status); const isResolved = ['RESOLVED', 'CLOSED'].includes(ticket.status); const formatDate = (date: Date) => { return new Date(date).toLocaleDateString('en-US', { weekday: 'short', month: 'short', day: 'numeric', year: 'numeric', hour: 'numeric', minute: '2-digit'}); }; return ( <div className="max-w-4xl mx-auto"> {/* Back Link */} <Link href="/support/tickets" className="inline-flex items-center gap-1 text-gray-600 hover:text-gray-900 mb-6" > <Icon name="chevron-left" size={16} /> Back to Tickets </Link> {/* Ticket Header */} <div className="bg-white rounded-lg border border-gray-200 p-6 mb-6"> {/* Status Badges */} <div className="flex flex-wrap items-center gap-2 mb-4"> <span className="text-sm font-medium text-gray-500">{ticket.ticketNumber}</span> <span className={`px-2 py-0.5 text-xs font-medium rounded-full ${statusConfig.bgColor} ${statusConfig.color}`} > {statusConfig.label} </span> <span className={`px-2 py-0.5 text-xs font-medium rounded-full ${priorityConfig.bgColor} ${priorityConfig.color}`} > {priorityConfig.label} </span> <span className="px-2 py-0.5 text-xs font-medium rounded-full bg-gray-100 text-gray-600"> {categoryConfig.label} </span> </div> {/* Subject */} <h1 className="text-2xl font-bold text-gray-900 mb-4">{ticket.subject}</h1> {/* Meta Info */} <div className="flex flex-wrap gap-6 text-sm text-gray-500 mb-4"> <span>Created: {formatDate(ticket.createdAt)}</span> <span>Updated: {formatDate(ticket.updatedAt)}</span> {ticket.resolvedAt && <span>Resolved: {formatDate(ticket.resolvedAt)}</span>} </div> {/* Description */} <div className="prose prose-sm max-w-none"> <p className="whitespace-pre-wrap">{ticket.description}</p> </div> {/* Related Items */} {(ticket.order || ticket.product) && ( <div className="mt-4 pt-4 border-t border-gray-100 flex flex-wrap gap-4 text-sm"> {ticket.order && ( <Link href={`/account/orders/${ticket.order.id}`} className="text-blue-600 hover:text-blue-700" > View Order #{ticket.order.id} </Link> )} {ticket.product && ( <Link href={`/product/${ticket.product.id}`} className="text-blue-600 hover:text-blue-700" > View Product: {ticket.product.title} </Link> )} </div> )} {/* Actions */} {canClose && ( <div className="mt-6 pt-4 border-t border-gray-100"> {!showCloseConfirm ? ( <button type="button" onClick={() => setShowCloseConfirm(true)} className="text-sm text-gray-500 hover:text-gray-700" > Close this ticket </button> ) : ( <div className="flex items-center gap-4"> <span className="text-sm text-gray-600"> Are you sure you want to close this ticket? </span> <button type="button" onClick={onCloseTicket} disabled={isLoading} className="px-3 py-1 text-sm bg-gray-100 text-gray-700 rounded hover:bg-gray-200" > Yes, close it </button> <button type="button" onClick={() => setShowCloseConfirm(false)} className="text-sm text-gray-500 hover:text-gray-700" > Cancel </button> </div> )} </div> )} </div> {/* Survey Form (for resolved tickets) */} {isResolved && showSurvey && !ticket.survey && ( <SurveyForm ticketId={ticket.id} /> )} {/* Message Thread */} <div className="bg-white rounded-lg border border-gray-200"> <div className="p-4 border-b border-gray-200"> <h2 className="text-lg font-semibold text-gray-900">Conversation</h2> </div> <MessageThread messages={ticket.messages || []} onSendMessage={canMessage ? onSendMessage : undefined} isLoading={isLoading} /> </div> </div> ); } |