Validate phone number
This commit is contained in:
parent
252452f5b0
commit
152626da18
|
@ -2,8 +2,11 @@
|
|||
(:require
|
||||
[re-frame.core :refer [subscribe dispatch dispatch-sync]]
|
||||
[syng-im.components.chat.input.simple-command :refer [simple-command-input-view]]
|
||||
[syng-im.utils.phone-number :refer [valid-mobile-number?]]
|
||||
[syng-im.utils.utils :refer [log toast http-post]]
|
||||
[syng-im.utils.logging :as log]))
|
||||
|
||||
(defn phone-input-view [command]
|
||||
[simple-command-input-view command {:keyboardType "phone-pad"}])
|
||||
[simple-command-input-view command {:keyboardType "phone-pad"}
|
||||
:validator (fn [message]
|
||||
(valid-mobile-number? message))])
|
||||
|
|
|
@ -26,10 +26,15 @@
|
|||
(dispatch [:stage-command chat-id command text])
|
||||
(cancel-command-input))
|
||||
|
||||
(defn simple-command-input-view [command input-options]
|
||||
(defn valid? [message validator]
|
||||
(if validator
|
||||
(validator message)
|
||||
(pos? (count message))))
|
||||
|
||||
(defn simple-command-input-view [command input-options & {:keys [validator]}]
|
||||
(let [chat-id-atom (subscribe [:get-current-chat-id])
|
||||
message-atom (subscribe [:get-chat-command-content])]
|
||||
(fn [command input-options]
|
||||
(fn [command input-options & {:keys [validator]}]
|
||||
(let [chat-id @chat-id-atom
|
||||
message @message-atom]
|
||||
[view {:style {:flexDirection "row"
|
||||
|
@ -63,10 +68,11 @@
|
|||
:onChangeText (fn [new-text]
|
||||
(set-input-message new-text))
|
||||
:onSubmitEditing (fn [e]
|
||||
(send-command chat-id command message))}
|
||||
(when (valid? message validator)
|
||||
(send-command chat-id command message)))}
|
||||
input-options)
|
||||
message]
|
||||
(if (pos? (count message))
|
||||
(if (valid? message validator)
|
||||
[touchable-highlight {:on-press (fn []
|
||||
(send-command chat-id command message))
|
||||
:underlay-color :transparent}
|
||||
|
|
|
@ -7,3 +7,9 @@
|
|||
|
||||
(defn format-phone-number [number]
|
||||
(str (.getNumber (js/PhoneNumber. number country-code "international"))))
|
||||
|
||||
(defn valid-mobile-number? [number]
|
||||
(when (string? number)
|
||||
(let [number-obj (js/PhoneNumber. number country-code "international")]
|
||||
(and (.isValid number-obj)
|
||||
(.isMobile number-obj)))))
|
||||
|
|
Loading…
Reference in New Issue