72 lines
1.8 KiB
TypeScript
72 lines
1.8 KiB
TypeScript
// @ts-nocheck
|
|
import React, { useState } from 'react';
|
|
import intl from 'react-intl-universal';
|
|
import { Intent, Alert } from '@blueprintjs/core';
|
|
import { useQueryClient } from 'react-query';
|
|
import { FormattedMessage as T, AppToaster } from '@/components';
|
|
|
|
import { withAlertStoreConnect } from '@/containers/Alert/withAlertStoreConnect';
|
|
import { withAlertActions } from '@/containers/Alert/withAlertActions';
|
|
|
|
import { compose } from '@/utils';
|
|
|
|
function AccountBulkActivateAlert({
|
|
name,
|
|
isOpen,
|
|
payload: { accountsIds },
|
|
|
|
// #withAlertActions
|
|
closeAlert,
|
|
|
|
// TODO: Implement bulk activate accounts hook and use it here
|
|
requestBulkActivateAccounts,
|
|
}) {
|
|
const [isLoading, setLoading] = useState(false);
|
|
const queryClient = useQueryClient();
|
|
const selectedRowsCount = 0;
|
|
|
|
// Handle alert cancel.
|
|
const handleClose = () => {
|
|
closeAlert(name);
|
|
};
|
|
|
|
// Handle Bulk activate account confirm.
|
|
const handleConfirmBulkActivate = () => {
|
|
setLoading(true);
|
|
requestBulkActivateAccounts(accountsIds)
|
|
.then(() => {
|
|
AppToaster.show({
|
|
message: intl.get('the_accounts_has_been_successfully_activated'),
|
|
intent: Intent.SUCCESS,
|
|
});
|
|
queryClient.invalidateQueries('accounts-table');
|
|
})
|
|
.catch((errors) => {})
|
|
.finally(() => {
|
|
setLoading(false);
|
|
closeAlert(name);
|
|
});
|
|
};
|
|
|
|
return (
|
|
<Alert
|
|
cancelButtonText={<T id={'cancel'} />}
|
|
confirmButtonText={`${intl.get('activate')} (${selectedRowsCount})`}
|
|
intent={Intent.WARNING}
|
|
isOpen={isOpen}
|
|
onCancel={handleClose}
|
|
onConfirm={handleConfirmBulkActivate}
|
|
loading={isLoading}
|
|
>
|
|
<p>
|
|
<T id={'are_sure_to_activate_this_accounts'} />
|
|
</p>
|
|
</Alert>
|
|
);
|
|
}
|
|
|
|
export default compose(
|
|
withAlertStoreConnect(),
|
|
withAlertActions,
|
|
)(AccountBulkActivateAlert);
|