11import type { IRoom , ISubscription } from '@rocket.chat/core-typings' ;
22import { useStableCallback } from '@rocket.chat/fuselage-hooks' ;
3- import { useMethod , useRouter } from '@rocket.chat/ui-contexts' ;
3+ import { useMethod , useRouter , useToastMessageDispatch } from '@rocket.chat/ui-contexts' ;
44
55import { roomCoordinator } from '../../../lib/rooms/roomCoordinator' ;
66import { Subscriptions } from '../../../stores' ;
@@ -13,6 +13,7 @@ type GoToRoomByIdOptions = {
1313export const useGoToRoom = ( ) : ( ( roomId : IRoom [ '_id' ] , options ?: GoToRoomByIdOptions ) => Promise < void > ) => {
1414 const router = useRouter ( ) ;
1515 const getRoomById = useMethod ( 'getRoomById' ) ;
16+ const dispatchToastMessage = useToastMessageDispatch ( ) ;
1617
1718 // TODO: remove params recycling
1819 return useStableCallback ( async ( roomId : IRoom [ '_id' ] , options ?: GoToRoomByIdOptions ) => {
@@ -25,7 +26,11 @@ export const useGoToRoom = (): ((roomId: IRoom['_id'], options?: GoToRoomByIdOpt
2526 return ;
2627 }
2728
28- const room = await getRoomById ( roomId ) ;
29- roomCoordinator . openRouteLink ( room . t , { rid : room . _id , ...room } , router . getSearchParameters ( ) , options ) ;
29+ try {
30+ const room = await getRoomById ( roomId ) ;
31+ roomCoordinator . openRouteLink ( room . t , { rid : room . _id , ...room } , router . getSearchParameters ( ) , options ) ;
32+ } catch ( error ) {
33+ dispatchToastMessage ( { type : 'error' , message : error } ) ;
34+ }
3035 } ) ;
3136} ;
0 commit comments