diff --git a/frontend/src/app/admin/page.tsx b/frontend/src/app/admin/page.tsx index 3e80638..2330ef3 100644 --- a/frontend/src/app/admin/page.tsx +++ b/frontend/src/app/admin/page.tsx @@ -2,17 +2,225 @@ import { AuthGuard } from '@/components/AuthGuard'; import { DashboardLayout } from '@/components/DashboardLayout'; -import { useQuery } from '@tanstack/react-query'; -import { adminApi } from '@/lib/api'; +import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'; +import { + adminApi, + adminNotificationsApi, + AdminNotificationConfig, + AdminNotificationConfigCreate, + AdminNotificationConfigUpdate, +} from '@/lib/api'; import { useAuthStore } from '@/store/authStore'; import { useRouter } from 'next/navigation'; -import { useEffect } from 'react'; -import { Users, Mail, Activity, Shield } from 'lucide-react'; +import { useEffect, useState } from 'react'; +import { + Users, + Mail, + Activity, + Shield, + Bell, + Plus, + Edit2, + Trash2, + Send, + CheckCircle, + XCircle, + Loader2, + X, +} from 'lucide-react'; import Link from 'next/link'; +// ── Admin Notification Modal ───────────────────────────────────────────── + +interface AdminNotificationModalProps { + config?: AdminNotificationConfig | null; + onClose: () => void; +} + +function AdminNotificationModal({ config, onClose }: AdminNotificationModalProps) { + const queryClient = useQueryClient(); + const isEdit = !!config; + + const [formData, setFormData] = useState({ + name: config?.name ?? '', + apprise_url: config?.apprise_url ?? '', + is_enabled: config?.is_enabled ?? true, + notify_on_errors: config?.notify_on_errors ?? true, + notify_on_system_events: config?.notify_on_system_events ?? true, + description: config?.description ?? '', + }); + const [error, setError] = useState(''); + + const onSuccess = () => { + queryClient.invalidateQueries({ queryKey: ['admin-notifications'] }); + onClose(); + }; + + const createMutation = useMutation({ + mutationFn: (data: AdminNotificationConfigCreate) => adminNotificationsApi.create(data), + onSuccess, + onError: () => setError('Failed to save. Please check the Apprise URL and try again.'), + }); + + const updateMutation = useMutation({ + mutationFn: (data: AdminNotificationConfigUpdate) => + adminNotificationsApi.update(config!.id, data), + onSuccess, + onError: () => setError('Failed to save. Please check the Apprise URL and try again.'), + }); + + const isPending = createMutation.isPending || updateMutation.isPending; + + const handleSubmit = (e: React.FormEvent) => { + e.preventDefault(); + setError(''); + if (!formData.name.trim() || !formData.apprise_url.trim()) { + setError('Name and Apprise URL are required.'); + return; + } + if (isEdit) { + updateMutation.mutate(formData); + } else { + createMutation.mutate(formData); + } + }; + + return ( +
+
+
+

+ {isEdit ? 'Edit System Alert Channel' : 'Add System Alert Channel'} +

+ +
+ +
+
+ + setFormData((p) => ({ ...p, name: e.target.value }))} + placeholder="e.g. Admin Telegram Alert" + className="w-full px-3 py-2 border border-gray-300 rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-purple-500" + /> +
+ +
+ + setFormData((p) => ({ ...p, apprise_url: e.target.value }))} + placeholder="tgram://bot_token/chat_id/" + className="w-full px-3 py-2 border border-gray-300 rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-purple-500" + /> +

+ Any valid{' '} + + Apprise + {' '} + notification URL. +

+
+ +
+ + setFormData((p) => ({ ...p, description: e.target.value || null }))} + placeholder="What is this channel used for?" + className="w-full px-3 py-2 border border-gray-300 rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-purple-500" + /> +
+ +
+

Triggers

