Guest User

Untitled

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