fix(preferences): fix preferences users page.

This commit is contained in:
a.bouhuolia
2021-03-22 19:23:36 +02:00
parent d79be910f9
commit a0f4947138
20 changed files with 451 additions and 307 deletions

View File

@@ -0,0 +1,6 @@
function UserActivateAlert() {
}

View File

@@ -0,0 +1,76 @@
import React from 'react';
import { Intent, Alert } from '@blueprintjs/core';
import { FormattedMessage as T, useIntl } from 'react-intl';
import { useDeleteUser } from 'hooks/query';
import { AppToaster } from 'components';
import withAlertStoreConnect from 'containers/Alert/withAlertStoreConnect';
import withAlertActions from 'containers/Alert/withAlertActions';
import { compose } from 'redux';
/**
* User delete alert.
*/
function UserDeleteAlert({
// #ownProps
name,
// #withAlertStoreConnect
isOpen,
payload: { userId },
// #withAlertActions
closeAlert,
}) {
const { formatMessage } = useIntl();
const { mutateAsync: deleteUserMutate, isLoading } = useDeleteUser();
const handleCancelUserDelete = () => {
closeAlert(name);
};
const handleConfirmUserDelete = () => {
deleteUserMutate(userId)
.then((response) => {
AppToaster.show({
message: formatMessage({
id: 'the_user_has_been_deleted_successfully',
}),
intent: Intent.SUCCESS,
});
})
.catch(({ response: { data: { errors } } }) => {
if (errors.find(e => e.type === 'CANNOT_DELETE_LAST_USER')) {
AppToaster.show({
message: 'Cannot delete the last user in the system.',
intent: Intent.DANGER,
});
}
closeAlert(name);
});
};
return (
<Alert
cancelButtonText={<T id={'cancel'} />}
confirmButtonText={<T id={'delete'} />}
intent={Intent.DANGER}
isOpen={isOpen}
onCancel={handleCancelUserDelete}
onConfirm={handleConfirmUserDelete}
loading={isLoading}
>
<p>
Once you delete this user, you won't be able to restore it later. Are
you sure you want to delete ?
</p>
</Alert>
);
}
export default compose(
withAlertStoreConnect(),
withAlertActions,
)(UserDeleteAlert);

View File

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