{"size": 1131, "ext": "js", "max_stars_repo_path": "src/redux/patients/patientsActions.js", "max_stars_repo_name": "fatacuciocolata/react-redux-med_system", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/redux/patients/patientsActions.js", "max_issues_repo_name": "fatacuciocolata/react-redux-med_system", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/redux/patients/patientsActions.js", "max_forks_repo_name": "fatacuciocolata/react-redux-med_system", "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": 20.5636363636, "max_line_length": 72, "alphanum_fraction": 0.6233421751}
import axios from "axios"

export const FETCH_PATIENTS = "FETCH_PATIENTS";
export const CREATE_PATIENT = "CREATE_PATIENT";
export const DELETE_PATIENT = "DELETE_PATIENT"

export const SHOW_ERRORS = "SHOW_ERRORS"

// FETCH PATIENTS 
export const fetchPatients = () => async (dispatch) => {
  const res = await axios.get(`http://localhost:8000/patients`)

  dispatch({
    type: FETCH_PATIENTS,
    payload: res.data
  });
};

// CREATE NEW PATIENT
export const createPatient = (data) => async (dispatch) => {
  const res = await axios.post(`http://localhost:8000/addPatient`, data)
  const id = res.data.id         

  dispatch({
    type: CREATE_PATIENT,
      payload: {
            id: id,
            ...data,
      }  });
};

// DELETE PATIENT
export const deletePatient = (id) => async (dispatch) => {
  console.log("deleted patient", id);
  await axios.delete(
    `http://localhost:8000/patients/${id}`
  );

  dispatch({
    type: DELETE_PATIENT,
    payload: {
      id: id
    }
  });
};

// SHOW ERRORS IF ANY
export const showErrors = (error) => {
    return {
      type: SHOW_ERRORS,
      payload: error
    }
  };

