Skip to content

Instantly share code, notes, and snippets.

@sadick254
Last active June 17, 2018 09:12
Show Gist options
  • Save sadick254/970597904d476cd7c52c659621f29ab6 to your computer and use it in GitHub Desktop.
Save sadick254/970597904d476cd7c52c659621f29ab6 to your computer and use it in GitHub Desktop.
export async function addVehicle(userId, vehicle) {
const data = await api.addVehicle(userId, vehicle, axios);
return dispatch({type: types.ADD_VEHICLE, data: {vehicle: data.data.addVehicle}});
}
export async function updateVehicle(vehicle, index) {
const data = api.updateVehicle(vehicle, axios);
return dispatch({type:types.UPDATE_VEHICLE, data: {vehicle: data.data.updateVehicle, index}})
}
function dispatch({type, data = {}}) {
if (data.errors) {
return Promise.reject(data.errors);
}
store.dispatch({
type,
...data
})
return Promise.resolve(data)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment