Fix batch-delete

Signed-off-by: soupette <cyril.lpz@gmail.com>
This commit is contained in:
soupette 2020-06-03 17:26:25 +02:00 committed by Alexandre Bodin
parent ca5f97aa5d
commit fa7d906494
3 changed files with 13 additions and 6 deletions

View File

@ -14,11 +14,7 @@ const RoleRow = ({ role, onRoleToggle, onRoleDuplicate, onRoleRemove, selectedRo
const handleRoleSelection = e => { const handleRoleSelection = e => {
e.stopPropagation(); e.stopPropagation();
if (role.usersCount) {
strapi.notification.info('Roles.ListPage.notification.delete-not-allowed');
} else {
onRoleToggle(role.id); onRoleToggle(role.id);
}
}; };
const handleClickDelete = () => { const handleClickDelete = () => {

View File

@ -53,10 +53,20 @@ const RoleListPage = () => {
const handleConfirmDeleteData = async () => { const handleConfirmDeleteData = async () => {
try { try {
const filteredRoles = selectedRoles.filter(currentId => {
const currentRole = roles.find(role => role.id === currentId);
return currentRole.usersCount === 0;
});
if (selectedRoles.length !== filteredRoles.length) {
strapi.notification.info('Roles.ListPage.notification.delete-all-not-allowed');
}
await request('/admin/roles/batch-delete', { await request('/admin/roles/batch-delete', {
method: 'POST', method: 'POST',
body: { body: {
ids: selectedRoles, ids: filteredRoles,
}, },
}); });

View File

@ -345,6 +345,7 @@
"app.containers.AuthPage.ForgotPasswordSuccess.text.contact-admin": "If you do not receive this link, please contact your administrator.", "app.containers.AuthPage.ForgotPasswordSuccess.text.contact-admin": "If you do not receive this link, please contact your administrator.",
"app.containers.AuthPage.ForgotPasswordSuccess.title": "Email sent", "app.containers.AuthPage.ForgotPasswordSuccess.title": "Email sent",
"Roles.ListPage.notification.delete-not-allowed": "A role cannot be deleted if associated with users", "Roles.ListPage.notification.delete-not-allowed": "A role cannot be deleted if associated with users",
"Roles.ListPage.notification.delete-all-not-allowed": "Some roles could not be deleted since they are associated with users",
"Roles.RoleRow.user-count.plural": "{number} users", "Roles.RoleRow.user-count.plural": "{number} users",
"Roles.RoleRow.user-count.singular": "{number} user", "Roles.RoleRow.user-count.singular": "{number} user",
"Roles.components.List.empty.withSearch": "There is no role corresponding to the search ({search})..." "Roles.components.List.empty.withSearch": "There is no role corresponding to the search ({search})..."