import React, { useState, useMemo } from 'react'; import { motion, AnimatePresence } from 'framer-motion'; import type { Ticket } from '@nexus/shared'; import styles from './TicketGrid.module.css'; interface TicketGridProps { tickets: Ticket[]; onSelect: (ticket: Ticket) => void; loading?: boolean; } const priorityConfig: any = { P0: { label: 'P0', color: 'var(--red)', bg: 'rgba(239, 68, 68, 0.1)' }, P1: { label: 'P1', color: '#FB923C', bg: 'rgba(251, 146, 60, 0.1)' }, P2: { label: 'P2', color: 'var(--amber)', bg: 'rgba(245, 158, 11, 0.1)' }, P3: { label: 'P3', color: 'var(--green)', bg: 'rgba(16, 185, 129, 0.1)' }, }; const statusConfig: any = { open: { label: 'Open', color: 'var(--accent)' }, acknowledged: { label: 'Triage', color: 'var(--teal)' }, in_progress: { label: 'In Progress', color: 'var(--amber)' }, resolved: { label: 'Resolved', color: 'var(--green)' }, }; const toCamelCase = (str: string) => { return str .replace(/(?:^\w|[A-Z]|\b\w)/g, (word) => { return word.toUpperCase(); }) .replace(/\s+/g, ''); }; export const TicketGrid: React.FC = ({ tickets, onSelect, loading }) => { const [sortKey] = useState('priority'); const sortedTickets = useMemo(() => { const pOrder: any = { P0: 0, P1: 1, P2: 2, P3: 3 }; return [...tickets].sort((a, b) => { if (sortKey === 'priority') { const pa = a.priority?.toUpperCase() || 'P3'; const pb = b.priority?.toUpperCase() || 'P3'; return pOrder[pa] - pOrder[pb]; } return 0; }); }, [tickets, sortKey]); if (loading && tickets.length === 0) { return
Synchronizing scrum board...
; } return (
{sortedTickets.map((t) => { const p = priorityConfig[t.priority?.toUpperCase()] || priorityConfig.P3; const s = statusConfig[t.status?.toLowerCase()] || statusConfig.open; const id = t.id?.slice(0, 8).toUpperCase(); // SLA Logic const now = new Date(); const deadline = t.sla_deadline ? new Date(t.sla_deadline) : null; const diffMs = deadline ? deadline.getTime() - now.getTime() : 7200000; const diffMins = Math.round(diffMs / 60000); const isUrgent = diffMins < 30; return ( onSelect(t)} > ); })}
ID PR Ticket Subject Customer Status SLA Assigned To
{id} {p.label}
{t.title} {t.ai_metadata?.ai_score && ( AI {t.ai_metadata.ai_score}% )}
{t.ai_metadata?.sentiment === 'Negative' ? '🔴' : '⚪'} {toCamelCase(t.creator_name || 'System')}
{s.label}
{diffMins > 0 ? `${diffMins}m` : `-${Math.abs(diffMins)}m`}
{t.assigned_name ? t.assigned_name.slice(0, 2).toUpperCase() : '??'}
{t.assigned_name ? toCamelCase(t.assigned_name) : 'Unassigned'}
{sortedTickets.length === 0 && (
No tickets match current filters.
)}
); };