{"size": 1571, "ext": "js", "max_stars_repo_path": "src/redux/actions/categoryActions.js", "max_stars_repo_name": "osipuk/react-coreui", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/redux/actions/categoryActions.js", "max_issues_repo_name": "osipuk/react-coreui", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/redux/actions/categoryActions.js", "max_forks_repo_name": "osipuk/react-coreui", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 25.7540983607, "max_line_length": 63, "alphanum_fraction": 0.5652450668}
import axios from "axios";
import { FETCH_CATEGORIES, NEW_CATEGORY } from "./types";
import { Constants } from "../../constants/environment";

export const fetchCategories = () => dispatch => {
  axios
    .get(
      Constants.BASE_URL +
        `api/categories/location/home/5a6ec0b328d7b9001499a144`
    )
    .then(categories =>
      dispatch({
        type: FETCH_CATEGORIES,
        payload: categories.data
        //payload: categories.data.slice(0,10) //get first 10
      })
    );
};

export const createCategory = postData => dispatch => {
  console.log("action called- createCategory", postData);
  axios
    .post(Constants.BASE_URL + `api/categories/`, postData, {
      headers: {
        "content-type": "application/json"
      }
    })
    .then(newCategory =>
      dispatch({
        type: NEW_CATEGORY,
        payload: newCategory
      })
    )
    .catch(function(error) {
      console.log("ERROR", error);
    });
};

// export const createCategory = postData => dispatch => {
//   console.log("action called- createCategory", postData);
//   axios
//     .post(BASE_URL + `api/categories/`, {
//       method: "POST"
//       //payload: JSON.stringify(postData),
//       // headers: {
//       //   "content-type": "application/json"
//       // }
//     })
//     //.then(res => res.json)
//     .then(newCategory =>
//       dispatch({
//         type: NEW_CATEGORY,
//         payload: newCategory
//       })
//     )
//     .catch(function(error) {
//       console.log("ERROR", error);
//     });
// };
//console.log("postData", res);
