department-of-veterans-affairs/vets-website

View on GitHub
src/applications/personalization/view-representative/reducers/index.js

Summary

Maintainability
A
0 mins
Test Coverage
import {
  FETCH_REPRESENTATIVE_STARTED,
  FETCH_REPRESENTATIVE_SUCCESS,
  FETCH_REPRESENTATIVE_FAILED,
} from '../actions';

const initialState = {
  loading: true,
  error: null,
  representative: null,
};

function representative(state = initialState, action) {
  switch (action.type) {
    case FETCH_REPRESENTATIVE_FAILED:
      return {
        ...state,
        loading: false,
        error: action.response,
      };
    case FETCH_REPRESENTATIVE_SUCCESS:
      return {
        ...state,
        loading: false,
        representative: action.response,
      };
    case FETCH_REPRESENTATIVE_STARTED:
    default:
      return state;
  }
}

export default { representative };