import { Badge, Box, Button, Code, Divider, Drawer, Group, Paper, ScrollArea, Stack, Table, Text, Title } from '@mantine/core' import { useDisclosure } from '@mantine/hooks' import { useQuery } from '@tanstack/react-query' import { Link } from '@tanstack/react-router' import { useState } from 'react' import { TbBug, TbExternalLink, TbHistory, TbMessageReport } from 'react-icons/tb' export interface ErrorDataTableProps { appId?: string } export function ErrorDataTable({ appId }: ErrorDataTableProps) { const [opened, { open, close }] = useDisclosure(false) const [selectedError, setSelectedError] = useState(null) const [showStackTrace, setShowStackTrace] = useState(false) const { data: bugsData, isLoading } = useQuery({ queryKey: ['bugs', appId], queryFn: () => fetch(`/api/bugs?app=${appId || 'all'}&limit=10`).then((r) => r.json()), }) const bugs = bugsData?.data || [] const handleRowClick = (error: any) => { setSelectedError(error) setShowStackTrace(false) open() } const getSeverityColor = (sev: string) => { switch (sev?.toUpperCase()) { case 'OPEN': return 'red' case 'IN_PROGRESS': return 'orange' case 'ON_HOLD': return 'yellow' default: return 'gray' } } return ( <> LATEST ERROR REPORTS Error Message Reporter App Version Timestamp Severity {isLoading ? ( Loading errors... ) : bugs.length === 0 ? ( No errors found. ) : bugs.map((error: any) => ( handleRowClick(error)} style={{ cursor: 'pointer' }} > {error.description} {error.user?.name || error.userId || 'System'} {error.affectedVersion || 'N/A'} {new Date(error.createdAt).toLocaleString('en-GB', { day: '2-digit', month: '2-digit', year: 'numeric', hour: '2-digit', minute: '2-digit', second: '2-digit', hour12: false })} {(error.status || '').toUpperCase()} ))}
Error Investigation } styles={{ header: { padding: '24px', borderBottom: '1px solid var(--mantine-color-default-border)' }, }} > {selectedError && ( MESSAGE {selectedError.description} SOURCE {selectedError.source} APP VERSION {selectedError.affectedVersion || 'N/A'} STACK TRACE {showStackTrace && ( {selectedError.stackTrace} )} )} ) } import { SimpleGrid, ThemeIcon } from '@mantine/core'