0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-06 14:50:20 -05:00

Dont show name error when editing new token and not touching name field

This commit is contained in:
Florian Schroedl 2024-09-18 10:19:59 +02:00
parent 49ff0df7f6
commit 308fff05c3

View file

@ -169,7 +169,8 @@ Token names should only contain letters and digits separated by . characters.")}
(mf/defc form
{::mf/wrap-props false}
[{:keys [token token-type]}]
(let [token (or token {:type token-type})
(let [validate-name? (mf/use-state (not (:id token)))
token (or token {:type token-type})
color? (wtt/color-token? token)
selected-set-tokens (mf/deref refs/workspace-selected-token-set-tokens)
active-theme-tokens (mf/deref refs/workspace-active-theme-sets-tokens)
@ -198,7 +199,10 @@ Token names should only contain letters and digits separated by . characters.")}
(debounce (fn [e]
(let [value (dom/get-target-val e)
errors (validate-name value)]
(reset! name-errors errors)))))
;; Prevent showing error when just going to another field on a new token
(when-not (and validate-name? (str/empty? value))
(reset! validate-name? false)
(reset! name-errors errors))))))
on-update-name (mf/use-callback
(mf/deps on-update-name-debounced)
(fn [e]