Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(console): joining tenant should navigate user to the new tenant #5602

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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,9 +43,11 @@
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]);

Check warning on line 50 in packages/console/src/pages/AcceptInvitation/index.tsx

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

packages/console/src/pages/AcceptInvitation/index.tsx#L50

[react-hooks/exhaustive-deps] React Hook useEffect has a missing dependency: 'resetTenants'. Either include it or remove the dependency array.

// No invitation returned, indicating the current signed-in user is not the invitee.
if (error?.status === 404) {
Expand Down
Loading