mirror of
https://github.com/status-im/status-mobile.git
synced 2025-01-27 08:55:39 +00:00
Validate phone number
Former-commit-id: 152626da18b1d062762d873d339688a7c4b15ad7
This commit is contained in:
parent
a077b29f9e
commit
65210893fe
@ -2,8 +2,11 @@
|
|||||||
(:require
|
(:require
|
||||||
[re-frame.core :refer [subscribe dispatch dispatch-sync]]
|
[re-frame.core :refer [subscribe dispatch dispatch-sync]]
|
||||||
[syng-im.components.chat.input.simple-command :refer [simple-command-input-view]]
|
[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.utils :refer [log toast http-post]]
|
||||||
[syng-im.utils.logging :as log]))
|
[syng-im.utils.logging :as log]))
|
||||||
|
|
||||||
(defn phone-input-view [command]
|
(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])
|
(dispatch [:stage-command chat-id command text])
|
||||||
(cancel-command-input))
|
(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])
|
(let [chat-id-atom (subscribe [:get-current-chat-id])
|
||||||
message-atom (subscribe [:get-chat-command-content])]
|
message-atom (subscribe [:get-chat-command-content])]
|
||||||
(fn [command input-options]
|
(fn [command input-options & {:keys [validator]}]
|
||||||
(let [chat-id @chat-id-atom
|
(let [chat-id @chat-id-atom
|
||||||
message @message-atom]
|
message @message-atom]
|
||||||
[view {:style {:flexDirection "row"
|
[view {:style {:flexDirection "row"
|
||||||
@ -63,10 +68,11 @@
|
|||||||
:onChangeText (fn [new-text]
|
:onChangeText (fn [new-text]
|
||||||
(set-input-message new-text))
|
(set-input-message new-text))
|
||||||
:onSubmitEditing (fn [e]
|
:onSubmitEditing (fn [e]
|
||||||
(send-command chat-id command message))}
|
(when (valid? message validator)
|
||||||
|
(send-command chat-id command message)))}
|
||||||
input-options)
|
input-options)
|
||||||
message]
|
message]
|
||||||
(if (pos? (count message))
|
(if (valid? message validator)
|
||||||
[touchable-highlight {:on-press (fn []
|
[touchable-highlight {:on-press (fn []
|
||||||
(send-command chat-id command message))
|
(send-command chat-id command message))
|
||||||
:underlay-color :transparent}
|
:underlay-color :transparent}
|
||||||
|
@ -7,3 +7,9 @@
|
|||||||
|
|
||||||
(defn format-phone-number [number]
|
(defn format-phone-number [number]
|
||||||
(str (.getNumber (js/PhoneNumber. number country-code "international"))))
|
(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…
x
Reference in New Issue
Block a user