-
Notifications
You must be signed in to change notification settings - Fork 0
/
SignUp.js
154 lines (141 loc) · 6.15 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
import { Formik } from 'formik'
import React, { useState } from 'react'
import {Octicons, Ionicons, Fontisto} from '@expo/vector-icons'
//import * as Google from 'expo-google-app-auth'
import axios from 'axios'
import { TextInput } from 'react-native-gesture-handler'
import { ActivityIndicator, View } from 'react-native'
import { InnerContainer,
LeftIcon,
PageLogo,
PageTitle,
LoginContainer,
SubTitle,
Colors,
StyledFormArea,
StyledInputLabel,
StyledTextInput,
RightIcon,
MsgBox,
StyledButton,
ButtonText,
Line } from '/Users/anyakathpalia/Desktop/MSB/temp/styles'
const SignUp = ({navigation}) => {
const [hidePassword, setHidePassword] = useState(true)
const [loading, setLoading] = useState(false)
const [message, setMessage] = useState("")
const [googleLoading, setGoogleLoading] = useState(false)
const handleLogin = (values) => {
setLoading(true)
//const url = "" ;
axios.post(url, values)
.then((response) => {
const result = response.data
console.log(result)
if(result == '0'){
setMessage("Username or password is wrong. Please try again")
}
else{
data = {email: values.email, user: result}
navigation.navigate('Home', data)
}
})
.catch(error => console.log(error))
setLoading(false)
}
return (
<LoginContainer>
<InnerContainer>
<PageLogo resizeMode='cover' source={require('/Users/anyakathpalia/Desktop/MSB/temp/Login/icon.png')}/>
<PageTitle>My Success Bits</PageTitle>
<SubTitle>Welcome</SubTitle>
<Formik
initialValues={{ username: '', email: '', password: ''}}
onSubmit={(values) => {
setLoading(true);
if(values.username == '' || values.email == '' || values.password == ''){
//setLoading(true)
console.log("Fill all details")
setMessage("Fill all details")
setLoading(false)
}
else{
setLoading(true)
handleLogin(values)
}
}}
>
{({handleChange, handleBlur, handleSubmit, values}) => (
<StyledFormArea>
<MyTextInput
label="Username"
icon="person"
placeholder="Enter username"
placeholderTextColor={Colors.alternative}
onChangeText={handleChange('username')}
onBlur={handleBlur('username')}
value={values.username}
keyboardType="email-address"
/>
<MyTextInput
label="Email Address"
icon="mail"
placeholder="Enter email"
placeholderTextColor={Colors.alternative}
onChangeText={handleChange('email')}
onBlur={handleBlur('email')}
value={values.email}
keyboardType="email-address"
/>
<MyTextInput
label="Password"
icon="lock"
placeholder="password"
placeholderTextColor={Colors.alternative}
onChangeText={handleChange('password')}
onBlur={handleBlur('password')}
value={values.password}
secureTextEntry={hidePassword}
isPassword={true}
hidePassword={hidePassword}
setHidePassword={setHidePassword}
/>
<MsgBox>{message}</MsgBox>
{loading &&
<StyledButton disbaled={true}>
<ActivityIndicator size="large" color="#ffffff" />
</StyledButton>
}
{!loading &&
<StyledButton onPress={handleSubmit}>
<ButtonText>Sign up</ButtonText>
</StyledButton>
}
<Line />
<StyledButton onPress={() => navigation.navigate('Log In')}>
<ButtonText>Already a member? Login</ButtonText>
</StyledButton>
</StyledFormArea>
)}
</Formik>
</InnerContainer>
</LoginContainer>
)
}
const MyTextInput = ({label, icon, isPassword, hidePassword, setHidePassword, ...props}) => {
return (
<View>
<LeftIcon>
<Octicons name={icon} size={30} color={Colors.alternative} />
</LeftIcon>
<StyledInputLabel>{label}</StyledInputLabel>
<StyledTextInput {...props}/>
{ isPassword && (
<RightIcon onPress={() => setHidePassword(!hidePassword)}>
<Ionicons name={hidePassword ? 'md-eye-off' : 'md-eye'} size={30} color={Colors.alternative} />
</RightIcon>
)}
</View>
)
}
export default SignUp