fix: Simplify notification settings and fix notification test on dashboard.

This commit is contained in:
Elisiário Couto
2025-09-11 12:16:47 +01:00
parent 5a823d62f0
commit 91020e32ea
5 changed files with 39 additions and 58 deletions

View File

@@ -102,7 +102,7 @@ export default function Notifications() {
if (!testService) return; if (!testService) return;
testMutation.mutate({ testMutation.mutate({
service: testService, service: testService.toLowerCase(),
message: testMessage, message: testMessage,
}); });
}; };
@@ -113,7 +113,7 @@ export default function Notifications() {
`Are you sure you want to delete the ${serviceName} notification service?`, `Are you sure you want to delete the ${serviceName} notification service?`,
) )
) { ) {
deleteServiceMutation.mutate(serviceName); deleteServiceMutation.mutate(serviceName.toLowerCase());
} }
}; };

View File

@@ -3,29 +3,31 @@ import { useState } from "react";
import Sidebar from "../components/Sidebar"; import Sidebar from "../components/Sidebar";
import Header from "../components/Header"; import Header from "../components/Header";
export const Route = createRootRoute({ function RootLayout() {
component: () => { const [sidebarOpen, setSidebarOpen] = useState(false);
const [sidebarOpen, setSidebarOpen] = useState(false);
return ( return (
<div className="flex h-screen bg-gray-100"> <div className="flex h-screen bg-gray-100">
<Sidebar sidebarOpen={sidebarOpen} setSidebarOpen={setSidebarOpen} /> <Sidebar sidebarOpen={sidebarOpen} setSidebarOpen={setSidebarOpen} />
{/* Mobile overlay */} {/* Mobile overlay */}
{sidebarOpen && ( {sidebarOpen && (
<div <div
className="fixed inset-0 z-40 bg-gray-600 bg-opacity-75 lg:hidden" className="fixed inset-0 z-40 bg-gray-600 bg-opacity-75 lg:hidden"
onClick={() => setSidebarOpen(false)} onClick={() => setSidebarOpen(false)}
/> />
)} )}
<div className="flex flex-col flex-1 overflow-hidden"> <div className="flex flex-col flex-1 overflow-hidden">
<Header setSidebarOpen={setSidebarOpen} /> <Header setSidebarOpen={setSidebarOpen} />
<main className="flex-1 overflow-y-auto p-6"> <main className="flex-1 overflow-y-auto p-6">
<Outlet /> <Outlet />
</main> </main>
</div>
</div> </div>
); </div>
}, );
}
export const Route = createRootRoute({
component: RootLayout,
}); });

View File

@@ -4,8 +4,5 @@ import { TanStackRouterVite } from "@tanstack/router-vite-plugin";
// https://vite.dev/config/ // https://vite.dev/config/
export default defineConfig({ export default defineConfig({
plugins: [ plugins: [TanStackRouterVite(), react()],
TanStackRouterVite(),
react(),
],
}); });

View File

@@ -36,14 +36,11 @@ async def get_notification_settings() -> APIResponse:
if discord_config.get("webhook") if discord_config.get("webhook")
else None, else None,
telegram=TelegramConfig( telegram=TelegramConfig(
token="***" token="***" if telegram_config.get("api-key") else "",
if (telegram_config.get("token") or telegram_config.get("api-key")) chat_id=telegram_config.get("chat-id", 0),
else "",
chat_id=telegram_config.get("chat_id")
or telegram_config.get("chat-id", 0),
enabled=telegram_config.get("enabled", True), enabled=telegram_config.get("enabled", True),
) )
if (telegram_config.get("token") or telegram_config.get("api-key")) if telegram_config.get("api-key")
else None, else None,
filters=NotificationFilters( filters=NotificationFilters(
case_insensitive=filters_config.get("case-insensitive", []), case_insensitive=filters_config.get("case-insensitive", []),
@@ -79,8 +76,8 @@ async def update_notification_settings(settings: NotificationSettings) -> APIRes
if settings.telegram: if settings.telegram:
notifications_config["telegram"] = { notifications_config["telegram"] = {
"token": settings.telegram.token, "api-key": settings.telegram.token,
"chat_id": settings.telegram.chat_id, "chat-id": settings.telegram.chat_id,
"enabled": settings.telegram.enabled, "enabled": settings.telegram.enabled,
} }
@@ -155,24 +152,12 @@ async def get_notification_services() -> APIResponse:
"telegram": { "telegram": {
"name": "Telegram", "name": "Telegram",
"enabled": bool( "enabled": bool(
( notifications_config.get("telegram", {}).get("api-key")
notifications_config.get("telegram", {}).get("token") and notifications_config.get("telegram", {}).get("chat-id")
or notifications_config.get("telegram", {}).get("api-key")
)
and (
notifications_config.get("telegram", {}).get("chat_id")
or notifications_config.get("telegram", {}).get("chat-id")
)
), ),
"configured": bool( "configured": bool(
( notifications_config.get("telegram", {}).get("api-key")
notifications_config.get("telegram", {}).get("token") and notifications_config.get("telegram", {}).get("chat-id")
or notifications_config.get("telegram", {}).get("api-key")
)
and (
notifications_config.get("telegram", {}).get("chat_id")
or notifications_config.get("telegram", {}).get("chat-id")
)
), ),
"active": notifications_config.get("telegram", {}).get("enabled", True), "active": notifications_config.get("telegram", {}).get("enabled", True),
}, },

View File

@@ -109,9 +109,8 @@ class NotificationService:
"""Check if Telegram notifications are enabled""" """Check if Telegram notifications are enabled"""
telegram_config = self.notifications_config.get("telegram", {}) telegram_config = self.notifications_config.get("telegram", {})
return bool( return bool(
telegram_config.get("token") telegram_config.get("api-key")
or telegram_config.get("api-key") and telegram_config.get("chat-id")
and (telegram_config.get("chat_id") or telegram_config.get("chat-id"))
and telegram_config.get("enabled", True) and telegram_config.get("enabled", True)
) )
@@ -174,10 +173,8 @@ class NotificationService:
ctx.obj = { ctx.obj = {
"notifications": { "notifications": {
"telegram": { "telegram": {
"api-key": telegram_config.get("token") "api-key": telegram_config.get("api-key"),
or telegram_config.get("api-key"), "chat-id": telegram_config.get("chat-id"),
"chat-id": telegram_config.get("chat_id")
or telegram_config.get("chat-id"),
} }
} }
} }