diff --git a/frontend/src/api/uptime.ts b/frontend/src/api/uptime.ts index 7cc4dbf5..9ad55e4f 100644 --- a/frontend/src/api/uptime.ts +++ b/frontend/src/api/uptime.ts @@ -26,7 +26,7 @@ export const getMonitors = async () => { return response.data; }; -export const getMonitorHistory = async (id: string) => { - const response = await client.get(`/uptime/monitors/${id}/history`); +export const getMonitorHistory = async (id: string, limit: number = 50) => { + const response = await client.get(`/uptime/monitors/${id}/history?limit=${limit}`); return response.data; }; diff --git a/frontend/src/pages/Notifications.tsx b/frontend/src/pages/Notifications.tsx index e46cfa92..73a87ea5 100644 --- a/frontend/src/pages/Notifications.tsx +++ b/frontend/src/pages/Notifications.tsx @@ -3,7 +3,7 @@ import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'; import { getProviders, createProvider, updateProvider, deleteProvider, testProvider, NotificationProvider } from '../api/notifications'; import { Card } from '../components/ui/Card'; import { Button } from '../components/ui/Button'; -import { Bell, Plus, Trash2, Edit2, Send } from 'lucide-react'; +import { Bell, Plus, Trash2, Edit2, Send, Check, X, Loader2 } from 'lucide-react'; import { useForm } from 'react-hook-form'; const ProviderForm: React.FC<{ @@ -24,6 +24,25 @@ const ProviderForm: React.FC<{ } }); + const [testStatus, setTestStatus] = useState<'idle' | 'success' | 'error'>('idle'); + + const testMutation = useMutation({ + mutationFn: testProvider, + onSuccess: () => { + setTestStatus('success'); + setTimeout(() => setTestStatus('idle'), 3000); + }, + onError: () => { + setTestStatus('error'); + setTimeout(() => setTestStatus('idle'), 3000); + } + }); + + const handleTest = () => { + const formData = watch(); + testMutation.mutate(formData as any); + }; + const type = watch('type'); const setTemplate = (template: string) => { @@ -141,6 +160,18 @@ const ProviderForm: React.FC<{
+
diff --git a/frontend/src/pages/Uptime.tsx b/frontend/src/pages/Uptime.tsx index b7b42d09..662d9e26 100644 --- a/frontend/src/pages/Uptime.tsx +++ b/frontend/src/pages/Uptime.tsx @@ -7,7 +7,7 @@ import { formatDistanceToNow } from 'date-fns'; const MonitorCard: React.FC<{ monitor: any }> = ({ monitor }) => { const { data: history } = useQuery({ queryKey: ['uptimeHistory', monitor.id], - queryFn: () => getMonitorHistory(monitor.id), + queryFn: () => getMonitorHistory(monitor.id, 60), refetchInterval: 60000, }); @@ -50,22 +50,30 @@ const MonitorCard: React.FC<{ monitor: any }> = ({ monitor }) => { - {/* Simple History Bar */} -
- {history?.slice(0, 20).reverse().map((beat: any, i: number) => ( + {/* Heartbeat Bar (Last 60 checks / 1 Hour) */} +
+ {/* Fill with empty bars if not enough history to keep alignment right-aligned */} + {Array.from({ length: Math.max(0, 60 - (history?.length || 0)) }).map((_, i) => ( +
+ ))} + + {history?.slice().reverse().map((beat: any, i: number) => (
))} {(!history || history.length === 0) && ( -
No history available
+
No history available
)}