Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for userId in sample app #527

Merged
merged 4 commits into from
Apr 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions SampleApp/javascript/js/SettingsTab.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down Expand Up @@ -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: "[email protected]" }),
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: "[email protected]/userId" }),
React.createElement(Button, { title: "Login", onPress: this.onLoginTapped })));
}
updateState() {
Expand All @@ -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 });
}
})
}
});
}
Expand Down
29 changes: 24 additions & 5 deletions SampleApp/typescript/ts/SettingsTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,16 @@ class SettingsTab extends Component<Props, State> {

private renderLoggedOut() {
console.log("renderLoggedOut")
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/
return (
<View style={styles.emailContainer}>
<TextInput
value={this.state.email}
style={styles.emailTextInput}
autoCapitalize="none"
autoCompleteType="email"
autoCompleteType= {emailRegex.test(this.state.email) ? "email" : "none"}
onChangeText={(text) => this.setState({ isLoggedIn: false, email: text })}
placeholder="[email protected]" />
placeholder="[email protected]/userId" />
<Button
title="Login"
onPress={this.onLoginTapped}
Expand All @@ -75,13 +76,24 @@ class SettingsTab extends Component<Props, State> {

private onLoginTapped = () => {
console.log("onLoginTapped")
Iterable.setEmail(this.state.email)
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/
if (emailRegex.test(this.state.email)) {
Iterable.setEmail(this.state.email)
} else{
Iterable.setUserId(this.state.email)
}
this.updateState()
}

private onLogoutTapped = () => {
console.log("onLogoutTapped")
Iterable.setEmail(undefined)

const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if (emailRegex.test(this.state.email)) {
Iterable.setEmail(undefined)
} else {
Iterable.setUserId(undefined)
}
this.updateState()
}

Expand All @@ -91,7 +103,14 @@ class SettingsTab extends Component<Props, State> {
if (email) {
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 })
}
})
}
})
}
Expand Down
Loading