Commit 4ebd4c27 authored by Remy Huet's avatar Remy Huet

Improve message and return

parent d1393999
Pipeline #31770 failed with stage
in 1 minute and 25 seconds
......@@ -10,7 +10,7 @@ import { createCategory } from '../../actions/categoriesActions';
function CategoryCreate({ dispatch, userToken, callback }) {
const handleFormSubmit = (values) => {
dispatch(createCategory(userToken, values)).then(callback);
dispatch(createCategory(userToken, values)).then(callback).catch(callback);
};
return (
......
......@@ -15,7 +15,7 @@ function CategoryDelete({
cancelButton={<Button as={Link} to="/categories">Retour</Button>}
confirmButton={(
<Button
onClick={() => dispatch(deleteCategory(userToken, id)).then(callback)}
onClick={() => dispatch(deleteCategory(userToken, id)).then(callback).catch(callback)}
content="Oui"
/>
)}
......
......@@ -7,10 +7,12 @@ import { submit } from 'redux-form';
import CategoryForm from '../../forms/Category';
function CategoryEdit({ id, dispatch }) {
function CategoryEdit({
id, name, parentId, dispatch, callback,
}) {
const handleFormSubmit = (values) => {
// Todo :
dispatch({ type: 'VALUES', payload: values });
dispatch({ type: 'VALUES', payload: values }).then(callback).catch(callback);
};
return (
......
......@@ -62,13 +62,14 @@ function Categories({
</Dimmer>)}
{categoriesAction && categoriesActionSuccess !== null && (
<Message
floated="center"
header={categoriesActionInfo}
positive={categoriesActionSuccess}
negative={!categoriesActionSuccess}
onDismiss={() => dispatch({ type: 'CATEGORY_MESSAGE_DISMISS' })}
/>
<Message
floated="center"
floating
header={categoriesActionInfo}
positive={categoriesActionSuccess}
negative={!categoriesActionSuccess}
onDismiss={() => dispatch({ type: 'CATEGORY_MESSAGE_DISMISS' })}
/>
)}
<Button floated="right" style={{ marginBottom: '1em' }} color="orange" icon="redo" onClick={() => dispatch(fetchCategories(userToken))} />
......@@ -94,6 +95,7 @@ function Categories({
id={id}
name={name}
parentId={parentId}
callback={() => history.push('/categories')}
/>
),
delete: (
......@@ -127,9 +129,9 @@ Categories.propTypes = {
).isRequired,
dispatch: PropTypes.func.isRequired,
userToken: PropTypes.string.isRequired,
categoriesAction: PropTypes.string.isRequired,
categoriesActionInfo: PropTypes.string.isRequired,
categoriesActionSuccess: PropTypes.bool.isRequired,
categoriesAction: PropTypes.string,
categoriesActionInfo: PropTypes.string,
categoriesActionSuccess: PropTypes.bool,
match: PropTypes.shape({
params: PropTypes.object,
}).isRequired,
......@@ -138,6 +140,12 @@ Categories.propTypes = {
}).isRequired,
};
Categories.defaultProps = {
categoriesAction: null,
categoriesActionInfo: null,
categoriesActionSuccess: null,
};
export default connect(store => ({
categoriesFetched: store.categories.fetched,
categoriesFetching: store.categories.fetching,
......
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