feat: handle error delete role.

This commit is contained in:
elforjani13
2021-11-27 18:51:35 +02:00
parent 8b28d6894f
commit 0c806366cd
4 changed files with 31 additions and 3 deletions

View File

@@ -21,6 +21,7 @@ import {
import RolesFormContent from './RolesFormContent';
import withDashboardActions from 'containers/Dashboard/withDashboardActions';
import { handleDeleteErrors } from '../utils';
import { compose, transformToForm } from 'utils';
@@ -82,8 +83,14 @@ function RolesForm({
history.push('/preferences/users');
};
const onError = (errors) => {
const onError = ({
response: {
data: { errors },
},
}) => {
setSubmitting(false);
handleDeleteErrors(errors);
};
if (isNewMode) {
createRolePermissionMutate(form).then(onSuccess).catch(onError);

View File

@@ -10,4 +10,22 @@ export const handleDeleteErrors = (errors) => {
intent: Intent.DANGER,
});
}
if (errors.find((error) => error.type === 'INVALIDATE_PERMISSIONS')) {
AppToaster.show({
message: intl.get('roles.error.the_submit_role_has_invalid_permissions'),
intent: Intent.DANGER,
});
}
if (
errors.find(
(error) => error.type === 'CANNOT_DELETE_ROLE_ASSOCIATED_TO_USERS',
)
) {
AppToaster.show({
message: intl.get(
'roles.error.you_cannot_delete_role_that_associated_to_users',
),
intent: Intent.DANGER,
});
}
};