Advertisement
Guest User

Untitled

a guest
Apr 9th, 2017
547
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, { Component } from 'react';
  2. import { connect } from 'react-redux';
  3. import { Text } from 'react-native';
  4. import{ emailChanged, passwordChanged, loginUser } from '../actions';
  5. import { Card, CardSection, Button, Input, Spinner } from './common';
  6.  
  7.  
  8. class LoginForm extends Component {
  9.   onEmailChange(text) {
  10.     this.props.emailChanged(text);
  11.   }
  12.   onPasswordChange(text) {
  13.     this.props.passwordChanged(text);
  14.   }
  15.   onPressButton(){
  16.     const { email, password } = this.props;
  17.  
  18.     this.props.loginUser({email,password});
  19.   }
  20.  
  21.   renderButton() {
  22.     if(this.props.loading) {
  23.       return <Spinner size="large" />;
  24.     }
  25.     return (
  26.       <Button onPress={this.onPressButton.bind(this)}>
  27.         Login
  28.       </Button>
  29.     );
  30.   }
  31.  
  32.   render(){
  33.     return(
  34.       <Card>
  35.         <CardSection>
  36.           <Input
  37.             label='Email'
  38.             placeholder="example@gmail.com"
  39.             onChangeText={this.onEmailChange.bind(this)}
  40.             value = {this.props.email}
  41.             />
  42.         </CardSection>
  43.         <CardSection>
  44.           <Input
  45.             secureTextEntry
  46.             label='Password'
  47.             placeholder='Password'
  48.             onChangeText={this.onPasswordChange.bind(this)}
  49.             value = {this.props.password}
  50.           />
  51.         </CardSection>
  52.         <Text style={styles.errorTextStyle}>
  53.           {this.props.error}
  54.         </Text>
  55.         <CardSection>
  56.           {this.renderButton()}
  57.         </CardSection>
  58.       </Card>
  59.     );
  60.   }
  61. }
  62.  
  63. const styles = {
  64.   errorTextStyle: {
  65.     fontSize: 20,
  66.     alignSelf: 'center',
  67.     color: 'red'
  68.   }
  69. }
  70.  
  71. const mapStateToProps = ({ auth }) => {
  72.   const { email, password, error, loading } = auth;
  73.   console.log(error);
  74.   return { email,password, error, loading };
  75. };
  76.  
  77. export default connect(mapStateToProps,
  78.   { emailChanged, passwordChanged, loginUser })
  79.   (LoginForm);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement