diff --git a/client/src/containers/Sales/Estimates/EstimateForm/EstimateFloatingActions.js b/client/src/containers/Sales/Estimates/EstimateForm/EstimateFloatingActions.js index 0351a910e..0433b8e9a 100644 --- a/client/src/containers/Sales/Estimates/EstimateForm/EstimateFloatingActions.js +++ b/client/src/containers/Sales/Estimates/EstimateForm/EstimateFloatingActions.js @@ -12,6 +12,7 @@ import { import { FormattedMessage as T } from 'react-intl'; import { CLASSES } from 'common/classes'; import classNames from 'classnames'; +import { useHistory } from 'react-router-dom'; import { useFormikContext } from 'formik'; import { If, Icon } from 'components'; import { useEstimateFormContext } from './EstimateFormProvider'; @@ -20,6 +21,7 @@ import { useEstimateFormContext } from './EstimateFormProvider'; * Estimate floating actions bar. */ export default function EstimateFloatingActions() { + const history = useHistory(); const { resetForm, submitForm, isSubmitting } = useFormikContext(); // Estimate form context. @@ -62,6 +64,7 @@ export default function EstimateFloatingActions() { }; const handleCancelBtnClick = (event) => { + history.goBack(); }; diff --git a/client/src/containers/Sales/Estimates/EstimateForm/EstimateForm.js b/client/src/containers/Sales/Estimates/EstimateForm/EstimateForm.js index 6ab5488d4..a985ec1b8 100644 --- a/client/src/containers/Sales/Estimates/EstimateForm/EstimateForm.js +++ b/client/src/containers/Sales/Estimates/EstimateForm/EstimateForm.js @@ -21,10 +21,7 @@ import withSettings from 'containers/Settings/withSettings'; import { AppToaster } from 'components'; import { ERROR } from 'common/errors'; -import { - compose, - orderingLinesIndexes, -} from 'utils'; +import { compose, orderingLinesIndexes } from 'utils'; import { useEstimateFormContext } from './EstimateFormProvider'; import { transformToEditForm, defaultEstimate } from './utils'; @@ -55,7 +52,7 @@ function EstimateForm({ () => ({ ...(!isEmpty(estimate) ? { - ...transformToEditForm(estimate) + ...transformToEditForm(estimate), } : { ...defaultEstimate, @@ -126,7 +123,11 @@ function EstimateForm({ } }; - const onError = (errors) => { + const onError = ({ + response: { + data: { errors }, + }, + }) => { if (errors) { handleErrors(errors, { setErrors }); } diff --git a/client/src/containers/Sales/Estimates/EstimateForm/utils.js b/client/src/containers/Sales/Estimates/EstimateForm/utils.js index fd7e5e7d0..f980b9b2a 100644 --- a/client/src/containers/Sales/Estimates/EstimateForm/utils.js +++ b/client/src/containers/Sales/Estimates/EstimateForm/utils.js @@ -31,7 +31,7 @@ export const transformToEditForm = (estimate) => ({ ...transformToForm(estimate, defaultEstimateEntry), })), ...repeatValue( - defaultEstimate, + defaultEstimateEntry, Math.max(MIN_LINES_NUMBER - estimate.entries.length, 0), ), ], diff --git a/client/src/containers/Sales/Receipts/ReceiptForm/ReceiptForm.js b/client/src/containers/Sales/Receipts/ReceiptForm/ReceiptForm.js index 3aa6f02b9..12b892a79 100644 --- a/client/src/containers/Sales/Receipts/ReceiptForm/ReceiptForm.js +++ b/client/src/containers/Sales/Receipts/ReceiptForm/ReceiptForm.js @@ -136,8 +136,10 @@ function ReceiptForm({ }; // Handle the request error. - const onError = (errors) => { - handleErrors(errors, { setErrors }); + const onError = ({response:{data:{errors}}}) => { + if(errors){ + handleErrors(errors, { setErrors }); + } setSubmitting(false); };