feat(warehouseTransfer): handle error.

This commit is contained in:
elforjani13
2022-02-03 01:03:00 +02:00
committed by a.bouhuolia
parent a50d6358f4
commit b5ebcca12d
2 changed files with 24 additions and 3 deletions

View File

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

View File

@@ -1,8 +1,9 @@
import React from 'react';
import intl from 'react-intl-universal';
import clsx from 'classnames';
import { useFormikContext } from 'formik';
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 {
@@ -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,
});
}
};