"use client"; import { useEffect, useState } from "react"; import { motion } from "framer-motion"; import { Bell, Plus, RefreshCw, ShieldAlert, CheckCircle2, AlertTriangle } from "lucide-react"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Badge } from "@/components/ui/badge"; import { toast } from "sonner"; import Link from "next/link"; import type { MonitorLastResult } from "@/lib/monitoring/check"; type MonitorRow = { id: string; domain: string; type: string; enabled: boolean; lastChecked: string | null; lastResult: MonitorLastResult | null; }; function statusBadge(result: MonitorLastResult | null) { if (!result) return Pending; if (result.status === "alert") return Alert; if (result.status === "warning") return Warning; return OK; } export default function MonitoringPage() { const [domain, setDomain] = useState(""); const [type, setType] = useState<"DNS" | "SSL" | "UPTIME">("DNS"); const [monitors, setMonitors] = useState([]); const [loading, setLoading] = useState(true); const load = async () => { const res = await fetch("/api/monitors"); if (res.status === 401) { setMonitors([]); setLoading(false); return; } if (res.ok) { const data = await res.json(); setMonitors(data.monitors ?? []); } setLoading(false); }; useEffect(() => { load(); }, []); const addMonitor = async () => { const res = await fetch("/api/monitors", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ domain, type }), }); if (res.status === 401) { toast.error("Sign in to add monitors"); return; } if (!res.ok) { toast.error("Could not create monitor"); return; } const data = await res.json(); setMonitors((m) => [data.monitor, ...m]); setDomain(""); toast.success("Monitor added — worker checks every ~5 min"); }; return (

Monitoring

DNS change detection and SSL expiry alerts. Background worker runs on your VPS.

Add monitor setDomain(e.target.value)} className="flex-1" />

{loading ? "Loading…" : `${monitors.length} monitor(s)`}

{!loading && monitors.length === 0 && (

No monitors yet.

Sign in {" "} to track domains.

)}
); }