text: import * as PRODUCT from '../constants/productConstants'
  
  export const productListReducer = (state = { products: [] }, action) => {
    switch (action.type) {
      case PRODUCT.PRODUCT_LIST_REQUEST:
        return { loading: true }
  
      case PRODUCT.PRODUCT_LIST_SUCCESS:
        return {
          loading: false,
          products: action.payload.products,
          pages: action.payload.pages,
          page: action.payload.page,
        }
  
      case PRODUCT.PRODUCT_LIST_FAIL:
        return { loading: false, error: action.payload }
  
      default:
        return state
    }
  }
  
  export const productDetailsReducer = (
    state = { product: { reviews: [] } },
    action
  ) => {
    switch (action.type) {
      case PRODUCT.PRODUCT_DETAILS_REQUEST:
        return { loading: true, ...state }
  
      case PRODUCT.PRODUCT_DETAILS_SUCCESS:
        return { loading: false, product: action.payload }
  
      case PRODUCT.PRODUCT_DETAILS_FAIL:
        return { loading: false, error: action.payload }
  
      default:
        return state
    }
  }
  
  export const productDeleteReducer = (state = {}, action) => {
    switch (action.type) {
      case PRODUCT.PRODUCT_DELETE_REQUEST:
        return { loading: true, ...state }
  
      case PRODUCT.PRODUCT_DELETE_SUCCESS:
        return { loading: false, success: true }
  
      case PRODUCT.PRODUCT_DELETE_FAIL:
        return { loading: false, error: action.payload }
  
      case PRODUCT.PRODUCT_DELETE_RESET:
        return {}
  
      default:
        return state
    }
  }
  
  export const productCreateReducer = (state = {}, action) => {
    switch (action.type) {
      case PRODUCT.PRODUCT_CREATE_REQUEST:
        return { loading: true, ...state }
  
      case PRODUCT.PRODUCT_CREATE_SUCCESS:
        return { loading: false, product: action.payload, success: true }
  
      case PRODUCT.PRODUCT_CREATE_FAIL:
        return { loading: false, error: action.payload }
  
      case PRODUCT.PRODUCT_CREATE_RESET:
        return {}
  
      default:
        return state
    }
  }
  
  export const productUpdateReducer = (state = { product: {} }, action) => {
    switch (action.type) {
      case PRODUCT.PRODUCT_UPDATE_REQUEST:
        return { loading: true, ...state }
  
      case PRODUCT.PRODUCT_UPDATE_SUCCESS:
        return { loading: false, product: action.payload, success: true }
  
      case PRODUCT.PRODUCT_UPDATE_FAIL:
        return { loading: false, error: action.payload }
  
      case PRODUCT.PRODUCT_UPDATE_RESET:
        return { product: {} }
  
      default:
        return state
    }
  }
  
  export const reviewCreateReducer = (state = {}, action) => {
    switch (action.type) {
      case PRODUCT.PRODUCT_CREATE_REVIEW_REQUEST:
        return { loading: true }
  
      case PRODUCT.PRODUCT_CREATE_REVIEW_SUCCESS:
        return { loading: false, success: true }
  
      case PRODUCT.PRODUCT_CREATE_REVIEW_FAIL:
        return { loading: false, error: action.payload }
  
      case PRODUCT.PRODUCT_CREATE_REVIEW_RESET:
        return {}
  
      default:
        return state
    }
  }
  
  export const productTopReducer = (state = { products: [] }, action) => {
    switch (action.type) {
      case PRODUCT.PRODUCT_TOP_REQUEST:
        return { loading: true, products: [] }
  
      case PRODUCT.PRODUCT_TOP_SUCCESS:
        return { loading: false, products: action.payload }
  
      case PRODUCT.PRODUCT_TOP_FAIL:
        return { loading: false, error: action.payload }
  
      default:
        return state
    }
  }
  