From 9014e1229f7135d0d6c8c57bc98b5fb1428e4cee Mon Sep 17 00:00:00 2001 From: elforjani3 Date: Sat, 2 Jan 2021 15:19:56 +0200 Subject: [PATCH] fix: item error message. --- client/src/containers/Items/ItemForm.js | 7 +++---- client/src/store/items/items.actions.js | 15 +++++++++++++-- 2 files changed, 16 insertions(+), 6 deletions(-) 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); };