Skip to content

Commit

Permalink
fix(console): refresh invitation list after inviting members
Browse files Browse the repository at this point in the history
  • Loading branch information
charIeszhao committed Mar 29, 2024
1 parent a77fd3f commit dc6a707
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function Invitations() {
const { canInviteMember, canRemoveMember } = useCurrentTenantScopes();

const { data, error, isLoading, mutate } = useSWR<TenantInvitationResponse[], RequestError>(
`api/tenant/${currentTenantId}/invitations`,
'api/tenants/:tenantId/invitations',
async () =>
cloudApi.get('/api/tenants/:tenantId/invitations', { params: { tenantId: currentTenantId } })
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ function Members() {
const { t } = useTranslation(undefined, { keyPrefix: 'admin_console.tenant_members' });
const cloudApi = useAuthedCloudApi();
const { currentTenantId } = useContext(TenantsContext);
const { canInviteMember, canRemoveMember, canUpdateMemberRole } = useCurrentTenantScopes();
const { canRemoveMember, canUpdateMemberRole } = useCurrentTenantScopes();

const { data, error, isLoading, mutate } = useSWR<TenantMemberResponse[], RequestError>(
`api/tenant/${currentTenantId}/members`,
`api/tenants/:tenantId/members`,
async () =>
cloudApi.get('/api/tenants/:tenantId/members', { params: { tenantId: currentTenantId } })
);
Expand Down
19 changes: 17 additions & 2 deletions packages/console/src/pages/TenantSettings/TenantMembers/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import classNames from 'classnames';
import { useState } from 'react';
import { useContext, useState } from 'react';
import { Route, Routes } from 'react-router-dom';
import useSWRMutation from 'swr/mutation';

import InvitationIcon from '@/assets/icons/invitation.svg';
import MembersIcon from '@/assets/icons/members.svg';
import PlusIcon from '@/assets/icons/plus.svg';
import { useAuthedCloudApi } from '@/cloud/hooks/use-cloud-api';
import { TenantSettingsTabs } from '@/consts';
import { TenantsContext } from '@/contexts/TenantsProvider';
import Button from '@/ds-components/Button';
import Spacer from '@/ds-components/Spacer';
import useCurrentTenantScopes from '@/hooks/use-current-tenant-scopes';
Expand All @@ -28,6 +31,14 @@ function TenantMembers() {
`/tenant-settings/${TenantSettingsTabs.Members}/${invitationsRoute}`
);

const { currentTenantId } = useContext(TenantsContext);
const cloudApi = useAuthedCloudApi();
const { trigger: mutateInvitations } = useSWRMutation(
'api/tenants/:tenantId/invitations',
async () =>
cloudApi.get('/api/tenants/:tenantId/invitations', { params: { tenantId: currentTenantId } })
);

return (
<div className={styles.container}>
<div className={styles.tabButtons}>
Expand Down Expand Up @@ -73,7 +84,11 @@ function TenantMembers() {
onClose={(isSuccessful) => {
setShowInviteModal(false);
if (isSuccessful) {
navigate('invitations');
if (isInvitationTab) {
void mutateInvitations();
} else {
navigate('invitations');
}
}
}}
/>
Expand Down

0 comments on commit dc6a707

Please sign in to comment.