1
1
import React , { Component } from 'react'
2
- import { TextInput , View , StyleSheet , KeyboardAvoidingView , ImageBackground , ScrollView } from 'react-native'
2
+ import { TextInput , View , StyleSheet , KeyboardAvoidingView , ImageBackground , ScrollView , ActivityIndicator } from 'react-native'
3
3
import { Button , Text , Icon , Badge } from 'react-native-elements'
4
4
import { Formik } from 'formik'
5
5
import * as yup from 'yup'
@@ -19,42 +19,58 @@ export class Inscription extends Component {
19
19
date : "" ,
20
20
show : false ,
21
21
showError : false ,
22
+ showErrorEmail : false ,
23
+ loading : true ,
22
24
user : '' ,
23
- dummy : 1 ,
24
- // users: null
25
+ usersEmail : [ ]
25
26
}
26
27
}
27
28
28
29
componentDidMount ( ) {
29
30
30
- // fetch(`http://192.168.43.242:8000/api/users`, {
31
- //
32
- // method: 'GET',
33
- // headers: {
34
- // Accept: 'application/json',
35
- // 'Content-Type': 'application/json',
36
- // }
37
- // })
38
- // .then(resp => {
39
- // return resp.json()
40
- // })
41
- // .then(responseData => {
42
- // this.setState({users: responseData})
43
- // })
44
- // .catch(err => {
45
- // console.log(err)
46
- // })
31
+ fetch ( `http://398927b4.ngrok.io/api/users` , {
32
+
33
+ method : 'GET' ,
34
+ headers : {
35
+ Accept : 'application/json' ,
36
+ 'Content-Type' : 'application/json' ,
37
+ }
38
+ } )
39
+ . then ( resp => {
40
+ return resp . json ( )
41
+ } )
42
+ . then ( responseData => {
43
+ responseData . map ( x => { this . state . usersEmail . push ( x . email ) } )
44
+ this . setState ( { loading : false } )
45
+ } )
46
+ . catch ( err => {
47
+ console . log ( err )
48
+ } )
47
49
}
48
50
49
51
async registerCall ( values ) {
50
52
51
- // this.state.users.map(x => { console.log(x) })
53
+ this . setState ( { loading : true } )
54
+
55
+ let { usersEmail } = this . state
56
+
57
+ let check = usersEmail . map ( x => {
58
+
59
+ if ( x === values . email ) {
60
+ return false
61
+ }
62
+ } )
63
+
64
+ if ( check === false ) {
65
+ this . setState ( { showErrorEmail : true } )
66
+ this . setState ( { loading : false } )
67
+ }
52
68
53
69
let date = values . birthDate . replace ( '/' , '-' ) . replace ( '/' , '-' ) + "T00:00:00"
54
70
let birthDate = new Date ( date )
55
71
let weight = parseInt ( values . poids )
56
72
57
- fetch ( `http://c3f47f4f .ngrok.io/api/users` , {
73
+ fetch ( `http://398927b4 .ngrok.io/api/users` , {
58
74
59
75
method : 'POST' ,
60
76
headers : {
@@ -84,6 +100,7 @@ export class Inscription extends Component {
84
100
. then ( ( data ) => {
85
101
86
102
if ( data ) {
103
+ this . setState ( { loading : false } )
87
104
this . setState ( { user : data . firstname } )
88
105
this . setState ( { show :true } )
89
106
setTimeout ( ( ) => {
@@ -99,10 +116,8 @@ export class Inscription extends Component {
99
116
100
117
handleClose = ( ) => {
101
118
this . setState ( { show : false } )
102
- }
103
-
104
- refreshPage = ( ) => {
105
- this . setState ( { dummy : 1 } )
119
+ this . setState ( { showError : false } )
120
+ this . setState ( { showErrorEmail : false } )
106
121
}
107
122
108
123
render ( ) {
@@ -111,19 +126,23 @@ export class Inscription extends Component {
111
126
112
127
email : yup . string ( )
113
128
. label ( 'Email' )
129
+ . strict ( )
130
+ . lowercase ( 'Majuscules non valides' )
114
131
. email ( 'Veuillez entrer un email valide' )
115
132
. ensure ( )
116
- . lowercase ( )
117
- . required ( 'Champ obligatoire ') ,
133
+ . required ( 'Champ obligatoire' )
134
+ . notOneOf ( this . state . usersEmail , 'Adresse email déjà existant ') ,
118
135
119
136
password : yup . string ( )
120
137
. label ( 'Password' )
121
138
. required ( 'Champ obligatoire' )
122
- . min ( 6 , 'Minimum 6 caractères' ) ,
139
+ . min ( 6 , 'Minimum 6 caractères' )
140
+ . matches ( / ^ \S + $ / , 'Espaces non autorisés' ) ,
123
141
124
142
passwordVerify : yup . string ( )
125
143
. label ( 'Password verify' )
126
144
. required ( 'Champ obligatoire' )
145
+ . matches ( / ^ \S + $ / , 'Espaces non autorisés' )
127
146
. oneOf ( [ yup . ref ( 'password' ) , null ] , 'La vérification a échouée' ) ,
128
147
129
148
prenom : yup . string ( )
@@ -194,13 +213,36 @@ export class Inscription extends Component {
194
213
onRequestClose = { this . handleClose }
195
214
theme = "danger"
196
215
title = "Erreur"
216
+ subtitle = "Un problème est survenu sur le serveur, veuillez réessayer !"
217
+ headerIconComponent = { < Ionicons name = "ios-alert" size = { 70 } color = "white" /> }
218
+ titleStyle = { { fontSize : 30 } }
219
+ subtitleStyle = { { fontSize : 18 } }
220
+ >
221
+
222
+ < SCLAlertButton theme = "danger" onPress = { this . handleClose } > Réessayer</ SCLAlertButton >
223
+
224
+ </ SCLAlert >
225
+
226
+ </ View >
227
+
228
+ < View style = { {
229
+ backgroundColor : '#fff' ,
230
+ alignItems : 'center' ,
231
+ justifyContent : 'center'
232
+ } } >
233
+
234
+ < SCLAlert
235
+ show = { this . state . showErrorEmail }
236
+ onRequestClose = { this . handleClose }
237
+ theme = "danger"
238
+ title = "Erreur"
197
239
subtitle = "L' addresse email que vous avez entré existe déjà !"
198
240
headerIconComponent = { < Ionicons name = "ios-alert" size = { 70 } color = "white" /> }
199
241
titleStyle = { { fontSize : 30 } }
200
242
subtitleStyle = { { fontSize : 18 } }
201
243
>
202
244
203
- < SCLAlertButton theme = "danger" onPress = { this . refreshPage } > Réessayer </ SCLAlertButton >
245
+ < SCLAlertButton theme = "danger" onPress = { this . handleClose } > Retour </ SCLAlertButton >
204
246
205
247
</ SCLAlert >
206
248
@@ -593,8 +635,14 @@ export class Inscription extends Component {
593
635
</ View >
594
636
) }
595
637
</ Formik >
638
+ < View style = { { flex : 1 } } />
596
639
</ View >
597
640
</ ScrollView >
641
+
642
+ < View style = { [ ( this . state . loading ) ? styles . loading : '' ] } >
643
+ < ActivityIndicator size = { 50 } color = "brown" animating = { this . state . loading } />
644
+ </ View >
645
+
598
646
</ KeyboardAvoidingView >
599
647
)
600
648
}
@@ -638,7 +686,8 @@ const styles = StyleSheet.create({
638
686
639
687
keyboard : {
640
688
641
- marginBottom : 0
689
+ marginBottom : 0 ,
690
+ paddingBottom : 0
642
691
} ,
643
692
644
693
headerLogo : {
@@ -669,6 +718,18 @@ const styles = StyleSheet.create({
669
718
backgroundColor : '#fff' ,
670
719
} ,
671
720
721
+ loading : {
722
+ position : 'absolute' ,
723
+ left : 0 ,
724
+ right : 0 ,
725
+ top : 0 ,
726
+ bottom : 0 ,
727
+ alignItems : 'center' ,
728
+ justifyContent : 'center' ,
729
+ backgroundColor : 'rgba(255,255,255, 0.8)' ,
730
+
731
+ }
732
+
672
733
} )
673
734
674
735
0 commit comments