-
Notifications
You must be signed in to change notification settings - Fork 0
/
signup.js
256 lines (236 loc) · 7.05 KB
/
signup.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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
import React from "react";
import {
StyleSheet,
Text,
TextInput,
View,
KeyboardAvoidingView,
StatusBar,
Image
} from "react-native";
import AwesomeButton from "react-native-really-awesome-button";
import ModalDropDown from "react-native-modal-dropdown";
import * as firebase from "firebase";
//Built a signup screen that includes text inputs of each placeholder. with no auto Cap and no auto correcting. Making sure everytime
//you finish one part, it move onto the next one with the "next() or arrow" button depending on which device you have
export default class signUpScreen extends React.Component {
//For Top Page Details
static navigationOptions = ({ navigation }) => {
return {
title: "Sign Up"
};
};
state = {
error: false,
successs: false,
firstName: "",
lastName: "",
email: "",
type: "",
options: ["Artist", "Author"],
password: "",
errorMessage: null
};
signOut = () => {
firebase.auth().signOut();
};
handleSignUp = () => {
this.signOut();
return firebase
.auth()
.createUserWithEmailAndPassword(this.state.email, this.state.password)
.then(userCredentials => {
console.log(userCredentials.user);
return userCredentials.user.updateProfile({
displayName: this.state.firstName + " " + this.state.lastName
});
})
.catch(error => this.setState({ errorMessage: error.message }));
};
saveNewUser = event => {
console.log(`Creating new ${this.state.type} please work`);
return fetch(`http://localhost:8000/api/${this.state.type}s/`, {
method: "POST",
credentials: "include",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
name: `${this.state.firstName}` + " " + `${this.state.lastName}`,
email: `${this.state.email}`
})
})
.then(res => {
console.log(`Created new ${this.state.type}`);
if (res.ok) {
return res.json();
}
throw new Error("Content validation");
})
.then(artist => {
this.setState({
success: true
});
})
.catch(err => {
this.setState({
error: true
});
});
};
/* from yt tutorial https://www.youtube.com/watch?v=TkuQAjnaSbM&t=128s */
render() {
return (
<KeyboardAvoidingView behavior="padding" style={styleSignUp.container}>
<View style={styleSignUp.container}>
<StatusBar barStyle="light-content" />
<Text>Welcome To</Text>
<Image
style={{ width: 300, height: 200, resizeMode: "contain" }}
source={require("./assets/xpression.png")}
/>
<Text>Where Artists and Authors Unite</Text>
<View style={styleSignUp.rowContainer}>
<TextInput
id="fName"
borderWidth={1}
placeholder="First Name"
placeholderTextColor="rgba(255,255,255,0.7)"
returnKeyType="next"
onSubmitEditing={() => this.lastName.focus()}
autoCapitalize="none"
autoCorrect={false}
style={styleSignUp.textInputs2}
onChangeText={firstName => this.setState({ firstName })}
value={this.state.firstName}
/>
<TextInput
id="LName"
borderWidth={1}
placeholder="Last Name"
placeholderTextColor="rgba(255,255,255,0.7)"
returnKeyType="next"
onSubmitEditing={() => this.eMail.focus()}
autoCapitalize="none"
autoCorrect={false}
style={styleSignUp.textInputs2}
ref={input => (this.lastName = input)}
onChangeText={lastName => this.setState({ lastName })}
value={this.state.lastName}
/>
</View>
<View style={styleSignUp.signUpContainer}>
<TextInput
id="emailing"
placeholder="E-Mail"
autoCapitalize="none"
placeholderTextColor="rgba(255,255,255,0.7)"
returnKeyType="next"
onSubmitEditing={() => this.passwordInput.focus()}
autoCapitalize="none"
autoCorrect={false}
keyboardType="email-address"
style={styleSignUp.textInputs}
ref={input => (this.eMail = input)}
onChangeText={email => this.setState({ email })}
value={this.state.email}
/>
<TextInput
placeholder="Password"
placeholderTextColor="rgba(255,255,255,0.7)"
returnKeyType="next"
secureTextEntry
style={styleSignUp.textInputs}
ref={input => (this.passwordInput = input)}
autoCorrect={false}
autoCapitalize="none"
style={styleSignUp.textInputs}
onChangeText={password => this.setState({ password })}
value={this.state.password}
/>
</View>
<ModalDropDown
style={styleSignUp.selectionType}
text="Select Type"
options={this.state.options}
dropdownStyle={{
height: 70,
Width: "40%"
}}
onSelect={type =>
this.setState({ type: `${this.state.options[type]}` })
}
value={this.state.type}
/>
</View>
<View style={styleSignUp.onebutton}>
<AwesomeButton
progress={true}
progressLoadingTime={3000}
width={100}
textColor="#000000"
backgroundColor="#5ce1e6"
alignItems="center"
onPress={() => {
this.handleSignUp()
.then(() => {
return this.saveNewUser();
})
.then(() => {
this.props.navigation.navigate("EditProfile", {
type: this.state.type
});
});
}}
>
<Text>Register</Text>
</AwesomeButton>
</View>
</KeyboardAvoidingView>
);
}
}
const styleSignUp = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#ff0080",
alignItems: "center",
justifyContent: "center"
},
SignUpContainer: {
padding: 10
},
textInputs: {
height: 40,
backgroundColor: "rgba(255,255,255,0.2)",
marginBottom: 10,
color: "#FFF",
paddingHorizontal: 103,
marginRight: 1,
borderWidth: 1
},
textInputs2: {
height: 40,
backgroundColor: "rgba(255,255,255,0.2)",
marginBottom: 10,
color: "#FFF",
paddingHorizontal: 33.5,
marginRight: 1
},
onebutton: {
marginBottom: 20,
alignItems: "center",
textAlign: "right"
},
rowContainer: {
flexDirection: "row",
alignItems: "center"
},
selectionType: {
backgroundColor: "rgba(255,255,255,0.2)",
marginBottom: 10,
paddingHorizontal: 95,
paddingVertical: 10,
borderWidth: 1
}
});