From f16e22e521daf2b8e746a820bab60669bb93639a Mon Sep 17 00:00:00 2001 From: Henry Dollman Date: Fri, 13 Sep 2024 18:19:12 -0400 Subject: [PATCH] updates to settings page and alerts --- beszel/internal/alerts/alerts.go | 14 +++---- .../components/routes/settings/general.tsx | 21 +++++++---- .../src/components/routes/settings/layout.tsx | 37 ++++++++----------- .../routes/settings/notifications.tsx | 36 +++++++++++------- .../routes/settings/sidebar-nav.tsx | 4 +- beszel/site/src/components/routes/system.tsx | 8 ++-- .../systems-table/systems-table.tsx | 2 +- beszel/site/src/components/table-alerts.tsx | 21 +++++------ 8 files changed, 75 insertions(+), 68 deletions(-) diff --git a/beszel/internal/alerts/alerts.go b/beszel/internal/alerts/alerts.go index 55e464a..7e840c8 100644 --- a/beszel/internal/alerts/alerts.go +++ b/beszel/internal/alerts/alerts.go @@ -29,7 +29,7 @@ type AlertData struct { LinkText string } -type UserAlertSettings struct { +type UserNotificationSettings struct { Emails []string `json:"emails"` Webhooks []string `json:"webhooks"` } @@ -166,16 +166,16 @@ func (am *AlertManager) sendAlert(data AlertData) { dbx.Params{"user": data.UserID}, ) if err != nil { - log.Println("Failed to get user settings", "err", err.Error()) + am.app.Logger().Error("Failed to get user settings", "err", err.Error()) return } // unmarshal user settings - userAlertSettings := UserAlertSettings{ + userAlertSettings := UserNotificationSettings{ Emails: []string{}, Webhooks: []string{}, } if err := record.UnmarshalJSONField("settings", &userAlertSettings); err != nil { - log.Println("Failed to unmarshal user settings", "err", err.Error()) + am.app.Logger().Error("Failed to unmarshal user settings", "err", err.Error()) } // send alerts via webhooks for _, webhook := range userAlertSettings.Webhooks { @@ -186,13 +186,12 @@ func (am *AlertManager) sendAlert(data AlertData) { } // send alerts via email if len(userAlertSettings.Emails) == 0 { - log.Println("No email addresses found") + // log.Println("No email addresses found") return } addresses := []mail.Address{} for _, email := range userAlertSettings.Emails { addresses = append(addresses, mail.Address{Address: email}) - log.Println("Sending alert via email to", email) } message := mailer.Message{ To: addresses, @@ -211,6 +210,7 @@ func (am *AlertManager) sendAlert(data AlertData) { } } +// SendShoutrrrAlert sends an alert via a Shoutrrr URL func (am *AlertManager) SendShoutrrrAlert(notificationUrl, title, message, link, linkText string) error { // services that support title param supportsTitle := []string{"bark", "discord", "gotify", "ifttt", "join", "matrix", "ntfy", "opsgenie", "pushbullet", "pushover", "slack", "teams", "telegram", "zulip"} @@ -259,7 +259,7 @@ func (am *AlertManager) SendShoutrrrAlert(notificationUrl, title, message, link, if err == nil { am.app.Logger().Info("Sent shoutrrr alert", "title", title) } else { - am.app.Logger().Error("Error sending shoutrrr alert", "errs", err) + am.app.Logger().Error("Error sending shoutrrr alert", "err", err.Error()) return err } return nil diff --git a/beszel/site/src/components/routes/settings/general.tsx b/beszel/site/src/components/routes/settings/general.tsx index b28b46f..e645807 100644 --- a/beszel/site/src/components/routes/settings/general.tsx +++ b/beszel/site/src/components/routes/settings/general.tsx @@ -13,6 +13,7 @@ import { LoaderCircleIcon, SaveIcon } from 'lucide-react' import { UserSettings } from '@/types' import { saveSettings } from './layout' import { useState } from 'react' +// import { Input } from '@/components/ui/input' export default function SettingsProfilePage({ userSettings }: { userSettings: UserSettings }) { const [isLoading, setIsLoading] = useState(false) @@ -30,17 +31,22 @@ export default function SettingsProfilePage({ userSettings }: { userSettings: Us

General

-

- Set your preferred language and chart display options. +

+ Change general application options.

+ {/*

Language

-

- Additional language support coming soon. +

+ Internationalization will be added in a future release. Please see the{' '} + + discussion on GitHub + {' '} + for more details.

- +
*/}

Chart options

-

Adjust display options for charts.

+

+ Adjust display options for charts. +