-
Notifications
You must be signed in to change notification settings - Fork 11k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix surfaced redirection issue when editing room info
- Loading branch information
1 parent
9da8139
commit 4b57621
Showing
3 changed files
with
35 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
apps/meteor/client/views/room/providers/hooks/useRedirectOnSettingsChanged.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import type { ISubscription } from '@rocket.chat/core-typings'; | ||
import { useRouter } from '@rocket.chat/ui-contexts'; | ||
import { useEffect } from 'react'; | ||
|
||
import { LegacyRoomManager } from '../../../../../app/ui-utils/client'; | ||
|
||
export const useRedirectOnSettingsChanged = (subscription?: ISubscription | null) => { | ||
const router = useRouter(); | ||
|
||
const routeType = router.getRouteName() === 'channel' ? 'c' : 'p'; | ||
const routeName = router.getRouteParameters().name; | ||
|
||
const subExists = !!subscription; | ||
|
||
useEffect(() => { | ||
if (!subExists) { | ||
return; | ||
} | ||
const redirect = async () => { | ||
if (routeType !== subscription.t || routeName !== subscription.name) { | ||
await LegacyRoomManager.close(routeType + routeName); | ||
router.navigate({ | ||
pattern: subscription.t === 'c' ? '/channel/:name/:tab?/:context?' : '/group/:name/:tab?/:context?', | ||
params: { name: subscription.name }, | ||
search: router.getSearchParameters(), | ||
}); | ||
} | ||
}; | ||
redirect(); | ||
}, [subscription?.t, subscription?.name, routeType, routeName, router, subExists]); | ||
}; |