diff --git a/apps/meteor/client/hooks/useHideRoomAction.tsx b/apps/meteor/client/hooks/useHideRoomAction.tsx index b6ee1439645d3..d3159a41d6bc8 100644 --- a/apps/meteor/client/hooks/useHideRoomAction.tsx +++ b/apps/meteor/client/hooks/useHideRoomAction.tsx @@ -19,6 +19,7 @@ type HideRoomProps = { type HideRoomOptions = { redirect?: boolean; + currentRoomId?: string; }; const CLOSE_ENDPOINTS_BY_ROOM_TYPE = { @@ -29,7 +30,7 @@ const CLOSE_ENDPOINTS_BY_ROOM_TYPE = { l: '/v1/channels.close', // livechat } as const; -export const useHideRoomAction = ({ rid: roomId, type, name }: HideRoomProps, { redirect = true }: HideRoomOptions = {}) => { +export const useHideRoomAction = ({ rid: roomId, type, name }: HideRoomProps, { redirect = true,currentRoomId="" }: HideRoomOptions = {}) => { const { t } = useTranslation(); const setModal = useSetModal(); const closeModal = useEffectEvent(() => setModal()); @@ -50,6 +51,9 @@ export const useHideRoomAction = ({ rid: roomId, type, name }: HideRoomProps, { } }, onSuccess: () => { + if(currentRoomId===roomId){ + redirect=true: + } if (redirect) { router.navigate('/home'); } diff --git a/apps/meteor/client/hooks/useRoomMenuActions.ts b/apps/meteor/client/hooks/useRoomMenuActions.ts index 46308772b4295..90a118328c3d0 100644 --- a/apps/meteor/client/hooks/useRoomMenuActions.ts +++ b/apps/meteor/client/hooks/useRoomMenuActions.ts @@ -25,6 +25,7 @@ type RoomMenuActionsProps = { cl?: boolean; roomOpen?: boolean; hideDefaultOptions: boolean; + currentRoomId: string; }; export const useRoomMenuActions = ({ @@ -35,6 +36,7 @@ export const useRoomMenuActions = ({ cl, roomOpen, hideDefaultOptions, + currentRoomId, }: RoomMenuActionsProps): { title: string; items: GenericMenuItemProps[] }[] => { const { t } = useTranslation(); const subscription = useUserSubscription(rid, fields); @@ -53,8 +55,10 @@ export const useRoomMenuActions = ({ } return !((cl != null && !cl) || ['d', 'l'].includes(type)); })(); - - const handleHide = useHideRoomAction({ rid, type, name }, { redirect: false }); + if(roomOpen===true ){ + currentRoomId=rid; + } + const handleHide = useHideRoomAction({ rid, type, name }, { redirect: false,currentRoomId:currentRoomId }); const handleToggleFavorite = useToggleFavoriteAction({ rid, isFavorite }); const handleToggleRead = useToggleReadAction({ rid, isUnread, subscription }); const handleLeave = useLeaveRoomAction({ rid, type, name, roomOpen });