-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCreateAccount.js
120 lines (115 loc) · 2.86 KB
/
CreateAccount.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
import React, {Component} from 'react'
import firebase from 'react-native-firebase'
import {
Alert,
StyleSheet,
ScrollView,
View,
Text,
Button
} from 'react-native';
import {
InputWithLabel,
PickerWithLabel,
AppButton,
} from './UI';
export default class CreateAccount extends Component<Props> {
constructor(props){
super(props);
}
static navigationOptions = {
title:'Join SET',
};
state = { email: '', password: '', errorMessage: null }
handleSignUp = () => {
if(this.state.email!='' && this.state.password!=''){
firebase
.auth()
.createUserWithEmailAndPassword(this.state.email, this.state.password)
.then(() => this.props.navigation.navigate('Login'))
.catch(error => this.setState({ errorMessage: error.message }))
}else if(this.state.email==''){
this.setState({ errorMessage:'Please enter email address.'})
}else if(this.state.password==''){
this.setState({ errorMessage:'Please enter password.'})
}
}
render() {
return (
<ScrollView style={styles.container}>
<Text style={styles.displayText}>SET</Text>
<Text>Sign Up</Text>
{this.state.errorMessage &&
<Text style={{ color: 'red' }}>
{this.state.errorMessage}
</Text>}
<View style={styles.headerWrapper}>
<InputWithLabel style={styles.input}
label={'Email'}
value={this.state.email}
autoCapitalize="none"
onChangeText={email => this.setState({email})}
orientation={'vertical'}
/>
</View>
<View style={styles.headerWrapper}>
<InputWithLabel style={styles.input}
label={'Password'}
value={this.state.password}
onChangeText={(password) => {this.setState({password})}}
orientation={'vertical'}
secureTextEntry={true}
autoCapitalize="none"
/>
</View>
<View style={styles.center}>
<AppButton style={styles.button}
title={'Create'}
theme={'primary'}
onPress={this.handleSignUp}
/>
<Button
title="Already have an account? Login"
onPress={() => this.props.navigation.navigate('Login')}
/>
</View>
</ScrollView>
)
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
padding: 20,
backgroundColor: '#fff',
},
center:{
justifyContent: 'center',
alignItems: 'center',
},
input: {
fontSize: 20,
color: 'black',
},
headerWrapper: {
borderBottomColor: 'black',
borderBottomWidth: 1,
marginBottom: 20,
},
picker: {
color: 'black',
marginTop: 10,
marginBottom: 10,
},
button: {
marginTop: 30,
marginBottom: 50,
width: 150,
alignItems: 'center',
borderRadius:100,
},
displayText: {
fontSize: 30,
marginBottom: 30,
},
});