department-of-veterans-affairs/vets-website

View on GitHub
src/applications/mhv-medical-records/actions/allergies.js

Summary

Maintainability
C
7 hrs
Test Coverage
import { Actions } from '../util/actionTypes';
import { getAllergies, getAllergy } from '../api/MrApi';
import * as Constants from '../util/constants';
import { addAlert } from './alerts';
import { dispatchDetails } from '../util/helpers';
import { getListWithRetry } from './common';

export const getAllergiesList = (isCurrent = false) => async dispatch => {
  dispatch({
    type: Actions.Allergies.UPDATE_LIST_STATE,
    payload: Constants.loadStates.FETCHING,
  });
  try {
    const response = await getListWithRetry(dispatch, getAllergies);
    dispatch({
      type: Actions.Allergies.GET_LIST,
      response,
      isCurrent,
    });
  } catch (error) {
    dispatch(addAlert(Constants.ALERT_TYPE_ERROR, error));
    throw error;
  }
};

export const getAllergyDetails = (id, allergyList) => async dispatch => {
  try {
    await dispatchDetails(
      id,
      allergyList,
      dispatch,
      getAllergy,
      Actions.Allergies.GET_FROM_LIST,
      Actions.Allergies.GET,
    );
  } catch (error) {
    dispatch(addAlert(Constants.ALERT_TYPE_ERROR, error));
    throw error;
  }
};

export const clearAllergyDetails = () => async dispatch => {
  dispatch({ type: Actions.Allergies.CLEAR_DETAIL });
};

export const reloadRecords = () => async dispatch => {
  dispatch({ type: Actions.Allergies.COPY_UPDATED_LIST });
};