🐛 Fix show validation errors below inputs instead of showing a toast

This commit is contained in:
Luis de Dios 2026-09-16 22:42:12 +02:00
parent 14c3135e21
commit f3ca997d2a

View File

@ -21,7 +21,6 @@
[app.util.i18n :as i18n :refer [tr]]
[app.util.storage :as storage]
[beicon.v2.core :as rx]
[cuerdas.core :as str]
[rumext.v2 :as mf]))
;; --- PAGE: Register
@ -81,42 +80,40 @@
(mf/use-fn
(fn [cause]
(reset! submitted? false)
(let [{:keys [type code] :as edata} (ex-data cause)]
(let [{:keys [type code] :as edata} (ex-data cause)
set-field-error!
(fn [field message]
(swap! form assoc-in [:extra-errors field] message)
(swap! form assoc-in [:touched field] true))]
(condp = [type code]
[:restriction :email-does-not-match-invitation]
(st/emit! (ntf/error (tr "errors.email-does-not-match-invitation")))
(set-field-error! :email {:message (tr "errors.email-does-not-match-invitation")})
[:restriction :registration-disabled]
(st/emit! (ntf/error (tr "errors.registration-disabled")))
(set-field-error! :email {:message (tr "errors.registration-disabled")})
[:restriction :email-domain-is-not-allowed]
(st/emit! (ntf/error (tr "errors.email-domain-not-allowed")))
(set-field-error! :email {:message (tr "errors.email-domain-not-allowed")})
[:restriction :email-has-permanent-bounces]
(st/emit! (ntf/error (tr "errors.email-has-permanent-bounces" (:email edata))))
(set-field-error! :email {:message (tr "errors.email-has-permanent-bounces" (:email edata))})
[:restriction :email-has-complaints]
(st/emit! (ntf/error (tr "errors.email-has-permanent-bounces" (:email edata))))
(set-field-error! :email {:message (tr "errors.email-has-permanent-bounces" (:email edata))})
[:validation :email-already-exists]
(st/emit! (ntf/error (tr "errors.email-already-exists")))
(set-field-error! :email {:message (tr "errors.email-already-exists")})
[:validation :email-as-password]
(st/emit! (ntf/error (tr "errors.email-as-password")))
(set-field-error! :password {:message (tr "errors.email-as-password")})
[:validation :weak-password]
(let [details (:details edata)
items (when (seq details)
(->> details
(map #(str "<li>" (tr %) "</li>"))
(str/join "")))
detail (when items
(str "<ul>" items "</ul>"))]
(st/emit! (ntf/show {:content (tr "errors.weak-password")
:detail detail
:is-html true
:type :toast
:level :error})))
(let [options (when (seq (:details edata))
(mapv tr (:details edata)))]
(set-field-error! :password {:message (tr "errors.weak-password")
:options options}))
(do
(when-let [explain (get edata :explain)]