| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- import React, { Component} from 'react';
- import { Text } from 'react-native';
- import { connect } from 'react-redux';
- import { Card, CardSection, Input, Button, Spinner } from './common';
- import { emailChanged, passwordChanged, loginUser } from '../actions/';
- import { Actions } from 'react-native-router-flux';
- class LoginForm extends Component {
- onEmailChange(text) {
- this.props.emailChanged(text);
- }
- onPasswordChange(text){
- this.props.passwordChanged(text);
- }
- onRegisterPress() {
- Actions.register();
- }
- onLoginPress(){
- const { email, password } = this.props;
- this.props.loginUser({ email, password });
- }
- renderButton() {
- if (this.props.loading) {
- return <Spinner size="large" />;
- }
- return (
- <Button onPress={this.onLoginPress.bind(this)}>
- Ingresar
- </Button>
- );
- }
- render() {
- return (
- <Card>
- <CardSection>
- <Input
- label="Email"
- placeholder="email@gmail.com"
- value={this.props.email}
- onChangeText={this.onEmailChange.bind(this)}
- />
- </CardSection>
- <CardSection>
- <Input
- secureTextEntry
- label="Clave"
- placeholder="clave"
- value={this.props.password}
- onChangeText={this.onPasswordChange.bind(this)}
- />
- </CardSection>
- <Text style={styles.errorTextStyle}>
- {this.props.error}
- </Text>
- <CardSection>
- {this.renderButton()}
- </CardSection>
- <CardSection>
- <Button onPress={this.onRegisterPress.bind(this)}>
- Registrarse
- </Button>
- </CardSection>
- </Card>
- );
- }
- }
- const styles = {
- errorTextStyle: {
- fontSize: 20,
- alignSelf: 'center',
- color: 'red'
- }
- }
- const mapStateToProps = ({ auth }) => {
- const { email, password, error, loading } = auth;
- return { email, password, error, loading };
- };
- export default connect(mapStateToProps, {
- emailChanged, passwordChanged, loginUser
- } )(LoginForm);
|