Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[teams] inactivate Leave Team action for last team owner #6477

Merged
merged 1 commit into from
Nov 2, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions components/dashboard/src/teams/Members.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export default function() {
const [ showInviteModal, setShowInviteModal ] = useState<boolean>(false);
const [ searchText, setSearchText ] = useState<string>('');
const [ roleFilter, setRoleFilter ] = useState<TeamMemberRole | undefined>();
const [ leaveTeamEnabled, setLeaveTeamEnabled ] = useState<boolean>(false);

useEffect(() => {
if (!team) {
Expand All @@ -46,6 +47,12 @@ export default function() {
})();
}, [ team ]);

useEffect(() => {
const owners = members.filter(m => m.role === "owner");
const isOwner = owners.some(o => o.userId === user?.id);
setLeaveTeamEnabled(!isOwner || owners.length > 1);
}, [ members ]);

const ownMemberInfo = members.find(m => m.userId === user?.id);

const getInviteURL = (inviteId: string) => {
Expand Down Expand Up @@ -179,9 +186,9 @@ export default function() {
<span className="flex-grow" />
<ItemFieldContextMenu menuEntries={m.userId === user?.id
? [{
title: 'Leave Team',
customFontStyle: 'text-red-600 dark:text-red-400 hover:text-red-800 dark:hover:text-red-300',
onClick: () => removeTeamMember(m.userId)
title: leaveTeamEnabled ? 'Leave Team' : 'Remaining owner',
customFontStyle: leaveTeamEnabled ? 'text-red-600 dark:text-red-400 hover:text-red-800 dark:hover:text-red-300' : 'text-gray-400 dark:text-gray-200',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
customFontStyle: leaveTeamEnabled ? 'text-red-600 dark:text-red-400 hover:text-red-800 dark:hover:text-red-300' : 'text-gray-400 dark:text-gray-200',
customFontStyle: leaveTeamEnabled ? 'text-red-600 dark:text-red-400 hover:text-red-800 dark:hover:text-red-300' : 'text-gray-400 dark:text-gray-200 cursor-not-allowed',

How about also adapting the cursor to show that there is no action? E.g. cursor-not-allowed or cursor-default.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that the label is changed to Remaining owner, I don't think it's necessary to change the cursor. Also, there is no other example in the dashboard to provide feedback using the "not-allowed" cursor.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to have some server-side validation for this as well?

onClick: () => leaveTeamEnabled && removeTeamMember(m.userId)
}]
: (ownMemberInfo?.role === 'owner'
? [{
Expand Down