Spaces:
Paused
Paused
dushyantsingh0 commited on
Commit ·
9357dea
1
Parent(s): 30e9e58
intial commits
Browse files
api/v1/attachments.py
CHANGED
|
@@ -215,11 +215,15 @@ async def delete_attachment(
|
|
| 215 |
|
| 216 |
attachment, ticket = row[0], row[1]
|
| 217 |
|
|
|
|
|
|
|
|
|
|
| 218 |
# Permission: Sender of the attachment OR Admin OR Owner of the Parent Ticket
|
| 219 |
is_uploader = attachment.uploader_id == current_user.id
|
| 220 |
is_ticket_owner = (ticket.created_by == current_user.id) if ticket else False
|
| 221 |
|
| 222 |
if not (is_staff or is_uploader or is_ticket_owner):
|
|
|
|
| 223 |
raise HTTPException(status_code=403, detail="Not authorized to delete this attachment")
|
| 224 |
|
| 225 |
attachment.deleted_at = datetime.utcnow()
|
|
|
|
| 215 |
|
| 216 |
attachment, ticket = row[0], row[1]
|
| 217 |
|
| 218 |
+
from core.logging import get_logger
|
| 219 |
+
logger = get_logger(__name__)
|
| 220 |
+
|
| 221 |
# Permission: Sender of the attachment OR Admin OR Owner of the Parent Ticket
|
| 222 |
is_uploader = attachment.uploader_id == current_user.id
|
| 223 |
is_ticket_owner = (ticket.created_by == current_user.id) if ticket else False
|
| 224 |
|
| 225 |
if not (is_staff or is_uploader or is_ticket_owner):
|
| 226 |
+
logger.warning(f"PERMISSION DENIED: User {current_user.id} (role={current_user.role}) attempted to delete attachment {attachment_id}. Uploader={attachment.uploader_id}, TicketOwner={ticket.created_by if ticket else 'N/A'}")
|
| 227 |
raise HTTPException(status_code=403, detail="Not authorized to delete this attachment")
|
| 228 |
|
| 229 |
attachment.deleted_at = datetime.utcnow()
|
api/v1/tickets.py
CHANGED
|
@@ -100,7 +100,14 @@ async def list_tickets(
|
|
| 100 |
# Strictly enforce workspace isolation
|
| 101 |
target_ws, effective_role = await get_effective_context(db, current_user, workspace_id)
|
| 102 |
|
| 103 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
stmt = stmt.where(Ticket.workspace_id == target_ws)
|
| 105 |
|
| 106 |
if status_filter:
|
|
@@ -118,7 +125,14 @@ async def get_ticket(
|
|
| 118 |
db: AsyncSession = Depends(get_db)
|
| 119 |
) -> Any:
|
| 120 |
"""Get a specific ticket."""
|
| 121 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
if not current_user.is_platform_admin:
|
| 123 |
stmt = stmt.where(Ticket.workspace_id == current_user.workspace_id)
|
| 124 |
|
|
@@ -165,6 +179,46 @@ async def escalate_ticket(
|
|
| 165 |
) -> Any:
|
| 166 |
"""Manually escalate a ticket."""
|
| 167 |
return await TicketService.escalate_ticket(ticket_id, current_user, db, arq_pool)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 168 |
@router.post("/{ticket_id}/summarize/", status_code=status.HTTP_202_ACCEPTED)
|
| 169 |
async def summarize_ticket_manual(
|
| 170 |
ticket_id: UUID,
|
|
|
|
| 100 |
# Strictly enforce workspace isolation
|
| 101 |
target_ws, effective_role = await get_effective_context(db, current_user, workspace_id)
|
| 102 |
|
| 103 |
+
from sqlalchemy.orm import selectinload
|
| 104 |
+
stmt = select(Ticket).options(
|
| 105 |
+
joinedload(Ticket.creator),
|
| 106 |
+
joinedload(Ticket.assignee),
|
| 107 |
+
joinedload(Ticket.resolver),
|
| 108 |
+
joinedload(Ticket.feedback),
|
| 109 |
+
selectinload(Ticket.attachments)
|
| 110 |
+
).where(Ticket.deleted_at.is_(None))
|
| 111 |
stmt = stmt.where(Ticket.workspace_id == target_ws)
|
| 112 |
|
| 113 |
if status_filter:
|
|
|
|
| 125 |
db: AsyncSession = Depends(get_db)
|
| 126 |
) -> Any:
|
| 127 |
"""Get a specific ticket."""
|
| 128 |
+
from sqlalchemy.orm import selectinload
|
| 129 |
+
stmt = select(Ticket).options(
|
| 130 |
+
joinedload(Ticket.creator),
|
| 131 |
+
joinedload(Ticket.assignee),
|
| 132 |
+
joinedload(Ticket.resolver),
|
| 133 |
+
joinedload(Ticket.feedback),
|
| 134 |
+
selectinload(Ticket.attachments)
|
| 135 |
+
).where(Ticket.id == ticket_id, Ticket.deleted_at.is_(None))
|
| 136 |
if not current_user.is_platform_admin:
|
| 137 |
stmt = stmt.where(Ticket.workspace_id == current_user.workspace_id)
|
| 138 |
|
|
|
|
| 179 |
) -> Any:
|
| 180 |
"""Manually escalate a ticket."""
|
| 181 |
return await TicketService.escalate_ticket(ticket_id, current_user, db, arq_pool)
|
| 182 |
+
from models.audit_log import AuditLog
|
| 183 |
+
from schemas.system import AuditLogRead
|
| 184 |
+
from core.permissions import ALL_SC_ROLES
|
| 185 |
+
|
| 186 |
+
@router.get("/{ticket_id}/audit/", response_model=List[AuditLogRead])
|
| 187 |
+
async def get_ticket_audit_logs(
|
| 188 |
+
ticket_id: UUID,
|
| 189 |
+
current_user: User = Depends(get_current_user),
|
| 190 |
+
db: AsyncSession = Depends(get_db)
|
| 191 |
+
) -> Any:
|
| 192 |
+
"""Get audit logs for a specific ticket. Enforces BOLA."""
|
| 193 |
+
# 1. Verify Ticket Access
|
| 194 |
+
stmt = select(Ticket).where(Ticket.id == ticket_id, Ticket.deleted_at.is_(None))
|
| 195 |
+
if not current_user.is_platform_admin:
|
| 196 |
+
stmt = stmt.where(Ticket.workspace_id == current_user.workspace_id)
|
| 197 |
+
|
| 198 |
+
ticket = (await db.execute(stmt)).unique().scalar_one_or_none()
|
| 199 |
+
if not ticket:
|
| 200 |
+
raise HTTPException(status_code=404, detail="Ticket not found")
|
| 201 |
+
|
| 202 |
+
is_staff = current_user.role in ALL_SC_ROLES
|
| 203 |
+
if not is_staff and ticket.created_by != current_user.id:
|
| 204 |
+
raise HTTPException(status_code=403, detail="Access denied")
|
| 205 |
+
|
| 206 |
+
# 2. Fetch Logs
|
| 207 |
+
audit_stmt = (
|
| 208 |
+
select(AuditLog, User.full_name)
|
| 209 |
+
.outerjoin(User, AuditLog.user_id == User.id)
|
| 210 |
+
.where(AuditLog.entity_id == ticket_id, AuditLog.entity_type == "ticket")
|
| 211 |
+
.order_by(AuditLog.created_at.desc())
|
| 212 |
+
)
|
| 213 |
+
|
| 214 |
+
result = await db.execute(audit_stmt)
|
| 215 |
+
logs = []
|
| 216 |
+
for log_obj, actor_name in result.all():
|
| 217 |
+
setattr(log_obj, "actor_name", actor_name or "System/AI")
|
| 218 |
+
logs.append(log_obj)
|
| 219 |
+
|
| 220 |
+
return logs
|
| 221 |
+
|
| 222 |
@router.post("/{ticket_id}/summarize/", status_code=status.HTTP_202_ACCEPTED)
|
| 223 |
async def summarize_ticket_manual(
|
| 224 |
ticket_id: UUID,
|
core/database.py
CHANGED
|
@@ -39,8 +39,8 @@ def get_engine():
|
|
| 39 |
|
| 40 |
pool_class = NullPool if is_worker else AsyncAdaptedQueuePool
|
| 41 |
pool_kwargs = {} if is_worker else {
|
| 42 |
-
"pool_size":
|
| 43 |
-
"max_overflow":
|
| 44 |
"pool_timeout": 30,
|
| 45 |
"pool_recycle": 300,
|
| 46 |
"pool_pre_ping": True
|
|
|
|
| 39 |
|
| 40 |
pool_class = NullPool if is_worker else AsyncAdaptedQueuePool
|
| 41 |
pool_kwargs = {} if is_worker else {
|
| 42 |
+
"pool_size": 10,
|
| 43 |
+
"max_overflow": 20,
|
| 44 |
"pool_timeout": 30,
|
| 45 |
"pool_recycle": 300,
|
| 46 |
"pool_pre_ping": True
|
frontend/apps/customer/src/App.tsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
import { useState, useEffect } from "react";
|
| 2 |
-
import { useAuth, useTickets, useWorkspace, LoginCard, setPortalType, NexusLogo, useKnowledgeBase } from "@nexus/shared";
|
| 3 |
|
| 4 |
setPortalType('customer');
|
| 5 |
import { Sidebar } from "./components/Sidebar";
|
|
|
|
| 1 |
import { useState, useEffect } from "react";
|
| 2 |
+
import { useAuth, useTickets, useWorkspace, LoginCard, setPortalType, NexusLogo, useKnowledgeBase, NeuralBackground } from "@nexus/shared";
|
| 3 |
|
| 4 |
setPortalType('customer');
|
| 5 |
import { Sidebar } from "./components/Sidebar";
|
frontend/apps/customer/src/components/ThreadView.tsx
CHANGED
|
@@ -56,6 +56,7 @@ export const ThreadView: React.FC<ThreadViewProps> = ({ ticket: initialTicket, o
|
|
| 56 |
// AI Intensity States
|
| 57 |
const [isRegeneratingSummary, setIsRegeneratingSummary] = useState(false);
|
| 58 |
const [isEscalating, setIsEscalating] = useState(false);
|
|
|
|
| 59 |
const [showConfirmEscalate, setShowConfirmEscalate] = useState(false);
|
| 60 |
|
| 61 |
// Sidebar States
|
|
@@ -79,24 +80,62 @@ export const ThreadView: React.FC<ThreadViewProps> = ({ ticket: initialTicket, o
|
|
| 79 |
const bottomRef = useRef<HTMLDivElement>(null);
|
| 80 |
const fileInputRef = useRef<HTMLInputElement>(null);
|
| 81 |
|
|
|
|
|
|
|
| 82 |
const refreshData = useCallback(async (bypassCache = false) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
try {
|
| 84 |
-
const
|
| 85 |
-
const
|
|
|
|
| 86 |
api.get(ticketUrl),
|
| 87 |
-
api.get(`tickets/${
|
|
|
|
| 88 |
]);
|
|
|
|
| 89 |
setTicket(ticketResp.data);
|
| 90 |
setDescDraft(ticketResp.data.description);
|
| 91 |
setMessages(messagesResp.data);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
setForbidden(false);
|
| 93 |
} catch (err: any) {
|
| 94 |
console.error("Failed to refresh data", err);
|
| 95 |
if (err.response?.status === 403) {
|
| 96 |
setForbidden(true);
|
| 97 |
}
|
|
|
|
|
|
|
|
|
|
| 98 |
}
|
| 99 |
-
}, [initialTicket.id]);
|
| 100 |
|
| 101 |
useEffect(() => {
|
| 102 |
// Standard data fetch on mount, NO force-refresh (bypassCache=false)
|
|
@@ -105,8 +144,6 @@ export const ThreadView: React.FC<ThreadViewProps> = ({ ticket: initialTicket, o
|
|
| 105 |
if (userString) setCurrentUser(JSON.parse(userString));
|
| 106 |
}, [refreshData, initialTicket.id]);
|
| 107 |
|
| 108 |
-
|
| 109 |
-
|
| 110 |
// Real-time Event Listener
|
| 111 |
useEffect(() => {
|
| 112 |
const handleLiveEvent = (event: Event) => {
|
|
@@ -185,45 +222,6 @@ export const ThreadView: React.FC<ThreadViewProps> = ({ ticket: initialTicket, o
|
|
| 185 |
};
|
| 186 |
}, [isResizing]);
|
| 187 |
|
| 188 |
-
// --- HISTORY LOGIC ---
|
| 189 |
-
const historyEvents = useMemo(() => {
|
| 190 |
-
if (!ticket) return [];
|
| 191 |
-
const events: { id: string; time: string; label: string; detail: string; icon: string }[] = [];
|
| 192 |
-
|
| 193 |
-
// 1. Creation
|
| 194 |
-
events.push({
|
| 195 |
-
id: 'creation',
|
| 196 |
-
time: ticket.created_at,
|
| 197 |
-
label: 'INCIDENT LOGGED',
|
| 198 |
-
detail: 'Core ticket state initialized via portal.',
|
| 199 |
-
icon: '🎫'
|
| 200 |
-
});
|
| 201 |
-
|
| 202 |
-
// 2. Escalation
|
| 203 |
-
if (ticket.is_escalated) {
|
| 204 |
-
events.push({
|
| 205 |
-
id: 'escalation',
|
| 206 |
-
time: ticket.is_escalated,
|
| 207 |
-
label: 'CRITICAL ESCALATION',
|
| 208 |
-
detail: 'Incident priority elevated for lead intervention.',
|
| 209 |
-
icon: '🚨'
|
| 210 |
-
});
|
| 211 |
-
}
|
| 212 |
-
|
| 213 |
-
// 3. Resolution
|
| 214 |
-
if (ticket.status === 'RESOLVED' || ticket.status === 'CLOSED') {
|
| 215 |
-
events.push({
|
| 216 |
-
id: 'resolution',
|
| 217 |
-
time: ticket.resolved_at || new Date().toISOString(),
|
| 218 |
-
label: 'RESOLVED & VERIFIED',
|
| 219 |
-
detail: 'Ticket state transitioned to closure.',
|
| 220 |
-
icon: '✅'
|
| 221 |
-
});
|
| 222 |
-
}
|
| 223 |
-
|
| 224 |
-
return events.sort((a, b) => new Date(b.time).getTime() - new Date(a.time).getTime());
|
| 225 |
-
}, [ticket]);
|
| 226 |
-
|
| 227 |
// --- MENTION LOGIC ---
|
| 228 |
const handleMentionInput = (e: React.ChangeEvent<HTMLTextAreaElement>) => {
|
| 229 |
const val = e.target.value;
|
|
@@ -450,8 +448,14 @@ export const ThreadView: React.FC<ThreadViewProps> = ({ ticket: initialTicket, o
|
|
| 450 |
</div>
|
| 451 |
|
| 452 |
<div className={styles.headerActions}>
|
| 453 |
-
<button
|
| 454 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 455 |
</button>
|
| 456 |
{['RESOLVED', 'CLOSED'].includes((ticket.status || '').toUpperCase()) && (
|
| 457 |
<button onClick={() => setShowReopenModal(true)} disabled={isReopening} className={`${styles.btn} ${styles.btnSecondary}`} style={{ padding: '8px 16px' }}>
|
|
|
|
| 56 |
// AI Intensity States
|
| 57 |
const [isRegeneratingSummary, setIsRegeneratingSummary] = useState(false);
|
| 58 |
const [isEscalating, setIsEscalating] = useState(false);
|
| 59 |
+
const [historyEvents, setHistoryEvents] = useState<any[]>([]);
|
| 60 |
const [showConfirmEscalate, setShowConfirmEscalate] = useState(false);
|
| 61 |
|
| 62 |
// Sidebar States
|
|
|
|
| 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(() => {
|
| 90 |
+
setIsLoading(false);
|
| 91 |
+
}, 30000);
|
| 92 |
+
|
| 93 |
try {
|
| 94 |
+
const ticketId = initialTicket.id;
|
| 95 |
+
const ticketUrl = `tickets/${ticketId}/${bypassCache ? '?bypass_cache=true' : ''}`;
|
| 96 |
+
const [ticketResp, messagesResp, auditResp] = await Promise.all([
|
| 97 |
api.get(ticketUrl),
|
| 98 |
+
api.get(`tickets/${ticketId}/messages/`),
|
| 99 |
+
api.get(`tickets/${ticketId}/audit/`)
|
| 100 |
]);
|
| 101 |
+
|
| 102 |
setTicket(ticketResp.data);
|
| 103 |
setDescDraft(ticketResp.data.description);
|
| 104 |
setMessages(messagesResp.data);
|
| 105 |
+
|
| 106 |
+
// Transform raw audit logs into UI-friendly history events
|
| 107 |
+
const rawLogs = auditResp.data;
|
| 108 |
+
const mappedEvents = rawLogs.map((log: any) => {
|
| 109 |
+
let label = log.action.toUpperCase();
|
| 110 |
+
let icon = '📝';
|
| 111 |
+
let detail = `Action performed by ${log.actor_name}`;
|
| 112 |
+
|
| 113 |
+
if (log.action === 'create') { icon = '🎫'; label = 'INCIDENT LOGGED'; detail = 'Incident initialized via portal.'; }
|
| 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 {
|
| 120 |
+
id: log.id,
|
| 121 |
+
time: log.created_at,
|
| 122 |
+
label,
|
| 123 |
+
detail,
|
| 124 |
+
icon
|
| 125 |
+
};
|
| 126 |
+
});
|
| 127 |
+
setHistoryEvents(mappedEvents);
|
| 128 |
setForbidden(false);
|
| 129 |
} catch (err: any) {
|
| 130 |
console.error("Failed to refresh data", err);
|
| 131 |
if (err.response?.status === 403) {
|
| 132 |
setForbidden(true);
|
| 133 |
}
|
| 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)
|
|
|
|
| 144 |
if (userString) setCurrentUser(JSON.parse(userString));
|
| 145 |
}, [refreshData, initialTicket.id]);
|
| 146 |
|
|
|
|
|
|
|
| 147 |
// Real-time Event Listener
|
| 148 |
useEffect(() => {
|
| 149 |
const handleLiveEvent = (event: Event) => {
|
|
|
|
| 222 |
};
|
| 223 |
}, [isResizing]);
|
| 224 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 225 |
// --- MENTION LOGIC ---
|
| 226 |
const handleMentionInput = (e: React.ChangeEvent<HTMLTextAreaElement>) => {
|
| 227 |
const val = e.target.value;
|
|
|
|
| 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>
|
| 460 |
{['RESOLVED', 'CLOSED'].includes((ticket.status || '').toUpperCase()) && (
|
| 461 |
<button onClick={() => setShowReopenModal(true)} disabled={isReopening} className={`${styles.btn} ${styles.btnSecondary}`} style={{ padding: '8px 16px' }}>
|
frontend/apps/internal/src/components/TicketDetails.tsx
CHANGED
|
@@ -153,13 +153,21 @@ export const TicketDetails: React.FC<TicketDetailsProps> = ({ initialTicket, onB
|
|
| 153 |
const refreshData = useCallback(async (bypassCache: boolean = false) => {
|
| 154 |
if (!initialTicket?.id) return;
|
| 155 |
setLoading(true);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 156 |
try {
|
| 157 |
const ticketUrl = `tickets/${initialTicket.id}/${bypassCache ? '?bypass_cache=true' : ''}`;
|
| 158 |
-
const [ticketResp, messagesResp, auditResp, traceResp] = await Promise.allSettled([
|
| 159 |
api.get(ticketUrl),
|
| 160 |
api.get(`tickets/${initialTicket.id}/messages/`),
|
| 161 |
api.get(`system/audit/?entity_type=ticket&entity_id=${initialTicket.id}`),
|
| 162 |
-
api.get(`ai/trace/${initialTicket.id}/`)
|
|
|
|
| 163 |
]);
|
| 164 |
|
| 165 |
if (ticketResp.status === 'fulfilled') {
|
|
@@ -175,15 +183,16 @@ export const TicketDetails: React.FC<TicketDetailsProps> = ({ initialTicket, onB
|
|
| 175 |
setScratchpadText(t.ai_metadata?.summaries?.internal_summary || t.ai_metadata?.summaries?.customer_summary || "");
|
| 176 |
}
|
| 177 |
*/
|
| 178 |
-
|
| 179 |
-
api.get(`tickets/${t.id}/attachments/`).then(res => setTicketAttachments(res.data));
|
| 180 |
}
|
|
|
|
| 181 |
if (messagesResp.status === 'fulfilled') setMessages(messagesResp.value.data);
|
| 182 |
if (auditResp.status === 'fulfilled') setAuditLogs(auditResp.value.data);
|
| 183 |
if (traceResp.status === 'fulfilled') setAiTraces(traceResp.value.data.interactions || []);
|
|
|
|
| 184 |
} catch (err) {
|
| 185 |
console.error("Diagnostic failure:", err);
|
| 186 |
} finally {
|
|
|
|
| 187 |
setLoading(false);
|
| 188 |
}
|
| 189 |
}, [initialTicket?.id]);
|
|
@@ -733,10 +742,15 @@ export const TicketDetails: React.FC<TicketDetailsProps> = ({ initialTicket, onB
|
|
| 733 |
<button
|
| 734 |
className={styles.toggleBtn}
|
| 735 |
onClick={() => refreshData(true)}
|
|
|
|
| 736 |
title="Force Refresh"
|
| 737 |
-
style={{
|
|
|
|
|
|
|
|
|
|
|
|
|
| 738 |
>
|
| 739 |
-
<RefreshCw size={18} className={loading ? styles.spin : ''} color=
|
| 740 |
</button>
|
| 741 |
|
| 742 |
{isStaff && !ticket.is_escalated && (
|
|
|
|
| 153 |
const refreshData = useCallback(async (bypassCache: boolean = false) => {
|
| 154 |
if (!initialTicket?.id) return;
|
| 155 |
setLoading(true);
|
| 156 |
+
|
| 157 |
+
// Safety Watchdog: Force clear loading after 30s if network hangs
|
| 158 |
+
const watchdog = setTimeout(() => {
|
| 159 |
+
setLoading(false);
|
| 160 |
+
console.warn("Refresh sequence timed out. Releasing UI lock.");
|
| 161 |
+
}, 30000);
|
| 162 |
+
|
| 163 |
try {
|
| 164 |
const ticketUrl = `tickets/${initialTicket.id}/${bypassCache ? '?bypass_cache=true' : ''}`;
|
| 165 |
+
const [ticketResp, messagesResp, auditResp, traceResp, attachResp] = await Promise.allSettled([
|
| 166 |
api.get(ticketUrl),
|
| 167 |
api.get(`tickets/${initialTicket.id}/messages/`),
|
| 168 |
api.get(`system/audit/?entity_type=ticket&entity_id=${initialTicket.id}`),
|
| 169 |
+
api.get(`ai/trace/${initialTicket.id}/`),
|
| 170 |
+
api.get(`tickets/${initialTicket.id}/attachments/`)
|
| 171 |
]);
|
| 172 |
|
| 173 |
if (ticketResp.status === 'fulfilled') {
|
|
|
|
| 183 |
setScratchpadText(t.ai_metadata?.summaries?.internal_summary || t.ai_metadata?.summaries?.customer_summary || "");
|
| 184 |
}
|
| 185 |
*/
|
|
|
|
|
|
|
| 186 |
}
|
| 187 |
+
|
| 188 |
if (messagesResp.status === 'fulfilled') setMessages(messagesResp.value.data);
|
| 189 |
if (auditResp.status === 'fulfilled') setAuditLogs(auditResp.value.data);
|
| 190 |
if (traceResp.status === 'fulfilled') setAiTraces(traceResp.value.data.interactions || []);
|
| 191 |
+
if (attachResp.status === 'fulfilled') setTicketAttachments(attachResp.value.data);
|
| 192 |
} catch (err) {
|
| 193 |
console.error("Diagnostic failure:", err);
|
| 194 |
} finally {
|
| 195 |
+
clearTimeout(watchdog);
|
| 196 |
setLoading(false);
|
| 197 |
}
|
| 198 |
}, [initialTicket?.id]);
|
|
|
|
| 742 |
<button
|
| 743 |
className={styles.toggleBtn}
|
| 744 |
onClick={() => refreshData(true)}
|
| 745 |
+
disabled={loading}
|
| 746 |
title="Force Refresh"
|
| 747 |
+
style={{
|
| 748 |
+
marginRight: 8,
|
| 749 |
+
opacity: loading ? 0.4 : 1,
|
| 750 |
+
cursor: loading ? 'not-allowed' : 'pointer'
|
| 751 |
+
}}
|
| 752 |
>
|
| 753 |
+
<RefreshCw size={18} className={loading ? styles.spin : ''} color={loading ? 'var(--primary)' : 'var(--text-dim)'} />
|
| 754 |
</button>
|
| 755 |
|
| 756 |
{isStaff && !ticket.is_escalated && (
|