personProfileReducer.js 2.45 KB
Newer Older
李彥志's avatar
李彥志 committed
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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
import ActionTypes from '../../actions';
import InitialState from './personProfileInitialState';
import appGlobal from '../../lib/common/AppGlobal';

const initialState = new InitialState();
export default function authReducer(state = initialState, action) {
  if (!(state instanceof InitialState)) return initialState.mergeDeep(state);
  switch (action.type) {
    case ActionTypes.GET_PERSONPROFILE_PERSONALINFO_REQUEST: {
      const nextState = state
        .setIn(['state'], action.type)
        .setIn(['isLoading'], true);
      return nextState;
    }
    case ActionTypes.GET_PERSONPROFILE_EMRRELATIONSHIP_REQUEST:
    case ActionTypes.EDIT_PERSONALPHOTO_REQUEST:
    case ActionTypes.DELETE_PERSONALPHOTO_REQUEST: {
      const nextState = state
        .setIn(['state'], action.state)
        .setIn(['isLoading'], true);
      return nextState;
    }
    case ActionTypes.GET_PERSONPROFILE_EMRRELATIONSHIP_SUCCESS: {
      const nextState = state
        .setIn(['emrRelationships'], action.payload)
        .setIn(['isLoading'], false);
      return nextState;
    }

    case ActionTypes.EDIT_PERSONALPHOTO_SUCCESS:
    case ActionTypes.DELETE_PERSONALPHOTO_SUCCESS: {
      const nextState = state
        .setIn(['photo'], action.payload)
        .setIn(['isLoading'], false);
      return nextState;
    }

    case ActionTypes.GET_PERSONPROFILE_PERSONALINFO_SUCCESS: {
      const data = action.payload;
      const nextState = state
        .setIn(['data'], data)
        .setIn(['avatarSource'], appGlobal.avatarSource())
        .setIn(['personalInfo'], action.payload)
        .setIn(['isLoading'], false)
        .setIn(['state'], action.type);
      return nextState;
    }

    case ActionTypes.EDIT_PERSONALPROFILE_SUCCESS: {
      const data = action.payload.user;
      const nextState = state
        .setIn(['data'], data)
        .setIn(['avatarSource'], appGlobal.avatarSource())
        .setIn(['personalInfo'], action.payload)
        .setIn(['isLoading'], false)
        .setIn(['state'], action.type);
      return nextState;
    }


    case ActionTypes.GET_PERSONPROFILE_EMRRELATIONSHIP_FAILURE:
    case ActionTypes.GET_PERSONPROFILE_PERSONALINFO_FAILURE: {
      return state.setIn(['isLoading'], false).setIn(['error'], action.payload);
    }
    case ActionTypes.EDIT_PERSONALPHOTO_FAILURE:
    case ActionTypes.DELETE_PERSONALPHOTO_FAILURE: {
      return state.setIn(['isLoading'], false).setIn(['error'], action.payload);
    }
    default:
  }
  return state;
}