department-of-veterans-affairs/vets-website

View on GitHub
src/platform/monitoring/external-services/reducer.js

Summary

Maintainability
A
0 mins
Test Coverage
import {
  FETCH_BACKEND_STATUSES_FAILURE,
  FETCH_BACKEND_STATUSES_SUCCESS,
  LOADING_BACKEND_STATUSES,
} from './actions';

const INITIAL_STATE = {
  loading: false,
  statuses: null,
  maintenanceWindows: [],
};

export default function externalServiceStatuses(state = INITIAL_STATE, action) {
  switch (action.type) {
    case LOADING_BACKEND_STATUSES:
      return { ...state, loading: true };

    case FETCH_BACKEND_STATUSES_FAILURE:
      return { ...state, loading: false };

    case FETCH_BACKEND_STATUSES_SUCCESS: {
      const {
        statuses,
        maintenance_windows: maintenanceWindows,
      } = action.data.attributes;
      return { ...state, loading: false, statuses, maintenanceWindows };
    }

    default:
      return state;
  }
}