fix: items alert.

This commit is contained in:
elforjani3
2021-01-26 18:16:10 +02:00
parent c8f817b16d
commit 01ee2e5c40
13 changed files with 466 additions and 296 deletions

View File

@@ -0,0 +1,77 @@
import React from 'react';
import {
FormattedMessage as T,
useIntl,
} from 'react-intl';
import { Intent, Alert } from '@blueprintjs/core';
import { queryCache } from 'react-query';
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 inactivate alert.
*/
function ItemInactivateAlert({
name,
// #withAlertStoreConnect
isOpen,
payload: { itemId },
// #withItemsActions
requestInactiveItem,
// #withAlertActions
closeAlert,
}) {
const { formatMessage } = useIntl();
// handle cancel inactivate alert.
const handleCancelInactivateItem = () => {
closeAlert(name);
};
// Handle confirm item Inactive.
const handleConfirmItemInactive = () => {
requestInactiveItem(itemId)
.then(() => {
closeAlert(name);
AppToaster.show({
message: formatMessage({
id: 'the_item_has_been_inactivated_successfully',
}),
intent: Intent.SUCCESS,
});
queryCache.invalidateQueries('items-table');
})
.catch((error) => {
closeAlert(name);
});
};
return (
<Alert
cancelButtonText={<T id={'cancel'} />}
confirmButtonText={<T id={'inactivate'} />}
intent={Intent.WARNING}
isOpen={isOpen}
onCancel={handleCancelInactivateItem}
onConfirm={handleConfirmItemInactive}
>
<p>
<T id={'are_sure_to_inactive_this_item'} />
</p>
</Alert>
);
}
export default compose(
withAlertStoreConnect(),
withAlertActions,
withItemsActions,
)(ItemInactivateAlert);