text: import axios from 'axios';
  import { getToken } from '../helpers/auth';
  
  const url = `${process.env.API_URL}/api/v1/sales`;
  
  export const setSalesError = (error) => (
    {
      type: 'SET_SALES_ERROR',
      error
    }
  );
  
  export const fetchSales = () => dispatch =>
    axios.get(url, {
      headers: {
        "Authorization": `Bearer ${getToken()}`
      }
    })
      .then(({ data }) => data.message != undefined ? dispatch(setSales(data.orders)) : dispatch(setSalesError(data.error)))
      .catch(error => dispatch(setSalesError(error)));
  
  export const setSales = (sales) => (
    {
      type: 'SET_SALES',
      sales
    }
  )
  
  export const setSale = (sale) => (
    {
      type: 'SET_SALE',
      sale
    }
  )
  
  export const fetchSale = (id) => dispatch =>
    axios.get(url + `/${id}`, {
      headers: {
        "Authorization": `Bearer ${getToken()}`
      }
    })
      .then(({ data }) => data.message != undefined ? dispatch(setSale(data.orderDetails)) : dispatch(setSaleError(data.error)))
      .catch(error => {
        dispatch(setSale([]));
        dispatch(setSaleError(error))
      });
  