import React from 'react'; import { FormattedMessage as T, FormattedHTMLMessage, useIntl, } from 'react-intl'; import { Intent, Alert } from '@blueprintjs/core'; import { AppToaster } from 'components'; import withAlertStoreConnect from 'containers/Alert/withAlertStoreConnect'; import withAlertActions from 'containers/Alert/withAlertActions'; import { useDeleteInventoryAdjustment } from 'hooks/query'; import { compose } from 'utils'; /** * Inventory Adjustment delete alerts. */ function InventoryAdjustmentDeleteAlert({ name, // #withAlertStoreConnect isOpen, payload: { inventoryId }, // #withAlertActions closeAlert, }) { const { formatMessage } = useIntl(); const { mutateAsync: deleteInventoryAdjMutate, isLoading } = useDeleteInventoryAdjustment(); // handle cancel delete alert. const handleCancelInventoryAdjustmentDelete = () => { closeAlert(name); }; // Handle the confirm delete of the inventory adjustment transaction. const handleConfirmInventoryAdjustmentDelete = () => { deleteInventoryAdjMutate(inventoryId) .then(() => { AppToaster.show({ message: formatMessage({ id: 'the_adjustment_has_been_deleted_successfully', }), intent: Intent.SUCCESS, }); }) .catch((errors) => {}) .finally(() => { closeAlert(name); }); }; return ( } confirmButtonText={} icon="trash" intent={Intent.DANGER} isOpen={isOpen} onCancel={handleCancelInventoryAdjustmentDelete} onConfirm={handleConfirmInventoryAdjustmentDelete} loading={isLoading} >

); } export default compose( withAlertStoreConnect(), withAlertActions, )(InventoryAdjustmentDeleteAlert);