@@ -20,28 +20,34 @@ export class Inscription extends Component {
20
20
show : false ,
21
21
showError : false ,
22
22
showErrorEmail : false ,
23
- loading : true ,
23
+ loading : false ,
24
24
user : '' ,
25
- usersEmail : [ ]
25
+ emailCheck : ''
26
26
}
27
27
}
28
28
29
- componentDidMount ( ) {
29
+ async emailCheck ( values ) {
30
30
31
- fetch ( `http://398927b4.ngrok.io/api/users` , {
31
+ this . setState ( { loading : true } )
32
+
33
+ fetch ( `http://d2714e36.ngrok.io/users/check/` + values . email , {
32
34
33
- method : 'GET ' ,
35
+ method : 'POST ' ,
34
36
headers : {
35
37
Accept : 'application/json' ,
36
38
'Content-Type' : 'application/json' ,
37
39
}
38
40
} )
39
- . then ( resp => {
40
- return resp . json ( )
41
+ . then ( async resp => {
42
+ if ( resp . status === 302 ) {
43
+ return resp . json ( )
44
+ }
41
45
} )
42
46
. then ( responseData => {
43
- responseData . map ( x => { this . state . usersEmail . push ( x . email ) } )
44
- this . setState ( { loading : false } )
47
+ if ( responseData ) {
48
+ this . setState ( { emailCheck : responseData . email } )
49
+ }
50
+ this . registerCall ( values )
45
51
} )
46
52
. catch ( err => {
47
53
console . log ( err )
@@ -50,27 +56,22 @@ export class Inscription extends Component {
50
56
51
57
async registerCall ( values ) {
52
58
53
- this . setState ( { loading : true } )
54
-
55
- let { usersEmail } = this . state
59
+ let { emailCheck } = this . state
60
+ let check
56
61
57
- let check = usersEmail . map ( x => {
58
-
59
- if ( x === values . email ) {
60
- return false
61
- }
62
- } )
62
+ if ( emailCheck === values . email ) {
63
+ check = false
64
+ } else {
65
+ check = true
66
+ }
63
67
64
68
if ( check === false ) {
65
69
this . setState ( { showErrorEmail : true } )
66
70
this . setState ( { loading : false } )
71
+ return false
67
72
}
68
73
69
- let date = values . birthDate . replace ( '/' , '-' ) . replace ( '/' , '-' ) + "T00:00:00"
70
- let birthDate = new Date ( date )
71
- let weight = parseInt ( values . poids )
72
-
73
- fetch ( `http://398927b4.ngrok.io/api/users` , {
74
+ fetch ( `http://d2714e36.ngrok.io/signup` , {
74
75
75
76
method : 'POST' ,
76
77
headers : {
@@ -81,8 +82,8 @@ export class Inscription extends Component {
81
82
"firstname" : values . prenom ,
82
83
"lastname" : values . nom ,
83
84
"email" : values . email ,
84
- "birthDate" : birthDate ,
85
- "weight" : weight ,
85
+ "birthDate" : values . birthDate ,
86
+ "weight" : parseInt ( values . poids ) ,
86
87
"password" : values . password ,
87
88
} )
88
89
@@ -104,12 +105,13 @@ export class Inscription extends Component {
104
105
this . setState ( { user : data . firstname } )
105
106
this . setState ( { show :true } )
106
107
setTimeout ( ( ) => {
107
- this . setState ( { show :false } )
108
+ // this.setState({ show:false })
108
109
this . props . navigation . navigate ( 'SignIn' ) ;
109
110
} , 2000 )
110
111
}
111
112
} )
112
113
. catch ( err => {
114
+ console . log ( err )
113
115
this . setState ( { showError : true } )
114
116
} )
115
117
}
@@ -130,8 +132,7 @@ export class Inscription extends Component {
130
132
. lowercase ( 'Majuscules non valides' )
131
133
. email ( 'Veuillez entrer un email valide' )
132
134
. ensure ( )
133
- . required ( 'Champ obligatoire' )
134
- . notOneOf ( this . state . usersEmail , 'Adresse email déjà existant' ) ,
135
+ . required ( 'Champ obligatoire' ) ,
135
136
136
137
password : yup . string ( )
137
138
. label ( 'Password' )
@@ -177,9 +178,8 @@ export class Inscription extends Component {
177
178
178
179
< KeyboardAvoidingView
179
180
contentContainerStyle = { styles . keyboard }
180
- behavior = { "padding" }
181
- enabled
182
- keyboardVerticalOffset = { 10 }
181
+ behavior = { "height" }
182
+ keyboardVerticalOffset = { - 10 }
183
183
>
184
184
185
185
{ /* Modal : Inscription réussit */ }
@@ -218,7 +218,7 @@ export class Inscription extends Component {
218
218
theme = "danger"
219
219
title = "Erreur"
220
220
subtitle = "Un problème est survenu sur le serveur, veuillez réessayer !"
221
- headerIconComponent = { < Ionicons name = "ios-alert" size = { 70 } color = "white" /> }
221
+ headerIconComponent = { < Ionicons name = "ios-alert" size = { 90 } color = "white" /> }
222
222
titleStyle = { { fontSize : 30 } }
223
223
subtitleStyle = { { fontSize : 18 } }
224
224
>
@@ -243,7 +243,7 @@ export class Inscription extends Component {
243
243
theme = "danger"
244
244
title = "Erreur"
245
245
subtitle = "L' addresse email que vous avez entré existe déjà !"
246
- headerIconComponent = { < Ionicons name = "ios-alert" size = { 70 } color = "white" /> }
246
+ headerIconComponent = { < Ionicons name = "ios-alert" size = { 90 } color = "white" /> }
247
247
titleStyle = { { fontSize : 30 } }
248
248
subtitleStyle = { { fontSize : 18 } }
249
249
>
@@ -285,7 +285,7 @@ export class Inscription extends Component {
285
285
poids : '' ,
286
286
} }
287
287
288
- onSubmit = { values => this . registerCall ( values ) }
288
+ onSubmit = { values => this . emailCheck ( values ) }
289
289
validationSchema = { validationSchema }
290
290
>
291
291
@@ -693,8 +693,7 @@ const styles = StyleSheet.create({
693
693
694
694
keyboard : {
695
695
696
- marginBottom : 0 ,
697
- paddingBottom : 0
696
+ marginBottom : 0
698
697
} ,
699
698
700
699
headerLogo : {
0 commit comments