Skip to content

Commit

Permalink
remove isRemovingSelf param and unused imports
Browse files Browse the repository at this point in the history
  • Loading branch information
pauloamorimbr committed Jan 8, 2025
1 parent f0541cb commit fb8b347
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 32 deletions.
3 changes: 0 additions & 3 deletions jsapp/js/account/organization/MemberActionsDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
4 changes: 1 addition & 3 deletions jsapp/js/account/organization/MemberRemoveModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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],
Expand Down
54 changes: 28 additions & 26 deletions jsapp/js/account/organization/membersQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand All @@ -66,29 +67,27 @@ export function usePatchOrganizationMember(username: string) {
const orgId = orgQuery.data?.id;

return useMutation({
mutationFn: async (data: Partial<OrganizationMember>) => (
mutationFn: async (data: Partial<OrganizationMember>) =>
// 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<OrganizationMember>(getMemberEndpoint(orgId!, username), data)
),
fetchPatch<OrganizationMember>(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();
Expand All @@ -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],
});
}
},
});
Expand All @@ -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<PaginatedResponse<OrganizationMember>>(
apiUrl + '?' + params,
Expand All @@ -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;

Expand Down

0 comments on commit fb8b347

Please sign in to comment.