import React, { useState } from "react"; import { useQuery, useQueryClient } from "@tanstack/react-query"; import { Button } from "@/components/ui/button"; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"; import { Plus, MapPin, Activity, Wifi, WifiOff } from "lucide-react"; import { regionalService } from "@/services/regionalService"; import { RegionalService } from "@/types/regional.types"; import { AddRegionalAgentDialog } from "./AddRegionalAgentDialog"; import { RegionalAgentCard } from "./RegionalAgentCard"; import { useToast } from "@/hooks/use-toast"; export const RegionalMonitoringContent = () => { const [addDialogOpen, setAddDialogOpen] = useState(false); const { toast } = useToast(); const queryClient = useQueryClient(); const { data: regionalServices = [], isLoading, error } = useQuery({ queryKey: ['regional-services'], queryFn: regionalService.getRegionalServices, refetchInterval: 30000, // Refetch every 30 seconds }); const handleAgentAdded = () => { queryClient.invalidateQueries({ queryKey: ['regional-services'] }); toast({ title: "Regional Agent Added", description: "The regional monitoring agent has been successfully configured.", }); }; const handleDeleteAgent = async (id: string) => { try { await regionalService.deleteRegionalService(id); queryClient.invalidateQueries({ queryKey: ['regional-services'] }); toast({ title: "Agent Removed", description: "The regional monitoring agent has been removed.", }); } catch (error) { toast({ title: "Error", description: "Failed to remove the regional monitoring agent.", variant: "destructive", }); } }; const onlineAgents = regionalServices.filter(agent => agent.connection === 'online').length; const totalAgents = regionalServices.length; return (
Manage distributed monitoring agents across different regions
Regional monitoring agents
Currently connected
Disconnected agents
Get started by adding your first regional monitoring agent to extend your monitoring coverage.