Spaces:
Paused
Paused
Download frontend/apps/customer/src/components/ThreadView.tsx from 3SCError404/nexus: direct link, hf CLI and curl.
- Browser
- Download file 41.9 kB
-
https://huggingface.co/spaces/3SCError404/nexus/resolve/main/frontend/apps/customer/src/components/ThreadView.tsx
- Command line
-
hf download hf://spaces/3SCError404/nexus/frontend/apps/customer/src/components/ThreadView.tsx
-
curl -L -o ThreadView.tsx https://huggingface.co/spaces/3SCError404/nexus/resolve/main/frontend/apps/customer/src/components/ThreadView.tsx
41.9 kB
| import React, { useState, useEffect, useRef } from 'react'; | |
| import { StatusBadge, PriorityBadge } from './Badges'; | |
| import { api, NexusMarkdown, getFileIcon, getStorageKey } from '@nexus/shared'; | |
| const COLORS = { | |
| brand: "var(--primary)", | |
| brandLight: "rgba(99, 102, 241, 0.1)", | |
| border: "var(--border-subtle)", | |
| bg: "var(--bg-dark)", | |
| card: "var(--bg-card)", | |
| text: "var(--text-main)", | |
| muted: "var(--text-muted)", | |
| success: "var(--success)", | |
| warning: "var(--warning)", | |
| error: "var(--error)", | |
| gray50: "rgba(255, 255, 255, 0.03)", | |
| gray200: "var(--border-subtle)", | |
| gray300: "rgba(255, 255, 255, 0.1)", | |
| gray400: "var(--text-muted)", | |
| gray600: "var(--text-muted)", | |
| gray700: "var(--text-main)", | |
| gray800: "var(--bg-dark)", | |
| gray900: "var(--text-main)", | |
| }; | |
| interface ThreadViewProps { | |
| ticket: any; | |
| onBack: () => void; | |
| onNavigate?: (ticket: any) => void; | |
| } | |
| export const ThreadView: React.FC<ThreadViewProps> = ({ ticket: initialTicket, onBack, onNavigate }) => { | |
| const [ticket, setTicket] = useState(initialTicket); | |
| const [messages, setMessages] = useState<any[]>([]); | |
| const [newMessage, setNewMessage] = useState(""); | |
| const [sending, setSending] = useState(false); | |
| // Description Edit State | |
| const [isEditingDesc, setIsEditingDesc] = useState(false); | |
| const [descDraft, setDescDraft] = useState(initialTicket.description); | |
| const [savingDesc, setSavingDesc] = useState(false); | |
| const [isUploading, setIsUploading] = useState(false); | |
| // Feedback States | |
| const [ratingDraft, setRatingDraft] = useState<number | null>(ticket.rating || null); | |
| const [hoverRating, setHoverRating] = useState<number | null>(null); | |
| const [commentDraft, setCommentDraft] = useState(""); | |
| const [isSubmittingFeedback, setIsSubmittingFeedback] = useState(false); | |
| const [showConfirmEscalate, setShowConfirmEscalate] = useState(false); | |
| // AI Regeneration States | |
| const [isRegeneratingSummary, setIsRegeneratingSummary] = useState(false); | |
| const [hasRegeneratedThisSession, setHasRegeneratedThisSession] = useState(false); | |
| const [isReopening, setIsReopening] = useState(false); | |
| // Sidebar States | |
| const [isSidebarOpen, setIsSidebarOpen] = useState(false); | |
| const [sidebarTab, setSidebarTab] = useState<'messages' | 'files'>('messages'); | |
| const bottomRef = useRef<HTMLDivElement>(null); | |
| const fileInputRef = useRef<HTMLInputElement>(null); | |
| useEffect(() => { | |
| refreshData(); | |
| }, [initialTicket.id]); | |
| // Real-time Summary Hydration Listener | |
| useEffect(() => { | |
| const token = localStorage.getItem(getStorageKey('token')); | |
| const user = JSON.parse(localStorage.getItem(getStorageKey('user')) || '{}'); | |
| if (token && user.workspace_id) { | |
| const ws = new WebSocket(api.defaults.baseURL?.replace('http', 'ws') + `ws/${user.workspace_id}?token=${token}`); | |
| ws.onmessage = (event) => { | |
| const data = JSON.parse(event.data); | |
| if (data.event === 'summary_updated' && data.ticket_id === ticket.id) { | |
| refreshData(); | |
| setIsRegeneratingSummary(false); | |
| } else if (data.event === 'ticket_updated' && data.ticket_id === ticket.id) { | |
| refreshData(); | |
| } | |
| }; | |
| return () => ws.close(); | |
| } | |
| }, [ticket.id]); | |
| useEffect(() => { | |
| bottomRef.current?.scrollIntoView({ behavior: 'smooth' }); | |
| }, [messages]); | |
| const refreshData = async () => { | |
| try { | |
| const [ticketResp, messagesResp] = await Promise.all([ | |
| api.get(`tickets/${initialTicket.id}/`), | |
| api.get(`tickets/${initialTicket.id}/messages/`) | |
| ]); | |
| setTicket(ticketResp.data); | |
| setDescDraft(ticketResp.data.description); | |
| setMessages(messagesResp.data); | |
| } catch (err) { | |
| console.error("Failed to refresh data:", err); | |
| } | |
| }; | |
| const handleSend = async () => { | |
| if (!newMessage.trim()) return; | |
| setSending(true); | |
| try { | |
| const resp = await api.post(`tickets/${ticket.id}/messages/`, { | |
| content: newMessage, | |
| is_internal: false | |
| }); | |
| setMessages([...messages, resp.data]); | |
| setNewMessage(""); | |
| } catch (err) { | |
| console.error("Failed to send message:", err); | |
| } finally { | |
| setSending(false); | |
| } | |
| }; | |
| const handleUpdateDescription = async () => { | |
| setSavingDesc(true); | |
| try { | |
| const resp = await api.patch(`tickets/${ticket.id}/`, { description: descDraft }); | |
| setTicket(resp.data); | |
| setIsEditingDesc(false); | |
| } catch (err) { | |
| console.error("Failed to update description:", err); | |
| } finally { | |
| setSavingDesc(false); | |
| } | |
| }; | |
| const handleRegenerateSummary = async () => { | |
| // Only allow once per session to honor rate limit requirement | |
| if (hasRegeneratedThisSession && !ticket.summary) return; | |
| setIsRegeneratingSummary(true); | |
| try { | |
| // Use the lightweight summarize endpoint | |
| await api.post(`tickets/${ticket.id}/summarize/`); | |
| setHasRegeneratedThisSession(true); | |
| } catch (err) { | |
| console.error("Failed to trigger summary:", err); | |
| setIsRegeneratingSummary(false); | |
| } | |
| }; | |
| const handleReopenDuplicate = async () => { | |
| if (!ticket?.id) return; | |
| setIsReopening(true); | |
| try { | |
| await api.post(`tickets/${ticket.id}/reopen-duplicate/`); | |
| // We force a refresh to pick up the new Open status and AI task signals | |
| window.location.reload(); | |
| } catch (err) { | |
| console.error("Reopen failed:", err); | |
| alert("Failed to reopen ticket. Please try again."); | |
| } finally { | |
| setIsReopening(false); | |
| } | |
| }; | |
| const handleEscalate = async () => { | |
| try { | |
| const resp = await api.post(`tickets/${ticket.id}/escalate/`); | |
| setTicket(resp.data); | |
| setShowConfirmEscalate(false); | |
| // Refresh messages to show the system notification | |
| const messagesResp = await api.get(`tickets/${ticket.id}/messages/`); | |
| setMessages(messagesResp.data); | |
| } catch (err) { | |
| console.error("Escalation failed:", err); | |
| alert("Failed to escalate ticket. It might already be escalated."); | |
| } | |
| }; | |
| const handleSubmitFeedback = async () => { | |
| if (!ratingDraft) return; | |
| setIsSubmittingFeedback(true); | |
| try { | |
| const resp = await api.post(`tickets/${ticket.id}/feedback/`, { | |
| rating: ratingDraft, | |
| comment: commentDraft | |
| }); | |
| setTicket({ ...ticket, rating: resp.data.rating }); | |
| alert("Thank you for your feedback!"); | |
| } catch (err) { | |
| console.error("Feedback submission failed:", err); | |
| alert("Failed to submit feedback."); | |
| } finally { | |
| setIsSubmittingFeedback(false); | |
| } | |
| }; | |
| const handlePaste = async (e: React.ClipboardEvent, isMainDesc: boolean) => { | |
| const items = e.clipboardData.items; | |
| let fileItem = null; | |
| for (let i = 0; i < items.length; i++) { | |
| if (items[i].kind === "file") { | |
| fileItem = items[i]; | |
| break; | |
| } | |
| } | |
| if (fileItem) { | |
| e.preventDefault(); | |
| const file = fileItem.getAsFile(); | |
| if (!file) return; | |
| await handleUpload(file, isMainDesc); | |
| } | |
| }; | |
| const handleUpload = async (file: File, isMainDesc: boolean) => { | |
| setIsUploading(true); | |
| const formData = new FormData(); | |
| formData.append("file", file); | |
| const isImage = file.type.startsWith("image/"); | |
| const placeholder = isImage | |
| ? `\n![Uploading ${file.name}...]()\n` | |
| : `\n[Uploading ${file.name}...]()\n`; | |
| if (isMainDesc) setDescDraft((curr: string) => curr + placeholder); | |
| else setNewMessage((curr: string) => curr + placeholder); | |
| try { | |
| const resp = await api.post(`tickets/${ticket.id}/attachments/`, formData, { | |
| headers: { 'Content-Type': 'multipart/form-data' } | |
| }); | |
| const backendBase = api.defaults.baseURL?.endsWith('/') ? api.defaults.baseURL : api.defaults.baseURL + '/'; | |
| const downloadUrl = `${backendBase}tickets/attachments/${resp.data.id}/download/`; | |
| let finalMarkdown = ""; | |
| if (isImage) { | |
| finalMarkdown = `\n\n`; | |
| } else { | |
| const icon = getFileIcon(file.name); | |
| finalMarkdown = `\n${icon} [${file.name}](${downloadUrl})\n`; | |
| } | |
| if (isMainDesc) setDescDraft((curr: string) => curr.replace(placeholder, finalMarkdown)); | |
| else setNewMessage((curr: string) => curr.replace(placeholder, finalMarkdown)); | |
| } catch (err) { | |
| console.error("Upload failed:", err); | |
| alert("Failed to upload file."); | |
| if (isMainDesc) setDescDraft((curr: string) => curr.replace(placeholder, "")); | |
| else setNewMessage((curr: string) => curr.replace(placeholder, "")); | |
| } finally { | |
| setIsUploading(false); | |
| } | |
| }; | |
| const formatETA = (dateStr: string) => { | |
| if (!dateStr) return "TBD"; | |
| const date = new Date(dateStr); | |
| return date.toLocaleString([], { month: 'short', day: 'numeric', hour: '2-digit', minute: '2-digit' }); | |
| }; | |
| return ( | |
| <div style={{ display: "flex", flexDirection: "column", height: "calc(100vh - 64px)", background: COLORS.bg, overflow: "hidden" }}> | |
| {/* Universal Sticky Header */} | |
| <div style={{ padding: "12px 32px", borderBottom: `1px solid ${COLORS.border}`, background: COLORS.card, display: "flex", alignItems: "center", gap: 16 }}> | |
| <button onClick={onBack} style={{ background: "rgba(255,255,255,0.05)", border: `1px solid ${COLORS.border}`, borderRadius: 8, padding: "6px 14px", fontSize: 13, cursor: "pointer", color: COLORS.text, fontWeight: 700 }}>← Back</button> | |
| <div style={{ flex: 1 }}> | |
| <h1 style={{ fontSize: 16, fontWeight: 800, margin: 0, color: COLORS.text, fontFamily: 'var(--font-header)' }}>{ticket.title}</h1> | |
| <div style={{ display: "flex", gap: 10, alignItems: "center", marginTop: 4 }}> | |
| <span style={{ fontSize: 10, color: COLORS.brand, fontWeight: 800, fontFamily: "monospace", background: "rgba(99, 102, 241, 0.1)", padding: "2px 8px", borderRadius: 4, letterSpacing: '0.05em' }}>{ticket.id.slice(0, 8)}</span> | |
| <StatusBadge status={ticket.status} /> | |
| <PriorityBadge priority={ticket.priority} /> | |
| </div> | |
| </div> | |
| <div style={{ display: 'flex', gap: 12, alignItems: 'center' }}> | |
| {ticket.is_escalated && ( | |
| <div style={{ | |
| display: 'flex', alignItems: 'center', gap: 8, padding: '6px 14px', | |
| background: '#be123c', color: '#fff', borderRadius: 8, fontSize: 11, | |
| fontWeight: 900, letterSpacing: '0.05em', boxShadow: '0 4px 12px rgba(190, 18, 60, 0.2)', | |
| animation: 'pulse 2s infinite' | |
| }}> | |
| <span style={{ fontSize: 14 }}>🚨</span> CASE ESCALATED | |
| </div> | |
| )} | |
| {!ticket.is_escalated && !['RESOLVED', 'CLOSED'].includes((ticket.status || '').toUpperCase()) && ( | |
| <div style={{ display: "flex", gap: 8 }}> | |
| {showConfirmEscalate ? ( | |
| <> | |
| <button onClick={() => setShowConfirmEscalate(false)} style={{ background: "rgba(255,255,255,0.05)", color: COLORS.text, border: `1px solid ${COLORS.border}`, borderRadius: 8, padding: "8px 16px", fontSize: 11, fontWeight: 800, cursor: "pointer" }}>CANCEL</button> | |
| <button onClick={handleEscalate} style={{ background: "#be123c", color: "#fff", border: "none", borderRadius: 8, padding: "8px 16px", fontSize: 11, fontWeight: 900, cursor: "pointer", boxShadow: "0 4px 12px rgba(190, 18, 60, 0.2)" }}>CONFIRM P0</button> | |
| </> | |
| ) : ( | |
| <button | |
| onClick={() => setShowConfirmEscalate(true)} | |
| style={{ | |
| background: "rgba(190, 18, 60, 0.1)", | |
| color: "#be123c", | |
| border: "1px solid #fda4af", | |
| borderRadius: 8, | |
| padding: "8px 16px", | |
| fontSize: 11, | |
| fontWeight: 800, | |
| cursor: "pointer", | |
| transition: 'all 0.2s' | |
| }} | |
| onMouseEnter={e => e.currentTarget.style.background = 'rgba(190, 18, 60, 0.15)'} | |
| onMouseLeave={e => e.currentTarget.style.background = 'rgba(190, 18, 60, 0.1)'} | |
| > | |
| ESCALATE CASE | |
| </button> | |
| )} | |
| </div> | |
| )} | |
| <button | |
| onClick={() => setIsSidebarOpen(!isSidebarOpen)} | |
| style={{ | |
| background: "var(--brand-gradient)", | |
| color: "#fff", | |
| border: "none", | |
| borderRadius: 8, | |
| padding: "8px 16px", | |
| fontSize: 11, | |
| fontWeight: 800, | |
| cursor: "pointer", | |
| display: "flex", | |
| alignItems: "center", | |
| gap: 8, | |
| transition: 'all 0.2s', | |
| boxShadow: '0 4px 10px rgba(109, 40, 217, 0.2)' | |
| }} | |
| > | |
| {isSidebarOpen ? "HIDE MESSAGES" : "SHOW MESSAGES"} | |
| </button> | |
| </div> | |
| </div> | |
| <div style={{ display: "flex", flex: 1, overflow: "hidden", position: "relative" }}> | |
| {/* Main Content Area (Detail Workstation) */} | |
| <div style={{ | |
| flex: 1, | |
| overflowY: "auto", | |
| padding: "40px", | |
| background: "#fff", | |
| transition: "all 0.3s cubic-bezier(0.4, 0, 0.2, 1)" | |
| }}> | |
| {ticket.is_escalated && ( | |
| <div style={{ | |
| marginBottom: 40, | |
| padding: "32px", | |
| background: "#fff1f2", | |
| borderRadius: 24, | |
| border: "1px solid #fda4af", | |
| display: "flex", | |
| alignItems: "center", | |
| gap: 20, | |
| boxShadow: "0 10px 30px -10px rgba(190, 18, 60, 0.1)" | |
| }}> | |
| <div style={{ width: 56, height: 56, borderRadius: 16, background: "#be123c", display: "flex", alignItems: "center", justifyContent: "center", fontSize: 24, boxShadow: "0 5px 15px rgba(190, 18, 60, 0.3)" }}>🚨</div> | |
| <div style={{ flex: 1 }}> | |
| <div style={{ fontSize: 13, fontWeight: 900, color: "#be123c", textTransform: "uppercase", letterSpacing: "0.15em", marginBottom: 6 }}>Urgent Escalation Status</div> | |
| <p style={{ fontSize: 15, color: '#9f1239', margin: 0, lineHeight: 1.6, fontWeight: 600 }}> | |
| Strategic intervention active. Workspace leads are monitoring this investigation. | |
| </p> | |
| </div> | |
| </div> | |
| )} | |
| {ticket.status === 'CLOSED' && ticket.duplicate_of_id && ( | |
| <div style={{ | |
| marginBottom: 40, | |
| padding: "24px 32px", | |
| background: COLORS.brandLight, | |
| borderRadius: 24, | |
| border: `1px solid ${COLORS.brand}`, | |
| display: "flex", | |
| alignItems: "center", | |
| gap: 20, | |
| boxShadow: "0 4px 20px rgba(99, 102, 241, 0.1)" | |
| }}> | |
| <div style={{ width: 40, height: 40, borderRadius: 12, background: COLORS.brand, display: "flex", alignItems: "center", justifyContent: "center", fontSize: 18 }}>🖇️</div> | |
| <div style={{ flex: 1 }}> | |
| <div style={{ fontSize: 11, fontWeight: 900, color: COLORS.brand, textTransform: "uppercase", letterSpacing: "0.1em", marginBottom: 2 }}>Duplicate Record Linked</div> | |
| <p style={{ fontSize: 14, color: COLORS.text, margin: 0, fontWeight: 600 }}> | |
| This ticket was marked as a duplicate of <span style={{ fontFamily: 'monospace', color: COLORS.brand }}>#{ticket.duplicate_of_id.slice(0, 8)}</span>. | |
| </p> | |
| </div> | |
| <button | |
| onClick={handleReopenDuplicate} | |
| disabled={isReopening} | |
| style={{ | |
| background: COLORS.brand, | |
| color: "#fff", | |
| border: "none", | |
| borderRadius: 10, | |
| padding: "10px 20px", | |
| fontSize: 11, | |
| fontWeight: 900, | |
| cursor: isReopening ? "default" : "pointer", | |
| transition: 'all 0.2s', | |
| boxShadow: '0 4px 12px rgba(99, 102, 241, 0.2)' | |
| }} | |
| > | |
| {isReopening ? "REOPENING..." : "NOT A DUPLICATE? REOPEN"} | |
| </button> | |
| </div> | |
| )} | |
| {/* Ticket Insights Grid */} | |
| <div style={{ display: "grid", gridTemplateColumns: "repeat(auto-fit, minmax(220px, 1fr))", gap: 24, marginBottom: 40 }}> | |
| <div style={{ padding: 20, border: `1px solid var(--border-subtle)`, borderRadius: 16, background: "#fff", boxShadow: '0 1px 3px rgba(0,0,0,0.02)' }}> | |
| <h3 style={{ fontSize: 10, fontWeight: 900, color: 'var(--text-muted)', textTransform: 'uppercase', letterSpacing: '0.15em', margin: '0 0 12px 0' }}>Ticket Priority</h3> | |
| <div style={{ display: "flex", alignItems: "center", gap: 10 }}> | |
| <div style={{ | |
| width: 10, height: 10, borderRadius: "50%", | |
| background: ticket.priority === "P0" ? "var(--error)" : ticket.priority === "P1" ? "var(--warning)" : "var(--primary)" | |
| }} /> | |
| <div style={{ fontSize: 14, fontWeight: 800, color: 'var(--text-main)' }}>{ticket.priority} · {ticket.priority === 'P0' ? 'Critical' : 'Standard'}</div> | |
| </div> | |
| </div> | |
| <div style={{ padding: 20, border: `1px solid var(--border-subtle)`, borderRadius: 16, background: "#fff", boxShadow: '0 1px 3px rgba(0,0,0,0.02)' }}> | |
| <h3 style={{ fontSize: 10, fontWeight: 900, color: 'var(--text-muted)', textTransform: 'uppercase', letterSpacing: '0.15em', margin: '0 0 12px 0' }}>Assignee</h3> | |
| <div style={{ display: "flex", alignItems: "center", gap: 10 }}> | |
| <div style={{ width: 24, height: 24, borderRadius: 6, background: "rgba(15, 23, 42, 0.05)", border: `1px solid var(--border-subtle)`, display: "flex", alignItems: "center", justifyContent: "center", fontSize: 10, fontWeight: 900, color: 'var(--primary)' }}>{ticket.assigned_name ? ticket.assigned_name[0] : "?"}</div> | |
| <div style={{ fontSize: 14, fontWeight: 800, color: 'var(--text-main)' }}>{ticket.assigned_name || "Nexus Tactical Team"}</div> | |
| </div> | |
| </div> | |
| <div style={{ padding: 20, border: `1px solid var(--border-subtle)`, borderRadius: 16, background: "#fff", boxShadow: '0 1px 3px rgba(0,0,0,0.02)' }}> | |
| <h3 style={{ fontSize: 10, fontWeight: 900, color: 'var(--text-muted)', textTransform: 'uppercase', letterSpacing: '0.15em', margin: '0 0 12px 0' }}>Estimated ETA</h3> | |
| <div style={{ fontSize: 14, fontWeight: 800, color: 'var(--text-main)' }}>{formatETA(ticket.expected_resolution_at)}</div> | |
| </div> | |
| </div> | |
| {/* AI Assessment Card */} | |
| {(ticket.summary || ticket.ai_metadata) ? ( | |
| <div style={{ | |
| background: ticket.summary ? "rgba(30, 64, 175, 0.03)" : "rgba(241, 245, 249, 0.5)", | |
| borderRadius: 24, | |
| border: `1px solid ${ticket.summary ? 'var(--border-subtle)' : '#e2e8f0'}`, | |
| padding: "32px", | |
| marginBottom: "40px", | |
| boxShadow: ticket.summary ? "0 10px 30px -10px rgba(30, 64, 175, 0.1)" : "none", | |
| position: 'relative', | |
| overflow: 'hidden' | |
| }}> | |
| <div style={{ | |
| position: 'absolute', top: 0, left: 0, width: 4, height: '100%', | |
| background: ticket.summary ? 'var(--primary)' : '#94a3b8', | |
| transition: 'background 0.3s' | |
| }} /> | |
| <div style={{ display: "flex", alignItems: "center", gap: 12, marginBottom: 16 }}> | |
| <span style={{ fontSize: 24, animation: ticket.summary ? "none" : "pulse 2s infinite" }}>{ticket.summary ? "✨" : "🧠"}</span> | |
| <h3 style={{ | |
| fontSize: 13, fontWeight: 900, margin: 0, | |
| color: ticket.summary ? 'var(--primary)' : '#64748b', | |
| textTransform: "uppercase", letterSpacing: "0.2em" | |
| }}> | |
| {isRegeneratingSummary ? "Neural Sync in Progress..." : (ticket.summary ? "Intelligence Summary" : "Analyzing Neural Context...")} | |
| </h3> | |
| {ticket.summary && ( | |
| <button | |
| onClick={handleRegenerateSummary} | |
| disabled={hasRegeneratedThisSession || isRegeneratingSummary} | |
| style={{ | |
| marginLeft: 'auto', | |
| padding: "4px 12px", | |
| background: hasRegeneratedThisSession ? "rgba(16, 185, 129, 0.1)" : "rgba(30, 64, 175, 0.05)", | |
| border: "none", | |
| borderRadius: 6, | |
| fontSize: 10, | |
| fontWeight: 900, | |
| color: hasRegeneratedThisSession ? "var(--success)" : "var(--primary)", | |
| cursor: hasRegeneratedThisSession ? "default" : "pointer", | |
| textTransform: "uppercase", | |
| letterSpacing: "0.1em", | |
| display: 'flex', | |
| alignItems: 'center', | |
| gap: 4 | |
| }} | |
| > | |
| {hasRegeneratedThisSession ? "✓ SYNCED" : (isRegeneratingSummary ? "SYNCING..." : "REGENERATE")} | |
| </button> | |
| )} | |
| </div> | |
| <p style={{ | |
| fontSize: 16, | |
| color: ticket.summary ? 'var(--text-main)' : 'var(--text-muted)', | |
| lineHeight: 1.8, margin: 0, | |
| fontWeight: 500, | |
| fontStyle: ticket.summary ? "normal" : "italic" | |
| }}> | |
| {ticket.summary || "Strategizing forensic analysis. Your automated summary will hydrate shortly as our neural nodes process the workspace signals..."} | |
| </p> | |
| </div> | |
| ) : ( | |
| /* Simplified fallback - Only show the manual trigger */ | |
| <div style={{ | |
| padding: "48px 32px", | |
| background: "rgba(30, 64, 175, 0.03)", | |
| borderRadius: 24, | |
| border: "1px dashed #bfdbfe", | |
| marginBottom: 40, | |
| textAlign: 'center', | |
| display: 'flex', | |
| flexDirection: 'column', | |
| alignItems: 'center', | |
| gap: 20, | |
| boxShadow: "inset 0 2px 4px rgba(30, 64, 175, 0.02)" | |
| }}> | |
| <div style={{ | |
| width: 56, height: 56, borderRadius: '50%', background: '#fff', | |
| display: 'flex', alignItems: 'center', justifyContent: 'center', | |
| fontSize: 24, boxShadow: '0 4px 12px rgba(30, 64, 175, 0.1)', | |
| animation: isRegeneratingSummary ? 'pulse 2s infinite' : 'none' | |
| }}>{isRegeneratingSummary ? "⚡" : "🧠"}</div> | |
| <button | |
| onClick={handleRegenerateSummary} | |
| disabled={isRegeneratingSummary} | |
| style={{ | |
| padding: "12px 32px", | |
| background: isRegeneratingSummary ? "#94a3b8" : "var(--primary)", | |
| color: "#fff", | |
| border: "none", | |
| borderRadius: 12, | |
| fontSize: 13, | |
| fontWeight: 800, | |
| cursor: isRegeneratingSummary ? "default" : "pointer", | |
| boxShadow: "0 4px 12px rgba(30, 64, 175, 0.2)", | |
| display: 'flex', | |
| alignItems: 'center', | |
| gap: 10, | |
| transition: 'all 0.2s' | |
| }} | |
| > | |
| {isRegeneratingSummary ? "Analyzing Neural Pathways..." : "🚀 Generate Quick Summary"} | |
| </button> | |
| </div> | |
| )} | |
| {/* Description Block */} | |
| <div style={{ background: "#fff", borderRadius: 20, padding: "32px", border: `1px solid var(--border-subtle)`, marginBottom: 40, boxShadow: "0 4px 20px rgba(0,0,0,0.03)" }}> | |
| <div style={{ display: "flex", justifyContent: "space-between", alignItems: "center", marginBottom: 24 }}> | |
| <h3 style={{ fontSize: 12, fontWeight: 900, margin: 0, color: 'var(--text-muted)', textTransform: "uppercase", letterSpacing: '0.15em' }}>Ticket Description</h3> | |
| {ticket.status !== 'closed' && ( | |
| <button | |
| onClick={() => setIsEditingDesc(!isEditingDesc)} | |
| style={{ background: "var(--brand-gradient)", color: '#fff', border: "none", fontSize: 10, fontWeight: 900, cursor: "pointer", padding: "8px 16px", borderRadius: 8, textTransform: "uppercase", letterSpacing: '0.1em' }} | |
| > | |
| {isEditingDesc ? "Abort Edit" : "Edit Details"} | |
| </button> | |
| )} | |
| </div> | |
| {isEditingDesc ? ( | |
| <div> | |
| <textarea | |
| value={descDraft} | |
| onChange={e => setDescDraft(e.target.value)} | |
| onPaste={e => handlePaste(e, true)} | |
| placeholder="Update forensic intelligence..." | |
| style={{ width: "100%", minHeight: 200, padding: 20, borderRadius: 16, border: `2px solid var(--primary)`, fontSize: 15, outline: "none", resize: "vertical", fontFamily: "inherit", background: "#f8fafc", color: 'var(--text-main)', lineHeight: 1.6 }} | |
| /> | |
| <div style={{ marginTop: 16, display: "flex", justifyContent: "flex-end", gap: 16 }}> | |
| <button | |
| onClick={handleUpdateDescription} | |
| disabled={savingDesc || isUploading} | |
| style={{ padding: "10px 24px", background: 'var(--primary)', color: "#fff", border: "none", borderRadius: 10, fontSize: 13, fontWeight: 800, cursor: "pointer", boxShadow: '0 4px 12px rgba(30, 64, 175, 0.2)' }} | |
| > | |
| {savingDesc ? "Syncing..." : "Sync intelligence"} | |
| </button> | |
| </div> | |
| </div> | |
| ) : ( | |
| <div style={{ fontSize: 16, color: 'var(--text-main)', lineHeight: 1.8 }}> | |
| <NexusMarkdown content={ticket.description} /> | |
| </div> | |
| )} | |
| </div> | |
| {/* Related Metadata Section */} | |
| <div style={{ display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(300px, 1fr))', gap: 32, marginBottom: 40 }}> | |
| {ticket.similar_articles && ticket.similar_articles.length > 0 && ( | |
| <div> | |
| <h3 style={{ fontSize: 11, fontWeight: 900, marginBottom: 16, color: 'var(--text-muted)', textTransform: 'uppercase', letterSpacing: '0.15em' }}>Recommended Protocols</h3> | |
| <div style={{ display: "flex", flexDirection: "column", gap: 12 }}> | |
| {ticket.similar_articles.map((art: any) => ( | |
| <a key={art.id} href={`/kb/${art.id}`} target="_blank" rel="noreferrer" style={{ padding: "16px", background: "#fff", border: `1px solid var(--border-subtle)`, borderRadius: 16, textDecoration: "none", display: "flex", justifyContent: "space-between", alignItems: "center", transition: "all 0.2s", boxShadow: '0 1px 2px rgba(0,0,0,0.02)' }}> | |
| <span style={{ fontSize: 14, fontWeight: 700, color: 'var(--text-main)' }}>{art.title}</span> | |
| <span style={{ fontSize: 11, color: 'var(--primary)', fontWeight: 900 }}>PROTOCOL →</span> | |
| </a> | |
| ))} | |
| </div> | |
| </div> | |
| )} | |
| {ticket.similar_tickets && ticket.similar_tickets.length > 0 && ( | |
| <div> | |
| <h3 style={{ fontSize: 11, fontWeight: 900, marginBottom: 16, color: 'var(--text-muted)', textTransform: 'uppercase', letterSpacing: '0.15em' }}>Similar Tickets Found</h3> | |
| <div style={{ display: "flex", flexDirection: "column", gap: 12 }}> | |
| {ticket.similar_tickets.map((sim: any) => ( | |
| <div key={sim.id} onClick={() => onNavigate?.({ id: sim.id })} style={{ padding: "16px", background: "#fff", border: `1px solid var(--border-subtle)`, borderRadius: 16, cursor: "pointer", display: "flex", justifyContent: "space-between", alignItems: "center", boxShadow: '0 1px 2px rgba(0,0,0,0.02)' }}> | |
| <span style={{ fontSize: 14, fontWeight: 700, color: 'var(--text-main)' }}>{sim.title}</span> | |
| <span style={{ fontSize: 10, color: 'var(--primary)', fontWeight: 900 }}>{(sim.similarity * 100).toFixed(0)}% BIOMETRIC MATCH</span> | |
| </div> | |
| ))} | |
| </div> | |
| </div> | |
| )} | |
| </div> | |
| {/* Resolution Details Block */} | |
| {(ticket.status?.toUpperCase() === 'RESOLVED' || ticket.status?.toUpperCase() === 'CLOSED') && ( | |
| <div style={{ | |
| background: "rgba(16, 185, 129, 0.05)", | |
| borderRadius: 24, | |
| padding: "32px", | |
| border: `1px solid var(--success)`, | |
| marginTop: "40px", | |
| boxShadow: "0 10px 30px -10px rgba(16, 185, 129, 0.1)" | |
| }}> | |
| <div style={{ display: "flex", justifyContent: "space-between", alignItems: "flex-start", marginBottom: 24 }}> | |
| <div> | |
| <h3 style={{ fontSize: 13, fontWeight: 900, margin: "0 0 8px 0", color: 'var(--success)', textTransform: "uppercase", letterSpacing: "0.15em" }}>Forensic Resolution Case</h3> | |
| <div style={{ fontSize: 12, color: 'var(--text-muted)' }}> | |
| Authenticated by <strong>{ticket.resolved_by_name || "Nexus Strategic Agent"}</strong> • {formatETA(ticket.resolved_at)} | |
| </div> | |
| </div> | |
| <div style={{ background: "rgba(16, 185, 129, 0.1)", color: 'var(--success)', padding: "6px 16px", borderRadius: "100px", fontSize: 10, fontWeight: 900 }}>FINALIZED</div> | |
| </div> | |
| <div style={{ | |
| fontSize: 15, | |
| color: 'var(--text-main)', | |
| lineHeight: 1.8, | |
| background: "#fff", | |
| padding: "24px", | |
| borderRadius: 16, | |
| border: `1px solid var(--border-subtle)` | |
| }}> | |
| <NexusMarkdown content={ticket.resolution_text || "Case finalized without specific notation."} /> | |
| </div> | |
| {/* Feedback Section */} | |
| <div style={{ marginTop: 32, paddingTop: 32, borderTop: `1px dashed var(--border-subtle)` }}> | |
| {ticket.rating ? ( | |
| <div style={{ display: "flex", alignItems: "center", gap: 12 }}> | |
| <div style={{ fontSize: 13, fontWeight: 900, color: 'var(--success)', textTransform: 'uppercase' }}>Service Rating:</div> | |
| <div style={{ display: "flex", gap: 4 }}> | |
| {[1, 2, 3, 4, 5].map(star => ( | |
| <span key={star} style={{ fontSize: 20, color: star <= ticket.rating ? "var(--warning)" : "rgba(0,0,0,0.05)" }}>★</span> | |
| ))} | |
| </div> | |
| </div> | |
| ) : ( | |
| <div> | |
| <div style={{ fontSize: 13, fontWeight: 900, color: 'var(--success)', marginBottom: 16, textTransform: 'uppercase' }}>Operational Feedback</div> | |
| <div style={{ display: "flex", alignItems: "center", gap: 20, flexWrap: "wrap" }}> | |
| <div style={{ display: "flex", gap: 6 }}> | |
| {[1, 2, 3, 4, 5].map(star => ( | |
| <button | |
| key={star} | |
| onMouseEnter={() => setHoverRating(star)} | |
| onMouseLeave={() => setHoverRating(null)} | |
| onClick={() => setRatingDraft(star)} | |
| style={{ | |
| background: "none", border: "none", padding: 0, cursor: "pointer", fontSize: 28, | |
| color: star <= (hoverRating || ratingDraft || 0) ? "var(--warning)" : "rgba(0,0,0,0.05)", | |
| transition: "transform 0.1s" | |
| }} | |
| > | |
| ★ | |
| </button> | |
| ))} | |
| </div> | |
| <input | |
| placeholder="Add strategic feedback..." | |
| value={commentDraft} | |
| onChange={(e) => setCommentDraft(e.target.value)} | |
| style={{ flex: 1, minWidth: 260, padding: "12px 16px", borderRadius: 12, border: `1px solid var(--border-subtle)`, fontSize: 14, background: "#f8fafc", color: 'var(--text-main)' }} | |
| /> | |
| <button | |
| onClick={handleSubmitFeedback} | |
| disabled={!ratingDraft || isSubmittingFeedback} | |
| style={{ | |
| background: ratingDraft ? 'var(--success)' : "rgba(0,0,0,0.05)", | |
| color: "#fff", border: "none", borderRadius: 10, padding: "12px 24px", fontSize: 12, fontWeight: 900, | |
| cursor: ratingDraft ? "pointer" : "default" | |
| }} | |
| > | |
| {isSubmittingFeedback ? "SYNCING..." : "SUBMIT FEEDBACK"} | |
| </button> | |
| </div> | |
| </div> | |
| )} | |
| </div> | |
| </div> | |
| )} | |
| </div> | |
| {/* Interaction Sidebar (Right Drawer) */} | |
| <aside style={{ | |
| width: isSidebarOpen ? 480 : 0, | |
| height: '100%', | |
| background: "#fff", | |
| borderLeft: `1px solid var(--border-subtle)`, | |
| display: "flex", | |
| flexDirection: "column", | |
| overflow: "hidden", | |
| transition: "all 0.3s cubic-bezier(0.4, 0, 0.2, 1)", | |
| position: 'relative' | |
| }}> | |
| {/* Sidebar Tabs */} | |
| <div style={{ display: "flex", background: "#f8fafc", borderBottom: `1px solid var(--border-subtle)` }}> | |
| <button | |
| onClick={() => setSidebarTab('messages')} | |
| style={{ | |
| flex: 1, padding: "16px", fontSize: 11, fontWeight: 900, | |
| color: sidebarTab === 'messages' ? 'var(--primary)' : 'var(--text-muted)', | |
| background: sidebarTab === 'messages' ? '#fff' : 'transparent', | |
| borderBottom: sidebarTab === 'messages' ? '3px solid var(--primary)' : '3px solid transparent', | |
| letterSpacing: '0.1em', cursor: 'pointer', transition: 'all 0.2s' | |
| }} | |
| >CONVERSATION</button> | |
| <button | |
| onClick={() => setSidebarTab('files')} | |
| style={{ | |
| flex: 1, padding: "16px", fontSize: 11, fontWeight: 900, | |
| color: sidebarTab === 'files' ? 'var(--primary)' : 'var(--text-muted)', | |
| background: sidebarTab === 'files' ? '#fff' : 'transparent', | |
| borderBottom: sidebarTab === 'files' ? '3px solid var(--primary)' : '3px solid transparent', | |
| letterSpacing: '0.1em', cursor: 'pointer', transition: 'all 0.2s' | |
| }} | |
| >VAULT ASSETS</button> | |
| </div> | |
| <div style={{ flex: 1, display: "flex", flexDirection: "column", overflow: "hidden" }}> | |
| {sidebarTab === 'messages' ? ( | |
| <> | |
| <div style={{ flex: 1, overflowY: "auto", padding: "32px", display: "flex", flexDirection: "column", gap: 24 }}> | |
| {messages.map((msg: any) => { | |
| const isMe = msg.sender_role?.toLowerCase() === 'customer' || !msg.sender_role; | |
| return ( | |
| <div key={msg.id} style={{ alignSelf: isMe ? "flex-end" : "flex-start", maxWidth: "85%" }}> | |
| <div style={{ | |
| background: isMe ? 'var(--primary)' : "#f1f5f9", | |
| color: isMe ? "#fff" : 'var(--text-main)', | |
| padding: "16px 20px", | |
| borderRadius: isMe ? "20px 20px 4px 20px" : "20px 20px 20px 4px", | |
| fontSize: 14, lineHeight: 1.6, boxShadow: "0 4px 12px rgba(0,0,0,0.05)" | |
| }}> | |
| <NexusMarkdown content={msg.content} /> | |
| </div> | |
| <div style={{ fontSize: 10, color: 'var(--text-muted)', marginTop: 8, textAlign: isMe ? 'right' : 'left', fontWeight: 800, textTransform: 'uppercase', letterSpacing: '0.05em' }}> | |
| {isMe ? "You" : msg.sender_name} • {new Date(msg.created_at).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })} | |
| </div> | |
| </div> | |
| ); | |
| })} | |
| <div ref={bottomRef} /> | |
| </div> | |
| <div style={{ padding: "24px", background: "#fff", borderTop: `1px solid var(--border-subtle)` }}> | |
| <textarea | |
| value={newMessage} | |
| onChange={e => setNewMessage(e.target.value)} | |
| placeholder="Type intelligence response..." | |
| style={{ width: "100%", minHeight: 100, padding: "16px", borderRadius: 16, border: `1px solid var(--border-subtle)`, fontSize: 14, outline: "none", resize: "none", background: "#f8fafc", fontFamily: "inherit" }} | |
| /> | |
| <div style={{ display: 'flex', justifyContent: 'space-between', marginTop: 16 }}> | |
| <input | |
| type="file" | |
| ref={fileInputRef} | |
| style={{ display: 'none' }} | |
| onChange={(e) => { | |
| const file = e.target.files?.[0]; | |
| if (file) handleUpload(file, false); | |
| }} | |
| /> | |
| <button onClick={() => fileInputRef.current?.click()} style={{ background: "#f8fafc", border: "1px solid var(--border-subtle)", borderRadius: 10, padding: "10px 16px", cursor: 'pointer' }}>📎</button> | |
| <button | |
| onClick={handleSend} | |
| disabled={!newMessage.trim() || sending} | |
| style={{ padding: "10px 32px", background: 'var(--primary)', color: "#fff", border: "none", borderRadius: 10, fontSize: 13, fontWeight: 800, cursor: 'pointer' }} | |
| >SEND</button> | |
| </div> | |
| </div> | |
| </> | |
| ) : ( | |
| <div style={{ padding: "32px", display: "flex", flexDirection: "column", gap: 16 }}> | |
| {(() => { | |
| const allAttachments = [ | |
| ...(ticket.attachments || []), | |
| ...messages.flatMap(m => m.attachments || []) | |
| ]; | |
| if (allAttachments.length === 0) { | |
| return <div style={{ textAlign: 'center', padding: "40px", color: 'var(--text-muted)', fontSize: 14 }}>Zero secure assets in vault.</div>; | |
| } | |
| const backendBase = api.defaults.baseURL?.endsWith('/') ? api.defaults.baseURL : api.defaults.baseURL + '/'; | |
| return allAttachments.map((att: any, i) => { | |
| const downloadUrl = `${backendBase}tickets/attachments/${att.id}/download/`; | |
| return ( | |
| <div | |
| key={i} | |
| onClick={() => { | |
| const token = localStorage.getItem(getStorageKey('token')); | |
| const authedUrl = `${downloadUrl}${token ? `?token=${encodeURIComponent(token)}` : ''}`; | |
| window.open(authedUrl, '_blank'); | |
| }} | |
| style={{ | |
| padding: "16px", | |
| background: "#f8fafc", | |
| borderRadius: 16, | |
| border: `1px solid var(--border-subtle)`, | |
| display: "flex", | |
| alignItems: "center", | |
| gap: 16, | |
| cursor: 'pointer', | |
| transition: 'all 0.2s' | |
| }} | |
| onMouseEnter={e => e.currentTarget.style.background = '#f1f5f9'} | |
| onMouseLeave={e => e.currentTarget.style.background = '#f8fafc'} | |
| > | |
| <span style={{ fontSize: 24 }}>{getFileIcon(att.filename)}</span> | |
| <div style={{ flex: 1 }}> | |
| <div style={{ fontSize: 13, fontWeight: 700, color: 'var(--text-main)' }}>{att.filename}</div> | |
| <div style={{ fontSize: 11, color: 'var(--text-muted)' }}>VAULT ASSET • CLICK TO VIEW</div> | |
| </div> | |
| </div> | |
| ); | |
| }); | |
| })()} | |
| </div> | |
| )} | |
| </div> | |
| </aside> | |
| </div> | |
| </div> | |
| ); | |
| }; | |