From fb8b347ad9302aa3a06f3084204d054c55143bdb Mon Sep 17 00:00:00 2001 From: Paulo Amorim Date: Wed, 8 Jan 2025 14:57:25 -0300 Subject: [PATCH] remove isRemovingSelf param and unused imports --- .../organization/MemberActionsDropdown.tsx | 3 -- .../organization/MemberRemoveModal.tsx | 4 +- jsapp/js/account/organization/membersQuery.ts | 54 ++++++++++--------- 3 files changed, 29 insertions(+), 32 deletions(-) diff --git a/jsapp/js/account/organization/MemberActionsDropdown.tsx b/jsapp/js/account/organization/MemberActionsDropdown.tsx index 5dfd13166b..2987bc8818 100644 --- a/jsapp/js/account/organization/MemberActionsDropdown.tsx +++ b/jsapp/js/account/organization/MemberActionsDropdown.tsx @@ -18,9 +18,6 @@ import {OrganizationUserRole} from './organizationQuery'; // Styles import styles from './memberActionsDropdown.module.scss'; -import {queryClient} from 'jsapp/js/query/queryClient'; -import {QueryKeys} from 'jsapp/js/query/queryKeys'; -import { useNavigation } from 'react-router-dom'; import router from 'jsapp/js/router/router'; import { ROUTES } from 'jsapp/js/router/routerConstants'; diff --git a/jsapp/js/account/organization/MemberRemoveModal.tsx b/jsapp/js/account/organization/MemberRemoveModal.tsx index 49992d4c0c..dc59dd00bd 100644 --- a/jsapp/js/account/organization/MemberRemoveModal.tsx +++ b/jsapp/js/account/organization/MemberRemoveModal.tsx @@ -12,8 +12,6 @@ import envStore from 'jsapp/js/envStore'; import subscriptionStore from 'jsapp/js/account/subscriptionStore'; import {useRemoveOrganizationMember} from './membersQuery'; import {notify} from 'alertifyjs'; -import {ROUTES} from 'jsapp/js/router/routerConstants'; -import router from 'jsapp/js/router/router'; interface MemberRemoveModalProps { username: string; @@ -37,7 +35,7 @@ export default function MemberRemoveModal( onCancel, }: MemberRemoveModalProps ) { - const removeMember = useRemoveOrganizationMember({isRemovingSelf}); + const removeMember = useRemoveOrganizationMember(); const mmoLabel = getSimpleMMOLabel( envStore.data, subscriptionStore.activeSubscriptions[0], diff --git a/jsapp/js/account/organization/membersQuery.ts b/jsapp/js/account/organization/membersQuery.ts index c60389c730..cc3d736187 100644 --- a/jsapp/js/account/organization/membersQuery.ts +++ b/jsapp/js/account/organization/membersQuery.ts @@ -50,9 +50,10 @@ export interface OrganizationMember { } function getMemberEndpoint(orgId: string, username: string) { - return endpoints.ORGANIZATION_MEMBER_URL - .replace(':organization_id', orgId) - .replace(':username', username); + return endpoints.ORGANIZATION_MEMBER_URL.replace( + ':organization_id', + orgId + ).replace(':username', username); } /** @@ -66,29 +67,27 @@ export function usePatchOrganizationMember(username: string) { const orgId = orgQuery.data?.id; return useMutation({ - mutationFn: async (data: Partial) => ( + mutationFn: async (data: Partial) => // We're asserting the `orgId` is not `undefined` here, because the parent // query (`useOrganizationMembersQuery`) wouldn't be enabled without it. // Plus all the organization-related UI (that would use this hook) is // accessible only to logged in users. - fetchPatch(getMemberEndpoint(orgId!, username), data) - ), + fetchPatch(getMemberEndpoint(orgId!, username), data), onSettled: () => { // We invalidate query, so it will refetch (instead of refetching it // directly, see: https://github.com/TanStack/query/discussions/2468) - queryClient.invalidateQueries({queryKey: [QueryKeys.organizationMembers]}); + queryClient.invalidateQueries({ + queryKey: [QueryKeys.organizationMembers], + }); }, }); } /** - * Mutation hook for removing member from organiztion. It ensures that all + * Mutation hook for removing member from organization. It ensures that all * related queries refetch data (are invalidated). */ -interface RemoveOrganizationMemberParams { - isRemovingSelf?: boolean; -} -export function useRemoveOrganizationMember(params?: RemoveOrganizationMemberParams) { +export function useRemoveOrganizationMember() { const queryClient = useQueryClient(); const session = useSession(); @@ -97,23 +96,21 @@ export function useRemoveOrganizationMember(params?: RemoveOrganizationMemberPar const orgId = orgQuery.data?.id; return useMutation({ - mutationFn: async (username: string) => { - if (username === session.currentLoggedAccount?.username) { - // If user is removing themselves, we need to clear the session - session.refreshAccount(); - } - + mutationFn: async (username: string) => // We're asserting the `orgId` is not `undefined` here, because the parent // query (`useOrganizationMembersQuery`) wouldn't be enabled without it. // Plus all the organization-related UI (that would use this hook) is // accessible only to logged in users. - return fetchDelete(getMemberEndpoint(orgId!, username)); - }, - onSettled: () => { - if (params?.isRemovingSelf) { + fetchDelete(getMemberEndpoint(orgId!, username)) + , + onSuccess: (_data, username) => { + if (username === session.currentLoggedAccount?.username) { + // If user is removing themselves, we need to clear the session session.refreshAccount(); } else { - queryClient.invalidateQueries({queryKey: [QueryKeys.organizationMembers]}); + queryClient.invalidateQueries({ + queryKey: [QueryKeys.organizationMembers], + }); } }, }); @@ -134,8 +131,10 @@ async function getOrganizationMembers( offset: offset.toString(), }); - const apiUrl = endpoints.ORGANIZATION_MEMBERS_URL - .replace(':organization_id', orgId); + const apiUrl = endpoints.ORGANIZATION_MEMBERS_URL.replace( + ':organization_id', + orgId + ); return fetchGet>( apiUrl + '?' + params, @@ -149,7 +148,10 @@ async function getOrganizationMembers( * A hook that gives you paginated list of organization members. Uses * `useOrganizationQuery` to get the id. */ -export default function useOrganizationMembersQuery({limit, offset}: PaginatedQueryHookParams) { +export default function useOrganizationMembersQuery({ + limit, + offset, +}: PaginatedQueryHookParams) { const orgQuery = useOrganizationQuery(); const orgId = orgQuery.data?.id;