fix(web): SpaceInviteCard navigates to /channels/:spaceId (not the non-existent /spaces/:id)
This commit is contained in:
@@ -96,6 +96,9 @@ describe('SpaceInviteCard', () => {
|
|||||||
// Specifically NOT called with empty string or undefined
|
// Specifically NOT called with empty string or undefined
|
||||||
expect(mockJoinByCode).not.toHaveBeenCalledWith('abc', '');
|
expect(mockJoinByCode).not.toHaveBeenCalledWith('abc', '');
|
||||||
expect(mockJoinByCode).not.toHaveBeenCalledWith('abc', undefined);
|
expect(mockJoinByCode).not.toHaveBeenCalledWith('abc', undefined);
|
||||||
|
// After a successful join, the app must navigate to the space via the real
|
||||||
|
// route (/channels/:spaceId), not the non-existent /spaces/:id route.
|
||||||
|
await waitFor(() => expect(mockNavigate).toHaveBeenCalledWith('/channels/S1'));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('navigates to space when join returns "already a member" (no error shown)', async () => {
|
it('navigates to space when join returns "already a member" (no error shown)', async () => {
|
||||||
@@ -111,7 +114,7 @@ describe('SpaceInviteCard', () => {
|
|||||||
const btn = await screen.findByRole('button', { name: /^join$/i });
|
const btn = await screen.findByRole('button', { name: /^join$/i });
|
||||||
await user.click(btn);
|
await user.click(btn);
|
||||||
|
|
||||||
await waitFor(() => expect(mockNavigate).toHaveBeenCalledWith('/spaces/S1'));
|
await waitFor(() => expect(mockNavigate).toHaveBeenCalledWith('/channels/S1'));
|
||||||
expect(screen.queryByText(/already a member of this space/i)).not.toBeInTheDocument();
|
expect(screen.queryByText(/already a member of this space/i)).not.toBeInTheDocument();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -54,14 +54,14 @@ export function SpaceInviteCard({ payload, senderName }: Props) {
|
|||||||
// the DM transport origin nor window.location.origin. Empty string maps
|
// the DM transport origin nor window.location.origin. Empty string maps
|
||||||
// to undefined so joinByCode follows its local-instance branch.
|
// to undefined so joinByCode follows its local-instance branch.
|
||||||
const space = await joinByCode(payload.inviteCode, payload.spaceInstanceOrigin || undefined);
|
const space = await joinByCode(payload.inviteCode, payload.spaceInstanceOrigin || undefined);
|
||||||
navigate(`/spaces/${space.id}`);
|
navigate(`/channels/${space.id}`);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const msg = (err as Error)?.message ?? '';
|
const msg = (err as Error)?.message ?? '';
|
||||||
if (msg.toLowerCase().includes('already a member')) {
|
if (msg.toLowerCase().includes('already a member')) {
|
||||||
// Already a member is a successful state — just navigate to the space.
|
// Already a member is a successful state — just navigate to the space.
|
||||||
// Look up the space in the store by id; if not found (rare race), stay
|
// Look up the space in the store by id; if not found (rare race), stay
|
||||||
// silent rather than block the user with a noisy error.
|
// silent rather than block the user with a noisy error.
|
||||||
navigate(`/spaces/${payload.spaceId}`);
|
navigate(`/channels/${payload.spaceId}`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setJoinError(msg || 'Failed to join');
|
setJoinError(msg || 'Failed to join');
|
||||||
|
|||||||
Reference in New Issue
Block a user