Add a validation for the about form in the admin panel.

This commit is contained in:
2024-04-19 08:24:18 +03:00
parent a8fc0ab70c
commit 634f7e41e2
4 changed files with 40 additions and 2 deletions
+23
View File
@@ -258,6 +258,29 @@
(res/status 500)
(res/send (ex-message err))))))))
(defn htmx-about-validation-handler-factory
[]
(fn [req res]
(let [channel (chan)
about-content (.-content (.-body req))]
(go
(try
(let [error (cond
(= (count about-content) 0)
"Content must nonempty!!!"
:else
nil)]
(res/status 200)
(.render res "about_content_validation"
(-> {:error error
:about-content about-content
:layout false}
(clj->js))))
(catch js/Error err
(res/status 500)
(res/send (ex-message err))))))))
(defn htmx-update-about-handler-factory
[client]
(fn [req res]
+7
View File
@@ -94,6 +94,13 @@
(. app use "/admin"
(handlers/user-not-authorized-factory))
(. app post "/htmx/validation/about/"
handlers/is-user-authorized
(handlers/htmx-about-validation-handler-factory))
(. app use "/htmx/validation/about/"
(handlers/user-not-authorized-factory))
(. app patch "/htmx/about/"
handlers/is-user-authorized
(handlers/htmx-update-about-handler-factory client))