formatos.js 687 Bytes
import { merge } from 'ramda'

import {
  REQUEST_FORMATOS,
  RECEIVE_FORMATOS,
  ERROR_FORMATOS
} from '../actions/formatos'


const formatos = {
  data: [],
  current: null,
  loading: true,
  pages: null,
  busqueda: { page: 1, text: '' },
}

export default (state, action) => {
  switch (action.type) {
    case REQUEST_FORMATOS:
      return merge(state, { loading: true, pages: null })
    case RECEIVE_FORMATOS:
      return merge(
        state,
        { loading: false, data: action.formatos, pages: action.pages })
    case ERROR_FORMATOS:
      return merge(
        state,
        { loading: false, data: [], pages: null })
    default:
      return state || formatos
  }
}