fbi-cde/crime-data-frontend

View on GitHub
src/actions/region.js

Summary

Maintainability
A
0 mins
Test Coverage
import {
  UCR_REGION_FAILED,
  UCR_REGION_FETCHING,
  UCR_REGION_RECEIVED,
} from './constants'
import api from '../util/api/lookups'
import reshapeData from '../util/region'

export const failedUcrRegion = error => ({
  type: UCR_REGION_FAILED,
  error,
})

export const fetchingUcrRegion = () => ({
  type: UCR_REGION_FETCHING,
})

export const receivedUcrRegion = regions => ({
  type: UCR_REGION_RECEIVED,
  regions,
})

export const fetchUcrRegion = () => dispatch => {
  dispatch(fetchingUcrRegion())
  return Promise.all([api.getRegions()])
    // .then(r => ({ results: r.results }))
    .then(data => dispatch(receivedUcrRegion(reshapeData(data))))
    .catch(error => dispatch(failedUcrRegion(error)))
}