-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSignupScreen.js
249 lines (198 loc) · 7.48 KB
/
SignupScreen.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
import {
SafeAreaView,
Platform,
StyleSheet,
ScrollView,
View,
Text,
StatusBar,
Alert,
TouchableOpacity,
TextInput,
Image,
ImageBackground,
Linking,
FlatList,
Dimensions,
AsyncStorage,
ActivityIndicator,
} from 'react-native';
import NetInfo from "@react-native-community/netinfo";
import Loader from './Loader.js';
import React, {Component} from 'react';
import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view';
import Button from 'react-native-button';
const GLOBAL = require('./Global');
class SignupScreen extends React.Component {
constructor() {
super();
this.state={
phone:'',
password:'',
hidePassword: true,
name:'',
email:'',
result:'',
loading:''
}
}
showLoading() {
this.setState({loading: true})
}
hideLoading() {
this.setState({loading: false})
}
managePasswordVisibility = () => {
this.setState({ hidePassword: !this.state.hidePassword });
}
buttonClickListener = () =>{
NetInfo.fetch().then(state => {
if (state.isConnected == false){
alert('Please connect to internet')
return
}
})
let reg = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/ ;
if (this.state.name == ''){
alert('Please Enter Username')
}
if (this.state.email == ''){
alert('Please Enter Email id')
}
else if (this.state.email != '' && reg.test(this.state.email) === false){
alert('Please Enter Valid Email')
}
else if (this.state.phone == ''){
alert('Please Enter Mobile Number')
}
else if (this.state.password == ''){
alert('Please Enter password')
}else if (this.state.password.length < 6){
alert('Password must be 6 chracter long')
}
//password
else {
this.showLoading()
fetch('http://pumpfit.in/admin/webservices/register_otp', {
method: 'POST',
headers: {
'x-api-key': 'c3a3cf7c211b7c07b2495d8aef9761fc',
'Content-Type': 'application/json',
},
body: JSON.stringify({
mobile: this.state.phone,
email:this.state.email
}),
}).then((response) => response.json())
.then((responseJson) => {
this.hideLoading()
if (responseJson.status == true ) {
GLOBAL.username = this.state.name
GLOBAL.email = this.state.email
GLOBAL.password = this.state.password
GLOBAL.mobile = this.state.phone
GLOBAL.otp = responseJson.otp
// alert(JSON.stringify(GLOBAL.email))
alert('OTP Sent To Your Registered Mobile Number.')
this.props.navigation.navigate('OtpScreen')
}else {
alert(responseJson.message)
}
})
.catch((error) => {
console.error(error);
});
}
}
render() {
if(this.state.loading){
return(
<View style={{flex: 1}}>
<ActivityIndicator style = {{position: 'absolute',
left: 0,
right: 0,
top: 0,
bottom: 0,
backgroundColor: 'white',
justifyContent: 'center',
alignItems: 'center'}}
size="large" color="#e41582" />
</View>
)
}
return(
<View style={{flex:1,backgroundColor:'transparent'}}>
<ImageBackground style={{resizeMode:'contain',height:'100%',width:'100%'}} source={require('./login.png')}>
<KeyboardAwareScrollView keyboardShouldPersistTaps="always">
<Text style={{fontSize:42,fontFamily:'Exo2-Medium',color:'white',width:'90%',alignSelf:'center',textAlign:'center',marginTop:'31%'}}>Create New</Text>
<Text style={{fontSize:42,fontFamily:'Exo2-Medium',color:'white',width:'90%',alignSelf:'center',textAlign:'center',marginTop:-8}}>Account</Text>
<View style={{backgroundColor: 'rgba(0,0,0,0.3)',marginLeft:'5%',width:'90%',height:46,borderRadius:10,marginTop:26}}>
<TextInput
style={{fontSize:17,fontFamily:'Exo2-Medium',color:'rgba(255, 255, 255, 0.6)',width:'94%',height:46,marginLeft:'3%'}}
placeholder="Name"
placeholderTextColor="rgba(255, 255, 255, 0.6)"
maxLength={50}
onChangeText={(text) => this.setState({name: text})}
value={this.state.name}
/>
</View>
<View style={{backgroundColor: 'rgba(0,0,0,0.3)',marginLeft:'5%',width:'90%',height:46,borderRadius:10,marginTop:10}}>
<TextInput
style={{fontSize:17,fontFamily:'Exo2-Medium',color:'rgba(255, 255, 255, 0.6)',width:'94%',height:46,marginLeft:'3%'}}
placeholder="Email"
placeholderTextColor="rgba(255, 255, 255, 0.6)"
maxLength={30}
onChangeText={(text) => this.setState({email: text})}
value={this.state.email}
/>
</View>
<View style={{backgroundColor: 'rgba(0,0,0,0.3)',marginLeft:'5%',width:'90%',height:46,borderRadius:10,marginTop:10}}>
<TextInput
style={{fontSize:17,fontFamily:'Exo2-Medium',color:'rgba(255, 255, 255, 0.6)',width:'94%',height:46,marginLeft:'3%'}}
placeholder="Mobile No."
placeholderTextColor="rgba(255, 255, 255, 0.6)"
keyboardType="numeric"
maxLength={10}
onChangeText={(text) => this.setState({phone: text})}
value={this.state.phone}
/>
</View>
<View style={{backgroundColor: 'rgba(0,0,0,0.3)',marginLeft:'5%',width:'90%',height:46,borderRadius:10,marginTop:10,flexDirection:'row',alignItems:'center',justifyContent:'space-between'}}>
<TextInput
style={{fontSize:17,fontFamily:'Exo2-Medium',color:'rgba(255, 255, 255, 0.6)',width:'80%',height:46,marginLeft:'3%'}}
placeholder="Password"
secureTextEntry={this.state.hidePassword}
placeholderTextColor="rgba(255, 255, 255, 0.6)"
maxLength={30}
onChangeText={(text) => this.setState({password: text})}
value={this.state.password}
/>
<TouchableOpacity style={{marginRight:18}}
onPress = { this.managePasswordVisibility }>
<Image
style={{height:23,width:23,resizeMode:'contain'}}
source={(this.state.hidePassword) ? require('./hide1.png') : require('./show1.png') }
/>
</TouchableOpacity>
</View>
<Button
style={{fontSize: 18, color: '#161718',fontFamily:'Exo2-SemiBold'}}
containerStyle={{height:50,width:'90%',alignSelf:'center',marginTop:32,borderRadius:10,backgroundColor:'white',justifyContent:'center'}}
onPress={()=>this.buttonClickListener()}>
CREATE ACCOUNT
</Button>
<View style={{flexDirection:'row',alignItems:'center',justifyContent:'space-between',width:'56%',alignSelf:'center',marginTop:18}}>
<Text style={{fontSize:18,fontFamily:'Exo2-Medium',color:'rgba(255, 255, 255, 0.6)'}}>Already a member?</Text>
<Button
style={{fontSize: 18, color: 'white',fontFamily:'Exo2-Medium'}}
onPress={()=>this.props.navigation.goBack()}>
Log In
</Button>
</View>
</KeyboardAwareScrollView>
</ImageBackground>
</View>
);
}
}
export default SignupScreen;