Spaces:
Paused

dushyantsingh0 commited on
Commit
16bf212
·
1 Parent(s): 970c341

intial commits

Browse files
frontend/apps/customer/src/App.tsx CHANGED
@@ -42,6 +42,7 @@ function AuthenticatedPortal({ user, refreshUser, authLoading, logout }: any) {
42
  const [active, setActive] = useState<"dashboard" | "tickets" | "kb" | "analytics" | "thread" | "workspace" | "nexus" | "new_ticket">("dashboard");
43
  const [showSettings, setShowSettings] = useState(false);
44
  const [selectedTicket, setSelectedTicket] = useState<any>(null);
 
45
  const [isSidebarCollapsed, setIsSidebarCollapsed] = useState(() => {
46
  const saved = localStorage.getItem('nexus_sidebar_collapsed');
47
  return saved === null ? true : saved === 'true';
@@ -123,8 +124,8 @@ function AuthenticatedPortal({ user, refreshUser, authLoading, logout }: any) {
123
  <div className="mesh-bg" />
124
  <Sidebar
125
  active={active}
126
- setActive={(v: any) => { setActive(v); setSelectedTicket(null); }}
127
- onNewTicket={() => setActive("new_ticket")}
128
  onSettings={() => setShowSettings(true)}
129
  user={user}
130
  isCollapsed={isSidebarCollapsed}
@@ -172,9 +173,18 @@ function AuthenticatedPortal({ user, refreshUser, authLoading, logout }: any) {
172
  ticket={selectedTicket}
173
  onBack={() => setActive("tickets")}
174
  onNavigate={(t: any) => setSelectedTicket(t)}
 
 
 
 
 
 
 
 
 
 
175
  />
176
  )}
177
- {active === "kb" && <KnowledgeBase onNewTicket={() => setActive("new_ticket")} />}
178
  {active === "new_ticket" && (
179
  <NewTicketView
180
  onBack={() => setActive("dashboard")}
 
42
  const [active, setActive] = useState<"dashboard" | "tickets" | "kb" | "analytics" | "thread" | "workspace" | "nexus" | "new_ticket">("dashboard");
43
  const [showSettings, setShowSettings] = useState(false);
44
  const [selectedTicket, setSelectedTicket] = useState<any>(null);
45
+ const [selectedArticleId, setSelectedArticleId] = useState<string | null>(null);
46
  const [isSidebarCollapsed, setIsSidebarCollapsed] = useState(() => {
47
  const saved = localStorage.getItem('nexus_sidebar_collapsed');
48
  return saved === null ? true : saved === 'true';
 
124
  <div className="mesh-bg" />
125
  <Sidebar
126
  active={active}
127
+ setActive={(v: any) => { setActive(v); setSelectedTicket(null); setSelectedArticleId(null); }}
128
+ onNewTicket={() => { setActive("new_ticket"); setSelectedArticleId(null); }}
129
  onSettings={() => setShowSettings(true)}
130
  user={user}
131
  isCollapsed={isSidebarCollapsed}
 
173
  ticket={selectedTicket}
174
  onBack={() => setActive("tickets")}
175
  onNavigate={(t: any) => setSelectedTicket(t)}
176
+ onNavigateArticle={(articleId: string) => {
177
+ setSelectedArticleId(articleId);
178
+ setActive("kb");
179
+ }}
180
+ />
181
+ )}
182
+ {active === "kb" && (
183
+ <KnowledgeBase
184
+ onNewTicket={() => { setActive("new_ticket"); setSelectedArticleId(null); }}
185
+ initialArticleId={selectedArticleId}
186
  />
187
  )}
 
188
  {active === "new_ticket" && (
189
  <NewTicketView
190
  onBack={() => setActive("dashboard")}
frontend/apps/customer/src/components/KnowledgeBase.tsx CHANGED
@@ -22,9 +22,10 @@ interface Article {
22
 
23
  interface KnowledgeBaseProps {
24
  onNewTicket?: () => void;
 
25
  }
26
 
27
- export const KnowledgeBase: React.FC<KnowledgeBaseProps> = ({ onNewTicket }) => {
28
  const { workspace } = useWorkspace();
29
  const { articles: globalArticles, categories: globalCategories, loading: globalLoading } = useKnowledgeBase(workspace?.id);
30
 
@@ -102,6 +103,20 @@ export const KnowledgeBase: React.FC<KnowledgeBaseProps> = ({ onNewTicket }) =>
102
  }
103
  }, [searchInput]);
104
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
105
 
106
  const handleSearchTrigger = (e?: React.FormEvent) => {
107
  if (e) e.preventDefault();
 
22
 
23
  interface KnowledgeBaseProps {
24
  onNewTicket?: () => void;
25
+ initialArticleId?: string | null;
26
  }
27
 
28
+ export const KnowledgeBase: React.FC<KnowledgeBaseProps> = ({ onNewTicket, initialArticleId }) => {
29
  const { workspace } = useWorkspace();
30
  const { articles: globalArticles, categories: globalCategories, loading: globalLoading } = useKnowledgeBase(workspace?.id);
31
 
 
103
  }
104
  }, [searchInput]);
105
 
106
+ useEffect(() => {
107
+ const loadInitialArticle = async () => {
108
+ if (initialArticleId) {
109
+ try {
110
+ const resp = await api.get(`kb/articles/${initialArticleId}/`);
111
+ setSelectedArticle(resp.data);
112
+ } catch (err) {
113
+ console.error("Failed to fetch initial article:", err);
114
+ }
115
+ }
116
+ };
117
+ loadInitialArticle();
118
+ }, [initialArticleId]);
119
+
120
 
121
  const handleSearchTrigger = (e?: React.FormEvent) => {
122
  if (e) e.preventDefault();
frontend/apps/customer/src/components/ThreadView.module.css CHANGED
@@ -159,13 +159,116 @@
159
  .mainContent {
160
  flex: 1;
161
  overflow-y: auto;
162
- padding: 40px 64px 120px;
163
  display: flex;
164
  flex-direction: column;
165
  gap: 32px;
166
  min-width: 0;
167
  }
168
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
169
  /* --- AI Intelligence Card (The Purple Highlight) --- */
170
  .aiIntelligenceCard {
171
  background: var(--primary-glow);
@@ -424,6 +527,25 @@
424
  box-shadow: 0 4px 12px rgba(0,0,0,0.05);
425
  }
426
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
427
  /* --- Sidebar Toggle --- */
428
  .feedToggle {
429
  background: var(--text-main);
 
159
  .mainContent {
160
  flex: 1;
161
  overflow-y: auto;
162
+ padding: 32px 48px 120px;
163
  display: flex;
164
  flex-direction: column;
165
  gap: 32px;
166
  min-width: 0;
167
  }
168
 
169
+ /* --- Three-Column Workspace Layout --- */
170
+ .horizontalWorkspace {
171
+ display: flex;
172
+ flex: 1;
173
+ overflow: hidden;
174
+ height: 100%;
175
+ }
176
+
177
+ .leftSidebar {
178
+ width: 320px;
179
+ background: var(--bg-card);
180
+ border-right: 1px solid var(--border-subtle);
181
+ display: flex;
182
+ flex-direction: column;
183
+ transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
184
+ overflow-y: auto;
185
+ flex-shrink: 0;
186
+ }
187
+
188
+ .leftSidebarCollapsed {
189
+ width: 0;
190
+ border-right: none;
191
+ overflow: hidden;
192
+ opacity: 0;
193
+ }
194
+
195
+ .sidebarSection {
196
+ padding: 24px;
197
+ border-bottom: 1px solid var(--border-subtle);
198
+ }
199
+
200
+ .sidebarSection:last-child {
201
+ border-bottom: none;
202
+ }
203
+
204
+ .sidebarSectionTitle {
205
+ font-size: 10px;
206
+ font-weight: 900;
207
+ color: var(--text-muted);
208
+ text-transform: uppercase;
209
+ letter-spacing: 0.1em;
210
+ margin-bottom: 16px;
211
+ }
212
+
213
+ .knowledgeItem {
214
+ display: flex;
215
+ align-items: center;
216
+ gap: 12px;
217
+ padding: 12px;
218
+ background: var(--bg-hover);
219
+ border: 1px solid var(--border-subtle);
220
+ border-radius: 10px;
221
+ cursor: pointer;
222
+ transition: all 0.2s;
223
+ text-decoration: none;
224
+ color: var(--text-main);
225
+ margin-bottom: 8px;
226
+ }
227
+
228
+ .knowledgeItem:hover {
229
+ border-color: var(--primary);
230
+ background: var(--bg-card);
231
+ box-shadow: 0 4px 12px rgba(0,0,0,0.05);
232
+ }
233
+
234
+ .knowledgeTitle {
235
+ font-size: 13px;
236
+ font-weight: 700;
237
+ line-height: 1.4;
238
+ flex: 1;
239
+ }
240
+
241
+ .parallelItem {
242
+ padding: 12px;
243
+ background: var(--bg-hover);
244
+ border: 1px solid var(--border-subtle);
245
+ border-radius: 10px;
246
+ cursor: pointer;
247
+ transition: all 0.2s;
248
+ margin-bottom: 8px;
249
+ }
250
+
251
+ .parallelItem:hover {
252
+ border-color: var(--primary);
253
+ background: var(--bg-card);
254
+ }
255
+
256
+ .parallelHeader {
257
+ display: flex;
258
+ justify-content: space-between;
259
+ align-items: center;
260
+ margin-bottom: 6px;
261
+ }
262
+
263
+ .matchBadge {
264
+ font-size: 9px;
265
+ font-weight: 900;
266
+ color: var(--primary);
267
+ background: var(--primary-glow);
268
+ padding: 2px 6px;
269
+ border-radius: 4px;
270
+ }
271
+
272
  /* --- AI Intelligence Card (The Purple Highlight) --- */
273
  .aiIntelligenceCard {
274
  background: var(--primary-glow);
 
527
  box-shadow: 0 4px 12px rgba(0,0,0,0.05);
528
  }
529
 
530
+ .toggleBtn {
531
+ background: transparent;
532
+ border: 1px solid var(--border-subtle);
533
+ cursor: pointer;
534
+ padding: 8px;
535
+ border-radius: 10px;
536
+ display: flex;
537
+ align-items: center;
538
+ justify-content: center;
539
+ transition: all 0.2s;
540
+ color: var(--text-muted);
541
+ }
542
+
543
+ .toggleBtn:hover {
544
+ background: var(--bg-hover);
545
+ border-color: var(--primary);
546
+ color: var(--primary);
547
+ }
548
+
549
  /* --- Sidebar Toggle --- */
550
  .feedToggle {
551
  background: var(--text-main);
frontend/apps/customer/src/components/ThreadView.tsx CHANGED
@@ -29,6 +29,7 @@ interface ThreadViewProps {
29
  ticket: Ticket;
30
  onBack: () => void;
31
  onNavigate?: (ticket: { id: string }) => void;
 
32
  }
33
 
34
  export const ThreadView: React.FC<ThreadViewProps> = ({ ticket: initialTicket, onBack, onNavigate }) => {
@@ -61,6 +62,7 @@ export const ThreadView: React.FC<ThreadViewProps> = ({ ticket: initialTicket, o
61
 
62
  // Sidebar States
63
  const [isSidebarOpen, setIsSidebarOpen] = useState(true);
 
64
  const [forbidden, setForbidden] = useState(false);
65
  const [sidebarWidth, setSidebarWidth] = useState(400);
66
  const [isResizing, setIsResizing] = useState(false);
@@ -79,11 +81,12 @@ export const ThreadView: React.FC<ThreadViewProps> = ({ ticket: initialTicket, o
79
 
80
  const bottomRef = useRef<HTMLDivElement>(null);
81
  const fileInputRef = useRef<HTMLInputElement>(null);
82
-
83
  const [isLoading, setIsLoading] = useState(false);
84
 
85
  const refreshData = useCallback(async (bypassCache = false) => {
86
- if (isLoading) return;
 
87
  setIsLoading(true);
88
 
89
  const watchdog = setTimeout(() => {
@@ -114,6 +117,11 @@ export const ThreadView: React.FC<ThreadViewProps> = ({ ticket: initialTicket, o
114
  else if (log.action === 'escalation') { icon = '🚨'; label = 'CRITICAL ESCALATION'; detail = 'Priority elevated to P0.'; }
115
  else if (log.action === 'update' && log.new_value?.status === 'RESOLVED') { icon = '✅'; label = 'RESOLVED'; detail = 'Incident successfully addressed.'; }
116
  else if (log.action === 'update' && log.new_value?.status === 'ACKNOWLEDGED') { icon = '🛡️'; label = 'ACKNOWLEDGED'; detail = 'Agent has initiated review.'; }
 
 
 
 
 
117
  else if (log.action === 'reopen') { icon = '🔄'; label = 'REOPENED'; detail = log.new_value?.reason || 'Resumed for further review.'; }
118
 
119
  return {
@@ -134,15 +142,16 @@ export const ThreadView: React.FC<ThreadViewProps> = ({ ticket: initialTicket, o
134
  } finally {
135
  clearTimeout(watchdog);
136
  setIsLoading(false);
 
137
  }
138
- }, [initialTicket.id, isLoading]);
139
 
140
  useEffect(() => {
141
  // Standard data fetch on mount, NO force-refresh (bypassCache=false)
142
  refreshData(false);
143
  const userString = localStorage.getItem(getStorageKey('user'));
144
  if (userString) setCurrentUser(JSON.parse(userString));
145
- }, [refreshData, initialTicket.id]);
146
 
147
  // Real-time Event Listener
148
  useEffect(() => {
@@ -167,7 +176,7 @@ export const ThreadView: React.FC<ThreadViewProps> = ({ ticket: initialTicket, o
167
 
168
  window.addEventListener('nexus-live-event', handleLiveEvent);
169
  return () => window.removeEventListener('nexus-live-event', handleLiveEvent);
170
- }, [ticket?.id, refreshData]);
171
 
172
  // Reset state only when navigating to a DIFFERENT ticket ID
173
  useEffect(() => {
@@ -407,11 +416,19 @@ export const ThreadView: React.FC<ThreadViewProps> = ({ ticket: initialTicket, o
407
  const handleDeleteAttachment = async (attachmentId: string) => {
408
  if (!window.confirm("Permanently remove this asset?")) return;
409
  try {
 
410
  await api.delete(`tickets/attachments/${attachmentId}/`);
411
- setTicket(curr => ({ ...curr, attachments: curr.attachments?.filter(a => a.id !== attachmentId) }));
412
- setMessages(prev => prev.map(m => ({ ...m, attachments: m.attachments?.filter(a => a.id !== attachmentId) })));
413
- } catch {
414
- console.error("Asset deletion failed");
 
 
 
 
 
 
 
415
  }
416
  };
417
 
@@ -448,12 +465,21 @@ export const ThreadView: React.FC<ThreadViewProps> = ({ ticket: initialTicket, o
448
  </div>
449
 
450
  <div className={styles.headerActions}>
 
 
 
 
 
 
 
 
 
451
  <button
452
  className={styles.headerBtn}
453
  onClick={() => refreshData(true)}
454
  disabled={isLoading}
455
  title="Refresh Intelligence"
456
- style={{ opacity: isLoading ? 0.5 : 1, cursor: isLoading ? 'not-allowed' : 'pointer' }}
457
  >
458
  <RefreshCcw size={18} className={isLoading ? styles.spin : ''} />
459
  </button>
@@ -520,23 +546,19 @@ export const ThreadView: React.FC<ThreadViewProps> = ({ ticket: initialTicket, o
520
  <div className={styles.duplicateTitle}>Duplicate Submission Detected</div>
521
  <div className={styles.duplicateSub}>
522
  This inquiry has been consolidated into an existing thread:
523
- <span
524
- className={styles.duplicateLink}
525
- onClick={() => onNavigate?.({ id: ticket.duplicate_of_id! })}
526
- style={{ marginLeft: 8 }}
527
- >
528
- #{ticket.duplicate_of_id.slice(0, 8).toUpperCase()} {ticket.duplicate_of_title && `— ${ticket.duplicate_of_title}`}
529
- </span>
530
- </div>
531
- </div>
532
- </div>
533
- )}
534
-
535
  <div className={styles.aiIntelligenceCard}>
536
  <div className={styles.aiHeader}>
537
- <div className={styles.aiBadge}><Sparkles size={16} /> AI INTELLIGENCE SUMMARY</div>
538
- <button onClick={handleRegenerateSummary} className={styles.btnSecondary} style={{ padding: '6px 12px', fontSize: 10, height: 'auto' }} disabled={isRegeneratingSummary}>
539
- <RefreshCcw size={12} className={isRegeneratingSummary ? styles.spin : ''} /> Regenerate
 
 
 
 
 
 
 
540
  </button>
541
  </div>
542
  <div className={styles.intelligenceSurface}>
@@ -548,127 +570,121 @@ export const ThreadView: React.FC<ThreadViewProps> = ({ ticket: initialTicket, o
548
  ) : ticket.summary ? (
549
  <NexusMarkdown content={ticket.summary} />
550
  ) : (
551
- <span style={{ opacity: 0.5 }}>AI analysis in progress. Initial forensic scan complete.</span>
 
 
552
  )}
553
  </div>
554
  </div>
555
 
556
- <div className={styles.descriptionCard}>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
557
  <div className={styles.sectionHeader}>
558
- <div className={styles.sectionLabel}>TICKET DESCRIPTION</div>
559
- {!isEditingDesc && (
560
- <button onClick={() => setIsEditingDesc(true)} style={{ background: 'transparent', border: 'none', color: 'var(--primary)', fontSize: 11, fontWeight: 900, cursor: 'pointer' }}>Edit Description</button>
 
 
 
 
 
 
561
  )}
562
  </div>
 
563
  {isEditingDesc ? (
564
  <div style={{ display: 'flex', flexDirection: 'column', gap: 16 }}>
565
- <textarea value={descDraft} onChange={e => setDescDraft(e.target.value)} onPaste={(e) => handlePaste(e, true)} style={{ width: '100%', minHeight: 200, padding: 24, borderRadius: 20, background: 'var(--bg-dark)', border: '1.5px solid var(--primary)', color: 'var(--text-main)', fontSize: 15, outline: 'none', resize: 'vertical' }} />
 
 
 
 
 
 
566
  <div style={{ display: 'flex', gap: 12, justifyContent: 'flex-end' }}>
567
  <button onClick={() => setIsEditingDesc(false)} className={styles.btnSecondary} style={{ padding: '8px 20px' }}>CANCEL</button>
568
- <button onClick={handleUpdateDescription} disabled={savingDesc} className={styles.btnPrimary} style={{ padding: '8px 24px' }}>{savingDesc ? 'SAVING...' : 'SAVE CHANGES'}</button>
 
 
 
 
 
 
 
569
  </div>
570
  </div>
571
  ) : (
572
- <div className={styles.descriptionContent}><NexusMarkdown content={ticket.description} /></div>
573
- )}
574
- </div>
575
-
576
- <div style={{ display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(360px, 1fr))', gap: 32 }}>
577
- {ticket.similar_articles && ticket.similar_articles.length > 0 && (
578
- <div>
579
- <h3 className="metadata" style={{ marginBottom: 20, fontSize: 10, letterSpacing: '0.05em', fontWeight: 700, color: "var(--text-muted)" }}>Relevant Knowledge</h3>
580
- <div style={{ display: "flex", flexDirection: "column", gap: 16 }}>
581
- {ticket.similar_articles?.map((art) => (
582
- <a key={art.id} href={`/kb/${art.id}`} target="_blank" rel="noreferrer" className="organic-surface hover-lift" style={{ padding: "24px 32px", textDecoration: "none", display: "flex", justifyContent: "space-between", alignItems: "center", background: '#fff', borderRadius: 20 }}>
583
- <span style={{ fontSize: 15, fontWeight: 800, color: "var(--text-main)" }}>{art.title}</span>
584
- <ExternalLink size={16} style={{ color: "var(--primary)" }} />
585
- </a>
586
- ))}
587
- </div>
588
- </div>
589
- )}
590
-
591
- {ticket.similar_tickets && ticket.similar_tickets.length > 0 && (
592
- <div>
593
- <h3 className="metadata" style={{ marginBottom: 20, fontSize: 10, letterSpacing: '0.05em', fontWeight: 700, color: "var(--text-muted)" }}>Historical Parallels</h3>
594
- <div style={{ display: "flex", flexDirection: "column", gap: 12 }}>
595
- {ticket.similar_tickets?.map((sim) => (
596
- <div key={sim.id} onClick={() => onNavigate?.({ id: sim.id })} className="organic-surface hover-lift" style={{ padding: "16px 24px", cursor: "pointer", display: "flex", justifyContent: "space-between", alignItems: "center", background: '#fff', borderRadius: 16 }}>
597
- <span style={{ fontSize: 14, fontWeight: 700, color: "var(--text-main)" }}>{sim.title}</span>
598
- <span className="numeric" style={{ fontSize: 10, color: "var(--primary)", fontWeight: 800 }}>{(sim.similarity * 100).toFixed(0)}% MATCH</span>
599
- </div>
600
- ))}
601
- </div>
602
  </div>
603
  )}
604
- </div>
605
-
606
- {(['RESOLVED', 'CLOSED'].includes((ticket.status || '').toUpperCase()) || ticket.resolution_text) && (
607
- <div className={styles.resolutionCard}>
608
-
609
- <div className={styles.resolutionHeader}>
610
- <div className={styles.resolutionTitleArea}>
611
- <div className={styles.resolutionIcon}>
612
- <ShieldCheck size={28} />
613
- </div>
614
- <div className={styles.resolutionTitleText}>
615
- <h3>Incident Resolution Report</h3>
616
- <div className={styles.resolutionMeta}>
617
- <span>BY: {ticket.resolved_by_name?.toUpperCase() || 'NEXUS CORE'}</span>
618
- {ticket.resolved_at && <span>• {new Date(ticket.resolved_at).toLocaleString().toUpperCase()}</span>}
619
- </div>
 
 
620
  </div>
621
- </div>
622
- <div className={styles.verifiedBadge}>VERIFIED</div>
623
- </div>
624
-
625
- <div className={styles.resolutionContent}>
626
- <NexusMarkdown content={ticket.resolution_text || ticket.summary || "This incident has been formally documented and resolved by our specialist team. No further action is required at this time."} />
627
  </div>
628
 
629
- {!ticket.summary && ticket.resolution_text && (
630
- <div className={styles.technicalAnnex}>
631
- <div className={styles.annexLabel}>Technical Annex</div>
632
- <div className={styles.annexContent}>
633
- {ticket.resolution_text}
634
- </div>
635
- </div>
636
- )}
 
 
 
 
 
 
 
637
  </div>
638
  )}
639
 
640
- {(['RESOLVED', 'CLOSED'].includes((ticket.status || '').toUpperCase()) || ticket.resolution_text) && (
641
- <div>
642
- <h3 className="metadata" style={{ marginBottom: 16, fontSize: 11, letterSpacing: '0.08em', fontWeight: 800, color: "var(--text-muted)", textTransform: 'uppercase' }}>Service Satisfaction</h3>
643
- <div className={styles.feedbackSurface}>
644
- {ticket.rating ? (
645
- <>
646
- <div style={{ fontSize: 32, marginBottom: 16 }}>{['', '⭐', '⭐⭐', '⭐⭐⭐', '⭐⭐⭐⭐', '⭐⭐⭐⭐⭐'][ticket.rating]}</div>
647
- <h4 style={{ fontSize: 18, fontWeight: 800, color: 'var(--text-main)', marginBottom: 12 }}>Feedback Received</h4>
648
- <p style={{ fontSize: 15, color: 'var(--text-muted)', lineHeight: 1.6, margin: 0 }}>"{ticket.feedback_comment || "No written feedback provided."}"</p>
649
- </>
650
- ) : (
651
- <>
652
- <h4 style={{ fontSize: 18, fontWeight: 900, color: 'var(--text-main)', marginBottom: 12 }}>How was your experience?</h4>
653
- <div style={{ display: 'flex', justifyContent: 'center', gap: 16, marginBottom: 32 }}>
654
- {[1, 2, 3, 4, 5].map((star) => (
655
- <button key={star} onMouseEnter={() => setHoverRating(star)} onMouseLeave={() => setHoverRating(null)} onClick={() => setRatingDraft(star)} style={{ fontSize: 32, background: 'none', border: 'none', cursor: 'pointer', opacity: (hoverRating || ratingDraft || 0) >= star ? 1 : 0.2, transition: 'all 0.2s ease', transform: (hoverRating === star) ? 'scale(1.2)' : 'scale(1)' }}>⭐</button>
656
- ))}
657
- </div>
658
- <textarea
659
- value={commentDraft}
660
- onChange={e => setCommentDraft(e.target.value)}
661
- placeholder="Share your thoughts with the team..."
662
- className={styles.feedbackTextarea}
663
- />
664
- <button onClick={handleSubmitFeedback} disabled={!ratingDraft || isSubmittingFeedback} className={styles.btnPrimary} style={{ margin: '0 auto', padding: '14px 40px' }}>{isSubmittingFeedback ? 'SUBMITTING...' : 'SUBMIT FEEDBACK'}</button>
665
- </>
666
- )}
667
  </div>
668
  </div>
669
  )}
670
  </main>
671
 
 
672
  {isSidebarOpen && (
673
  <div onMouseDown={handleMouseDown} style={{ width: 12, cursor: 'col-resize', zIndex: 10, display: 'flex', alignItems: 'center', justifyContent: 'center', margin: "0 -6px", opacity: isResizing ? 1 : 0 }} className="sidebar-resizer">
674
  <div style={{ width: 2, height: 60, background: 'var(--primary)', borderRadius: 2, opacity: 0.4 }} />
 
29
  ticket: Ticket;
30
  onBack: () => void;
31
  onNavigate?: (ticket: { id: string }) => void;
32
+ onNavigateArticle?: (articleId: string) => void;
33
  }
34
 
35
  export const ThreadView: React.FC<ThreadViewProps> = ({ ticket: initialTicket, onBack, onNavigate }) => {
 
62
 
63
  // Sidebar States
64
  const [isSidebarOpen, setIsSidebarOpen] = useState(true);
65
+ const [isLeftSidebarOpen, setIsLeftSidebarOpen] = useState(window.innerWidth > 1440);
66
  const [forbidden, setForbidden] = useState(false);
67
  const [sidebarWidth, setSidebarWidth] = useState(400);
68
  const [isResizing, setIsResizing] = useState(false);
 
81
 
82
  const bottomRef = useRef<HTMLDivElement>(null);
83
  const fileInputRef = useRef<HTMLInputElement>(null);
84
+ const isRefreshing = useRef(false);
85
  const [isLoading, setIsLoading] = useState(false);
86
 
87
  const refreshData = useCallback(async (bypassCache = false) => {
88
+ if (isRefreshing.current) return;
89
+ isRefreshing.current = true;
90
  setIsLoading(true);
91
 
92
  const watchdog = setTimeout(() => {
 
117
  else if (log.action === 'escalation') { icon = '🚨'; label = 'CRITICAL ESCALATION'; detail = 'Priority elevated to P0.'; }
118
  else if (log.action === 'update' && log.new_value?.status === 'RESOLVED') { icon = '✅'; label = 'RESOLVED'; detail = 'Incident successfully addressed.'; }
119
  else if (log.action === 'update' && log.new_value?.status === 'ACKNOWLEDGED') { icon = '🛡️'; label = 'ACKNOWLEDGED'; detail = 'Agent has initiated review.'; }
120
+ else if (log.action === 'update' && log.new_value?.status === 'IN_PROGRESS') { icon = '⚙️'; label = 'IN PROGRESS'; detail = 'Agent is actively working on resolution.'; }
121
+ else if (log.action === 'update' && log.new_value?.priority) { icon = '⚡'; label = 'PRIORITY CHANGE'; detail = `Priority adjusted to ${log.new_value.priority}.`; }
122
+ else if (log.action === 'update' && log.new_value?.assigned_to) { icon = '👥'; label = 'ASSIGNMENT'; detail = `Incident assigned to ${log.new_value.assigned_to_name || 'specialist'}.`; }
123
+ else if (log.action === 'update' && log.new_value?.title) { icon = '✏️'; label = 'TITLE UPDATED'; detail = 'Incident title was refined.'; }
124
+ else if (log.action === 'update' && log.new_value?.description) { icon = '📝'; label = 'DESC UPDATED'; detail = 'Incident description was updated.'; }
125
  else if (log.action === 'reopen') { icon = '🔄'; label = 'REOPENED'; detail = log.new_value?.reason || 'Resumed for further review.'; }
126
 
127
  return {
 
142
  } finally {
143
  clearTimeout(watchdog);
144
  setIsLoading(false);
145
+ isRefreshing.current = false;
146
  }
147
+ }, [initialTicket.id]);
148
 
149
  useEffect(() => {
150
  // Standard data fetch on mount, NO force-refresh (bypassCache=false)
151
  refreshData(false);
152
  const userString = localStorage.getItem(getStorageKey('user'));
153
  if (userString) setCurrentUser(JSON.parse(userString));
154
+ }, [initialTicket.id]); // ONLY trigger on ID change, ignore refreshData ref to avoid loops
155
 
156
  // Real-time Event Listener
157
  useEffect(() => {
 
176
 
177
  window.addEventListener('nexus-live-event', handleLiveEvent);
178
  return () => window.removeEventListener('nexus-live-event', handleLiveEvent);
179
+ }, [ticket?.id]); // Removed refreshData from dependencies to prevent listener churn loops
180
 
181
  // Reset state only when navigating to a DIFFERENT ticket ID
182
  useEffect(() => {
 
416
  const handleDeleteAttachment = async (attachmentId: string) => {
417
  if (!window.confirm("Permanently remove this asset?")) return;
418
  try {
419
+ // Correct endpoint path matches main.py prefix + attachments.py route
420
  await api.delete(`tickets/attachments/${attachmentId}/`);
421
+ setTicket(curr => ({
422
+ ...curr,
423
+ attachments: (curr.attachments || []).filter(a => a.id !== attachmentId)
424
+ }));
425
+ setMessages(prev => prev.map(m => ({
426
+ ...m,
427
+ attachments: (m.attachments || []).filter(a => a.id !== attachmentId)
428
+ })));
429
+ } catch (err) {
430
+ console.error("Asset deletion failed", err);
431
+ alert("Failed to delete attachment. Please verify permissions.");
432
  }
433
  };
434
 
 
465
  </div>
466
 
467
  <div className={styles.headerActions}>
468
+ <div style={{ display: 'flex', gap: 6, marginRight: 12 }}>
469
+ <button className={styles.toggleBtn} onClick={() => setIsLeftSidebarOpen(!isLeftSidebarOpen)} title="Toggle Analysis">
470
+ <Maximize2 size={16} style={{ transform: 'rotate(90deg)' }} color={isLeftSidebarOpen ? 'var(--primary)' : 'var(--text-muted)'} />
471
+ </button>
472
+ <button className={styles.toggleBtn} onClick={() => setIsSidebarOpen(!isSidebarOpen)} title="Toggle Feed">
473
+ <Maximize2 size={16} color={isSidebarOpen ? 'var(--primary)' : 'var(--text-muted)'} />
474
+ </button>
475
+ </div>
476
+
477
  <button
478
  className={styles.headerBtn}
479
  onClick={() => refreshData(true)}
480
  disabled={isLoading}
481
  title="Refresh Intelligence"
482
+ style={{ opacity: isLoading ? 0.5 : 1, cursor: isLoading ? 'not-allowed' : 'pointer', marginRight: 12 }}
483
  >
484
  <RefreshCcw size={18} className={isLoading ? styles.spin : ''} />
485
  </button>
 
546
  <div className={styles.duplicateTitle}>Duplicate Submission Detected</div>
547
  <div className={styles.duplicateSub}>
548
  This inquiry has been consolidated into an existing thread:
549
+ {/* AI Intelligence Summary */}
 
 
 
 
 
 
 
 
 
 
 
550
  <div className={styles.aiIntelligenceCard}>
551
  <div className={styles.aiHeader}>
552
+ <div className={styles.aiBadge}>
553
+ <Sparkles size={16} /> AI Intelligence Summary
554
+ </div>
555
+ <button
556
+ className={styles.btnSecondary}
557
+ style={{ padding: '6px 12px', fontSize: 10, height: 'auto' }}
558
+ onClick={handleRegenerateSummary}
559
+ disabled={isRegeneratingSummary}
560
+ >
561
+ <RefreshCcw size={12} className={isRegeneratingSummary ? styles.spin : ''} /> {isRegeneratingSummary ? 'Regenerating...' : 'Regenerate'}
562
  </button>
563
  </div>
564
  <div className={styles.intelligenceSurface}>
 
570
  ) : ticket.summary ? (
571
  <NexusMarkdown content={ticket.summary} />
572
  ) : (
573
+ <div style={{ opacity: 0.5, fontStyle: "italic" }}>
574
+ Neural core is synthesizing high-fidelity resolution steps...
575
+ </div>
576
  )}
577
  </div>
578
  </div>
579
 
580
+ {/* Duplicate Alert HUD */}
581
+ {ticket.status === 'CLOSED' && ticket.duplicate_of_id && (
582
+ <div className={styles.duplicateAlert}>
583
+ <div className={styles.duplicateIcon}><Maximize2 size={20} /></div>
584
+ <div className={styles.duplicateContent}>
585
+ <div className={styles.duplicateTitle}>Duplicate Signal Detected</div>
586
+ <div className={styles.duplicateSub}>
587
+ This incident has been linked to <span className={styles.duplicateLink} onClick={() => onNavigate?.({ id: ticket.duplicate_of_id! })}>#{ticket.duplicate_of_id.slice(0, 8).toUpperCase()}</span>.
588
+ </div>
589
+ </div>
590
+ </div>
591
+ )}
592
+
593
+ {/* Ticket Description Card */}
594
+ <section className={styles.descriptionCard}>
595
  <div className={styles.sectionHeader}>
596
+ <div className={styles.sectionLabel}>Incident Dossier</div>
597
+ {!['RESOLVED', 'CLOSED'].includes((ticket.status || '').toUpperCase()) && !isEditingDesc && (
598
+ <button
599
+ className={styles.btnSecondary}
600
+ style={{ padding: '6px 12px', fontSize: 10 }}
601
+ onClick={() => setIsEditingDesc(true)}
602
+ >
603
+ Edit Description
604
+ </button>
605
  )}
606
  </div>
607
+
608
  {isEditingDesc ? (
609
  <div style={{ display: 'flex', flexDirection: 'column', gap: 16 }}>
610
+ <textarea
611
+ className={styles.feedbackTextarea}
612
+ value={descDraft}
613
+ onChange={(e) => setDescDraft(e.target.value)}
614
+ onPaste={(e) => handlePaste(e, true)}
615
+ style={{ minHeight: 200 }}
616
+ />
617
  <div style={{ display: 'flex', gap: 12, justifyContent: 'flex-end' }}>
618
  <button onClick={() => setIsEditingDesc(false)} className={styles.btnSecondary} style={{ padding: '8px 20px' }}>CANCEL</button>
619
+ <button
620
+ className={styles.btnPrimary}
621
+ onClick={handleSaveDescription}
622
+ disabled={savingDesc}
623
+ style={{ padding: '8px 24px' }}
624
+ >
625
+ {savingDesc ? <Loader2 size={16} className={styles.spin} /> : 'Save Description'}
626
+ </button>
627
  </div>
628
  </div>
629
  ) : (
630
+ <div className={styles.descriptionContent}>
631
+ <NexusMarkdown content={ticket.description || "No description provided."} />
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
632
  </div>
633
  )}
634
+ </section>
635
+
636
+ {/* Feedback Section (Conditional) */}
637
+ {ticket.status === 'RESOLVED' && !ticket.rating && (
638
+ <div className={styles.feedbackSurface}>
639
+ <div style={{ fontSize: 24, fontWeight: 900, marginBottom: 12 }}>How was the resolution?</div>
640
+ <p style={{ color: 'var(--text-muted)', marginBottom: 32 }}>Your feedback helps us optimize the Nexus neural core.</p>
641
+
642
+ <div style={{ display: 'flex', justifyContent: 'center', gap: 16, marginBottom: 40 }}>
643
+ {[1, 2, 3, 4, 5].map(star => (
644
+ <div
645
+ key={star}
646
+ onMouseEnter={() => setHoverRating(star)}
647
+ onMouseLeave={() => setHoverRating(null)}
648
+ onClick={() => setRatingDraft(star)}
649
+ style={{ cursor: 'pointer', fontSize: 32, transition: 'all 0.2s', transform: (hoverRating || ratingDraft || 0) >= star ? 'scale(1.2)' : 'scale(1)' }}
650
+ >
651
+ {(hoverRating || ratingDraft || 0) >= star ? '⭐' : '☆'}
652
  </div>
653
+ ))}
 
 
 
 
 
654
  </div>
655
 
656
+ <textarea
657
+ className={styles.feedbackTextarea}
658
+ placeholder="Additional testimony (optional)..."
659
+ value={commentDraft}
660
+ onChange={(e) => setCommentDraft(e.target.value)}
661
+ />
662
+
663
+ <button
664
+ className={styles.btnPrimary}
665
+ style={{ width: '100%', padding: '16px' }}
666
+ onClick={handleSubmitFeedback}
667
+ disabled={isSubmittingFeedback || !ratingDraft}
668
+ >
669
+ {isSubmittingFeedback ? 'Syncing...' : 'Submit Satisfaction Signal'}
670
+ </button>
671
  </div>
672
  )}
673
 
674
+ {ticket.rating && (
675
+ <div className={styles.feedbackSurface} style={{ textAlign: 'left', background: 'rgba(16, 185, 129, 0.05)', borderColor: 'var(--success)' }}>
676
+ <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 16 }}>
677
+ <div style={{ fontSize: 10, fontWeight: 900, color: 'var(--success)', textTransform: 'uppercase' }}>User Testimony Logged</div>
678
+ <div style={{ fontSize: 20 }}>{'⭐'.repeat(ticket.rating)}</div>
679
+ </div>
680
+ <div style={{ fontSize: 15, fontWeight: 500, color: 'var(--text-main)', fontStyle: 'italic' }}>
681
+ "{ticket.feedback_comment || "No written testimony provided."}"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
682
  </div>
683
  </div>
684
  )}
685
  </main>
686
 
687
+ {/* Right Sidebar: Feed */}
688
  {isSidebarOpen && (
689
  <div onMouseDown={handleMouseDown} style={{ width: 12, cursor: 'col-resize', zIndex: 10, display: 'flex', alignItems: 'center', justifyContent: 'center', margin: "0 -6px", opacity: isResizing ? 1 : 0 }} className="sidebar-resizer">
690
  <div style={{ width: 2, height: 60, background: 'var(--primary)', borderRadius: 2, opacity: 0.4 }} />
frontend/apps/customer/src/components/TopBar.tsx CHANGED
@@ -182,7 +182,16 @@ export const TopBar: React.FC<TopBarProps> = ({ title, subtitle, logoUrl, onSele
182
  }}>
183
  <div>
184
  <div style={{ display: 'flex', alignItems: 'center', gap: 16 }}>
185
- <h1 style={{ margin: 0, fontSize: 22, fontWeight: 900, color: "var(--primary)", letterSpacing: "-0.04em", fontFamily: "var(--font-heading)" }}>{title}</h1>
 
 
 
 
 
 
 
 
 
186
  {logoUrl && (
187
  <div style={{
188
  height: 22,
@@ -199,6 +208,7 @@ export const TopBar: React.FC<TopBarProps> = ({ title, subtitle, logoUrl, onSele
199
  maxWidth: 140,
200
  objectFit: 'contain',
201
  opacity: 1,
 
202
  transition: 'all 0.3s ease'
203
  }}
204
  />
 
182
  }}>
183
  <div>
184
  <div style={{ display: 'flex', alignItems: 'center', gap: 16 }}>
185
+ <h1 style={{
186
+ margin: 0,
187
+ fontSize: 22,
188
+ fontWeight: 900,
189
+ color: theme === 'light' ? '#000000' : "var(--primary)",
190
+ letterSpacing: "-0.04em",
191
+ fontFamily: "var(--font-heading)"
192
+ }}>
193
+ {title}
194
+ </h1>
195
  {logoUrl && (
196
  <div style={{
197
  height: 22,
 
208
  maxWidth: 140,
209
  objectFit: 'contain',
210
  opacity: 1,
211
+ filter: theme === 'light' ? 'grayscale(1) opacity(0.5)' : 'none',
212
  transition: 'all 0.3s ease'
213
  }}
214
  />
frontend/apps/internal/src/components/TopBar.tsx CHANGED
@@ -185,10 +185,15 @@ export const TopBar: React.FC<TopBarProps> = ({ title, subtitle, logoUrl, onTick
185
  <Menu size={20} />
186
  </button>
187
  )}
188
- <div className={styles.title} style={{ color: 'var(--primary)', fontWeight: 900, letterSpacing: '-0.04em' }}>{title}</div>
189
  {logoUrl && (
190
  <div className={styles.logoContainer}>
191
- <img src={logoUrl} alt="Workspace Branding" className={styles.logoImage} />
 
 
 
 
 
192
  </div>
193
  )}
194
  </div>
 
185
  <Menu size={20} />
186
  </button>
187
  )}
188
+ <div className={styles.title} style={{ color: theme === 'light' ? '#000000' : 'var(--primary)', fontWeight: 900, letterSpacing: '-0.04em' }}>{title}</div>
189
  {logoUrl && (
190
  <div className={styles.logoContainer}>
191
+ <img
192
+ src={logoUrl}
193
+ alt="Workspace Branding"
194
+ className={styles.logoImage}
195
+ style={{ filter: theme === 'light' ? 'grayscale(1) opacity(0.5)' : 'none' }}
196
+ />
197
  </div>
198
  )}
199
  </div>