Skip to content

Commit b6ff755

Browse files
committed
enable remove role button only for clear the fields
1 parent 16ae7b4 commit b6ff755

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

src/pages/userInvitation/UserInvitationUserGroupsTable.vue

+26-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,10 @@
118118
</TableCell>
119119
<TableCell>
120120
<PkpButton
121-
v-if="store.invitationPayload.userGroupsToAdd.length > 1"
121+
v-if="
122+
store.invitationPayload.userGroupsToAdd.length > 1 ||
123+
hasUserGroupsValue()
124+
"
122125
:is-warnable="true"
123126
@click="removeInvitedUserGroup(index)"
124127
>
@@ -169,6 +172,7 @@ const allUserGroupsToAdd = computed(
169172
() => store.invitationPayload.userGroupsToAdd,
170173
);
171174
updateWithSelectedUserGroups(props.userGroups);
175+
hasUserGroupsValue();
172176
173177
/**
174178
* update selected user group
@@ -182,6 +186,7 @@ function updateUserGroup(index, fieldName, newValue) {
182186
userGroupsUpdate[index][fieldName] = newValue;
183187
store.updatePayload('userGroupsToAdd', userGroupsUpdate, false);
184188
updateWithSelectedUserGroups(props.userGroups);
189+
hasUserGroupsValue();
185190
}
186191
187192
const availableUserGroups = computed(() => {
@@ -192,6 +197,19 @@ const availableUserGroups = computed(() => {
192197
});
193198
});
194199
200+
/**
201+
* check user groups array and show
202+
* remove role button only for clear the fields
203+
*/
204+
function hasUserGroupsValue() {
205+
if (store.invitationPayload.userGroupsToAdd[0]) {
206+
Object.values(store.invitationPayload.userGroupsToAdd[0]).some(
207+
(value) => value !== null,
208+
);
209+
}
210+
return false;
211+
}
212+
195213
/**
196214
* add user groups to the invitation payload
197215
*/
@@ -245,6 +263,13 @@ function removeUserGroup(userGroup, index) {
245263
*/
246264
function removeInvitedUserGroup(index) {
247265
const userGroupsUpdate = [...store.invitationPayload.userGroupsToAdd];
266+
if (hasUserGroupsValue && userGroupsUpdate.length === 1) {
267+
userGroupsUpdate.push({
268+
userGroupId: null,
269+
dateStart: null,
270+
masthead: null,
271+
});
272+
}
248273
userGroupsUpdate.splice(index, 1);
249274
store.updatePayload('userGroupsToAdd', userGroupsUpdate, false);
250275
updateWithSelectedUserGroups(props.userGroups);

0 commit comments

Comments
 (0)