Use phone's locale for phone number internationalization
This commit is contained in:
parent
f8a5237f44
commit
b21b4ecc1a
|
@ -7,7 +7,8 @@
|
||||||
"react-native-invertible-scroll-view",
|
"react-native-invertible-scroll-view",
|
||||||
"awesome-phonenumber",
|
"awesome-phonenumber",
|
||||||
"realm",
|
"realm",
|
||||||
"react-native-loading-spinner-overlay"
|
"react-native-loading-spinner-overlay",
|
||||||
|
"react-native-i18n"
|
||||||
],
|
],
|
||||||
"imageDirs": [
|
"imageDirs": [
|
||||||
"images"
|
"images"
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
[messenger.state :as state]
|
[messenger.state :as state]
|
||||||
[messenger.comm.intercom :as intercom :refer [set-user-phone-number]]
|
[messenger.comm.intercom :as intercom :refer [set-user-phone-number]]
|
||||||
[messenger.utils.utils :refer [log toast http-post]]
|
[messenger.utils.utils :refer [log toast http-post]]
|
||||||
|
[messenger.utils.phone-number :refer [format-phone-number]]
|
||||||
[messenger.utils.resources :as res]
|
[messenger.utils.resources :as res]
|
||||||
[messenger.components.spinner :refer [spinner]]
|
[messenger.components.spinner :refer [spinner]]
|
||||||
[messenger.android.sign-up-confirm :refer [sign-up-confirm]]
|
[messenger.android.sign-up-confirm :refer [sign-up-confirm]]
|
||||||
|
@ -15,9 +16,6 @@
|
||||||
|
|
||||||
(def nav-atom (atom nil))
|
(def nav-atom (atom nil))
|
||||||
|
|
||||||
(set! js/PhoneNumber (js/require "awesome-phonenumber"))
|
|
||||||
(def country-code "US")
|
|
||||||
|
|
||||||
(defn show-confirm-view []
|
(defn show-confirm-view []
|
||||||
(swap! state/app-state assoc :loading false)
|
(swap! state/app-state assoc :loading false)
|
||||||
(binding [state/*nav-render* false]
|
(binding [state/*nav-render* false]
|
||||||
|
@ -32,7 +30,7 @@
|
||||||
(intercom/sign-up phone-number whisper-identity show-confirm-view)))
|
(intercom/sign-up phone-number whisper-identity show-confirm-view)))
|
||||||
|
|
||||||
(defn update-phone-number [value]
|
(defn update-phone-number [value]
|
||||||
(let [formatted (str (.getNumber (js/PhoneNumber. value country-code "international")))]
|
(let [formatted (format-phone-number value)]
|
||||||
(set-user-phone-number formatted)))
|
(set-user-phone-number formatted)))
|
||||||
|
|
||||||
(defui Login
|
(defui Login
|
||||||
|
|
|
@ -4,16 +4,11 @@
|
||||||
[cljs.core.async :as async :refer [chan put! <!]]
|
[cljs.core.async :as async :refer [chan put! <!]]
|
||||||
[messenger.utils.utils :refer [log on-error http-post toast]]
|
[messenger.utils.utils :refer [log on-error http-post toast]]
|
||||||
[messenger.utils.crypt :refer [encrypt]]
|
[messenger.utils.crypt :refer [encrypt]]
|
||||||
|
[messenger.utils.phone-number :refer [format-phone-number]]
|
||||||
[messenger.comm.intercom :as intercom :refer [save-user-phone-number]]
|
[messenger.comm.intercom :as intercom :refer [save-user-phone-number]]
|
||||||
[messenger.models.contacts :as contacts-model]
|
[messenger.models.contacts :as contacts-model]
|
||||||
[syng-im.utils.logging :as log]))
|
[syng-im.utils.logging :as log]))
|
||||||
|
|
||||||
(set! js/PhoneNumber (js/require "awesome-phonenumber"))
|
|
||||||
(def country-code "US")
|
|
||||||
|
|
||||||
(defn- format-phone-number [number]
|
|
||||||
(str (.getNumber (js/PhoneNumber. number country-code "international"))))
|
|
||||||
|
|
||||||
(defn- get-contact-name [phone-contact]
|
(defn- get-contact-name [phone-contact]
|
||||||
(cstr/join " "
|
(cstr/join " "
|
||||||
(filter #(not (cstr/blank? %))
|
(filter #(not (cstr/blank? %))
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
(ns messenger.utils.phone-number)
|
||||||
|
|
||||||
|
(def i18n (js/require "react-native-i18n"))
|
||||||
|
(def locale (.-locale i18n))
|
||||||
|
(def country-code (subs locale 3 5))
|
||||||
|
(set! js/PhoneNumber (js/require "awesome-phonenumber"))
|
||||||
|
|
||||||
|
(defn format-phone-number [number]
|
||||||
|
(str (.getNumber (js/PhoneNumber. number country-code "international"))))
|
Loading…
Reference in New Issue