'use client' import { useRouter, useParams } from 'next/navigation' import { useQuery } from '@tanstack/react-query' import { monitorAPI } from '@/lib/api' import { DashboardLayout } from '@/components/layout/dashboard-layout' import { Button } from '@/components/ui/button' import { Card, CardContent } from '@/components/ui/card' import { Badge } from '@/components/ui/badge' export default function MonitorHistoryPage() { const router = useRouter() const params = useParams() const id = params?.id as string const { data: monitorData } = useQuery({ queryKey: ['monitor', id], queryFn: async () => { const response = await monitorAPI.get(id) return response.monitor }, }) const { data: historyData, isLoading } = useQuery({ queryKey: ['history', id], queryFn: async () => { const response = await monitorAPI.history(id) return response.snapshots }, }) if (isLoading) { return ( Loading history... ) } const snapshots = historyData || [] const monitor = monitorData return ( {/* Page Header */} router.push('/monitors')} className="gap-2"> Back {monitor?.name || 'Monitor History'} {monitor && ( {monitor.url} )} {monitor && ( { try { await monitorAPI.exportAuditTrail(id, 'json'); } catch (e) { console.error('Export failed:', e); } }} className="gap-2" > JSON { try { await monitorAPI.exportAuditTrail(id, 'csv'); } catch (e) { console.error('Export failed:', e); } }} className="gap-2" > CSV )} {/* History List */} Check History {snapshots.length === 0 ? ( No history yet The first check will happen soon ) : ( {snapshots.map((snapshot: any) => { // Determine border color based on HTTP status const getBorderColor = () => { if (snapshot.httpStatus >= 400 || snapshot.errorMessage) { return 'border-l-4 border-l-red-500' // Error (4xx, 5xx) } if (snapshot.httpStatus >= 200 && snapshot.httpStatus < 300) { if (snapshot.changed) { return 'border-l-4 border-l-green-500' // Success with change } return 'border-l-4 border-l-blue-400' // Success no change (neutral) } return 'border-l-4 border-l-blue-400' // Default neutral } return ( {snapshot.changed ? ( Changed ) : ( No Change )} {snapshot.errorMessage && ( Error )} {new Date(snapshot.createdAt).toLocaleString(undefined, { year: 'numeric', month: 'short', day: 'numeric', hour: '2-digit', minute: '2-digit', })} HTTP {snapshot.httpStatus} {snapshot.responseTime}ms {snapshot.changePercentage && ( {Number(snapshot.changePercentage).toFixed(2)}% changed )} {snapshot.errorMessage && ( {snapshot.errorMessage} )} {snapshot.summary && ( Summary {snapshot.summary} )} router.push(`/monitors/${id}/snapshot/${snapshot.id}`)} > {snapshot.errorMessage ? 'View Error' : 'View Details'} ) })} )} ) }
Loading history...
{monitor.url}
The first check will happen soon
{snapshot.errorMessage}
Summary
{snapshot.summary}