From a5590a438f12f608b2e23dc8fe51bfaf918700f8 Mon Sep 17 00:00:00 2001 From: KS Jannette Date: Sun, 1 Mar 2026 03:36:32 -0500 Subject: [PATCH] notifcation dongif setttings - save to DB --- .../internal/models/notification_config.go | 10 +++++----- frontend/src/pages/Alerts.jsx | 17 +++++++++++++++++ 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/backend-go/internal/models/notification_config.go b/backend-go/internal/models/notification_config.go index 8f9090c..6606a41 100644 --- a/backend-go/internal/models/notification_config.go +++ b/backend-go/internal/models/notification_config.go @@ -45,11 +45,11 @@ func (m *NotificationConfigModel) UpsertConfig(ctx context.Context, userID strin VALUES ($1, $2, $3, $4, $5, $6, $7, NOW()) ON CONFLICT (user_id) DO UPDATE SET - discord_webhook_url = COALESCE($2, user_notification_configs.discord_webhook_url), - telegram_chat_id = COALESCE($3, user_notification_configs.telegram_chat_id), - telegram_bot_token = COALESCE($4, user_notification_configs.telegram_bot_token), - email = COALESCE($5, user_notification_configs.email), - slack_webhook_url = COALESCE($6, user_notification_configs.slack_webhook_url), + discord_webhook_url = $2, + telegram_chat_id = $3, + telegram_bot_token = $4, + email = $5, + slack_webhook_url = $6, notification_enabled = $7, updated_at = NOW() RETURNING user_id, discord_webhook_url, telegram_chat_id, telegram_bot_token, diff --git a/frontend/src/pages/Alerts.jsx b/frontend/src/pages/Alerts.jsx index a85c032..4405356 100644 --- a/frontend/src/pages/Alerts.jsx +++ b/frontend/src/pages/Alerts.jsx @@ -65,6 +65,7 @@ export default function Alerts() { const [testingChannels, setTestingChannels] = useState(false); const [settingUpEmail, setSettingUpEmail] = useState(false); const [sendingDigest, setSendingDigest] = useState(false); + const [hasExistingConfig, setHasExistingConfig] = useState(false); useEffect(() => { async function fetchData() { @@ -86,6 +87,14 @@ export default function Alerts() { setTelegramChatId(configData.telegram_chat_id || ""); setEmail(configData.email || ""); setSlackWebhookUrl(configData.slack_webhook_url || ""); + + const hasSaved = + !!configData.discord_webhook_url || + !!configData.telegram_bot_token || + !!configData.telegram_chat_id || + !!configData.email || + !!configData.slack_webhook_url; + setHasExistingConfig(hasSaved); } catch (err) { setError(err.message); console.error("Failed to fetch data:", err); @@ -155,6 +164,13 @@ export default function Alerts() { } async function handleSaveNotificationConfig() { + if (hasExistingConfig) { + const confirmed = window.confirm( + "This will overwrite your previously saved notification settings. Continue?", + ); + if (!confirmed) return; + } + try { setNotificationLoading(true); setNotificationError(null); @@ -170,6 +186,7 @@ export default function Alerts() { }; await updateNotificationConfig(config); + setHasExistingConfig(true); setNotificationSuccess("Notification settings saved!"); setTimeout(() => setNotificationSuccess(null), 3000); } catch (err) {