fix(InviteUsers): fix invite users bugs.

This commit is contained in:
a.bouhuolia
2021-03-23 18:57:04 +02:00
parent ff559180fd
commit 5855d3f368
22 changed files with 543 additions and 404 deletions

View File

@@ -1,6 +1,69 @@
import React from 'react';
import { FormattedMessage as T, useIntl } from 'react-intl';
import { Alert, Intent } from '@blueprintjs/core';
import { AppToaster } from 'components';
import { useActivateUser } from 'hooks/query';
import withAlertStoreConnect from 'containers/Alert/withAlertStoreConnect';
import withAlertActions from 'containers/Alert/withAlertActions';
import { compose } from 'utils';
function UserActivateAlert() {
}
/**
* User inactivate alert.
*/
function UserActivateAlert({
// #ownProps
name,
// #withAlertStoreConnect
isOpen,
payload: { userId },
// #withAlertActions
closeAlert,
}) {
const { formatMessage } = useIntl();
const { mutateAsync: userActivateMutate } = useActivateUser();
const handleConfirmActivate = () => {
userActivateMutate(userId)
.then(() => {
AppToaster.show({
message: formatMessage({
id: 'the_user_has_been_activated_successfully',
}),
intent: Intent.SUCCESS,
});
closeAlert(name);
})
.catch((error) => {
closeAlert(name);
});
};
const handleCancel = () => {
closeAlert(name);
};
return (
<Alert
cancelButtonText={<T id={'cancel'} />}
confirmButtonText={<T id={'activate'} />}
intent={Intent.WARNING}
isOpen={isOpen}
onCancel={handleCancel}
onConfirm={handleConfirmActivate}
>
<p>
<T id={'are_sure_to_activate_this_account'} />
</p>
</Alert>
);
}
export default compose(
withAlertStoreConnect(),
withAlertActions,
)(UserActivateAlert);

View File

@@ -40,6 +40,7 @@ function UserDeleteAlert({
}),
intent: Intent.SUCCESS,
});
closeAlert(name);
})
.catch(({ response: { data: { errors } } }) => {
if (errors.find(e => e.type === 'CANNOT_DELETE_LAST_USER')) {

View File

@@ -36,9 +36,16 @@ function UserInactivateAlert({
}),
intent: Intent.SUCCESS,
});
closeAlert(name);
})
.catch((error) => {
.catch(({ response: { data: { errors } } }) => {
if (errors.find(e => e.type === 'CANNOT.TOGGLE.ACTIVATE.AUTHORIZED.USER')) {
AppToaster.show({
message: 'You could not activate/inactivate the same authorized user.',
intent: Intent.DANGER,
});
}
closeAlert(name);
});
};