Commit ce7f7b0e authored by Rémy Huet's avatar Rémy Huet 💻

Update in API

parent 9937a88b
......@@ -32,3 +32,13 @@ export function createCategory(token, data) {
}),
};
}
export function updateCategory(token, id, data) {
return {
type: 'UPDATE_CATEGORY',
payload: axios.put(`${env.api_uri}/api/v1/categories/${id}`, { parent_id: data.parentId, ...data },
{
headers: { Authorization: `Bearer ${token}` },
}),
};
}
......@@ -6,13 +6,13 @@ import { Confirm, Button, Header } from 'semantic-ui-react';
import { submit } from 'redux-form';
import CategoryForm from '../../forms/Category';
import { updateCategory } from '../../actions/categoriesActions';
function CategoryEdit({
id, name, parentId, dispatch, callback,
id, name, parentId, dispatch, callback, userToken,
}) {
const handleFormSubmit = (values) => {
// Todo :
dispatch({ type: 'VALUES', payload: values }).then(callback).catch(callback);
dispatch(updateCategory(userToken, id, values)).then(callback).catch(callback);
};
return (
......@@ -34,6 +34,9 @@ CategoryEdit.propTypes = {
parentId: PropTypes.number.isRequired,
dispatch: PropTypes.func.isRequired,
callback: PropTypes.func.isRequired,
userToken: PropTypes.string.isRequired,
};
export default connect()(CategoryEdit);
export default connect(store => ({
userToken: store.user.token,
}))(CategoryEdit);
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