All files / src/data/SingleSignOn reducer.js

0% Statements 0/13
0% Branches 0/12
0% Functions 0/1
0% Lines 0/10
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42                                                                                   
import { Map } from 'immutable';
 
import {
  USER_EXPIRED,
  REDIRECT_SUCCESS,
  USER_FOUND,
  SESSION_TERMINATED,
  LOADING_USER,
  USER_SIGNED_OUT,
  TRIGGER_USER_CLEAR,
} from './actions';
 
const initialState = new Map({
  user: null,
  isLoadingUser: false,
});
 
const reducer = (state = initialState, action) => {
  switch (action.type) {
    case REDIRECT_SUCCESS:
    case USER_FOUND:
      return new Map({
        user: new Map(action.payload),
        isLoadingUser: false,
      });
    case USER_EXPIRED:
    case SESSION_TERMINATED:
    case USER_SIGNED_OUT:
    case TRIGGER_USER_CLEAR:
      return new Map({
        user: null,
        isLoadingUser: false,
      });
    case LOADING_USER:
      return state.set('isLoadingUser', true);
    default:
      return state;
  }
};
 
export default reducer;