Advertisement
Guest User

Untitled

a guest
Jul 4th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. import React, { Component, PropTypes } from 'react';
  2. import { View, Image, TextInput, Text, Dimensions, Alert } from 'react-native';
  3. import { Font } from 'expo';
  4. import { connect } from 'react-redux';
  5. import { LoginButton } from '../SubComponents/LoginComponent/LoginButton';
  6. import { loginUser } from '../../actions'
  7.  
  8. class Login extends Component {
  9. static propTypes = {
  10. loginUser: PropTypes.func,
  11. navigate: PropTypes.func,
  12. };
  13.  
  14. constructor(props) {
  15. super(props);
  16.  
  17. this.state = {
  18. fontLoaded: false,
  19. email: '',
  20. password: '',
  21. showIndicator: false,
  22. };
  23. }
  24.  
  25. // this is where we dispatch the action for saga to listen.
  26. login() {
  27. this.props.loginUser(); // ==> this is the action
  28.  
  29. if (this.props.status === true) {
  30. // when the user click the button for the first time, the action is dispatched and returned a new state, but i don
  31. this.setState({ showIndicator: false });
  32. this.props.navigate('Dashboard');
  33. } else {
  34. Alert.alert('Enter your username and password correctly', '', [
  35. { text: 'Retry', onPress: () => {} },
  36. ]);
  37. }
  38. }
  39.  
  40. render() {
  41. return (
  42.  
  43.  
  44. <LoginButton font={this.passFont()} onPress={() => this.login()} />
  45. );
  46. }
  47. }
  48.  
  49.  
  50. const mapStateToProps = state => ({
  51. status: state.auth.success,
  52. });
  53.  
  54. export default connect(mapStateToProps, { loginUser })(Login);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement