feat(dashboard): add HTMX form data binding and redirect to RestoreSystemCollection

Update RestoreSystemCollection handler to support form-encoded requests from HTMX:

- Add 'form' struct tags to CollectionName and ResetType fields to enable binding
  from both JSON payloads and form submissions (required for HTMX compatibility)
- Add conditional HTMX redirect handling that sets HX-Redirect header when
  the request originates from HTMX, directing users to /collections after
  successful restoration

This change enables the system collection restore functionality to work seamlessly
with HTMX-based modal forms, improving the user experience by providing proper
navigation after the restore operation completes without requiring JavaScript
redirect logic.
This commit is contained in:
2026-03-01 21:10:05 -05:00
parent 07d1143b7b
commit 4f37a13519
+7 -2
View File
@@ -111,8 +111,8 @@ func (h *DashboardHandler) RestoreSystemCollection(c echo.Context) error {
userUUID := uuid.UUID(user.ID.Bytes)
var req struct {
CollectionName string `json:"collection_name"`
ResetType string `json:"reset_type"` // "full" or "keep_books"
CollectionName string `form:"collection_name" json:"collection_name"`
ResetType string `form:"reset_type" json:"reset_type"`
}
if err := c.Bind(&req); err != nil {
@@ -146,6 +146,11 @@ func (h *DashboardHandler) RestoreSystemCollection(c echo.Context) error {
return c.JSON(http.StatusInternalServerError, map[string]string{"error": "Failed to restore system collection"})
}
// Add redirect header for HTMX requests
if c.Request().Header.Get("HX-Request") == "true" {
c.Response().Header().Set("HX-Redirect", "/collections")
}
return c.JSON(http.StatusOK, map[string]string{"message": "System collection restored to defaults"})
}