Spaces:
Paused
Paused
File size: 41,885 Bytes
5eb4857 ebf9e6f 5eb4857 fdde098 5eb4857 fb7ec09 4d5026d fb7ec09 bd0fa52 2d3abb8 bd0fa52 5eb4857 428a35c 5eb4857 fb7ec09 5eb4857 0d8550d 5eb4857 0d8550d 5eb4857 0d8550d 5eb4857 fb7ec09 2131f07 fb7ec09 2131f07 fb7ec09 2131f07 fb7ec09 4d5026d 5eb4857 0d8550d 5eb4857 0d8550d 5eb4857 0d8550d 5eb4857 428a35c 5eb4857 428a35c 5eb4857 428a35c 5eb4857 428a35c 064e635 428a35c 2131f07 428a35c 5eb4857 428a35c 5eb4857 fdde098 5eb4857 fdde098 5eb4857 fdde098 5eb4857 fdde098 5eb4857 f07f7d7 87d18ae 5eb4857 bd0fa52 f07f7d7 4d5026d 5eb4857 bd0fa52 87d18ae bd0fa52 fdde098 bd0fa52 5eb4857 bd0fa52 5eb4857 bd0fa52 87d18ae fdde098 bd0fa52 5eb4857 bd0fa52 87d18ae bd0fa52 5eb4857 ebf9e6f 7e5f60c ebf9e6f 7e5f60c ebf9e6f 7e5f60c ebf9e6f 7e5f60c ebf9e6f 7e5f60c ebf9e6f 7e5f60c fb7ec09 7e5f60c fb7ec09 ebf9e6f 7e5f60c ebf9e6f 7e5f60c 4d5026d 7e5f60c 4d5026d fb7ec09 4d5026d fb7ec09 7e5f60c fb7ec09 4d5026d fb7ec09 4d5026d 2131f07 4d5026d 7e5f60c ebf9e6f 5eb4857 bd0fa52 87d18ae 5eb4857 a260ab7 5eb4857 87d18ae 5eb4857 bd0fa52 5eb4857 bd0fa52 5eb4857 bd0fa52 5eb4857 bd0fa52 5eb4857 bd0fa52 5eb4857 a27a4ab bd0fa52 2d3abb8 bd0fa52 2d3abb8 bd0fa52 2d3abb8 bd0fa52 5eb4857 94b1a89 5eb4857 fdde098 bd0fa52 5eb4857 bd0fa52 5eb4857 bd0fa52 5eb4857 bd0fa52 5eb4857 bd0fa52 5eb4857 bd0fa52 5eb4857 bd0fa52 5eb4857 bd0fa52 5eb4857 bd0fa52 5eb4857 bd0fa52 5eb4857 bd0fa52 5eb4857 bd0fa52 5eb4857 bd0fa52 5eb4857 bd0fa52 5eb4857 bd0fa52 5eb4857 bd0fa52 5eb4857 bd0fa52 5eb4857 bd0fa52 5eb4857 bd0fa52 2d3abb8 bd0fa52 2d3abb8 2131f07 2d3abb8 2131f07 2d3abb8 5eb4857 bd0fa52 5eb4857 | 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 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 | 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>
);
};
|