+ + + +
+ + {error &&

{error}

} + +
+ + +
+
+
+
+ ); +} + +// ── Admin Page ─────────────────────────────────────────────────────────── + export default function AdminPage() { const { user } = useAuthStore(); const router = useRouter(); + const queryClient = useQueryClient(); + + const [showNotifModal, setShowNotifModal] = useState(false); + const [editingNotif, setEditingNotif] = useState(null); + const [testingNotifId, setTestingNotifId] = useState(null); + const [notifTestResults, setNotifTestResults] = useState< + Record + >({}); useEffect(() => { if (user && !user.is_superuser) { @@ -26,6 +234,60 @@ export default function AdminPage() { enabled: !!user?.is_superuser, }); + const { data: adminNotifications, isLoading: notifLoading } = useQuery({ + queryKey: ['admin-notifications'], + queryFn: adminNotificationsApi.list, + enabled: !!user?.is_superuser, + }); + + const deleteNotifMutation = useMutation({ + mutationFn: adminNotificationsApi.delete, + onSuccess: () => { + queryClient.invalidateQueries({ queryKey: ['admin-notifications'] }); + }, + }); + + const handleEditNotif = (config: AdminNotificationConfig) => { + setEditingNotif(config); + setShowNotifModal(true); + }; + + const handleDeleteNotif = async (id: number) => { + if (!confirm('Delete this system alert channel?')) return; + try { + await deleteNotifMutation.mutateAsync(id); + } catch { + alert('Failed to delete channel'); + } + }; + + const handleTestNotif = async (config: AdminNotificationConfig) => { + setTestingNotifId(config.id); + try { + const result = await adminNotificationsApi.test(config.apprise_url); + setNotifTestResults((prev) => ({ ...prev, [config.id]: result })); + } catch { + setNotifTestResults((prev) => ({ + ...prev, + [config.id]: { success: false, message: 'Test request failed' }, + })); + } finally { + setTestingNotifId(null); + setTimeout(() => { + setNotifTestResults((prev) => { + const next = { ...prev }; + delete next[config.id]; + return next; + }); + }, 5000); + } + }; + + const handleCloseNotifModal = () => { + setShowNotifModal(false); + setEditingNotif(null); + }; + // AuthGuard must always render so it can fetch the current user and handle // unauthenticated redirects. The early-return that was here prevented // AuthGuard from ever mounting on a direct navigation to /admin, leaving a @@ -115,9 +377,165 @@ export default function AdminPage() { + + {/* System Alert Channels */} +
+
+
+

+ + System Alert Channels +

+

+ Admin-level channels that receive system-wide error and event notifications. +

