'use client' import { useEffect } from 'react' import { useRouter, useParams } from 'next/navigation' import { useQuery } from '@tanstack/react-query' import { monitorAPI } from '@/lib/api' import { isAuthenticated } from '@/lib/auth' export default function MonitorHistoryPage() { const router = useRouter() const params = useParams() const id = params?.id as string useEffect(() => { if (!isAuthenticated()) { router.push('/login') } }, [router]) 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...

) } const snapshots = historyData || [] const monitor = monitorData return (
{/* Header */}

{monitor?.name || 'Monitor History'}

{monitor && (

{monitor.url}

)}
{/* Main Content */}

Check History

{snapshots.length === 0 ? (

No history yet

The first check will happen soon

) : (
{snapshots.map((snapshot: any) => (
{snapshot.changed ? 'Changed' : 'No Change'} {snapshot.error_message && ( Error )} {new Date(snapshot.created_at).toLocaleString()}
HTTP {snapshot.http_status} {snapshot.response_time}ms {snapshot.change_percentage && ( {snapshot.change_percentage.toFixed(2)}% changed )}
{snapshot.error_message && (

{snapshot.error_message}

)}
{snapshot.html_content && ( )}
))}
)}
) }