Skip to content

Commit

Permalink
Display edit manager option in org admins
Browse files Browse the repository at this point in the history
  • Loading branch information
oharsta authored and baszoetekouw committed Nov 15, 2023
1 parent d34c4e1 commit 9010fa1
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 11 deletions.
43 changes: 32 additions & 11 deletions client/src/components/redesign/OrganisationAdmins.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {ReactComponent as UserIcon} from "../../icons/users.svg";
import {ReactComponent as InviteIcon} from "../../icons/single-neutral-question.svg";
import {ReactComponent as HandIcon} from "../../icons/puppet_new.svg";
import {ReactComponent as ThrashIcon} from "../../icons/trash_new.svg";
import {ReactComponent as PencilIcon} from "../../icons/pencil-1.svg";
import CheckBox from "../CheckBox";
import {ReactComponent as TrashIcon} from "@surfnet/sds/icons/functional-icons/bin.svg";
import {ReactComponent as ChevronLeft} from "../../icons/chevron-left.svg";
Expand Down Expand Up @@ -139,7 +140,8 @@ class OrganisationAdmins extends React.Component {
this.setState({selectedMembers: {...selectedMembers}});
}

removeFromActionIcon = (entityId, isInvite, showConfirmation) => {
removeFromActionIcon = (entityId, isInvite, showConfirmation,e) => {
stopEvent(e);
const {user: currentUser, organisation} = this.props;
const members = organisation.organisation_memberships;
const invites = organisation.organisation_invitations || [];
Expand All @@ -150,7 +152,7 @@ class OrganisationAdmins extends React.Component {
this.setState({
confirmationDialogOpen: true,
isWarning: true,
confirmationDialogAction: () => this.removeFromActionIcon(entityId, isInvite, false),
confirmationDialogAction: e => this.removeFromActionIcon(entityId, isInvite, false,e),
cancelDialogAction: () => this.setState({confirmationDialogOpen: false}),
confirmationQuestion: question,
});
Expand Down Expand Up @@ -321,20 +323,29 @@ class OrganisationAdmins extends React.Component {
}

actionIcons = entity => {
const {organisation} = this.props;
const {user, organisation} = this.props;
const {selectedMembers} = this.state;
const showResendInvite = entity.invite === true && isInvitationExpired(entity);
const nbrOfAdmins = organisation.organisation_memberships.filter(m => m.role === "admin").length;
const oneAdminLeft = nbrOfAdmins < 2;
const selectedAdmins = Object.values(selectedMembers).filter(entry => entry.selected && entry.ref.role === "admin").length;
const noMoreAdminsToCheck = (selectedAdmins + 1) === nbrOfAdmins;
const isOrgAdmin = isUserAllowed(ROLES.ORG_ADMIN, user, organisation.id);
const showEdit = isOrgAdmin && !entity.invite && entity.role === "manager"
&& !isEmpty(organisation.units);

const showDelete = entity.invite || entity.role === "manager" || (!oneAdminLeft &&
(!noMoreAdminsToCheck || selectedMembers[this.getIdentifier(entity)].selected));
return (
<div className="admin-icons">
{showEdit && <div onClick={this.gotoMember(entity)}>
<Tooltip
tip={I18n.t("models.orgMembers.editManagerTooltip")}
children={<PencilIcon/>}
standalone={true}/>
</div>}
{showDelete &&
<div onClick={() => this.removeFromActionIcon(entity.id, entity.invite, true)}>
<div onClick={e => this.removeFromActionIcon(entity.id, entity.invite, true, e)}>
<Tooltip
tip={entity.invite ? I18n.t("models.orgMembers.removeInvitationTooltip") :
I18n.t("models.orgMembers.removeMemberTooltip")}
Expand All @@ -357,16 +368,28 @@ class OrganisationAdmins extends React.Component {
}

unitOptionCallback = unitOption => {
this.setState({unitOption: unitOption, selectedRole: unitOption === "all" ? this.state.selectedRole : this.roles[1]})
this.setState({
unitOption: unitOption,
selectedRole: unitOption === "all" ? this.state.selectedRole : this.roles[1]
})
}

setSelectedRole = selectedOption => {
this.setState({selectedRole: selectedOption, selectedUnits: selectedOption.value === "admin" ? [] : this.state.selectedUnits});
this.setState({
selectedRole: selectedOption,
selectedUnits: selectedOption.value === "admin" ? [] : this.state.selectedUnits
});
}

cancelSideScreen = e => {
stopEvent(e);
this.setState({selectedMemberId: null, selectedUnits: [], selectedRole: this.roles[1], idpDisplayName: null, unitOption: "all"});
this.setState({
selectedMemberId: null,
selectedUnits: [],
selectedRole: this.roles[1],
idpDisplayName: null,
unitOption: "all"
});
}

renderSelectedMember = (selectedMember, organisation) => {
Expand Down Expand Up @@ -446,7 +469,7 @@ class OrganisationAdmins extends React.Component {
const showImpersonation = currentUser.admin && !entity.invite && entity.user.id !== currentUser.id && impersonation_allowed;
return (
<div className={"action-icons-container"}>
{isAdmin && this.actionIcons(entity)}
{isAdmin && this.actionIcons(entity, currentUser)}
{showImpersonation && <div className="impersonation">
<HandIcon className="impersonate"
onClick={() => emitImpersonation(entity.user, this.props.history)}/>
Expand Down Expand Up @@ -593,9 +616,7 @@ class OrganisationAdmins extends React.Component {
const allowed = isOrgAdmin && !membership.invite && membership.role === "manager"
&& !isEmpty(organisation.units);
return allowed && this.gotoMember;
}

}
}}
loading={false}
onHover={true}
showNew={isAdmin}
Expand Down
1 change: 1 addition & 0 deletions client/src/locale/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ const en = {
invitation: "Invitation sent by {{inviter}} to {{email}} on {{date}}",
removeTooltipDisabled: "First select users to delete",
removeInvitationTooltip: "Delete invitation",
editManagerTooltip: "Edit manager",
removeMemberTooltip: "Delete member",
removeTooltip: "Delete all selected members",
mailTooltipDisabled: "First select users to email",
Expand Down
1 change: 1 addition & 0 deletions client/src/locale/nl.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ const nl = {
invitation: "Uitnodiging verstuurd door {{inviter}} naar {{email}} op {{date}}",
removeTooltipDisabled: "Selecteer eerst gebruikers om te verwijderen",
removeInvitationTooltip: "Verwijder uitnodiging",
editManagerTooltip: "Bewerk manager",
removeMemberTooltip: "Verwijder gebruiker",
removeTooltip: "Verwijder alle geselecteerde leden",
mailTooltipDisabled: "Selecteer eerst gebruikers om te e-mailen",
Expand Down

0 comments on commit 9010fa1

Please sign in to comment.