github.com/muhammedhassanm/blockchain@v0.0.0-20200120143007-697261defd4d/blockapps-ba-master/ui/src/scenes/Login/login.reducer.js (about)

     1  import {
     2    USER_LOGIN_SUBMIT,
     3    USER_LOGIN_SUCCESS,
     4    USER_LOGIN_FAILURE,
     5    USER_LOGOUT,
     6  } from './login.actions';
     7  
     8  const initialState = {
     9    username: null,
    10    role: null,
    11    error: null,
    12    authenticated: false,
    13    loginFailed: false
    14  };
    15  
    16  const reducer = function loginReducer (state = initialState, action) {
    17    switch(action.type) {
    18      case USER_LOGIN_SUBMIT:
    19        return initialState;
    20      case USER_LOGIN_SUCCESS:
    21        return {
    22          username: action.username,
    23          role: action.role,
    24          error: null,
    25          authenticated: true,
    26          loginFailed: false
    27        };
    28      case USER_LOGIN_FAILURE:
    29        return {
    30          username: null,
    31          role: null,
    32          error: action.error,
    33          authenticated: false,
    34          loginFailed: true
    35        };
    36      case USER_LOGOUT:
    37        return initialState;
    38      default:
    39        return state;
    40    }
    41  };
    42  
    43  export default reducer;