Guest User

Untitled

a guest
Feb 10th, 2019
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.54 KB | None | 0 0
  1. render() {
  2. const store = createStore(reducers, {}, applyMiddleware(ReduxThunk));
  3. return (
  4. <Provider store={store}>
  5. <Login />
  6. </Provider>
  7. );}}
  8.  
  9. render(){
  10. const {containerStyle, subContainerStyle, inputStyle} = styles;
  11. return(
  12. <View style={containerStyle}>
  13. <View style={subContainerStyle}>
  14. <TextInput
  15. placeholder="E-mail"
  16. style={inputStyle}
  17. value={this.props.email}
  18. onChangeText={email => this.props.emailChanged(email)}
  19. />
  20. </View>
  21.  
  22. <View style={subContainerStyle}>
  23. <TextInput
  24. secureTextEntry
  25. placeholder="Password"
  26. style={inputStyle}
  27. value={this.props.password}
  28. onChangeText={password => this.props.passwordChanged(password)}
  29. />
  30. </View>
  31.  
  32. <View style={subContainerStyle}>
  33. {this.renderLoginButton()}
  34. </View>
  35. </View>
  36. );}}
  37. const mapStateToProps = state => {
  38. return {
  39. email: state.auth.email,
  40. password: state.auth.password,
  41. loading: state.auth.loading
  42. };
  43. };
  44.  
  45. export default connect(mapStateToProps, { emailChanged, passwordChanged,loginWithEmail })(Login);
  46.  
  47. import { EMAIL_CHANGED, PASSWORD_CHANGED, LOGIN_USER, LOGIN_USER_SUCCESS, LOGIN_USER_FAIL } from '../actions/types';
  48.  
  49. const INITIAL_STATE = {
  50. email: '',
  51. password: '',
  52. loading: false
  53. };
  54.  
  55. export default (state = INITIAL_STATE, action) => {
  56. switch (action.type) {
  57. case EMAIL_CHANGED:
  58. console.log(state.email);
  59. return { ...state, email: action.payload };
  60. case PASSWORD_CHANGED:
  61. return { ...state, password: action.payload };
  62. case LOGIN_USER:
  63. return { ...state, loading: true };
  64. case LOGIN_USER_SUCCESS:
  65. return { ...state, loading: false };
  66. case LOGIN_USER_FAIL:
  67. return { ...state, loading: false };
  68. default:
  69. return { ...state };
  70.  
  71. }
  72. };
  73.  
  74. import { combineReducers } from 'redux';
  75. import LoginReducer from './LoginReducer';
  76.  
  77. export default combineReducers({
  78. auth: LoginReducer
  79. });
  80.  
  81. export const EMAIL_CHANGED = 'email_changed';
  82. export const PASSWORD_CHANGED = 'password_changed';
  83.  
  84. export const LOGIN_USER = 'login_user';
  85. export const LOGIN_USER_SUCCESS = 'login_user_succes';
  86. export const LOGIN_USER_FAIL = 'login_user_fail';
  87.  
  88. import { EMAIL_CHANGED, PASSWORD_CHANGED, LOGIN_USER, LOGIN_USER_SUCCESS, LOGIN_USER_FAIL } from './types';
  89.  
  90. export const emailChanged = (email) => {
  91. return (dispatch) => {
  92. dispatch({
  93. type: EMAIL_CHANGED,
  94. payload: email
  95. });
  96. };
  97. };
  98.  
  99. export const passwordChanged = (password) => {
  100. return (dispatch) => {
  101. dispatch({
  102. type: PASSWORD_CHANGED,
  103. payload: password
  104. });
  105. };
  106. };
Add Comment
Please, Sign In to add comment