More clear validation message in "Add new contact" form (#243)

This commit is contained in:
alwxndr 2016-09-22 17:06:00 +03:00
parent 878b3df32d
commit 9da9c1adfc
4 changed files with 21 additions and 13 deletions

View File

@ -176,7 +176,8 @@
:to-line-width 0} :to-line-width 0}
:onBlur on-blur}) :onBlur on-blur})
:on-change-text #(on-change-text %) :on-change-text #(on-change-text %)
:on-change #(on-change %)} value] :on-change #(on-change %)
:default-value value}]
[view {:style (st/underline-container line-color) [view {:style (st/underline-container line-color)
:onLayout #(r/set-state component {:max-line-width (get-width %)})} :onLayout #(r/set-state component {:max-line-width (get-width %)})}
[animated-view {:style (st/underline focus-line-color line-width)}]] [animated-view {:style (st/underline focus-line-color line-width)}]]

View File

@ -178,3 +178,6 @@
:right 0 :right 0
:width 200 :width 200
:height 170}) :height 170})
(def qr-input
{:margin-right 42})

View File

@ -28,8 +28,7 @@
[status-im.i18n :refer [label]] [status-im.i18n :refer [label]]
[cljs.spec :as s] [cljs.spec :as s]
[status-im.contacts.validations :as v] [status-im.contacts.validations :as v]
[status-im.contacts.styles :as st] [status-im.contacts.styles :as st]))
[status-im.components.styles :as cst]))
(def toolbar-title (def toolbar-title
@ -53,29 +52,32 @@
:photo-path (identicon id) :photo-path (identicon id)
:whisper-identity id}]))) :whisper-identity id}])))
(defn- validation-error-message [whisper-identity error]
(cond
(not (s/valid? ::v/unique-identity whisper-identity)) (label :t/contact-already-added)
(not (s/valid? ::v/whisper-identity whisper-identity)) (label :t/enter-valid-address)
:else error))
(defn toolbar-action [new-contact-identity error] (defn toolbar-action [new-contact-identity error]
(let [valid-contact? (and (let [error-message (validation-error-message new-contact-identity error)]
(s/valid? ::v/whisper-identity new-contact-identity) {:image {:source {:uri (if (str/blank? error-message)
(nil? error))]
{:image {:source {:uri (if valid-contact?
:icon_ok_blue :icon_ok_blue
:icon_ok_disabled)} :icon_ok_disabled)}
:style icon-search} :style icon-search}
:handler #(when valid-contact? :handler #(when (str/blank? error-message)
(on-add-contact new-contact-identity))})) (on-add-contact new-contact-identity))}))
(defview contact-whisper-id-input [whisper-identity error] (defview contact-whisper-id-input [whisper-identity error]
[] []
(let [error (if (str/blank? whisper-identity) "" error) (let [error (when-not (str/blank? whisper-identity)
error (if (s/valid? ::v/whisper-identity whisper-identity) (validation-error-message whisper-identity error))]
error
(label :t/enter-valid-address))]
[view button-input-container [view button-input-container
[text-field [text-field
{:error error {:error error
:error-color "#7099e6" :error-color "#7099e6"
:input-style st/qr-input
:value whisper-identity :value whisper-identity
:wrapper-style (merge button-input) :wrapper-style button-input
:label (label :t/address) :label (label :t/address)
:on-change-text #(do :on-change-text #(do
(dispatch [:set-in [:new-contact-identity] %]) (dispatch [:set-in [:new-contact-identity] %])
@ -83,6 +85,7 @@
[scan-button {:showLabel (zero? (count whisper-identity)) [scan-button {:showLabel (zero? (count whisper-identity))
:handler #(dispatch [:scan-qr-code {:toolbar-title (label :t/new-contact)} :set-contact-identity-from-qr])}]])) :handler #(dispatch [:scan-qr-code {:toolbar-title (label :t/new-contact)} :set-contact-identity-from-qr])}]]))
(defview new-contact [] (defview new-contact []
[new-contact-identity [:get :new-contact-identity] [new-contact-identity [:get :new-contact-identity]
error [:get :new-contact-address-error]] error [:get :new-contact-address-error]]

View File

@ -159,6 +159,7 @@
:whisper-identity "Whisper Identity" :whisper-identity "Whisper Identity"
:address-explication "Maybe here should be some text explaining what an address is and where to look for it" :address-explication "Maybe here should be some text explaining what an address is and where to look for it"
:enter-valid-address "Please enter a valid address or scan a QR code" :enter-valid-address "Please enter a valid address or scan a QR code"
:contact-already-added "The contact has already been added"
:unknown-address "Unknown address" :unknown-address "Unknown address"