+
+ +
+ + {notifLoading ? ( +
+
+
+ ) : adminNotifications && adminNotifications.length > 0 ? ( +
+ {adminNotifications.map((config) => { + const testResult = notifTestResults[config.id]; + const isTesting = testingNotifId === config.id; + return ( +
+
+
+
+

+ {config.name} +

+ {config.description && ( +

+ {config.description} +

+ )} +
+ + {config.is_enabled ? ( + + ) : ( + + )} + {config.is_enabled ? 'On' : 'Off'} + +
+ +
+ {config.notify_on_errors && ( + + On Errors + + )} + {config.notify_on_system_events && ( + + System Events + + )} +
+ + {testResult && ( +
+ {testResult.success ? ( + + ) : ( + + )} + {testResult.message} +
+ )} + +
+ + + +
+
+
+ ); + })} +
+ ) : ( +
+ +

No system alert channels configured yet.

+ +
+ )} +
)} + + {showNotifModal && ( + + )} ); } + diff --git a/frontend/src/app/notifications/page.tsx b/frontend/src/app/notifications/page.tsx new file mode 100644 index 0000000..0a2b159 --- /dev/null +++ b/frontend/src/app/notifications/page.tsx @@ -0,0 +1,347 @@ +'use client'; + +import { useState } from 'react'; +import { AuthGuard } from '@/components/AuthGuard'; +import { DashboardLayout } from '@/components/DashboardLayout'; +import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'; +import { notificationsApi, NotificationConfig, NotificationConfigCreate, NotificationConfigUpdate } from '@/lib/api'; +import { NotificationWizard } from '@/components/NotificationWizard'; +import { Plus, Edit2, Trash2, Bell, Send, CheckCircle, XCircle, Loader2 } from 'lucide-react'; + +const CHANNEL_DISPLAY: Record = { + telegram: { icon: '🤖', label: 'Telegram', color: 'bg-blue-100 text-blue-800' }, + discord: { icon: '💬', label: 'Discord', color: 'bg-indigo-100 text-indigo-800' }, + slack: { icon: '💼', label: 'Slack', color: 'bg-yellow-100 text-yellow-800' }, + email: { icon: '📧', label: 'Email', color: 'bg-green-100 text-green-800' }, + webhook: { icon: '🔗', label: 'Webhook', color: 'bg-purple-100 text-purple-800' }, + custom: { icon: '⚙️', label: 'Custom', color: 'bg-gray-100 text-gray-800' }, +}; + +export default function NotificationsPage() { + const [showWizard, setShowWizard] = useState(false); + const [editingConfig, setEditingConfig] = useState(null); + const [testingId, setTestingId] = useState(null); + const [testResults, setTestResults] = useState>({}); + const queryClient = useQueryClient(); + + const { data: notifications, isLoading } = useQuery({ + queryKey: ['notifications'], + queryFn: notificationsApi.list, + }); + + const createMutation = useMutation({ + mutationFn: (data: NotificationConfigCreate) => notificationsApi.create(data), + onSuccess: () => { + queryClient.invalidateQueries({ queryKey: ['notifications'] }); + setShowWizard(false); + setEditingConfig(null); + }, + }); + + const updateMutation = useMutation({ + mutationFn: ({ id, data }: { id: number; data: NotificationConfigUpdate }) => + notificationsApi.update(id, data), + onSuccess: () => { + queryClient.invalidateQueries({ queryKey: ['notifications'] }); + setShowWizard(false); + setEditingConfig(null); + }, + }); + + const deleteMutation = useMutation({ + mutationFn: notificationsApi.delete, + onSuccess: () => { + queryClient.invalidateQueries({ queryKey: ['notifications'] }); + }, + }); + + const toggleMutation = useMutation({ + mutationFn: ({ id, is_enabled }: { id: number; is_enabled: boolean }) => + notificationsApi.update(id, { is_enabled }), + onSuccess: () => { + queryClient.invalidateQueries({ queryKey: ['notifications'] }); + }, + }); + + const handleWizardComplete = (config: { + name: string; + channel: string; + apprise_url: string; + notify_on_errors: boolean; + notify_on_success: boolean; + }) => { + if (editingConfig) { + updateMutation.mutate({ id: editingConfig.id, data: config }); + } else { + createMutation.mutate(config); + } + }; + + const handleEdit = (config: NotificationConfig) => { + setEditingConfig(config); + setShowWizard(true); + }; + + const handleDelete = async (id: number) => { + if (!confirm('Delete this notification channel?')) return; + try { + await deleteMutation.mutateAsync(id); + } catch { + alert('Failed to delete notification channel'); + } + }; + + const handleTest = async (config: NotificationConfig) => { + if (!config.apprise_url) return; + setTestingId(config.id); + try { + const result = await notificationsApi.test(config.apprise_url); + setTestResults((prev) => ({ ...prev, [config.id]: result })); + } catch { + setTestResults((prev) => ({ + ...prev, + [config.id]: { success: false, message: 'Test request failed' }, + })); + } finally { + setTestingId(null); + setTimeout(() => { + setTestResults((prev) => { + const next = { ...prev }; + delete next[config.id]; + return next; + }); + }, 5000); + } + }; + + const handleOpenWizard = () => { + setEditingConfig(null); + setShowWizard(true); + }; + + const handleCancelWizard = () => { + setShowWizard(false); + setEditingConfig(null); + }; + + if (showWizard) { + return ( + + +
+
+ +
+
+
+
+ ); + } + + return ( + + +
+ {/* Header */} +
+
+

+ + Notification Channels +

+

+ Get alerts when emails are processed or errors occur. +

+
+ +
+ + {/* Content */} + {isLoading ? ( +
+
+
+ ) : notifications && notifications.length > 0 ? ( +
+ {notifications.map((config) => { + const channel = CHANNEL_DISPLAY[config.channel] ?? CHANNEL_DISPLAY.custom; + const testResult = testResults[config.id]; + const isTesting = testingId === config.id; + + return ( +
+
+
+
+ {channel.icon} +
+

+ {config.name} +

+ + {channel.label} + +
+
+ +
+ +
+ {config.notify_on_errors && ( + + On Errors + + )} + {config.notify_on_success && ( + + On Success + + )} + {!config.notify_on_errors && !config.notify_on_success && ( + + No triggers set + + )} +
+ + {testResult && ( +
+ {testResult.success ? ( + + ) : ( + + )} + {testResult.message} +
+ )} + +
+ + + +
+
+
+ ); + })} +
+ ) : ( +
+ +

+ No notification channels yet +

+

+ Add a channel to receive alerts when emails are processed or errors occur. +

+ +
+ )} + + {/* Info box */} +
+

About Notifications

+

+ Notifications are powered by{' '} + + Apprise + + , which supports 80+ notification services including Telegram, Discord, Slack, email, + and many more. Each channel can be configured independently with different triggers. +

+
+
+ + + ); +} diff --git a/frontend/src/components/DashboardLayout.tsx b/frontend/src/components/DashboardLayout.tsx index 11b5bee..c8348d5 100644 --- a/frontend/src/components/DashboardLayout.tsx +++ b/frontend/src/components/DashboardLayout.tsx @@ -14,7 +14,8 @@ import { User, Shield, Users, - CreditCard + CreditCard, + Bell } from 'lucide-react'; interface DashboardLayoutProps { @@ -35,6 +36,7 @@ export function DashboardLayout({ children }: DashboardLayoutProps) { const navigation = [ { name: 'Dashboard', href: '/dashboard', icon: LayoutDashboard }, { name: 'Mail Accounts', href: '/accounts', icon: Mail }, + { name: 'Notifications', href: '/notifications', icon: Bell }, { name: 'Settings', href: '/settings', icon: Settings }, ]; diff --git a/frontend/src/components/NotificationWizard.tsx b/frontend/src/components/NotificationWizard.tsx new file mode 100644 index 0000000..8bdf193 --- /dev/null +++ b/frontend/src/components/NotificationWizard.tsx @@ -0,0 +1,390 @@ +'use client'; + +import { useState } from 'react'; +import { ArrowLeft, Bell, Check, Eye, EyeOff, Send } from 'lucide-react'; + +interface NotificationWizardProps { + onComplete: (config: { + name: string; + channel: string; + apprise_url: string; + notify_on_errors: boolean; + notify_on_success: boolean; + }) => void; + onCancel: () => void; + initialData?: { + name: string; + channel: string; + apprise_url: string | null; + notify_on_errors: boolean; + notify_on_success: boolean; + } | null; +} + +const CHANNEL_OPTIONS = [ + { id: 'telegram', icon: '🤖', label: 'Telegram', description: 'Instant messages via Telegram bot' }, + { id: 'discord', icon: '💬', label: 'Discord', description: 'Server notifications via Discord webhook' }, + { id: 'slack', icon: '💼', label: 'Slack', description: 'Team alerts via Slack webhook' }, + { id: 'email', icon: '📧', label: 'Email', description: 'Email notifications via SMTP' }, + { id: 'webhook', icon: '🔗', label: 'Webhook', description: 'POST to any HTTP endpoint' }, + { id: 'custom', icon: '⚙️', label: 'Custom Apprise URL', description: 'Advanced: any supported Apprise format' }, +]; + +interface ChannelField { + key: string; + label: string; + placeholder: string; + type?: 'text' | 'password'; + hint?: string; + optional?: boolean; +} + +const CHANNEL_FIELDS: Record = { + telegram: [ + { + key: 'bot_token', + label: 'Bot Token', + placeholder: '110201543:AAHdqTcvCH1vGWJxfSeofSAs0K5PALDsaw', + hint: 'Get from @BotFather on Telegram', + }, + { + key: 'chat_id', + label: 'Chat ID', + placeholder: '12345678', + hint: 'Your Telegram chat or group ID', + }, + ], + discord: [ + { + key: 'webhook_url', + label: 'Discord Webhook URL', + placeholder: 'https://discord.com/api/webhooks/123456789/abcdef...', + hint: 'Paste the full webhook URL from Discord server settings → Integrations', + }, + ], + slack: [ + { + key: 'webhook_url', + label: 'Slack Webhook URL', + placeholder: 'https://hooks.slack.com/services/T00000000/B00000000/XXXX...', + hint: 'Create an Incoming Webhook in your Slack app settings', + }, + ], + email: [ + { key: 'username', label: 'Username / Email', placeholder: 'user@example.com' }, + { key: 'password', label: 'SMTP Password', placeholder: '••••••••', type: 'password' }, + { key: 'host', label: 'SMTP Host', placeholder: 'smtp.example.com' }, + { key: 'port', label: 'SMTP Port', placeholder: '587', optional: true }, + ], + webhook: [ + { + key: 'url', + label: 'Webhook URL', + placeholder: 'https://hooks.example.com/...', + hint: 'Full HTTP(S) URL — receives a JSON POST with notification data', + }, + ], + custom: [ + { + key: 'apprise_url', + label: 'Apprise URL', + placeholder: 'tgram://bot_token/chat_id/', + hint: 'Any valid Apprise notification URL — see apprise.readthedocs.io', + }, + ], +}; + +function buildAppriseUrl(channel: string, fields: Record): string { + switch (channel) { + case 'telegram': + if (!fields.bot_token || !fields.chat_id) return ''; + return `tgram://${fields.bot_token}/${fields.chat_id}/`; + case 'discord': { + const match = (fields.webhook_url ?? '').match( + /discord\.com\/api\/webhooks\/(\d+)\/([^/?]+)/ + ); + if (match) return `discord://${match[1]}/${match[2]}/`; + return ''; + } + case 'slack': { + const match = (fields.webhook_url ?? '').match( + /hooks\.slack\.com\/services\/([^/]+)\/([^/]+)\/([^/?]+)/ + ); + if (match) return `slack://${match[1]}/${match[2]}/${match[3]}/`; + return ''; + } + case 'email': + if (!fields.username || !fields.password || !fields.host) return ''; + return `mailtos://${encodeURIComponent(fields.username)}:${encodeURIComponent(fields.password)}@${fields.host}${ + fields.port ? `:${fields.port}` : '' + }`; + case 'webhook': + return fields.url || ''; + case 'custom': + return fields.apprise_url || ''; + default: + return ''; + } +} + +export function NotificationWizard({ onComplete, onCancel, initialData }: NotificationWizardProps) { + const [step, setStep] = useState<1 | 2 | 3>(initialData ? 3 : 1); + const [selectedChannel, setSelectedChannel] = useState(initialData?.channel ?? ''); + const [fields, setFields] = useState>({}); + const [name, setName] = useState(initialData?.name ?? ''); + const [notifyOnErrors, setNotifyOnErrors] = useState(initialData?.notify_on_errors ?? true); + const [notifyOnSuccess, setNotifyOnSuccess] = useState(initialData?.notify_on_success ?? false); + const [showUrl, setShowUrl] = useState(false); + + const builtUrl = buildAppriseUrl(selectedChannel, fields); + const effectiveUrl = builtUrl || initialData?.apprise_url || ''; + + const handleChannelSelect = (channelId: string) => { + setSelectedChannel(channelId); + setFields({}); + setStep(2); + }; + + const handleFieldChange = (key: string, value: string) => { + setFields((prev) => ({ ...prev, [key]: value })); + }; + + const canProceedStep2 = () => { + const hasAnyField = Object.values(fields).some((v) => v.trim()); + if (initialData?.apprise_url && !hasAnyField) return true; + const channelFields = CHANNEL_FIELDS[selectedChannel] ?? []; + return channelFields.every((f) => f.optional || (fields[f.key] ?? '').trim().length > 0); + }; + + const handleSubmit = () => { + if (!effectiveUrl || !name.trim()) return; + onComplete({ + name: name.trim(), + channel: selectedChannel, + apprise_url: effectiveUrl, + notify_on_errors: notifyOnErrors, + notify_on_success: notifyOnSuccess, + }); + }; + + // ── Step 1: Choose channel ───────────────────────────────────────────── + if (step === 1) { + return ( +
+
+

+ + Choose Notification Channel +

+

Select how you want to receive alerts.

+
+ +
+ {CHANNEL_OPTIONS.map((channel) => ( + + ))} +
+ + +
+ ); + } + + // ── Step 2: Fill in fields ───────────────────────────────────────────── + if (step === 2) { + const channelOption = CHANNEL_OPTIONS.find((c) => c.id === selectedChannel); + const channelFields = CHANNEL_FIELDS[selectedChannel] ?? []; + + return ( +
+ + +
+ {channelOption?.icon} +
+

{channelOption?.label}

+

{channelOption?.description}

+
+
+ + {initialData?.apprise_url && ( +

+ Leave all fields blank to keep the existing URL unchanged. +

+ )} + +
+ {channelFields.map((field) => ( +
+ + handleFieldChange(field.key, e.target.value)} + placeholder={field.placeholder} + className="w-full px-3 py-2 border border-gray-300 rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500" + /> + {field.hint &&

{field.hint}

} +
+ ))} +
+ +
+ + +
+
+ ); + } + + // ── Step 3: Preview + preferences ───────────────────────────────────── + return ( +
+ + +
+

