forked from vergnet/application-amicale
Implemented mail validation and improved responsiveness
This commit is contained in:
parent
6b336cfd03
commit
0b19915a62
1 changed files with 21 additions and 2 deletions
|
@ -1,7 +1,15 @@
|
||||||
// @flow
|
// @flow
|
||||||
|
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import {Keyboard, KeyboardAvoidingView, ScrollView, StyleSheet, TouchableWithoutFeedback, View} from "react-native";
|
import {
|
||||||
|
Alert,
|
||||||
|
Keyboard,
|
||||||
|
KeyboardAvoidingView,
|
||||||
|
ScrollView,
|
||||||
|
StyleSheet,
|
||||||
|
TouchableWithoutFeedback,
|
||||||
|
View
|
||||||
|
} from "react-native";
|
||||||
import {Avatar, Button, Card, HelperText, Text, TextInput, withTheme} from 'react-native-paper';
|
import {Avatar, Button, Card, HelperText, Text, TextInput, withTheme} from 'react-native-paper';
|
||||||
import ConnectionManager from "../../managers/ConnectionManager";
|
import ConnectionManager from "../../managers/ConnectionManager";
|
||||||
import {openBrowser} from "../../utils/WebBrowser";
|
import {openBrowser} from "../../utils/WebBrowser";
|
||||||
|
@ -15,12 +23,15 @@ type State = {
|
||||||
password: string,
|
password: string,
|
||||||
isEmailValidated: boolean,
|
isEmailValidated: boolean,
|
||||||
isPasswordValidated: boolean,
|
isPasswordValidated: boolean,
|
||||||
|
loading: boolean,
|
||||||
}
|
}
|
||||||
|
|
||||||
const ICON_AMICALE = require('../../assets/amicale.png');
|
const ICON_AMICALE = require('../../assets/amicale.png');
|
||||||
|
|
||||||
const RESET_PASSWORD_LINK = "https://www.amicale-insat.fr/password/reset";
|
const RESET_PASSWORD_LINK = "https://www.amicale-insat.fr/password/reset";
|
||||||
|
|
||||||
|
const emailRegex = /^.+@.+\..+$/;
|
||||||
|
|
||||||
class LoginScreen extends React.Component<Props, State> {
|
class LoginScreen extends React.Component<Props, State> {
|
||||||
|
|
||||||
state = {
|
state = {
|
||||||
|
@ -28,6 +39,7 @@ class LoginScreen extends React.Component<Props, State> {
|
||||||
password: '',
|
password: '',
|
||||||
isEmailValidated: false,
|
isEmailValidated: false,
|
||||||
isPasswordValidated: false,
|
isPasswordValidated: false,
|
||||||
|
loading: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
colors: Object;
|
colors: Object;
|
||||||
|
@ -63,7 +75,7 @@ class LoginScreen extends React.Component<Props, State> {
|
||||||
}
|
}
|
||||||
|
|
||||||
isEmailValid() {
|
isEmailValid() {
|
||||||
return false;
|
return emailRegex.test(this.state.email);
|
||||||
}
|
}
|
||||||
|
|
||||||
shouldShowEmailError() {
|
shouldShowEmailError() {
|
||||||
|
@ -106,12 +118,18 @@ class LoginScreen extends React.Component<Props, State> {
|
||||||
|
|
||||||
onSubmit() {
|
onSubmit() {
|
||||||
if (this.shouldEnableLogin()) {
|
if (this.shouldEnableLogin()) {
|
||||||
|
this.setState({loading: true});
|
||||||
ConnectionManager.getInstance().connect(this.state.email, this.state.password)
|
ConnectionManager.getInstance().connect(this.state.email, this.state.password)
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
console.log(data);
|
console.log(data);
|
||||||
|
Alert.alert('COOL', 'ÇA MARCHE');
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
|
Alert.alert('ERREUR', 'MDP OU MAIL INVALIDE');
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
this.setState({loading: false});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -188,6 +206,7 @@ class LoginScreen extends React.Component<Props, State> {
|
||||||
icon="send"
|
icon="send"
|
||||||
mode="contained"
|
mode="contained"
|
||||||
disabled={!this.shouldEnableLogin()}
|
disabled={!this.shouldEnableLogin()}
|
||||||
|
loading={this.state.loading}
|
||||||
onPress={this.onSubmit}
|
onPress={this.onSubmit}
|
||||||
style={{marginLeft: 'auto'}}>
|
style={{marginLeft: 'auto'}}>
|
||||||
LOGIN
|
LOGIN
|
||||||
|
|
Loading…
Reference in a new issue