Created
February 21, 2017 12:05
-
-
Save SuperManEver/30aa20e84d1a3cbed94421ac42f00797 to your computer and use it in GitHub Desktop.
This file contains 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
import { goBack, push } from 'react-router-redux'; | |
import { loadProducts } from '../ProductsContainerPage/actions'; | |
import { submitData } from './api'; | |
import { | |
CREATE_PRODUCT, | |
CREATE_PRODUCT_SUCCEEDED, | |
CREATE_PRODUCT_FAILED, | |
} from './constants'; | |
export const handleCancel = () => dispatch => dispatch(goBack()); | |
const creationStarted = () => ({ | |
type: CREATE_PRODUCT, | |
}); | |
const creationSucceeded = () => dispatch => { | |
dispatch({ type: CREATE_PRODUCT_SUCCEEDED }); | |
dispatch(push('/products')); | |
dispatch(loadProducts()); | |
}; | |
const creationFailed = (errorMessage) => ({ | |
type: CREATE_PRODUCT_FAILED, | |
errorMessage | |
}); | |
export const createProduct = (data) => | |
(dispatch) => { | |
dispatch(creationStarted()); | |
submitData( | |
data, | |
() => dispatch(creationSucceeded()), | |
(msg) => dispatch(creationFailed(msg)), | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment