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;
testMutation.mutate({
service: testService,
service: testService.toLowerCase(),
message: testMessage,
});
};
@@ -113,7 +113,7 @@ export default function Notifications() {
`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 Header from "../components/Header";
export const Route = createRootRoute({
component: () => {
const [sidebarOpen, setSidebarOpen] = useState(false);
function RootLayout() {
const [sidebarOpen, setSidebarOpen] = useState(false);
return (
<div className="flex h-screen bg-gray-100">
<Sidebar sidebarOpen={sidebarOpen} setSidebarOpen={setSidebarOpen} />
return (
<div className="flex h-screen bg-gray-100">
<Sidebar sidebarOpen={sidebarOpen} setSidebarOpen={setSidebarOpen} />
{/* Mobile overlay */}
{sidebarOpen && (
<div
className="fixed inset-0 z-40 bg-gray-600 bg-opacity-75 lg:hidden"
onClick={() => setSidebarOpen(false)}
/>
)}
{/* Mobile overlay */}
{sidebarOpen && (
<div
className="fixed inset-0 z-40 bg-gray-600 bg-opacity-75 lg:hidden"
onClick={() => setSidebarOpen(false)}
/>
)}
<div className="flex flex-col flex-1 overflow-hidden">
<Header setSidebarOpen={setSidebarOpen} />
<main className="flex-1 overflow-y-auto p-6">
<Outlet />
</main>
</div>
<div className="flex flex-col flex-1 overflow-hidden">
<Header setSidebarOpen={setSidebarOpen} />
<main className="flex-1 overflow-y-auto p-6">
<Outlet />
</main>
</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/
export default defineConfig({
plugins: [
TanStackRouterVite(),
react(),
],
plugins: [TanStackRouterVite(), react()],
});

View File

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

View File

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