From eb116cc65d972bceae3dc8ed5f0533d99f0a09c1 Mon Sep 17 00:00:00 2001 From: Adrian Tiberius Date: Wed, 22 Jun 2016 11:18:46 +0300 Subject: [PATCH] try using clojure spec for validation Former-commit-id: 42d8ea47dff1a9494522c764af8eb837512aacf1 --- project.clj | 4 ++-- src/status_im/contacts/validations.cljs | 10 ++++++++++ src/status_im/contacts/views/new_contact.cljs | 7 +++---- 3 files changed, 15 insertions(+), 6 deletions(-) create mode 100644 src/status_im/contacts/validations.cljs diff --git a/project.clj b/project.clj index 4007f3100d..15d97363cc 100644 --- a/project.clj +++ b/project.clj @@ -3,8 +3,8 @@ :url "http://example.com/FIXME" :license {:name "Eclipse Public License" :url "http://www.eclipse.org/legal/epl-v10.html"} - :dependencies [[org.clojure/clojure "1.7.0"] - [org.clojure/clojurescript "1.7.170"] + :dependencies [[org.clojure/clojure "1.9.0-alpha7"] + [org.clojure/clojurescript "1.9.76"] [reagent "0.5.1" :exclusions [cljsjs/react]] [re-frame "0.6.0"] [prismatic/schema "1.0.4"] diff --git a/src/status_im/contacts/validations.cljs b/src/status_im/contacts/validations.cljs new file mode 100644 index 0000000000..6fb1819054 --- /dev/null +++ b/src/status_im/contacts/validations.cljs @@ -0,0 +1,10 @@ +(ns status-im.contacts.validations + (:require [cljs.spec :as s])) + +(s/def ::not-empty-string (s/and string? not-empty)) + +(s/def ::name ::not-empty-string) +(s/def ::whisper-identity ::not-empty-string) + +(s/def ::contact (s/keys :req-un [::name ::whisper-identity] + :opt-un [::phone ::photo-path ::address])) \ No newline at end of file diff --git a/src/status_im/contacts/views/new_contact.cljs b/src/status_im/contacts/views/new_contact.cljs index 94b25f115f..7e797f1f04 100644 --- a/src/status_im/contacts/views/new_contact.cljs +++ b/src/status_im/contacts/views/new_contact.cljs @@ -23,6 +23,8 @@ form-text-input]] [status-im.qr-scanner.views.scan-button :refer [scan-button]] [status-im.i18n :refer [label]] + [cljs.spec :as s] + [status-im.contacts.validations :as v] [status-im.contacts.styles :as st])) @@ -32,9 +34,6 @@ [text {:style toolbar-title-text} (label :t/add-new-contact)]]) -(defn valid-form? [name address] - (and (not (str/blank? name)) (not (str/blank? address)))) - (defview contact-name-input [name] [] [text-input @@ -67,7 +66,7 @@ :style icon-back} :handler #(dispatch [:navigate-back])} :custom-content toolbar-title - :action {:image {:source {:uri (if (valid-form? name whisper-identity) + :action {:image {:source {:uri (if (s/valid? ::v/contact new-contact) :icon_ok_blue :icon_ok_disabled)} :style icon-search}