Guest User

Untitled

a guest
Jan 4th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.70 KB | None | 0 0
  1. TypeError: undefined is not a function (evaluating 'dispatch((0, _LoginActions.loginAction)(inputFormProp))')
  2.  
  3. import React, { Component } from 'react';
  4. import { Text, View, TextInput, ActivityIndicator, TouchableHighlight } from 'react-native';
  5. import { getLogger, issueToText } from '../core/utils';
  6. import styles from '../core/styles';
  7. import { Card, Button, FormLabel, FormInput } from "react-native-elements";
  8. import { connect } from 'react-redux'
  9. import {loginAction} from '../actions/LoginActions'
  10.  
  11. export class LoginComponent extends Component {
  12. constructor(props) {
  13. super(props);
  14. this.login = this.login.bind(this)
  15. }
  16.  
  17. render() {
  18. const { error, isLoading, username, password } = this.props;
  19.  
  20. const inputFormProp = {
  21. username: '',
  22. password: ''
  23. };
  24.  
  25. return (
  26. <View style={{ paddingVertical: 20 }}>
  27. <Card>
  28. <FormLabel>Email</FormLabel>
  29. <FormInput value={username} onChangeText={(text) => inputFormProp.username = text} />
  30. <FormLabel>Password</FormLabel>
  31. <FormInput value={password} onChangeText={(text) => inputFormProp.password = text} />
  32.  
  33. <Button
  34. buttonStyle={{ marginTop: 20 }}
  35. backgroundColor="#03A9F4"
  36. title="SIGN IN"
  37. onPress={this.login(inputFormProp)}
  38. />
  39. </Card>
  40. <ActivityIndicator animating={this.props.isLoading} style={styles.activityIndicator} size="large" />
  41. </View>
  42. );
  43. }
  44.  
  45.  
  46. login(inputFormProp) {
  47. const { store } = this.props.screenProps.store;
  48.  
  49. const { dispatch } = this.props
  50.  
  51. dispatch(loginAction(inputFormProp))
  52. .then(() => {
  53. if (this.props.error === null && this.props.isLoading === false) {
  54. if (store.getState().auth.token) {
  55. this.props.navigation.navigate('ProductList', { token: store.getState().auth.token });
  56. }
  57. }
  58. })
  59. .catch(error => {
  60. });
  61. }
  62.  
  63.  
  64. }
  65.  
  66. function mapStateToProps(state) {
  67. const { error, isLoading } = state.auth
  68.  
  69. return {
  70. error,
  71. isLoading,
  72. }
  73. }
  74.  
  75. export default connect(mapStateToProps)(LoginComponent)
  76.  
  77. const initialState = {
  78. auth: { isLoading: false, error: null },
  79. };
  80.  
  81.  
  82. const rootReducer = combineReducers({ product: productReducer, auth: authReducer
  83. });
  84.  
  85. const store = createStore(rootReducer, initialState, applyMiddleware(thunk,
  86. createLogger()));
  87.  
  88. export const MyNavigator = StackNavigator({
  89. Login: { screen: LoginComponent },
  90. ProductList: { screen: ProductList },
  91. });
  92.  
  93.  
  94.  
  95. export default class App extends Component {
  96. render() {
  97. return (
  98. <MyNavigator screenProps={{ store: { store } }} />
  99. );
  100. }
  101. };
Add Comment
Please, Sign In to add comment