Skip to content

Commit 88fbfe9

Browse files
committed
show messagewhen remove last role from users
1 parent ea0fcda commit 88fbfe9

File tree

2 files changed

+69
-79
lines changed

2 files changed

+69
-79
lines changed

public/globals.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -869,8 +869,9 @@ window.pkp = {
869869
'user.password': 'Password',
870870
'user.phone': 'Phone',
871871
'user.removeRole.message':
872-
"Are you sure you want to permanently remove this role? This action will revoke the user's access to all information and permissions associated with this role",
873-
'user.role.reviewer': 'Reviewer',
872+
'Are you sure you want to permanently remove this role? This action will revoke the user\'s access to all information and permissions associated with this role.',
873+
'user.removeRole.roleRemainMessage' :'You cannot remove the role. At least one role must be assigned to the user.',
874+
'user.role.reviewer': 'Reviewer',
874875
'user.role.reviewers': 'Reviewers',
875876
'user.roles': 'Roles',
876877
'user.signature': 'Signature',
@@ -889,7 +890,7 @@ window.pkp = {
889890
'userInvitation.edit.title': 'Edit Invitation',
890891
'userInvitation.modal.button': 'View All Users',
891892
'userInvitation.modal.message':
892-
"{$email} has been invited to new role in OJS. You can be updated about the user's decision on the User & Role page, your OJS notification and/or your email",
893+
'{$email} has been invited to new role in OJS. You can be updated about the user\'s decision on the User & Role page, your OJS notification and/or your email.',
893894
'userInvitation.modal.title': 'Invitation Sent',
894895
'userInvitation.roleTable.endDate': 'End Date',
895896
'userInvitation.roleTable.journalMasthead': 'Journal Masthead',
@@ -924,10 +925,6 @@ window.pkp = {
924925
"Once the user is enabled, they will regain access to OJS, and you'll be able to invite them to roles as needed.",
925926
'grid.user.grid.user.disableReasonDescription':
926927
"Please note that once a user is disabled, you won't be able to add them to any roles until they are enabled again.",
927-
'user.url': 'Homepage URL',
928-
'user.workingLanguages': 'Working Languages',
929-
'user.bioStatement': 'Bio Statement',
930-
'common.viewMoreDetails': 'View more details',
931928
},
932929
tinyMCE: {
933930
skinUrl: '/styles/tinymce',

src/pages/userInvitation/UserInvitationUserGroupsTable.vue

Lines changed: 65 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -40,41 +40,21 @@
4040
: t('invitation.masthead.hidden')
4141
}}
4242
</TableCell>
43-
<template v-if="numberOfActiveRoles > 1">
44-
<template v-if="!currentUserGroup.dateEnd">
45-
<TableCell>
46-
<PkpButton
47-
:is-warnable="true"
48-
@click="removeUserGroup(currentUserGroup, index)"
49-
>
50-
{{ t('invitation.role.removeRole.button') }}
51-
</PkpButton>
52-
</TableCell>
53-
</template>
54-
<template v-else>
55-
<TableCell>
56-
<div
57-
class="rounded border-light bg-[#fbe7f1] px-2 py-2 text-center text-lg-semibold leading-5"
58-
>
59-
{{ t('invitation.removeRoles') }}
60-
</div>
61-
</TableCell>
62-
</template>
63-
</template>
64-
<template v-else>
65-
<template v-if="!currentUserGroup.dateEnd">
66-
<TableCell></TableCell>
67-
</template>
68-
<template v-else>
69-
<TableCell>
70-
<div
71-
class="rounded border-light bg-[#fbe7f1] px-2 py-2 text-center text-lg-semibold leading-5"
72-
>
73-
{{ t('invitation.removeRoles') }}
74-
</div>
75-
</TableCell>
76-
</template>
77-
</template>
43+
<TableCell v-if="!currentUserGroup.dateEnd">
44+
<PkpButton
45+
:is-warnable="true"
46+
@click="removeUserGroup(currentUserGroup, index)"
47+
>
48+
{{ t('invitation.role.removeRole.button') }}
49+
</PkpButton>
50+
</TableCell>
51+
<TableCell v-else>
52+
<div
53+
class="rounded border-light bg-[#fbe7f1] px-2 py-2 text-center text-lg-semibold leading-5"
54+
>
55+
{{ t('invitation.removeRoles') }}
56+
</div>
57+
</TableCell>
7858
</TableRow>
7959
<template v-if="!store.invitationPayload.disabled">
8060
<TableRow
@@ -141,7 +121,7 @@
141121
<PkpButton
142122
v-if="
143123
store.invitationPayload.userGroupsToAdd.length > 1 ||
144-
hasUserGroupsValue()
124+
isUserGroupsToAddPopulated()
145125
"
146126
:is-warnable="true"
147127
@click="removeInvitedUserGroup(index)"
@@ -193,8 +173,6 @@ const allUserGroupsToAdd = computed(
193173
() => store.invitationPayload.userGroupsToAdd,
194174
);
195175
updateWithSelectedUserGroups(props.userGroups);
196-
hasUserGroupsValue();
197-
console.log(store.invitationPayload.currentUserGroups);
198176
199177
/**
200178
* update selected user group
@@ -208,7 +186,6 @@ function updateUserGroup(index, fieldName, newValue) {
208186
userGroupsUpdate[index][fieldName] = newValue;
209187
store.updatePayload('userGroupsToAdd', userGroupsUpdate, false);
210188
updateWithSelectedUserGroups(props.userGroups);
211-
hasUserGroupsValue();
212189
}
213190
214191
const availableUserGroups = computed(() => {
@@ -220,16 +197,14 @@ const availableUserGroups = computed(() => {
220197
});
221198
222199
/**
223-
* check user groups array and show
224-
* remove role button only for clear the fields
200+
* check any values filled with userGroupsToAdd
225201
*/
226-
function hasUserGroupsValue() {
227-
if (store.invitationPayload.userGroupsToAdd[0]) {
228-
return Object.values(store.invitationPayload.userGroupsToAdd[0]).some(
229-
(value) => value !== null,
230-
);
231-
}
232-
return false;
202+
function isUserGroupsToAddPopulated() {
203+
return store.invitationPayload.userGroupsToAdd[0]
204+
? Object.values(store.invitationPayload.userGroupsToAdd[0]).some(
205+
(value) => value !== null,
206+
)
207+
: false;
233208
}
234209
235210
/**
@@ -252,31 +227,49 @@ const {openDialog} = useModal();
252227
* @param index Number
253228
*/
254229
function removeUserGroup(userGroup, index) {
255-
openDialog({
256-
name: 'removeRole',
257-
title: t('invitation.role.removeRole.button'),
258-
message: t('user.removeRole.message'),
259-
actions: [
260-
{
261-
label: t('common.yes'),
262-
isWarnable: true,
263-
callback: (close) => {
264-
store.invitationPayload.currentUserGroups.find(
265-
(data, i) => i === index,
266-
).dateEnd = new Date();
267-
removeRole(store.invitationPayload.userId, userGroup.id);
268-
close();
230+
if (numberOfActiveRoles.value <= 1) {
231+
// user must have atleast one role
232+
openDialog({
233+
name: 'oneRoleRemain',
234+
title: t('invitation.role.removeRole.button'),
235+
message: t('user.removeRole.roleRemainMessage'),
236+
actions: [
237+
{
238+
label: t('common.close'),
239+
callback: (close) => {
240+
close();
241+
},
269242
},
270-
},
271-
{
272-
label: t('common.no'),
273-
callback: (close) => {
274-
close();
243+
],
244+
modalStyle: 'negative',
245+
});
246+
} else {
247+
openDialog({
248+
name: 'removeRole',
249+
title: t('invitation.role.removeRole.button'),
250+
message: t('user.removeRole.message'),
251+
actions: [
252+
{
253+
label: t('common.yes'),
254+
isWarnable: true,
255+
callback: (close) => {
256+
store.invitationPayload.currentUserGroups.find(
257+
(data, i) => i === index,
258+
).dateEnd = new Date();
259+
removeRole(store.invitationPayload.userId, userGroup.id);
260+
close();
261+
},
275262
},
276-
},
277-
],
278-
modalStyle: 'negative',
279-
});
263+
{
264+
label: t('common.no'),
265+
callback: (close) => {
266+
close();
267+
},
268+
},
269+
],
270+
modalStyle: 'negative',
271+
});
272+
}
280273
}
281274
282275
/**
@@ -285,7 +278,7 @@ function removeUserGroup(userGroup, index) {
285278
*/
286279
function removeInvitedUserGroup(index) {
287280
const userGroupsUpdate = [...store.invitationPayload.userGroupsToAdd];
288-
if (hasUserGroupsValue && userGroupsUpdate.length === 1) {
281+
if (isUserGroupsToAddPopulated && userGroupsUpdate.length === 1) {
289282
userGroupsUpdate.push({
290283
userGroupId: null,
291284
dateStart: null,

0 commit comments

Comments
 (0)