import { AlertConfiguration } from "@/services/alertConfigService"; import { Bell, Edit, Trash2 } from "lucide-react"; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table"; import { Switch } from "@/components/ui/switch"; import { Button } from "@/components/ui/button"; import { Badge } from "@/components/ui/badge"; import { alertConfigService } from "@/services/alertConfigService"; import { pb } from "@/lib/pocketbase"; interface CombinedChannel extends Partial { isWebhook?: boolean; url?: string; method?: string; description?: string; } interface NotificationChannelListProps { channels: CombinedChannel[]; onEdit: (config: AlertConfiguration) => void; onDelete: (id: string) => void; } export const NotificationChannelList = ({ channels, onEdit, onDelete }: NotificationChannelListProps) => { const toggleEnabled = async (config: CombinedChannel) => { if (!config.id) return; if (config.isWebhook) { // Handle webhook toggle try { const newEnabled = config.enabled ? "off" : "on"; await pb.collection('webhook').update(config.id, { enabled: newEnabled }); // Trigger refresh by calling onEdit with empty config onEdit({} as AlertConfiguration); } catch (error) { console.error("Error updating webhook:", error); } } else { // Handle alert config toggle await alertConfigService.updateAlertConfiguration(config.id, { enabled: !config.enabled }); // The parent component will refresh the list onEdit(config as AlertConfiguration); } }; const getChannelTypeLabel = (type: string | undefined) => { switch(type) { case "telegram": return "Telegram"; case "discord": return "Discord"; case "slack": return "Slack"; case "signal": return "Signal"; case "google_chat": return "Google Chat"; case "email": return "Email"; case "pushover": return "Pushover"; case "notifiarr": return "Notifiarr"; case "webhook": return "Webhook"; default: return type || "Unknown"; } }; const getChannelDetails = (config: CombinedChannel) => { if (config.isWebhook) { return `${config.method || 'POST'} ${config.url || ''}`; } switch(config.notification_type) { case "telegram": return config.telegram_chat_id || ''; case "discord": case "slack": case "google_chat": return config.discord_webhook_url || config.slack_webhook_url || config.google_chat_webhook_url || ''; case "signal": return config.signal_number || ''; case "email": return config.email_address || ''; default: return ''; } }; if (channels.length === 0) { return (

No notification channels configured

Add a notification channel to get alerts when your services go down.

); } return (
Name Type Details Status Created Actions {channels.map((channel) => ( {channel.notify_name} {getChannelTypeLabel(channel.notification_type)} {getChannelDetails(channel)} toggleEnabled(channel)} /> {channel.created ? new Date(channel.created).toLocaleDateString() : "-"}
))}
); };