-
Notifications
You must be signed in to change notification settings - Fork 0
/
InviteUser.js
193 lines (175 loc) · 5.34 KB
/
InviteUser.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
import React, { Component } from 'react';
import { StyleSheet, Text, View, TextInput, TouchableOpacity,TouchableHighlight, ScrollView, TouchableWithoutFeedback, Keyboard } from 'react-native';
import NavigationBar from 'react-native-navbar';
import { Ionicons , FontAwesome} from '@expo/vector-icons';
import * as firebase from 'firebase';
import { Analytics, ScreenHit } from 'expo-analytics';
class InviteUser extends React.Component {
constructor() {
super();
this.state = {
email: "",
emailEmpty: true,
}
global.analytics.hit(new ScreenHit('InviteUser'))
.then(() => console.log("success"))
.catch(e => console.log(e.message));
}
render() {
const { params } = this.props.navigation.state;
return (
<View style={styles.navbar}>
<NavigationBar
title = {{
title: 'Invite Partner',
}}
leftButton = {{
title: 'Cancel',
handler: () => {this.props.navigation.goBack();},
}}
/>
<TouchableWithoutFeedback onPress={Keyboard.dismiss} accessible={false}>
<View style={styles.container}>
<Text style={styles.titleText}>Invite Your</Text>
<Text style={styles.titleText}>Significant Other</Text>
<Text style={styles.subtitleText}>(They will create an account with this email and we'll make a joint timeline for the two of you!)</Text>
<TextInput
value={this.state.email}
keyboardType = 'email-address'
onChangeText={(email) => this.setState({ email: email, emailEmpty: email.length == 0 })}
placeholder='email'
placeholderTextColor = 'red'
autoCapitalize = 'none'
style={[this.state.emailEmpty ? styles.invalidInput : styles.validInput]}
/>
<TouchableOpacity
style={styles.button}
onPress={this.onInviteUser.bind(this)}
>
<Text style={styles.buttonText}>Invite</Text>
</TouchableOpacity>
<View style={styles.buttons}>
<TouchableHighlight onPress={() => {this.props.navigation.navigate('Home');}} >
<FontAwesome
size={30}
name='home'
color='white'
/>
</TouchableHighlight>
</View>
</View>
</TouchableWithoutFeedback>
</View>
);
}
onInviteUser() {
if (this.state.email.length != 0) {
this.inviteUserToMomento(this.emailToHeader(this.state.email), global.timelineName)
this.props.navigation.navigate('Home');
}
}
emailToHeader(email) {
return email.replace(".","*-*");
}
headerToEmail(header) {
return header.replace("*-*",".");
}
preAddUSer(userName, momentoName){
var myRef = firebase.database().ref('/users');
myRef.update({[userName]: {color: "blue", momentos: {[momentoName]: momentoName}}});
}
//Helper function to "inviteUserToMomento." function -- associate a momento with a user account.
grantUserMomento(userName, momentoName){
var myRef = firebase.database().ref('/users/' + userName +'/momentos');
myRef.update({[momentoName]: momentoName});
}
//myMomento.update({[title]: {title: title, description: description, imageUrl: imageURL, time: time}});
//BYDefault, you either create a "first momento," or join an already accessible momento
//remember, call the "emailToHeader" method to get the proper username
inviteUserToMomento(userName, momentoName){
var myRef = firebase.database().ref('/users/');
myRef.once('value').then(function(snapshot)
{
var data = snapshot.val();
console.log(data[this.emailToHeader(userName)]);
//If user exists, add the momento to their "list of momentos"
if(data[this.emailToHeader(userName)] !== undefined){
this.grantUserMomento(userName, momentoName);
}
//If the user does not exist, create them on the DataBase!
else{
this.preAddUSer(userName, momentoName);
}
}.bind(this))
}
}
const styles = StyleSheet.create({
navbar: {
flex: 1,
backgroundColor: 'white',
paddingHorizontal: 10,
paddingTop: 28,
},
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
backgroundColor: 'white',
},
titleText:{
fontFamily: 'Baskerville',
fontSize: 50,
alignItems: 'center',
justifyContent: 'center',
},
subtitleText:{
padding: 10,
fontFamily: 'Baskerville',
fontSize: 20,
fontStyle: 'italic',
alignSelf: 'center',
justifyContent: 'center',
},
buttons: {
alignItems: 'flex-end',
justifyContent: 'center',
},
button: {
alignItems: 'center',
backgroundColor: 'powderblue',
width: 200,
height: 44,
padding: 10,
borderWidth: 1,
borderColor: 'white',
borderRadius: 25,
marginBottom: 10,
},
buttonText:{
fontFamily: 'Baskerville',
fontSize: 20,
alignItems: 'center',
justifyContent: 'center',
},
validInput: {
width: 200,
fontFamily: 'Baskerville',
fontSize: 20,
height: 44,
padding: 10,
borderWidth: 1,
borderColor: 'black',
marginVertical: 10,
},
invalidInput: {
width: 200,
fontFamily: 'Baskerville',
fontSize: 20,
height: 44,
padding: 10,
borderWidth: 1,
borderColor: 'red',
marginVertical: 10,
}
});
export default InviteUser;