Skip to content

Instantly share code, notes, and snippets.

@SuperManEver
Created February 21, 2017 12:05
Show Gist options
  • Save SuperManEver/30aa20e84d1a3cbed94421ac42f00797 to your computer and use it in GitHub Desktop.
Save SuperManEver/30aa20e84d1a3cbed94421ac42f00797 to your computer and use it in GitHub Desktop.
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