Skip to content

Commit 95b59bf

Browse files
author
Ervin
committed
Page_inscription
1 parent 8b725c1 commit 95b59bf

File tree

1 file changed

+92
-31
lines changed

1 file changed

+92
-31
lines changed

App/view/Inscription.js

Lines changed: 92 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
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'
33
import { Button, Text, Icon, Badge } from 'react-native-elements'
44
import { Formik } from 'formik'
55
import * as yup from 'yup'
@@ -19,42 +19,58 @@ export class Inscription extends Component {
1919
date: "",
2020
show: false,
2121
showError: false,
22+
showErrorEmail: false,
23+
loading: true,
2224
user: '',
23-
dummy: 1,
24-
// users: null
25+
usersEmail: []
2526
}
2627
}
2728

2829
componentDidMount() {
2930

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+
})
4749
}
4850

4951
async registerCall(values) {
5052

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+
}
5268

5369
let date = values.birthDate.replace('/', '-').replace('/', '-') + "T00:00:00"
5470
let birthDate = new Date(date)
5571
let weight = parseInt(values.poids)
5672

57-
fetch(`http://c3f47f4f.ngrok.io/api/users`, {
73+
fetch(`http://398927b4.ngrok.io/api/users`, {
5874

5975
method: 'POST',
6076
headers: {
@@ -84,6 +100,7 @@ export class Inscription extends Component {
84100
.then((data) => {
85101

86102
if (data) {
103+
this.setState({loading: false})
87104
this.setState({user: data.firstname})
88105
this.setState({ show:true })
89106
setTimeout(() => {
@@ -99,10 +116,8 @@ export class Inscription extends Component {
99116

100117
handleClose = () => {
101118
this.setState({ show: false })
102-
}
103-
104-
refreshPage = () => {
105-
this.setState({dummy: 1})
119+
this.setState({ showError: false })
120+
this.setState({ showErrorEmail: false })
106121
}
107122

108123
render() {
@@ -111,19 +126,23 @@ export class Inscription extends Component {
111126

112127
email: yup.string()
113128
.label('Email')
129+
.strict()
130+
.lowercase('Majuscules non valides')
114131
.email('Veuillez entrer un email valide')
115132
.ensure()
116-
.lowercase()
117-
.required('Champ obligatoire'),
133+
.required('Champ obligatoire')
134+
.notOneOf(this.state.usersEmail, 'Adresse email déjà existant'),
118135

119136
password: yup.string()
120137
.label('Password')
121138
.required('Champ obligatoire')
122-
.min(6, 'Minimum 6 caractères'),
139+
.min(6, 'Minimum 6 caractères')
140+
.matches(/^\S+$/, 'Espaces non autorisés'),
123141

124142
passwordVerify: yup.string()
125143
.label('Password verify')
126144
.required('Champ obligatoire')
145+
.matches(/^\S+$/, 'Espaces non autorisés')
127146
.oneOf([yup.ref('password'), null], 'La vérification a échouée'),
128147

129148
prenom: yup.string()
@@ -194,13 +213,36 @@ export class Inscription extends Component {
194213
onRequestClose={this.handleClose}
195214
theme="danger"
196215
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"
197239
subtitle="L' addresse email que vous avez entré existe déjà !"
198240
headerIconComponent={<Ionicons name="ios-alert" size={70} color="white" />}
199241
titleStyle={{ fontSize: 30 }}
200242
subtitleStyle={{ fontSize: 18}}
201243
>
202244

203-
<SCLAlertButton theme="danger" onPress={this.refreshPage}>Réessayer</SCLAlertButton>
245+
<SCLAlertButton theme="danger" onPress={this.handleClose}>Retour</SCLAlertButton>
204246

205247
</SCLAlert>
206248

@@ -593,8 +635,14 @@ export class Inscription extends Component {
593635
</View>
594636
)}
595637
</Formik>
638+
<View style={{ flex : 1 }} />
596639
</View>
597640
</ScrollView>
641+
642+
<View style={[(this.state.loading) ? styles.loading : '']}>
643+
<ActivityIndicator size={50} color="brown" animating={this.state.loading}/>
644+
</View>
645+
598646
</KeyboardAvoidingView>
599647
)
600648
}
@@ -638,7 +686,8 @@ const styles = StyleSheet.create({
638686

639687
keyboard: {
640688

641-
marginBottom: 0
689+
marginBottom: 0,
690+
paddingBottom: 0
642691
},
643692

644693
headerLogo: {
@@ -669,6 +718,18 @@ const styles = StyleSheet.create({
669718
backgroundColor: '#fff',
670719
},
671720

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+
672733
})
673734

674735

0 commit comments

Comments
 (0)