Commit 04d02f56 authored by Rémy Huet's avatar Rémy Huet 💻

Add callback to create and delete to return

parent ec13ad21
Pipeline #31100 passed with stage
in 54 seconds
......@@ -8,9 +8,9 @@ import { Confirm, Header, Button } from 'semantic-ui-react';
import CategoryForm from '../../forms/Category';
import { createCategory } from '../../actions/categoriesActions';
function CategoryCreate({ dispatch, userToken }) {
function CategoryCreate({ dispatch, userToken, callback }) {
const handleFormSubmit = (values) => {
dispatch(createCategory(userToken, values));
dispatch(createCategory(userToken, values)).then(callback);
};
return (
......@@ -27,6 +27,7 @@ function CategoryCreate({ dispatch, userToken }) {
CategoryCreate.propTypes = {
dispatch: PropTypes.func.isRequired,
userToken: PropTypes.string.isRequired,
callback: PropTypes.func.isRequired,
};
export default connect(store => ({
......
......@@ -7,7 +7,7 @@ import { Confirm, Button, Header } from 'semantic-ui-react';
import { deleteCategory } from '../../actions/categoriesActions';
function CategoryDelete({
name, id, userToken, dispatch,
name, id, userToken, dispatch, callback,
}) {
return (
<Confirm
......@@ -15,7 +15,7 @@ function CategoryDelete({
cancelButton={<Button as={Link} to="/categories">Retour</Button>}
confirmButton={(
<Button
onClick={() => dispatch(deleteCategory(userToken, id))}
onClick={() => dispatch(deleteCategory(userToken, id)).then(callback)}
content="Oui"
/>
)}
......@@ -35,6 +35,7 @@ CategoryDelete.propTypes = {
id: PropTypes.number.isRequired,
userToken: PropTypes.string.isRequired,
dispatch: PropTypes.func.isRequired,
callback: PropTypes.func.isRequired,
};
export default connect(store => ({
......
......@@ -15,7 +15,7 @@ import CategoryDelete from '../components/Category/Delete';
import CategoryCreate from '../components/Category/Create';
function Categories({
categoriesFetched, categoriesFetching, categories, dispatch, userToken, match,
categoriesFetched, categoriesFetching, categories, dispatch, userToken, match, history,
}) {
const { params } = match;
// Map all categories in array of <Category />
......@@ -81,10 +81,13 @@ function Categories({
<CategoryDelete
id={id}
name={name}
callback={() => history.push('categories')}
/>
),
create: (
<CategoryCreate />
<CategoryCreate
callback={() => history.push('categories')}
/>
),
}[params.action])}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment