{"size": 912, "ext": "js", "max_stars_repo_path": "src/actions/orders.js", "max_stars_repo_name": "ziiw/simpleadmin", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/actions/orders.js", "max_issues_repo_name": "ziiw/simpleadmin", "max_issues_repo_issues_event_min_datetime": "2021-03-09T00:51:27.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-26T09:52:54.000Z", "max_forks_repo_path": "src/actions/orders.js", "max_forks_repo_name": "ziiw/simpleadmin", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 4, "max_forks_count": null, "avg_line_length": 26.0571428571, "max_line_length": 116, "alphanum_fraction": 0.5581140351}
import Axios from "axios"
import Constants from 'Helpers/Constants'

export const ACTIONS = {
  GET_ALL_ORDERS: 'GET_ALL_ORDERS',
  GET_ALL_ORDERS_FAILED: 'GET_ALL_ORDERS_FAILED',
}

export const getAllOrders = () => {
  return dispatch => {
    return new Promise ((resolve, reject) => {
      // Call auth provider
      // SimpleAuth in our case
      Axios.get(`${Constants.SERVER.HOST}/api/orders`, {headers: {'x-access-token': localStorage.getItem('token')}})
      .then(({data}) => {
        if (data.success) {
          dispatch({
            type: ACTIONS.GET_ALL_ORDERS,
            payload: {orders: data.orders}
          })
          resolve()
        } else {
          dispatch({
            type: ACTIONS.GET_ALL_ORDERS_FAILED,
            payload: {message: data.message}
          })
          reject()
        }
      }).catch((error) => {
        console.error(error)
      })
    })
  }
}
