diff --git a/SampleApp/javascript/js/SettingsTab.js b/SampleApp/javascript/js/SettingsTab.js index 74161dc5e..48792bc8d 100644 --- a/SampleApp/javascript/js/SettingsTab.js +++ b/SampleApp/javascript/js/SettingsTab.js @@ -6,14 +6,24 @@ import { Iterable } from '@iterable/react-native-sdk'; class SettingsTab extends Component { constructor(props) { super(props); + const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; this.onLoginTapped = () => { console.log("onLoginTapped"); - Iterable.setEmail(this.state.email); + if (emailRegex.test(this.state.email)) { + Iterable.setEmail(this.state.email); + this.updateState(); + } else { + Iterable.setUserId(this.state.email); + } this.updateState(); }; this.onLogoutTapped = () => { console.log("onLogoutTapped"); - Iterable.setEmail(undefined); + if (emailRegex.test(this.state.email)) { + Iterable.setEmail(undefined); + } else{ + Iterable.setUserId(undefined); + } this.updateState(); }; this.state = { isLoggedIn: false }; @@ -42,8 +52,9 @@ class SettingsTab extends Component { } renderLoggedOut() { console.log("renderLoggedOut"); + const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/ return (React.createElement(View, { style: styles.emailContainer }, - React.createElement(TextInput, { value: this.state.email, style: styles.emailTextInput, autoCapitalize: "none", autoCompleteType: "email", onChangeText: (text) => this.setState({ isLoggedIn: false, email: text }), placeholder: "user@example.com" }), + React.createElement(TextInput, { value: this.state.email, style: styles.emailTextInput, autoCapitalize: "none", autoCompleteType: emailRegex.test(this.state.email) ? "email" : "none", onChangeText: (text) => this.setState({ isLoggedIn: false, email: text }), placeholder: "user@example.com/userId" }), React.createElement(Button, { title: "Login", onPress: this.onLoginTapped }))); } updateState() { @@ -53,7 +64,14 @@ class SettingsTab extends Component { this.setState({ isLoggedIn: true, email: email }); } else { - this.setState({ isLoggedIn: false, email: undefined }); + Iterable.getUserId().then(userId => { + console.log("gotUserId: " + userId); + if(userId) { + this.setState({ isLoggedIn: true, email: userId }); + } else { + this.setState({ isLoggedIn: false, email: undefined }); + } + }) } }); } diff --git a/SampleApp/typescript/ts/SettingsTab.tsx b/SampleApp/typescript/ts/SettingsTab.tsx index 52ea872f8..a83cfdc75 100644 --- a/SampleApp/typescript/ts/SettingsTab.tsx +++ b/SampleApp/typescript/ts/SettingsTab.tsx @@ -56,15 +56,16 @@ class SettingsTab extends Component { private renderLoggedOut() { console.log("renderLoggedOut") + const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/ return ( this.setState({ isLoggedIn: false, email: text })} - placeholder="user@example.com" /> + placeholder="user@example.com/userId" />