feat(ui): show success message on user/group save, auto-refresh list
This commit is contained in:
parent
ecb3cbe442
commit
8bbdaf54ac
3 changed files with 14 additions and 7 deletions
|
|
@ -171,8 +171,8 @@ templ EditUserForm(u UserRow, groups []string) {
|
|||
<h3>Edit User</h3>
|
||||
<button class="btn-sm" hx-get="/admin/users/cancel-form" hx-target="#user-detail" hx-swap="innerHTML">Cancel</button>
|
||||
</div>
|
||||
<form hx-put={ "/admin/users/" + u.Username } hx-target="#user-list-body" hx-swap="innerHTML"
|
||||
hx-on::after-request="htmx.trigger('#user-detail', 'click')">
|
||||
<form hx-put={ "/admin/users/" + u.Username } hx-target="#user-detail" hx-swap="innerHTML"
|
||||
hx-on::after-request="htmx.trigger('#user-list-body', 'click')">
|
||||
<div class="form-group">
|
||||
<label>Username</label>
|
||||
<input type="text" class="input" value={ u.Username } readonly style="opacity:0.6"/>
|
||||
|
|
|
|||
|
|
@ -420,7 +420,7 @@ func EditUserForm(u UserRow, groups []string) templ.Component {
|
|||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 26, "\" hx-target=\"#user-list-body\" hx-swap=\"innerHTML\" hx-on::after-request=\"htmx.trigger('#user-detail', 'click')\"><div class=\"form-group\"><label>Username</label> <input type=\"text\" class=\"input\" value=\"")
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 26, "\" hx-target=\"#user-detail\" hx-swap=\"innerHTML\" hx-on::after-request=\"htmx.trigger('#user-list-body', 'click')\"><div class=\"form-group\"><label>Username</label> <input type=\"text\" class=\"input\" value=\"")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -390,13 +390,14 @@ func (h *Handler) editGroupForm(w http.ResponseWriter, r *http.Request) {
|
|||
func (h *Handler) updateGroup(w http.ResponseWriter, r *http.Request) {
|
||||
name := r.PathValue("name")
|
||||
desc := r.FormValue("description")
|
||||
// Update group description
|
||||
_, err := h.groupStore.db.Exec(`UPDATE groups SET description = ? WHERE name = ?`, desc, name)
|
||||
if err != nil {
|
||||
http.Error(w, "update failed", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
h.groupList(w, r)
|
||||
w.Header().Set("Content-Type", "text/html")
|
||||
w.Write([]byte(`<div class="alert success">Group updated successfully</div>
|
||||
<script>setTimeout(function(){htmx.trigger('#group-detail','click')},800)</script>`))
|
||||
}
|
||||
|
||||
func (h *Handler) editUserForm(w http.ResponseWriter, r *http.Request) {
|
||||
|
|
@ -423,10 +424,16 @@ func (h *Handler) updateUser(w http.ResponseWriter, r *http.Request) {
|
|||
groupVals := r.Form["group"]
|
||||
groups := ""
|
||||
for i, g := range groupVals {
|
||||
if i > 0 { groups += "," }
|
||||
if i > 0 {
|
||||
groups += ","
|
||||
}
|
||||
groups += g
|
||||
}
|
||||
h.store.GetDB().Exec(`UPDATE users SET role = ?, groups = ?, updated_at = CURRENT_TIMESTAMP WHERE username = ?`, role, groups, username)
|
||||
h.syncWriter.Sync()
|
||||
h.userRowsHandler(w, r)
|
||||
// Return success message and refresh user list
|
||||
w.Header().Set("Content-Type", "text/html")
|
||||
w.Write([]byte(`<div class="alert success">User updated successfully</div>
|
||||
<script>setTimeout(function(){htmx.trigger('#user-detail','click')},800)</script>`))
|
||||
// Trigger the refresh of the user list via HTMX
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue