Spaces:
Paused
Paused
Download frontend/apps/internal/src/components/TicketGrid.tsx from TeamError404/nexus: direct link, hf CLI and curl.
- Browser
- Download file 5.65 kB
-
https://huggingface.co/spaces/TeamError404/nexus/resolve/main/frontend/apps/internal/src/components/TicketGrid.tsx
- Command line
-
hf download hf://spaces/TeamError404/nexus/frontend/apps/internal/src/components/TicketGrid.tsx
-
curl -L -o TicketGrid.tsx https://huggingface.co/spaces/TeamError404/nexus/resolve/main/frontend/apps/internal/src/components/TicketGrid.tsx
5.65 kB
| 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<TicketGridProps> = ({ tickets, onSelect, loading }) => { | |
| const [sortKey] = useState<string>('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 <div className={styles.loading}>Synchronizing scrum board...</div>; | |
| } | |
| return ( | |
| <div className={styles.tableWrapper}> | |
| <table className={styles.table}> | |
| <thead> | |
| <tr> | |
| <th className={styles.thId}>ID</th> | |
| <th className={styles.thPriority}>PR</th> | |
| <th className={styles.thSubject}>Ticket Subject</th> | |
| <th className={styles.thCustomer}>Customer</th> | |
| <th className={styles.thStatus}>Status</th> | |
| <th className={styles.thSLA}>SLA</th> | |
| <th className={styles.thAgent}>Assigned To</th> | |
| </tr> | |
| </thead> | |
| <tbody> | |
| <AnimatePresence mode="popLayout"> | |
| {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 ( | |
| <motion.tr | |
| key={t.id} | |
| layoutId={t.id} | |
| initial={{ opacity: 0 }} | |
| animate={{ opacity: 1 }} | |
| exit={{ opacity: 0 }} | |
| className={styles.row} | |
| onClick={() => onSelect(t)} | |
| > | |
| <td className={styles.tdId}>{id}</td> | |
| <td className={styles.tdPriority}> | |
| <span className={styles.pTag} style={{ color: p.color, background: p.bg }}>{p.label}</span> | |
| </td> | |
| <td className={styles.tdSubject}> | |
| <div className={styles.titleGroup}> | |
| <span className={styles.title}>{t.title}</span> | |
| {t.ai_metadata?.ai_score && ( | |
| <span className={styles.aiBadge}>AI {t.ai_metadata.ai_score}%</span> | |
| )} | |
| </div> | |
| </td> | |
| <td className={styles.tdCustomer}> | |
| <div className={styles.customerGroup}> | |
| <span className={styles.sentiment}>{t.ai_metadata?.sentiment === 'Negative' ? '🔴' : '⚪'}</span> | |
| <span className={styles.name}>{toCamelCase(t.creator_name || 'System')}</span> | |
| </div> | |
| </td> | |
| <td className={styles.tdStatus}> | |
| <div className={styles.statusGroup}> | |
| <span className={styles.dot} style={{ background: s.color, boxShadow: `0 0 6px ${s.color}` }} /> | |
| <span className={styles.statusLabel}>{s.label}</span> | |
| </div> | |
| </td> | |
| <td className={styles.tdSLA}> | |
| <span className={`${styles.sla} ${isUrgent ? styles.slaUrgent : ''}`}> | |
| {diffMins > 0 ? `${diffMins}m` : `-${Math.abs(diffMins)}m`} | |
| </span> | |
| </td> | |
| <td className={styles.tdAgent}> | |
| <div className={styles.agentGroup}> | |
| <div className={styles.miniAvatar}>{t.assigned_name ? t.assigned_name.slice(0, 2).toUpperCase() : '??'}</div> | |
| <span className={styles.agentName}>{t.assigned_name ? toCamelCase(t.assigned_name) : 'Unassigned'}</span> | |
| </div> | |
| </td> | |
| </motion.tr> | |
| ); | |
| })} | |
| </AnimatePresence> | |
| </tbody> | |
| </table> | |
| {sortedTickets.length === 0 && ( | |
| <div className={styles.emptyState}>No tickets match current filters.</div> | |
| )} | |
| </div> | |
| ); | |
| }; | |