1
- import React , { useContext } from 'react' ;
2
- import { Text , StyleSheet , View , TextInput , Button , Image } from 'react-native' ;
1
+ import React , { useContext , useState } from 'react' ;
2
+ import {
3
+ Text ,
4
+ StyleSheet ,
5
+ View ,
6
+ TextInput ,
7
+ TouchableOpacity ,
8
+ } from 'react-native' ;
3
9
import { Formik } from 'formik' ;
10
+ import SafeAreaView from 'react-native-safe-area-view' ;
4
11
5
12
import { CTX } from '../tools/context' ;
6
13
import LoginSchema from '../validation/Login' ;
@@ -12,12 +19,18 @@ export default function LoginScreen(props) {
12
19
const authContext = useContext ( CTX ) ;
13
20
const { _authenticate} = authContext ;
14
21
22
+ const [ errorMessage , setErrorMessage ] = useState ( '' ) ;
23
+
15
24
async function _onLogin ( values ) {
16
25
const { email, password} = values ;
17
26
const accessToken = email + password ;
18
27
19
- _authenticate ( accessToken ) ;
20
- navigate ( 'Home' ) ;
28
+ if ( email === 'trinhchinchin@gmail.com' && password === '123' ) {
29
+ _authenticate ( accessToken ) ;
30
+ navigate ( 'Home' ) ;
31
+ }
32
+
33
+ setErrorMessage ( 'Email or Password is not correct.' ) ;
21
34
}
22
35
23
36
function _navigateForgot ( ) {
@@ -29,14 +42,17 @@ export default function LoginScreen(props) {
29
42
}
30
43
31
44
return (
32
- < View style = { styles . container } >
33
- < Image
45
+ < SafeAreaView style = { styles . container } >
46
+ { /* <Image
34
47
style={{width: 50, height: 50}}
35
48
source={require('../assets/logo.png')}
36
- />
37
- < Text > Login </ Text >
49
+ /> */ }
50
+ < Text style = { styles . greeting } > { 'Welcome back.' } </ Text >
51
+ < View style = { styles . errorMessage } >
52
+ < Text > { errorMessage } </ Text >
53
+ </ View >
38
54
< Formik
39
- initialValues = { { email : 'trinchinchin @gmail.com' , password : '123' } }
55
+ initialValues = { { email : 'trinhchinchin @gmail.com' , password : '123' } }
40
56
validationSchema = { LoginSchema }
41
57
onSubmit = { values => {
42
58
_onLogin ( values ) ;
@@ -50,52 +66,118 @@ export default function LoginScreen(props) {
50
66
touched,
51
67
} ) => (
52
68
< View >
53
- < Text > Email</ Text >
54
- < TextInput
55
- style = { { height : 40 } }
56
- placeholder = "Type here to email!"
57
- onChangeText = { handleChange ( 'email' ) }
58
- onBlur = { handleBlur ( 'email' ) }
59
- value = { values . email }
60
- />
61
- { errors . email && touched . email ? (
62
- < Text style = { styles . error } > { errors . email } </ Text >
63
- ) : null }
64
- < Text > Password</ Text >
65
- < TextInput
66
- style = { { height : 40 } }
67
- placeholder = "Type here to password!"
68
- onChangeText = { handleChange ( 'password' ) }
69
- onBlur = { handleBlur ( 'password' ) }
70
- value = { values . password }
71
- secureTextEntry
72
- />
73
- { errors . password && touched . password ? (
74
- < Text style = { styles . error } > { errors . password } </ Text >
75
- ) : null }
76
- < Button onPress = { handleSubmit } title = "Login" color = "#841584" />
69
+ < View style = { styles . form } >
70
+ < View >
71
+ < Text style = { styles . inputTitle } > Email Address</ Text >
72
+ < TextInput
73
+ style = { styles . input }
74
+ onChangeText = { handleChange ( 'email' ) }
75
+ onBlur = { handleBlur ( 'email' ) }
76
+ value = { values . email }
77
+ />
78
+ { errors . email && touched . email ? (
79
+ < Text style = { styles . error } > { errors . email } </ Text >
80
+ ) : null }
81
+ </ View >
82
+ < View style = { { marginTop : 32 } } >
83
+ < Text style = { styles . inputTitle } > Password</ Text >
84
+ < TextInput
85
+ style = { styles . input }
86
+ onChangeText = { handleChange ( 'password' ) }
87
+ onBlur = { handleBlur ( 'password' ) }
88
+ value = { values . password }
89
+ secureTextEntry
90
+ />
91
+ { errors . password && touched . password ? (
92
+ < Text style = { styles . error } > { errors . password } </ Text >
93
+ ) : null }
94
+ </ View >
95
+ </ View >
96
+ < TouchableOpacity style = { styles . button } onPress = { handleSubmit } >
97
+ < Text style = { styles . buttonText } > Login</ Text >
98
+ </ TouchableOpacity >
77
99
</ View >
78
100
) }
79
101
</ Formik >
80
- < Text > OR</ Text >
81
- < Text > Don't have an account?</ Text >
82
- < Button onPress = { _navigateRegister } title = "Sign Up" color = "#841584" />
83
- < Button
84
- onPress = { _navigateForgot }
85
- title = "Forgot your password?"
86
- color = "#841584"
87
- />
88
- </ View >
102
+ < View
103
+ style = { {
104
+ flexDirection : 'row' ,
105
+ alignSelf : 'center' ,
106
+ marginTop : 32 ,
107
+ } } >
108
+ < Text style = { { color : '#414959' } } > Don't have an account? </ Text >
109
+ < TouchableOpacity onPress = { _navigateRegister } >
110
+ < Text style = { styles . signUpText } > Sign Up</ Text >
111
+ </ TouchableOpacity >
112
+ </ View >
113
+
114
+ < View
115
+ style = { {
116
+ flexDirection : 'row' ,
117
+ alignSelf : 'center' ,
118
+ marginTop : 32 ,
119
+ } } >
120
+ < TouchableOpacity onPress = { _navigateForgot } color = "#841584" >
121
+ < Text style = { styles . signUpText } > Forgot password?</ Text >
122
+ </ TouchableOpacity >
123
+ </ View >
124
+ </ SafeAreaView >
89
125
) ;
90
126
}
91
127
92
128
const styles = StyleSheet . create ( {
93
129
container : {
94
130
flex : 1 ,
131
+ } ,
132
+ greeting : {
133
+ marginTop : 32 ,
134
+ fontSize : 18 ,
135
+ fontWeight : '400' ,
136
+ textAlign : 'center' ,
137
+ } ,
138
+ errorMessage : {
139
+ height : 72 ,
95
140
alignItems : 'center' ,
96
141
justifyContent : 'center' ,
142
+ marginHorizontal : 30 ,
143
+ } ,
144
+ form : {
145
+ marginBottom : 48 ,
146
+ marginHorizontal : 30 ,
147
+ } ,
148
+ inputTitle : {
149
+ color : '#8A8F9E' ,
150
+ fontSize : 10 ,
151
+ textTransform : 'uppercase' ,
152
+ } ,
153
+ input : {
154
+ borderBottomColor : '#8A8F9E' ,
155
+ borderBottomWidth : StyleSheet . hairlineWidth ,
156
+ height : 40 ,
157
+ fontSize : 15 ,
158
+ color : '#161F3D' ,
97
159
} ,
98
160
error : {
99
- color : 'red' ,
161
+ color : '#E9446A' ,
162
+ fontSize : 13 ,
163
+ fontWeight : '600' ,
164
+ textAlign : 'center' ,
165
+ } ,
166
+ button : {
167
+ marginHorizontal : 30 ,
168
+ backgroundColor : '#E9446A' ,
169
+ borderRadius : 4 ,
170
+ height : 52 ,
171
+ alignItems : 'center' ,
172
+ justifyContent : 'center' ,
173
+ } ,
174
+ buttonText : {
175
+ color : '#fff' ,
176
+ fontWeight : '500' ,
177
+ } ,
178
+ signUpText : {
179
+ color : '#E9446A' ,
180
+ fontSize : 13 ,
181
+ fontWeight : '500' ,
100
182
} ,
101
183
} ) ;
0 commit comments