diff --git a/screens/Amicale/LoginScreen.js b/screens/Amicale/LoginScreen.js index c1d398d..7f21cd2 100644 --- a/screens/Amicale/LoginScreen.js +++ b/screens/Amicale/LoginScreen.js @@ -1,9 +1,10 @@ // @flow import * as React from 'react'; -import {Keyboard, KeyboardAvoidingView, StyleSheet, TouchableWithoutFeedback, View} from "react-native"; -import {Button, Text, TextInput, Title} from 'react-native-paper'; +import {Keyboard, KeyboardAvoidingView, ScrollView, StyleSheet, TouchableWithoutFeedback, View} from "react-native"; +import {Avatar, Button, Card, HelperText, Text, TextInput, withTheme} from 'react-native-paper'; import ConnectionManager from "../../managers/ConnectionManager"; +import {openBrowser} from "../../utils/WebBrowser"; type Props = { navigation: Object, @@ -12,79 +13,228 @@ type Props = { type State = { email: string, password: string, + isEmailValidated: boolean, + isPasswordValidated: boolean, } +const ICON_AMICALE = require('../../assets/amicale.png'); -export default class LoginScreen extends React.Component { +const RESET_PASSWORD_LINK = "https://www.amicale-insat.fr/password/reset"; + +class LoginScreen extends React.Component { state = { email: '', password: '', + isEmailValidated: false, + isPasswordValidated: false, }; + colors: Object; + onEmailChange: Function; onPasswordChange: Function; + validateEmail: Function; + validatePassword: Function; + onSubmit: Function; + onEmailSubmit: Function; + onResetPasswordClick: Function; - constructor() { - super(); + passwordInputRef: Object; + + constructor(props) { + super(props); this.onEmailChange = this.onInputChange.bind(this, true); this.onPasswordChange = this.onInputChange.bind(this, false); + this.validateEmail = this.validateEmail.bind(this); + this.validatePassword = this.validatePassword.bind(this); + this.onSubmit = this.onSubmit.bind(this); + this.onEmailSubmit = this.onEmailSubmit.bind(this); + this.onResetPasswordClick = this.onResetPasswordClick.bind(this); + this.colors = props.theme.colors; + } + + onResetPasswordClick() { + openBrowser(RESET_PASSWORD_LINK, this.colors.primary); + } + + validateEmail() { + this.setState({isEmailValidated: true}); + } + + isEmailValid() { + return false; + } + + shouldShowEmailError() { + return this.state.isEmailValidated && !this.isEmailValid(); + } + + validatePassword() { + this.setState({isPasswordValidated: true}); + } + + isPasswordValid() { + return this.state.password !== ''; + } + + shouldShowPasswordError() { + return this.state.isPasswordValidated && !this.isPasswordValid(); + } + + shouldEnableLogin() { + return this.isEmailValid() && this.isPasswordValid(); } onInputChange(isEmail: boolean, value: string) { - if (isEmail) - this.setState({email: value}); - else - this.setState({password: value}); + if (isEmail) { + this.setState({ + email: value, + isEmailValidated: false, + }); + } else { + this.setState({ + password: value, + isPasswordValidated: false, + }); + } + } + + onEmailSubmit() { + this.passwordInputRef.focus(); } onSubmit() { - console.log('pressed'); - ConnectionManager.getInstance().connect(this.state.email, this.state.password) - .then((data) => { - console.log(data); - }) - .catch((error) => { - console.log(error); - }); + if (this.shouldEnableLogin()) { + ConnectionManager.getInstance().connect(this.state.email, this.state.password) + .then((data) => { + console.log(data); + }) + .catch((error) => { + console.log(error); + }); + } + } + + getFormInput() { + return ( + + + + EMAIL INVALID + + { + this.passwordInputRef = ref; + }} + label='Password' + mode='outlined' + value={this.state.password} + onChangeText={this.onPasswordChange} + onBlur={this.validatePassword} + onSubmitEditing={this.onSubmit} + error={this.shouldShowPasswordError()} + textContentType={'password'} + autoCapitalize={'none'} + autoCompleteType={'password'} + autoCorrect={false} + keyboardType={'default'} + returnKeyType={'done'} + secureTextEntry={true} + /> + + PLS ENTER PASSWORD + + + ); + } + + getMainCard() { + return ( + + } + /> + + {this.getFormInput()} + + + + + + ); + } + + getSecondaryCard() { + return ( + + + MDP OUBLIÉ ? t'es pas doué + + + + PAS DE COMPTE ? DOMMAGE PASSE À L'AMICALE + + + ); } render() { return ( - - - COUCOU - entrez vos identifiants - - - - + + + + {this.getMainCard()} + {this.getSecondaryCard()} - Pas de compte, dommage ! - - - - - + + ); } @@ -92,11 +242,12 @@ export default class LoginScreen extends React.Component { const styles = StyleSheet.create({ container: { - flex: 1 - }, - inner: { - padding: 24, flex: 1, + flexDirection: 'column', + justifyContent: 'center', + }, + card: { + margin: 10, }, header: { fontSize: 36, @@ -104,6 +255,9 @@ const styles = StyleSheet.create({ }, textInput: {}, btnContainer: { - marginTop: 12 + marginTop: 5, + marginBottom: 10, } }); + +export default withTheme(LoginScreen);