mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-20 23:00:34 +00:00
refactor: accounts alerts loading.
This commit is contained in:
@@ -1,8 +1,5 @@
|
|||||||
import React from 'react';
|
import React, { useState } from 'react';
|
||||||
import {
|
import { FormattedMessage as T, useIntl } from 'react-intl';
|
||||||
FormattedMessage as T,
|
|
||||||
useIntl,
|
|
||||||
} from 'react-intl';
|
|
||||||
import { Intent, Alert } from '@blueprintjs/core';
|
import { Intent, Alert } from '@blueprintjs/core';
|
||||||
import { queryCache } from 'react-query';
|
import { queryCache } from 'react-query';
|
||||||
import { AppToaster } from 'components';
|
import { AppToaster } from 'components';
|
||||||
@@ -24,9 +21,10 @@ function AccountActivateAlert({
|
|||||||
// #withAlertActions
|
// #withAlertActions
|
||||||
closeAlert,
|
closeAlert,
|
||||||
|
|
||||||
requestActivateAccount
|
requestActivateAccount,
|
||||||
}) {
|
}) {
|
||||||
const { formatMessage } = useIntl();
|
const { formatMessage } = useIntl();
|
||||||
|
const [isLoading, setLoading] = useState(false);
|
||||||
|
|
||||||
// Handle alert cancel.
|
// Handle alert cancel.
|
||||||
const handleCancel = () => {
|
const handleCancel = () => {
|
||||||
@@ -35,9 +33,9 @@ function AccountActivateAlert({
|
|||||||
|
|
||||||
// Handle activate account confirm.
|
// Handle activate account confirm.
|
||||||
const handleConfirmAccountActivate = () => {
|
const handleConfirmAccountActivate = () => {
|
||||||
|
setLoading(true);
|
||||||
requestActivateAccount(accountId)
|
requestActivateAccount(accountId)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
closeAlert('account-activate');
|
|
||||||
AppToaster.show({
|
AppToaster.show({
|
||||||
message: formatMessage({
|
message: formatMessage({
|
||||||
id: 'the_account_has_been_successfully_activated',
|
id: 'the_account_has_been_successfully_activated',
|
||||||
@@ -46,8 +44,10 @@ function AccountActivateAlert({
|
|||||||
});
|
});
|
||||||
queryCache.invalidateQueries('accounts-table');
|
queryCache.invalidateQueries('accounts-table');
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {})
|
||||||
|
.finally(() => {
|
||||||
closeAlert('account-activate');
|
closeAlert('account-activate');
|
||||||
|
setLoading(false);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -59,6 +59,7 @@ function AccountActivateAlert({
|
|||||||
isOpen={isOpen}
|
isOpen={isOpen}
|
||||||
onCancel={handleCancel}
|
onCancel={handleCancel}
|
||||||
onConfirm={handleConfirmAccountActivate}
|
onConfirm={handleConfirmAccountActivate}
|
||||||
|
loading={isLoading}
|
||||||
>
|
>
|
||||||
<p>
|
<p>
|
||||||
<T id={'are_sure_to_activate_this_account'} />
|
<T id={'are_sure_to_activate_this_account'} />
|
||||||
@@ -70,5 +71,5 @@ function AccountActivateAlert({
|
|||||||
export default compose(
|
export default compose(
|
||||||
withAlertStoreConnect(),
|
withAlertStoreConnect(),
|
||||||
withAlertActions,
|
withAlertActions,
|
||||||
withAccountsActions
|
withAccountsActions,
|
||||||
)(AccountActivateAlert);
|
)(AccountActivateAlert);
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import React from 'react';
|
import React, { useState } from 'react';
|
||||||
import {
|
import {
|
||||||
FormattedMessage as T,
|
FormattedMessage as T,
|
||||||
FormattedHTMLMessage,
|
FormattedHTMLMessage,
|
||||||
useIntl
|
useIntl,
|
||||||
} from 'react-intl';
|
} from 'react-intl';
|
||||||
import { Intent, Alert } from '@blueprintjs/core';
|
import { Intent, Alert } from '@blueprintjs/core';
|
||||||
import { queryCache } from 'react-query';
|
import { queryCache } from 'react-query';
|
||||||
@@ -22,22 +22,22 @@ function AccountBulkActivateAlert({
|
|||||||
// #withAlertActions
|
// #withAlertActions
|
||||||
closeAlert,
|
closeAlert,
|
||||||
|
|
||||||
requestBulkActivateAccounts
|
requestBulkActivateAccounts,
|
||||||
}) {
|
}) {
|
||||||
const { formatMessage } = useIntl();
|
const { formatMessage } = useIntl();
|
||||||
|
const [isLoading, setLoading] = useState(false);
|
||||||
const selectedRowsCount = 0;
|
const selectedRowsCount = 0;
|
||||||
|
|
||||||
// Handle alert cancel.
|
// Handle alert cancel.
|
||||||
const handleClose = () => {
|
const handleClose = () => {
|
||||||
closeAlert(name);
|
closeAlert(name);
|
||||||
}
|
};
|
||||||
|
|
||||||
// Handle Bulk activate account confirm.
|
// Handle Bulk activate account confirm.
|
||||||
const handleConfirmBulkActivate = () => {
|
const handleConfirmBulkActivate = () => {
|
||||||
|
setLoading(true);
|
||||||
requestBulkActivateAccounts(accountsIds)
|
requestBulkActivateAccounts(accountsIds)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
closeAlert(name);
|
|
||||||
|
|
||||||
AppToaster.show({
|
AppToaster.show({
|
||||||
message: formatMessage({
|
message: formatMessage({
|
||||||
id: 'the_accounts_has_been_successfully_activated',
|
id: 'the_accounts_has_been_successfully_activated',
|
||||||
@@ -46,7 +46,9 @@ function AccountBulkActivateAlert({
|
|||||||
});
|
});
|
||||||
queryCache.invalidateQueries('accounts-table');
|
queryCache.invalidateQueries('accounts-table');
|
||||||
})
|
})
|
||||||
.catch((errors) => {
|
.catch((errors) => {})
|
||||||
|
.finally(() => {
|
||||||
|
setLoading(false);
|
||||||
closeAlert(name);
|
closeAlert(name);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -61,6 +63,7 @@ function AccountBulkActivateAlert({
|
|||||||
isOpen={isOpen}
|
isOpen={isOpen}
|
||||||
onCancel={handleClose}
|
onCancel={handleClose}
|
||||||
onConfirm={handleConfirmBulkActivate}
|
onConfirm={handleConfirmBulkActivate}
|
||||||
|
loading={isLoading}
|
||||||
>
|
>
|
||||||
<p>
|
<p>
|
||||||
<T id={'are_sure_to_activate_this_accounts'} />
|
<T id={'are_sure_to_activate_this_accounts'} />
|
||||||
@@ -72,5 +75,5 @@ function AccountBulkActivateAlert({
|
|||||||
export default compose(
|
export default compose(
|
||||||
withAlertStoreConnect(),
|
withAlertStoreConnect(),
|
||||||
withAlertActions,
|
withAlertActions,
|
||||||
withAccountsActions
|
withAccountsActions,
|
||||||
)(AccountBulkActivateAlert);
|
)(AccountBulkActivateAlert);
|
||||||
|
|||||||
@@ -1,8 +1,5 @@
|
|||||||
import React from 'react';
|
import React, { useState } from 'react';
|
||||||
import {
|
import { FormattedMessage as T, useIntl } from 'react-intl';
|
||||||
FormattedMessage as T,
|
|
||||||
useIntl
|
|
||||||
} from 'react-intl';
|
|
||||||
import { Intent, Alert } from '@blueprintjs/core';
|
import { Intent, Alert } from '@blueprintjs/core';
|
||||||
import { queryCache } from 'react-query';
|
import { queryCache } from 'react-query';
|
||||||
import { AppToaster } from 'components';
|
import { AppToaster } from 'components';
|
||||||
@@ -27,9 +24,11 @@ function AccountBulkDeleteAlert({
|
|||||||
closeAlert,
|
closeAlert,
|
||||||
|
|
||||||
// #withAccountsActions
|
// #withAccountsActions
|
||||||
requestDeleteBulkAccounts
|
requestDeleteBulkAccounts,
|
||||||
}) {
|
}) {
|
||||||
const { formatMessage } = useIntl();
|
const { formatMessage } = useIntl();
|
||||||
|
const [isLoading, setLoading] = useState(false);
|
||||||
|
|
||||||
const selectedRowsCount = 0;
|
const selectedRowsCount = 0;
|
||||||
|
|
||||||
const handleCancel = () => {
|
const handleCancel = () => {
|
||||||
@@ -37,9 +36,9 @@ function AccountBulkDeleteAlert({
|
|||||||
};
|
};
|
||||||
// Handle confirm accounts bulk delete.
|
// Handle confirm accounts bulk delete.
|
||||||
const handleConfirmBulkDelete = () => {
|
const handleConfirmBulkDelete = () => {
|
||||||
|
setLoading(true);
|
||||||
requestDeleteBulkAccounts(accountsIds)
|
requestDeleteBulkAccounts(accountsIds)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
closeAlert(name);
|
|
||||||
AppToaster.show({
|
AppToaster.show({
|
||||||
message: formatMessage({
|
message: formatMessage({
|
||||||
id: 'the_accounts_has_been_successfully_deleted',
|
id: 'the_accounts_has_been_successfully_deleted',
|
||||||
@@ -49,8 +48,11 @@ function AccountBulkDeleteAlert({
|
|||||||
queryCache.invalidateQueries('accounts-table');
|
queryCache.invalidateQueries('accounts-table');
|
||||||
})
|
})
|
||||||
.catch((errors) => {
|
.catch((errors) => {
|
||||||
closeAlert(name);
|
|
||||||
handleDeleteErrors(errors);
|
handleDeleteErrors(errors);
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
setLoading(false);
|
||||||
|
closeAlert(name);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -65,6 +67,7 @@ function AccountBulkDeleteAlert({
|
|||||||
isOpen={isOpen}
|
isOpen={isOpen}
|
||||||
onCancel={handleCancel}
|
onCancel={handleCancel}
|
||||||
onConfirm={handleConfirmBulkDelete}
|
onConfirm={handleConfirmBulkDelete}
|
||||||
|
loading={isLoading}
|
||||||
>
|
>
|
||||||
<p>
|
<p>
|
||||||
<T id={'once_delete_these_accounts_you_will_not_able_restore_them'} />
|
<T id={'once_delete_these_accounts_you_will_not_able_restore_them'} />
|
||||||
@@ -76,5 +79,5 @@ function AccountBulkDeleteAlert({
|
|||||||
export default compose(
|
export default compose(
|
||||||
withAlertStoreConnect(),
|
withAlertStoreConnect(),
|
||||||
withAlertActions,
|
withAlertActions,
|
||||||
withAccountsActions
|
withAccountsActions,
|
||||||
)(AccountBulkDeleteAlert);
|
)(AccountBulkDeleteAlert);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import React from 'react';
|
import React, { useState } from 'react';
|
||||||
import { FormattedMessage as T, useIntl } from 'react-intl';
|
import { FormattedMessage as T, useIntl } from 'react-intl';
|
||||||
import { Intent, Alert } from '@blueprintjs/core';
|
import { Intent, Alert } from '@blueprintjs/core';
|
||||||
import { queryCache } from 'react-query';
|
import { queryCache } from 'react-query';
|
||||||
@@ -21,6 +21,7 @@ function AccountBulkInactivateAlert({
|
|||||||
closeAlert,
|
closeAlert,
|
||||||
}) {
|
}) {
|
||||||
const { formatMessage } = useIntl();
|
const { formatMessage } = useIntl();
|
||||||
|
const [isLoading, setLoading] = useState(false);
|
||||||
const selectedRowsCount = 0;
|
const selectedRowsCount = 0;
|
||||||
|
|
||||||
// Handle alert cancel.
|
// Handle alert cancel.
|
||||||
@@ -29,10 +30,9 @@ function AccountBulkInactivateAlert({
|
|||||||
};
|
};
|
||||||
// Handle Bulk Inactive accounts confirm.
|
// Handle Bulk Inactive accounts confirm.
|
||||||
const handleConfirmBulkInactive = () => {
|
const handleConfirmBulkInactive = () => {
|
||||||
|
setLoading(true);
|
||||||
requestBulkInactiveAccounts(accountsIds)
|
requestBulkInactiveAccounts(accountsIds)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
closeAlert(name);
|
|
||||||
|
|
||||||
AppToaster.show({
|
AppToaster.show({
|
||||||
message: formatMessage({
|
message: formatMessage({
|
||||||
id: 'the_accounts_have_been_successfully_inactivated',
|
id: 'the_accounts_have_been_successfully_inactivated',
|
||||||
@@ -41,7 +41,9 @@ function AccountBulkInactivateAlert({
|
|||||||
});
|
});
|
||||||
queryCache.invalidateQueries('accounts-table');
|
queryCache.invalidateQueries('accounts-table');
|
||||||
})
|
})
|
||||||
.catch((errors) => {
|
.catch((errors) => {})
|
||||||
|
.finally(() => {
|
||||||
|
setLoading(false);
|
||||||
closeAlert(name);
|
closeAlert(name);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -56,6 +58,7 @@ function AccountBulkInactivateAlert({
|
|||||||
isOpen={isOpen}
|
isOpen={isOpen}
|
||||||
onCancel={handleCancel}
|
onCancel={handleCancel}
|
||||||
onConfirm={handleConfirmBulkInactive}
|
onConfirm={handleConfirmBulkInactive}
|
||||||
|
loading={isLoading}
|
||||||
>
|
>
|
||||||
<p>
|
<p>
|
||||||
<T id={'are_sure_to_inactive_this_accounts'} />
|
<T id={'are_sure_to_inactive_this_accounts'} />
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import React from 'react';
|
import React, { useState } from 'react';
|
||||||
import {
|
import {
|
||||||
FormattedMessage as T,
|
FormattedMessage as T,
|
||||||
FormattedHTMLMessage,
|
FormattedHTMLMessage,
|
||||||
useIntl
|
useIntl,
|
||||||
} from 'react-intl';
|
} from 'react-intl';
|
||||||
import { Intent, Alert } from '@blueprintjs/core';
|
import { Intent, Alert } from '@blueprintjs/core';
|
||||||
import { queryCache } from 'react-query';
|
import { queryCache } from 'react-query';
|
||||||
@@ -30,9 +30,10 @@ function AccountDeleteAlert({
|
|||||||
requestDeleteAccount,
|
requestDeleteAccount,
|
||||||
|
|
||||||
// #withAlertActions
|
// #withAlertActions
|
||||||
closeAlert
|
closeAlert,
|
||||||
}) {
|
}) {
|
||||||
const { formatMessage } = useIntl();
|
const { formatMessage } = useIntl();
|
||||||
|
const [isLoading, setLoading] = useState(false);
|
||||||
|
|
||||||
// handle cancel delete account alert.
|
// handle cancel delete account alert.
|
||||||
const handleCancelAccountDelete = () => {
|
const handleCancelAccountDelete = () => {
|
||||||
@@ -41,9 +42,9 @@ function AccountDeleteAlert({
|
|||||||
|
|
||||||
// Handle confirm account delete.
|
// Handle confirm account delete.
|
||||||
const handleConfirmAccountDelete = () => {
|
const handleConfirmAccountDelete = () => {
|
||||||
|
setLoading(true);
|
||||||
requestDeleteAccount(accountId)
|
requestDeleteAccount(accountId)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
closeAlert(name);
|
|
||||||
AppToaster.show({
|
AppToaster.show({
|
||||||
message: formatMessage({
|
message: formatMessage({
|
||||||
id: 'the_account_has_been_successfully_deleted',
|
id: 'the_account_has_been_successfully_deleted',
|
||||||
@@ -54,6 +55,9 @@ function AccountDeleteAlert({
|
|||||||
})
|
})
|
||||||
.catch((errors) => {
|
.catch((errors) => {
|
||||||
handleDeleteErrors(errors);
|
handleDeleteErrors(errors);
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
setLoading(false);
|
||||||
closeAlert(name);
|
closeAlert(name);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -67,6 +71,7 @@ function AccountDeleteAlert({
|
|||||||
isOpen={isOpen}
|
isOpen={isOpen}
|
||||||
onCancel={handleCancelAccountDelete}
|
onCancel={handleCancelAccountDelete}
|
||||||
onConfirm={handleConfirmAccountDelete}
|
onConfirm={handleConfirmAccountDelete}
|
||||||
|
loading={isLoading}
|
||||||
>
|
>
|
||||||
<p>
|
<p>
|
||||||
<FormattedHTMLMessage
|
<FormattedHTMLMessage
|
||||||
@@ -74,11 +79,11 @@ function AccountDeleteAlert({
|
|||||||
/>
|
/>
|
||||||
</p>
|
</p>
|
||||||
</Alert>
|
</Alert>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default compose(
|
export default compose(
|
||||||
withAlertStoreConnect(),
|
withAlertStoreConnect(),
|
||||||
withAlertActions,
|
withAlertActions,
|
||||||
withAccountsActions
|
withAccountsActions,
|
||||||
)(AccountDeleteAlert);
|
)(AccountDeleteAlert);
|
||||||
|
|||||||
@@ -1,8 +1,5 @@
|
|||||||
import React from 'react';
|
import React, { useState } from 'react';
|
||||||
import {
|
import { FormattedMessage as T, useIntl } from 'react-intl';
|
||||||
FormattedMessage as T,
|
|
||||||
useIntl,
|
|
||||||
} from 'react-intl';
|
|
||||||
import { Intent, Alert } from '@blueprintjs/core';
|
import { Intent, Alert } from '@blueprintjs/core';
|
||||||
import { queryCache } from 'react-query';
|
import { queryCache } from 'react-query';
|
||||||
import { AppToaster } from 'components';
|
import { AppToaster } from 'components';
|
||||||
@@ -23,18 +20,18 @@ function AccountInactivateAlert({
|
|||||||
|
|
||||||
// #withAccountsActions
|
// #withAccountsActions
|
||||||
requestInactiveAccount,
|
requestInactiveAccount,
|
||||||
|
|
||||||
}) {
|
}) {
|
||||||
const { formatMessage } = useIntl();
|
const { formatMessage } = useIntl();
|
||||||
|
const [isLoading, setLoading] = useState(false);
|
||||||
|
|
||||||
const handleCancelInactiveAccount = () => {
|
const handleCancelInactiveAccount = () => {
|
||||||
closeAlert('account-inactivate');
|
closeAlert('account-inactivate');
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleConfirmAccountActive = () => {
|
const handleConfirmAccountActive = () => {
|
||||||
|
setLoading(true);
|
||||||
requestInactiveAccount(accountId)
|
requestInactiveAccount(accountId)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
closeAlert('account-inactivate');
|
|
||||||
AppToaster.show({
|
AppToaster.show({
|
||||||
message: formatMessage({
|
message: formatMessage({
|
||||||
id: 'the_account_has_been_successfully_inactivated',
|
id: 'the_account_has_been_successfully_inactivated',
|
||||||
@@ -43,7 +40,9 @@ function AccountInactivateAlert({
|
|||||||
});
|
});
|
||||||
queryCache.invalidateQueries('accounts-table');
|
queryCache.invalidateQueries('accounts-table');
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {})
|
||||||
|
.finally(() => {
|
||||||
|
setLoading(false);
|
||||||
closeAlert('account-inactivate');
|
closeAlert('account-inactivate');
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -56,6 +55,7 @@ function AccountInactivateAlert({
|
|||||||
isOpen={isOpen}
|
isOpen={isOpen}
|
||||||
onCancel={handleCancelInactiveAccount}
|
onCancel={handleCancelInactiveAccount}
|
||||||
onConfirm={handleConfirmAccountActive}
|
onConfirm={handleConfirmAccountActive}
|
||||||
|
loading={isLoading}
|
||||||
>
|
>
|
||||||
<p>
|
<p>
|
||||||
<T id={'are_sure_to_inactive_this_account'} />
|
<T id={'are_sure_to_inactive_this_account'} />
|
||||||
@@ -67,5 +67,5 @@ function AccountInactivateAlert({
|
|||||||
export default compose(
|
export default compose(
|
||||||
withAlertStoreConnect(),
|
withAlertStoreConnect(),
|
||||||
withAlertActions,
|
withAlertActions,
|
||||||
withAccountsActions
|
withAccountsActions,
|
||||||
)(AccountInactivateAlert);
|
)(AccountInactivateAlert);
|
||||||
|
|||||||
Reference in New Issue
Block a user