function submitNewExercise(data, workoutId) {
  return function(dispatch) {
    return fetch(`/api/workouts/${workoutId}/exercises`, {
      method: 'POST',
      headers: {
        'Content-type': 'application/json'
      },
      body: JSON.stringify(data)
    })
      .then(handleErrors)
      .then(resp => {
        return resp.json();
      })
      .then(exercise => {
        // Dispatch action that adds JSON response to store
        dispatch({type: 'ADD_EXERCISE', payload: exercise});
      })
    .catch((error) => {
      // Dispatch error to store if validation fails
      dispatch({type: 'ERROR'})
    })
  }
}
// Submits exercise data to Rails API which persists to the db
Submits exercise data to Rails API which persists to the db
Submits exercise data to Rails API which persists to the db
function submitNewExercise(data, workoutId) {
  return function(dispatch) {
    return fetch(`/api/workouts/${workoutId}/exercises`, {
      method: 'POST',
      headers: {
        'Content-type': 'application/json'
      },
      body: JSON.stringify(data)
    })
      .then(handleErrors)
      .then(resp => {
        return resp.json();
      })
      .then(exercise => {
        dispatch({type: 'ADD_EXERCISE', payload: exercise});
      })
    .catch((error) => {
      dispatch({type: 'ERROR'})
    })
  }
}
function submitNewExercise ( data , workoutId ) { return function ( dispatch ) { return fetch ( ` ${ workoutId } ` , { method : 'POST' , headers : { 'Content-type' : 'application/json' } , body : JSON . stringify ( data ) } ) . then ( handleErrors ) . then ( resp => { return resp . json ( ) ; } ) . then ( exercise => { dispatch ( { type : 'ADD_EXERCISE' , payload : exercise } ) ; } ) . catch ( ( error ) => { dispatch ( { type : 'ERROR' } ) } ) } }
Submits exercise data to Rails API which persists to the db
Submits exercise data to Rails API which persists to the db
// Dispatch action that adds JSON response to store // Dispatch error to store if validation fails