{"size": 1417, "ext": "js", "max_stars_repo_path": "frontend/actions/review_actions.js", "max_stars_repo_name": "Hakeemmidan/Jewely", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "frontend/actions/review_actions.js", "max_issues_repo_name": "Hakeemmidan/Jewely", "max_issues_repo_issues_event_min_datetime": "2019-09-04T00:54:06.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T23:44:09.000Z", "max_forks_repo_path": "frontend/actions/review_actions.js", "max_forks_repo_name": "Hakeemmidan/Jewely", "max_forks_repo_forks_event_min_datetime": "2020-11-23T04:34:19.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-23T04:34:19.000Z"}
{"max_stars_count": null, "max_issues_count": 20, "max_forks_count": 1, "avg_line_length": 24.8596491228, "max_line_length": 61, "alphanum_fraction": 0.6605504587}
import * as ReviewAPIUtil from '../util/review_api_util';
export const RECEIVE_REVIEW = 'RECEIVE_REVIEW';
export const REMOVE_REVIEW = 'REMOVE_REVIEW';
export const RECEIVE_REVIEW_ERRORS = 'RECEIVE_REVIEW_ERRORS';

const receiveReview = (review) => {
  return {
    type: RECEIVE_REVIEW,
    review,
  };
};

const receiveErrors = (errors) => {
  return {
    type: RECEIVE_REVIEW_ERRORS,
    errors,
  };
};

const deleteReview = (reviewId) => {
  return {
    type: REMOVE_REVIEW,
    reviewId,
  };
};

// Action creators ^^^
////////////////////////////////////////////
// Thunk action creators vvv

export const fetchReview = (id) => (dispatch) => {
  return ReviewAPIUtil.fetchReview(id).then((review) =>
    dispatch(receiveReview(review))
  );
};

export const updateReview = (review) => (dispatch) => {
  return ReviewAPIUtil.updateReview(review).then(
    (review) => dispatch(receiveReview(review)),
    (errs) => dispatch(receiveErrors(errs.responseJSON))
  );
};

export const createReview = (review) => (dispatch) => {
  return ReviewAPIUtil.createReview(review).then(
    (review) => dispatch(receiveReview(review)),
    (errs) => dispatch(receiveErrors(errs.responseJSON))
  );
};

export const removeReview = (reviewId) => (dispatch) => {
  return ReviewAPIUtil.removeReview(reviewId).then(
    () => dispatch(deleteReview(reviewId)),
    (errs) => dispatch(receiveErrors(errs.responseJSON))
  );
};
