import React from 'react';
import intl from 'react-intl-universal';
import { FormattedMessage as T, FormattedHTMLMessage } from 'components';
import { Intent, Alert } from '@blueprintjs/core';
import { AppToaster } from 'components';
import { useDeleteRole } from 'hooks/query';
import { handleDeleteErrors } from '../../Preferences/Users/Roles/utils';
import withAlertStoreConnect from 'containers/Alert/withAlertStoreConnect';
import withAlertActions from 'containers/Alert/withAlertActions';
import { compose } from 'utils';
/**
* Role delete alert.
*/
function RoleDeleteAlert({
name,
// #withAlertStoreConnect
isOpen,
payload: { roleId },
// #withAlertActions
closeAlert,
}) {
const { mutateAsync: deleteRole, isLoading } = useDeleteRole();
// Handle cancel delete role alert.
const handleCancelDelete = () => {
closeAlert(name);
};
// Handle confirm delete role.
const handleConfirmDeleteRole = () => {
deleteRole(roleId)
.then(() => {
AppToaster.show({
message: intl.get('roles.permission_schema.delete.alert_message'),
intent: Intent.SUCCESS,
});
})
.catch(
({
response: {
data: { errors },
},
}) => {
handleDeleteErrors(errors);
},
)
.finally(() => {
closeAlert(name);
});
};
return (