Guest User

Untitled

a guest
Jun 3rd, 2020
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import * as React from 'react';
  2. import {Text, View, TextInput, TouchableOpacity, Image} from 'react-native';
  3. import styles from "../../config/Styles";
  4. import { connect } from 'react-redux';
  5. import { login } from '../../redux/actions';
  6. import Input from '../../components/Input';
  7.  
  8.  
  9. class Login extends React.Component {
  10.     state= {
  11.         user: "",
  12.         password: "",
  13.         loader: false
  14.         }
  15.  
  16.     _getDisabled(){
  17.         let disabled = false;
  18.         if(!this.state.user)
  19.             disabled = true;
  20.         if(this.state.loader)
  21.             disabled = true;
  22.         if(!this.state.password || this.state.password.length <=5)
  23.             disabled = true;
  24.         return disabled;
  25.     }
  26.  
  27.     _login(){
  28.         this.setState({ loader : true })
  29.         this.props.login(this.state).then(($result) => {
  30.             //todo salio bien enviamos a otra vista donde veremos el perfild del usuario
  31.         }).catch( (err) => {
  32.             Alert.alert('Error',err.message);
  33.         })
  34.     }
  35.  
  36.     /** login() {
  37.         this.props.navigation.navigate('HomeFinalCustomer')
  38.         const { user, password, email, phone_number } = this.state
  39.         try {
  40.             // here place your signup logic
  41.             console.log('user successfully signed up!: ', success)
  42.         } catch (err) {
  43.             console.log('error signing up: ', err)
  44.         }
  45.     } **/
  46.  
  47.     render(){
  48.         return (
  49.           <View style={styles.container}>
  50.               <View style={styles.welcomeContainer}>
  51.                   <Image
  52.                       source={
  53.                           __DEV__
  54.                               ? require('../../assets/images/icon.png')
  55.                               : require('../../assets/images/icon.png')
  56.                       }
  57.                       style={styles.welcomeImage}
  58.                   />
  59.               </View>
  60.               <Text style={styles.text}>Usuario</Text>
  61.               <View style={styles.inputView} >
  62.                   <Input
  63.                       placeholder="Usuario..."
  64.                       value={this.state.user}
  65.                       onChangeText={text => this.setState({user:text})}
  66.                   />
  67.               </View>
  68.               <Text style={styles.text}>Password</Text>
  69.               <View style={styles.inputView} >
  70.                   <TextInput
  71.                       secureTextEntry
  72.                       style={styles.inputText}
  73.                       placeholder="Password..."
  74.                       placeholderTextColor="#003f5c"
  75.                       onChangeText={text => this.setState({password:text})}/>
  76.               </View>
  77.               <TouchableOpacity style={styles.loginBtn}  disabled={this._getDisabled()} onPress={()=> this._login()}>
  78.                   <Text style={styles.loginText}>LOGIN</Text>
  79.               </TouchableOpacity>
  80.               <TouchableOpacity  onPress={()=> this.props.navigation.navigate('RecoverPassword')}>
  81.                   <Text style={styles.forgot}>Olvide mi password</Text>
  82.               </TouchableOpacity>
  83.           </View>
  84.       );
  85.     }
  86. }
  87.  
  88. function MapStateToProps(state){
  89.     return {
  90.         user : state.session && state.session.user ? state.session.user : false
  91.     }
  92. }
  93.  
  94. export default connect(MapStateToProps, { login })(Login);
Add Comment
Please, Sign In to add comment