import { useState, useEffect, useCallback } from 'react'; import { useParams, useNavigate } from 'react-router-dom'; import type { ServiceStatusDetail } from '../../types/service'; import { getServiceStatusDetail } from '../../services/heartbeatService'; const STATUS_COLOR: Record = { UP: 'bg-green-500', DOWN: 'bg-red-500', UNKNOWN: 'bg-gray-400', }; const getUptimeBarColor = (pct: number): string => { if (pct >= 99.9) return 'bg-green-500'; if (pct >= 99) return 'bg-green-400'; if (pct >= 95) return 'bg-yellow-400'; if (pct >= 90) return 'bg-orange-400'; return 'bg-red-500'; }; const formatDate = (dateStr: string): string => { const d = new Date(dateStr); return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`; }; const formatTime = (dateStr: string): string => { return new Date(dateStr).toLocaleTimeString('ko-KR'); }; const ServiceStatusDetailPage = () => { const { serviceId } = useParams<{ serviceId: string }>(); const navigate = useNavigate(); const [detail, setDetail] = useState(null); const [isLoading, setIsLoading] = useState(true); const fetchData = useCallback(async () => { if (!serviceId) return; try { const res = await getServiceStatusDetail(Number(serviceId)); if (res.success && res.data) { setDetail(res.data); } } catch { // silent } finally { setIsLoading(false); } }, [serviceId]); useEffect(() => { fetchData(); const interval = setInterval(fetchData, 60000); return () => clearInterval(interval); }, [fetchData]); if (isLoading) { return
로딩 중...
; } if (!detail) { return
서비스를 찾을 수 없습니다
; } return (
{/* Header */}

{detail.serviceName}

{detail.serviceCode}
{detail.currentStatus === 'UP' ? 'Operational' : detail.currentStatus === 'DOWN' ? 'Down' : 'Unknown'}
{detail.lastResponseTime !== null && (
{detail.lastResponseTime}ms
)}
{/* Uptime Summary */}

90일 Uptime

{detail.uptimePercent90d.toFixed(3)}%
{/* 90-Day Bar */}
{detail.dailyUptime.map((day, idx) => (
{formatDate(day.date)}
Uptime: {day.uptimePercent.toFixed(1)}%
Checks: {day.upChecks}/{day.totalChecks}
))} {detail.dailyUptime.length === 0 && (
)}
{detail.dailyUptime.length > 0 ? formatDate(detail.dailyUptime[0].date) : ''} Today
{/* Daily Uptime Legend */}
99.9%+
99%+
95%+
90%+
<90%
{/* Recent Checks */}

최근 체크 이력

{detail.recentChecks.map((check, idx) => ( ))} {detail.recentChecks.length === 0 && ( )}
시간 상태 응답시간 에러
{formatTime(check.checkedAt)}
{check.status}
{check.responseTime !== null ? `${check.responseTime}ms` : '-'} {check.errorMessage || '-'}
체크 이력이 없습니다
); }; export default ServiceStatusDetailPage;