From c85150b83dd52af1108a38c6b91c884a7bf40a32 Mon Sep 17 00:00:00 2001 From: Paulo Amorim Date: Thu, 9 Jan 2025 12:31:27 -0300 Subject: [PATCH] feat(organizations): handle user removes itself flow TASK-1354 (#5393) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ### đŸ“Ŗ Summary The navigation and data flow is improved when an MMO organization admin removes itself from the organization. ### 📖 Description The objective of this PR is to: - Minimize wrong API calls due to permissions and session data that needs to be updated - Present a better flow for the user, redirecting them to the correct view after the removal There's still a big margin for improving, mainly due to some work needed in `useUsage`, but it unfolds into several other files and flows, so it's better to be handled in a separated PR ### 👀 Preview steps 1. ℹī¸ have an account and a project 2. Be the admin in an MMO 3. Navigate to Account Settings > Members 4. Remove yourself from the organization 5. 🔴 [on main] notice that the user is not redirected and there are some failed attempts to API calls due to permissions 6. đŸŸĸ [on PR] notice that the user is redirected and there's only 1 failed attempt to usage API --- .../organization/MemberActionsDropdown.tsx | 14 ++++-- .../organization/MemberRemoveModal.tsx | 20 ++++---- jsapp/js/account/organization/membersQuery.ts | 49 +++++++++++++------ .../account/organization/organizationQuery.ts | 3 +- jsapp/js/stores/useSession.tsx | 9 ++++ 5 files changed, 65 insertions(+), 30 deletions(-) diff --git a/jsapp/js/account/organization/MemberActionsDropdown.tsx b/jsapp/js/account/organization/MemberActionsDropdown.tsx index 960901d36f..2987bc8818 100644 --- a/jsapp/js/account/organization/MemberActionsDropdown.tsx +++ b/jsapp/js/account/organization/MemberActionsDropdown.tsx @@ -18,6 +18,8 @@ import {OrganizationUserRole} from './organizationQuery'; // Styles import styles from './memberActionsDropdown.module.scss'; +import router from 'jsapp/js/router/router'; +import { ROUTES } from 'jsapp/js/router/routerConstants'; interface MemberActionsDropdownProps { targetUsername: string; @@ -69,15 +71,21 @@ export default function MemberActionsDropdown( .replace('##TEAM_OR_ORGANIZATION##', mmoLabel); } + const onRemovalConfirmation = () => { + setIsRemoveModalVisible(false); + if (isAdminRemovingSelf) { + // Redirect to account root after leaving the organization + router.navigate(ROUTES.ACCOUNT_ROOT); + } + }; + return ( <> {isRemoveModalVisible && { - setIsRemoveModalVisible(false); - }} + onConfirmDone={onRemovalConfirmation} onCancel={() => setIsRemoveModalVisible(false)} /> } diff --git a/jsapp/js/account/organization/MemberRemoveModal.tsx b/jsapp/js/account/organization/MemberRemoveModal.tsx index 822c7b3e31..dc59dd00bd 100644 --- a/jsapp/js/account/organization/MemberRemoveModal.tsx +++ b/jsapp/js/account/organization/MemberRemoveModal.tsx @@ -66,6 +66,16 @@ export default function MemberRemoveModal( .replaceAll('##TEAM_OR_ORGANIZATION##', mmoLabel); } + const handleRemoveMember = async () => { + try { + await removeMember.mutateAsync(username); + } catch (error) { + notify('Failed to remove member', 'error'); + } finally { + onConfirmDone(); + } + }; + return ( onCancel()}> {textToDisplay.title} @@ -87,15 +97,7 @@ export default function MemberRemoveModal(