+ + Final Setup +

+

+ Name your channel and set notification preferences. +

+
+ +
+ + setName(e.target.value)} + placeholder="e.g. My Telegram Alert" + className="w-full px-3 py-2 border border-gray-300 rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500" + /> +
+ + {effectiveUrl && ( +
+
+

Apprise URL

+ +
+

+ {showUrl ? effectiveUrl : '•'.repeat(Math.min(effectiveUrl.length, 48))} +

+
+ )} + +
+

Notify me when:

+ + +
+ +
+ + +
+
+ ); +} diff --git a/frontend/src/lib/api.ts b/frontend/src/lib/api.ts index 81a63b2..efa34e0 100644 --- a/frontend/src/lib/api.ts +++ b/frontend/src/lib/api.ts @@ -485,4 +485,135 @@ export const adminApi = { }, }; +// ── Notification Types ────────────────────────────────────────────────── + +export interface NotificationConfig { + id: number; + user_id: number; + name: string; + channel: string; + apprise_url: string | null; + is_enabled: boolean; + config: Record; + notify_on_errors: boolean; + notify_on_success: boolean; + notify_threshold: number; + created_at: string; + updated_at: string; +} + +export interface NotificationConfigCreate { + name: string; + channel: string; + apprise_url?: string | null; + is_enabled?: boolean; + config?: Record; + notify_on_errors?: boolean; + notify_on_success?: boolean; + notify_threshold?: number; +} + +export interface NotificationConfigUpdate { + name?: string; + channel?: string; + apprise_url?: string | null; + is_enabled?: boolean; + config?: Record; + notify_on_errors?: boolean; + notify_on_success?: boolean; + notify_threshold?: number; +} + +export interface AdminNotificationConfig { + id: number; + name: string; + apprise_url: string; + is_enabled: boolean; + notify_on_errors: boolean; + notify_on_system_events: boolean; + description: string | null; + created_at: string; + updated_at: string; +} + +export interface AdminNotificationConfigCreate { + name: string; + apprise_url: string; + is_enabled?: boolean; + notify_on_errors?: boolean; + notify_on_system_events?: boolean; + description?: string | null; +} + +export interface AdminNotificationConfigUpdate { + name?: string; + apprise_url?: string; + is_enabled?: boolean; + notify_on_errors?: boolean; + notify_on_system_events?: boolean; + description?: string | null; +} + +// ── Notifications API ─────────────────────────────────────────────────── + +export const notificationsApi = { + async list(): Promise { + const response = await api.get('/notifications'); + return response.data; + }, + + async create(data: NotificationConfigCreate): Promise { + const response = await api.post('/notifications', data); + return response.data; + }, + + async update(id: number, data: NotificationConfigUpdate): Promise { + const response = await api.put(`/notifications/${id}`, data); + return response.data; + }, + + async delete(id: number): Promise { + await api.delete(`/notifications/${id}`); + }, + + async test(apprise_url: string): Promise<{ success: boolean; message: string }> { + const response = await api.post<{ success: boolean; message: string }>( + '/notifications/test', + { apprise_url } + ); + return response.data; + }, +}; + +// ── Admin Notifications API ───────────────────────────────────────────── + +export const adminNotificationsApi = { + async list(): Promise { + const response = await api.get('/admin/notifications'); + return response.data; + }, + + async create(data: AdminNotificationConfigCreate): Promise { + const response = await api.post('/admin/notifications', data); + return response.data; + }, + + async update(id: number, data: AdminNotificationConfigUpdate): Promise { + const response = await api.put(`/admin/notifications/${id}`, data); + return response.data; + }, + + async delete(id: number): Promise { + await api.delete(`/admin/notifications/${id}`); + }, + + async test(apprise_url: string): Promise<{ success: boolean; message: string }> { + const response = await api.post<{ success: boolean; message: string }>( + '/admin/notifications/test', + { apprise_url } + ); + return response.data; + }, +}; + export default api;