diff --git a/client/src/containers/Items/ItemForm.js b/client/src/containers/Items/ItemForm.js index 2acc022f0..b30b6c3ee 100644 --- a/client/src/containers/Items/ItemForm.js +++ b/client/src/containers/Items/ItemForm.js @@ -163,11 +163,10 @@ function ItemForm({ history.push('/items'); } }; - const onError = ({ response }) => { + const onError = (errors) => { setSubmitting(false); - - if (response.data.errors) { - const _errors = transformApiErrors(response.data.errors); + if (errors) { + const _errors = transformApiErrors(errors); setErrors({ ..._errors }); } }; diff --git a/client/src/store/items/items.actions.js b/client/src/store/items/items.actions.js index 1ffb414ef..f29f2f673 100644 --- a/client/src/store/items/items.actions.js +++ b/client/src/store/items/items.actions.js @@ -2,9 +2,20 @@ import ApiService from 'services/ApiService'; import t from 'store/types'; export const submitItem = ({ form }) => { - return (dispatch) => ApiService.post(`items`, form); -}; + return (dispatch) => + new Promise((resolve, reject) => { + ApiService.post('items', form) + .then((response) => { + resolve(response); + }) + .catch((error) => { + const { response } = error; + const { data } = response; + reject(data?.errors); + }); + }); +}; export const editItem = ({ id, form }) => { return (dispatch) => ApiService.post(`items/${id}`, form); };