mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-15 20:30:33 +00:00
87 lines
2.1 KiB
JavaScript
87 lines
2.1 KiB
JavaScript
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 { handleDeleteErrors } from 'containers/Accounts/utils';
|
|
|
|
import withAlertStoreConnect from 'containers/Alert/withAlertStoreConnect';
|
|
import withAlertActions from 'containers/Alert/withAlertActions';
|
|
import withDrawerActions from 'containers/Drawer/withDrawerActions';
|
|
|
|
import { useDeleteAccount } from 'hooks/query';
|
|
import { compose } from 'utils';
|
|
|
|
/**
|
|
* Account delete alerts.
|
|
*/
|
|
function AccountDeleteAlert({
|
|
name,
|
|
|
|
// #withAlertStoreConnect
|
|
isOpen,
|
|
payload: { accountId },
|
|
|
|
// #withAlertActions
|
|
closeAlert,
|
|
|
|
// #withDrawerActions
|
|
closeDrawer,
|
|
}) {
|
|
const { isLoading, mutateAsync: deleteAccount } = useDeleteAccount();
|
|
|
|
// handle cancel delete account alert.
|
|
const handleCancelAccountDelete = () => {
|
|
closeAlert(name);
|
|
};
|
|
// Handle confirm account delete.
|
|
const handleConfirmAccountDelete = () => {
|
|
deleteAccount(accountId)
|
|
.then(() => {
|
|
AppToaster.show({
|
|
message: intl.get('the_account_has_been_successfully_deleted'),
|
|
intent: Intent.SUCCESS,
|
|
});
|
|
closeAlert(name);
|
|
closeDrawer('account-drawer');
|
|
})
|
|
.catch(
|
|
({
|
|
response: {
|
|
data: { errors },
|
|
},
|
|
}) => {
|
|
handleDeleteErrors(errors);
|
|
closeAlert(name);
|
|
},
|
|
);
|
|
};
|
|
|
|
return (
|
|
<Alert
|
|
cancelButtonText={<T id={'cancel'} />}
|
|
confirmButtonText={<T id={'delete'} />}
|
|
icon="trash"
|
|
intent={Intent.DANGER}
|
|
isOpen={isOpen}
|
|
onCancel={handleCancelAccountDelete}
|
|
onConfirm={handleConfirmAccountDelete}
|
|
loading={isLoading}
|
|
>
|
|
<p>
|
|
<FormattedHTMLMessage
|
|
id={'once_delete_this_account_you_will_able_to_restore_it'}
|
|
/>
|
|
</p>
|
|
</Alert>
|
|
);
|
|
}
|
|
|
|
export default compose(
|
|
withAlertStoreConnect(),
|
|
withAlertActions,
|
|
withDrawerActions,
|
|
)(AccountDeleteAlert);
|