From ad0bfcac2c68dfcec9f67004cd3cfed0f9a5ae87 Mon Sep 17 00:00:00 2001 From: John O'Keefe Date: Wed, 29 Apr 2026 20:32:58 -0400 Subject: [PATCH] fix(admin): wire up default timezone setting in admin settings page The admin settings timezone dropdown was incomplete: it had no pre-selection of the current value, was missing consistent styling, and the form submission did not persist timezone changes. Changes: - frontend.go: load default_timezone from system_settings into the systemConfig map passed to the template - admin_settings.templ: match card styling used by the Base URL section; pre-select current timezone with selected?= attribute - sidecar.go: handle default_timezone in UpdateSystemConfiguration by writing to system_settings table instead of system_config; update HTMX response to include timezone section with current value - Add selectedAttr() helper for HTMX HTML string response --- internal/handlers/sidecar.go | 63 +++++++++++++++++++++++++++++++++- internal/router/frontend.go | 8 ++++- templates/admin_settings.templ | 34 +++++++++++------- 3 files changed, 90 insertions(+), 15 deletions(-) diff --git a/internal/handlers/sidecar.go b/internal/handlers/sidecar.go index 92c3b6a..9ba5cf9 100644 --- a/internal/handlers/sidecar.go +++ b/internal/handlers/sidecar.go @@ -388,6 +388,23 @@ func (h *SidecarHandler) UpdateSystemConfiguration(c *echo.Context) error { // Update each config value for key, value := range req { + if key == "default_timezone" { + if _, err := time.LoadLocation(value); err != nil { + return c.JSON(http.StatusBadRequest, map[string]string{ + "error": "invalid timezone", + }) + } + err := h.db.UpdateSystemSetting(ctx, database.UpdateSystemSettingParams{ + SettingKey: "default_timezone", + SettingValue: value, + }) + if err != nil { + return c.JSON(http.StatusInternalServerError, map[string]string{ + "error": "failed to update default timezone", + }) + } + continue + } _, err := h.db.SetSystemConfig(ctx, database.SetSystemConfigParams{ Key: key, Value: value, @@ -408,6 +425,12 @@ func (h *SidecarHandler) UpdateSystemConfiguration(c *echo.Context) error { return c.HTML(http.StatusInternalServerError, `
Failed to fetch updated configuration
`) } + defaultTimezone := "UTC" + tz, err := h.db.GetSystemTimezone(ctx) + if err == nil && tz != "" { + defaultTimezone = tz + } + // Render success message with updated form return c.HTML(http.StatusOK, fmt.Sprintf(`
@@ -437,6 +460,28 @@ func (h *SidecarHandler) UpdateSystemConfiguration(c *echo.Context) error {
+
+

System Defaults

+
+ + +

Default timezone for users who haven't set their own.

+
+
+ +
+
@@ -447,7 +492,16 @@ func (h *SidecarHandler) UpdateSystemConfiguration(c *echo.Context) error {

Device Sync: %s/api/sync

-`, baseURL.Value, baseURL.Value, baseURL.Value, baseURL.Value)) +`, baseURL.Value, + selectedAttr(defaultTimezone, "UTC"), + selectedAttr(defaultTimezone, "America/New_York"), + selectedAttr(defaultTimezone, "America/Chicago"), + selectedAttr(defaultTimezone, "America/Denver"), + selectedAttr(defaultTimezone, "America/Los_Angeles"), + selectedAttr(defaultTimezone, "America/Phoenix"), + selectedAttr(defaultTimezone, "America/Anchorage"), + selectedAttr(defaultTimezone, "Pacific/Honolulu"), + baseURL.Value, baseURL.Value, baseURL.Value)) } return c.JSON(http.StatusOK, map[string]string{ @@ -477,3 +531,10 @@ func sanitizeAll(s string, old string, new string) string { } return result } + +func selectedAttr(current, value string) string { + if current == value { + return " selected" + } + return "" +} diff --git a/internal/router/frontend.go b/internal/router/frontend.go index b63dc8e..2dca858 100644 --- a/internal/router/frontend.go +++ b/internal/router/frontend.go @@ -932,7 +932,13 @@ func registerFrontendRoutes(cfg *Config) { } systemConfig := map[string]string{ - "base_url": baseURL, + "base_url": baseURL, + "default_timezone": "UTC", + } + + defaultTimezone, err := cfg.Queries.GetSystemTimezone(c.Request().Context()) + if err == nil && defaultTimezone != "" { + systemConfig["default_timezone"] = defaultTimezone } var buf bytes.Buffer diff --git a/templates/admin_settings.templ b/templates/admin_settings.templ index 1bd0e26..f9d254c 100644 --- a/templates/admin_settings.templ +++ b/templates/admin_settings.templ @@ -51,19 +51,27 @@ templ AdminSettings(user User, systemConfig map[string]string, errorMessage stri -
-

System Defaults

- - +
+

System Defaults

+
+ + +

Default timezone for users who haven't set their own.

+