feat(warehouseTransfer): handle error.

This commit is contained in:
elforjani13
2022-02-03 01:03:00 +02:00
parent e7024955dd
commit 9d5440961b
2 changed files with 24 additions and 3 deletions

View File

@@ -25,6 +25,7 @@ import { compose, orderingLinesIndexes, transactionNumber } from 'utils';
import { import {
defaultWarehouseTransfer, defaultWarehouseTransfer,
transformValueToRequest, transformValueToRequest,
transformErrors,
transformToEditForm, transformToEditForm,
} from './utils'; } from './utils';
@@ -97,6 +98,9 @@ function WarehouseTransferForm({
data: { errors }, data: { errors },
}, },
}) => { }) => {
if (errors) {
transformErrors(errors, { setErrors });
}
setSubmitting(false); setSubmitting(false);
}; };

View File

@@ -1,8 +1,9 @@
import React from 'react'; import React from 'react';
import intl from 'react-intl-universal';
import clsx from 'classnames';
import { useFormikContext } from 'formik';
import moment from 'moment'; import moment from 'moment';
import intl from 'react-intl-universal';
import { Intent } from '@blueprintjs/core';
import { useFormikContext } from 'formik';
import { AppToaster } from 'components';
import { omit } from 'lodash'; import { omit } from 'lodash';
import { import {
@@ -105,3 +106,19 @@ export function transformValueToRequest(values) {
})), })),
}; };
} }
/**
* Transformes the response errors types.
*/
export const transformErrors = (errors, { setErrors }) => {
if (
errors.some(({ type }) => type === 'WAREHOUSES_TRANSFER_SHOULD_NOT_BE_SAME')
) {
AppToaster.show({
message: intl.get(
'warehouse_transfer.error.could_not_transfer_item_from_source_to_destination',
),
intent: Intent.DANGER,
});
}
};