Last active
June 17, 2018 09:12
-
-
Save sadick254/970597904d476cd7c52c659621f29ab6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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