Skip to content

Commit

Permalink
fix(console): joining tenant should navigate user to the new tenant (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
charIeszhao authored Apr 1, 2024
1 parent 4e59064 commit eeb095f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { OrganizationInvitationStatus } from '@logto/schemas';
import { OrganizationInvitationStatus, getTenantIdFromOrganizationId } from '@logto/schemas';
import { useContext, useState } from 'react';
import { useTranslation } from 'react-i18next';

Expand All @@ -20,7 +20,7 @@ type Props = {
function InvitationList({ invitations }: Props) {
const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' });
const cloudApi = useCloudApi();
const { prependTenant, navigateTenant } = useContext(TenantsContext);
const { prependTenant, navigateTenant, resetTenants } = useContext(TenantsContext);
const [isJoining, setIsJoining] = useState(false);
const [isCreateModalOpen, setIsCreateModalOpen] = useState(false);

Expand Down Expand Up @@ -48,7 +48,9 @@ function InvitationList({ invitations }: Props) {
params: { invitationId: id },
body: { status: OrganizationInvitationStatus.Accepted },
});
navigateTenant(organizationId.slice(2));
const data = await cloudApi.get('/api/tenants');
resetTenants(data);
navigateTenant(getTenantIdFromOrganizationId(organizationId));
} finally {
setIsJoining(false);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { OrganizationInvitationStatus, type TenantTag } from '@logto/schemas';
import {
OrganizationInvitationStatus,
getTenantIdFromOrganizationId,
type TenantTag,
} from '@logto/schemas';
import { useContext } from 'react';

import { useCloudApi } from '@/cloud/hooks/use-cloud-api';
Expand Down Expand Up @@ -37,10 +41,9 @@ function TenantInvitationDropdownItem({ data }: Props) {
params: { invitationId: id },
body: { status: OrganizationInvitationStatus.Accepted },
});
// TODO: @charles, need to fetch only the target tenant instance instead of all.
const data = await cloudApi.get('/api/tenants');
resetTenants(data);
navigateTenant(organizationId.slice(2));
navigateTenant(getTenantIdFromOrganizationId(organizationId));
}}
/>
</div>
Expand Down
8 changes: 5 additions & 3 deletions packages/console/src/pages/AcceptInvitation/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useLogto } from '@logto/react';
import { OrganizationInvitationStatus } from '@logto/schemas';
import { OrganizationInvitationStatus, getTenantIdFromOrganizationId } from '@logto/schemas';
import { useContext, useEffect } from 'react';
import { useTranslation } from 'react-i18next';
import { useParams } from 'react-router-dom';
Expand All @@ -21,7 +21,7 @@ function AcceptInvitation() {
const redirectUri = useRedirectUri();
const { invitationId = '' } = useParams();
const cloudApi = useCloudApi();
const { navigateTenant } = useContext(TenantsContext);
const { navigateTenant, resetTenants } = useContext(TenantsContext);

// The request is only made when the user has signed-in and the invitation ID is available.
// The response data is returned only when the current user matches the invitee email. Otherwise, it returns 404.
Expand All @@ -43,7 +43,9 @@ function AcceptInvitation() {
body: { status: OrganizationInvitationStatus.Accepted },
});

navigateTenant(organizationId.slice(2));
const data = await cloudApi.get('/api/tenants');
resetTenants(data);
navigateTenant(getTenantIdFromOrganizationId(organizationId));
})();
}, [cloudApi, error, invitation, navigateTenant, t]);

Expand Down

0 comments on commit eeb095f

Please sign in to comment.