mirror of
https://github.com/penpot/penpot.git
synced 2026-09-22 11:56:15 +00:00
🐛 Fix show validation errors below inputs instead of showing a toast
This commit is contained in:
parent
14c3135e21
commit
f3ca997d2a
@ -21,7 +21,6 @@
|
|||||||
[app.util.i18n :as i18n :refer [tr]]
|
[app.util.i18n :as i18n :refer [tr]]
|
||||||
[app.util.storage :as storage]
|
[app.util.storage :as storage]
|
||||||
[beicon.v2.core :as rx]
|
[beicon.v2.core :as rx]
|
||||||
[cuerdas.core :as str]
|
|
||||||
[rumext.v2 :as mf]))
|
[rumext.v2 :as mf]))
|
||||||
|
|
||||||
;; --- PAGE: Register
|
;; --- PAGE: Register
|
||||||
@ -81,42 +80,40 @@
|
|||||||
(mf/use-fn
|
(mf/use-fn
|
||||||
(fn [cause]
|
(fn [cause]
|
||||||
(reset! submitted? false)
|
(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]
|
(condp = [type code]
|
||||||
[:restriction :email-does-not-match-invitation]
|
[: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]
|
[: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]
|
[: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]
|
[: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]
|
[: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]
|
[: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]
|
[: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]
|
[:validation :weak-password]
|
||||||
(let [details (:details edata)
|
(let [options (when (seq (:details edata))
|
||||||
items (when (seq details)
|
(mapv tr (:details edata)))]
|
||||||
(->> details
|
(set-field-error! :password {:message (tr "errors.weak-password")
|
||||||
(map #(str "<li>" (tr %) "</li>"))
|
:options options}))
|
||||||
(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})))
|
|
||||||
|
|
||||||
(do
|
(do
|
||||||
(when-let [explain (get edata :explain)]
|
(when-let [explain (get edata :explain)]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user