import React, { useState } from 'react';
import { FormattedMessage as T, useIntl } from 'react-intl';
import { Intent, Alert } from '@blueprintjs/core';
import { size } from 'lodash';
import { AppToaster } from 'components';
import withItemsActions from 'containers/Items/withItemsActions';
import withAlertStoreConnect from 'containers/Alert/withAlertStoreConnect';
import withAlertActions from 'containers/Alert/withAlertActions';
import { compose } from 'utils';
/**
* Item bulk delete alert.
*/
function ItemBulkDeleteAlert({
name,
// #withAlertStoreConnect
isOpen,
payload: { itemsIds },
// #withItemsActions
requestDeleteBulkItems,
// #withAlertActions
closeAlert,
}) {
const { formatMessage } = useIntl();
const [isLoading, setLoading] = useState(false);
// handle cancel item bulk delete alert.
const handleCancelBulkDelete = () => {
closeAlert(name);
};
// Handle confirm items bulk delete.
const handleConfirmBulkDelete = () => {
setLoading(true);
requestDeleteBulkItems(itemsIds)
.then(() => {
AppToaster.show({
message: formatMessage({
id: 'the_items_has_been_deleted_successfully',
}),
intent: Intent.SUCCESS,
});
})
.catch((errors) => {})
.finally(() => {
setLoading(false);
closeAlert(name);
});
};
return (