// Cool code sample from [Medium](https://medium.com/@rajaraodv/adding-a-robust-form-validation-to-react-redux-apps-616ca240c124)
/For any field errors upon submission (i.e. not instant check)
//Note: In the below function, we kinda assume that the fields are valid and try to create post and handle errors if any later on.
const validateAndCreatePost = (values, dispatch) => {
return new Promise((resolve, reject) => {
dispatch(createPost(values)).then((response) => {
let data = response.payload.data;
//error..
if(response.payload.status != 200) {
//let other components know by updating the redux` state
dispatch(createPostFailure(response.payload));
reject(data); //this is for redux-form itself
} else {
//let other components by updating the redux` state
dispatch(createPostSuccess(response.payload));
resolve();//this is for redux-form itself
}
});//dispatch
});//return
};