[#19406] fix: add min char validation for nickname (#19517)

This commit is contained in:
Mohsen 2024-04-05 08:28:08 +03:00 committed by GitHub
parent 5bff89a58f
commit aead730d28
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 2 deletions

View File

@ -55,4 +55,5 @@
{:check (i18n/label :t/emojis)})
(validators/has-special-characters? s) (i18n/label :t/are-not-allowed
{:check (i18n/label :t/special-characters)})
(name-too-short? s) (i18n/label :t/minimum-characters {:min-chars min-length})
(name-too-long? s) (i18n/label :t/nickname-is-too-long)))

View File

@ -19,16 +19,19 @@
profile-picture (profile.utils/photo profile)
[unsaved-nickname set-unsaved-nickname] (rn/use-state nickname)
[error-msg set-error-msg] (rn/use-state nil)
[typing? set-typing?] (rn/use-state false)
has-nickname? (rn/use-memo (fn [] (not (string/blank? nickname)))
[nickname])
validate-nickname (rn/use-callback
(debounce/debounce
(fn [name]
(set-error-msg
(profile-validator/validation-nickname name)))
(profile-validator/validation-nickname name))
(set-typing? false))
300))
on-cancel (rn/use-callback #(rf/dispatch [:hide-bottom-sheet]))
on-nickname-change (rn/use-callback (fn [text]
(set-typing? true)
(set-unsaved-nickname text)
(validate-nickname text)))
on-nickname-submit (rn/use-callback
@ -74,7 +77,8 @@
[quo/bottom-actions
{:actions :two-actions
:button-one-label (i18n/label (if has-nickname? :t/update-nickname-title :t/add-nickname-title))
:button-one-props {:disabled? (or (string/blank? unsaved-nickname)
:button-one-props {:disabled? (or typing?
(string/blank? unsaved-nickname)
(not (string/blank? error-msg)))
:customization-color customization-color
:on-press on-nickname-submit}