11import { isRoomFederated } from '@rocket.chat/core-typings' ;
22import type { IUser , IInviteSubscription } from '@rocket.chat/core-typings' ;
3- import type { ComponentProps } from 'react' ;
3+ import { useEffectEvent } from '@rocket.chat/fuselage-hooks' ;
4+ import { useQueryClient } from '@tanstack/react-query' ;
5+ import { useEffect , type ComponentProps } from 'react' ;
46import { useTranslation } from 'react-i18next' ;
57
68import Header from './Header' ;
@@ -10,6 +12,7 @@ import type { IRoomWithFederationOriginalName } from './contexts/RoomContext';
1012import { useRoomInvitation } from './hooks/useRoomInvitation' ;
1113import RoomLayout from './layout/RoomLayout' ;
1214import { links } from '../../lib/links' ;
15+ import { roomsQueryKeys , subscriptionsQueryKeys } from '../../lib/queryKeys' ;
1316
1417type RoomInviteProps = Omit < ComponentProps < typeof RoomLayout > , 'header' | 'body' | 'aside' > & {
1518 userId ?: IUser [ '_id' ] ;
@@ -19,12 +22,25 @@ type RoomInviteProps = Omit<ComponentProps<typeof RoomLayout>, 'header' | 'body'
1922
2023const RoomInvite = ( { room, subscription, userId, ...props } : RoomInviteProps ) => {
2124 const { t } = useTranslation ( ) ;
25+ const queryClient = useQueryClient ( ) ;
2226 const { acceptInvite, rejectInvite, isPending } = useRoomInvitation ( room ) ;
2327
2428 const infoLink = isRoomFederated ( room ) ? { label : t ( 'Learn_more_about_Federation' ) , href : links . go . matrixFederation } : undefined ;
2529
2630 useGoToHomeOnRemoved ( room , userId ) ;
2731
32+ const invalidateQueries = useEffectEvent ( ( ) => {
33+ const reference = room . federationOriginalName ?? room . name ?? room . _id ;
34+ void queryClient . invalidateQueries ( { queryKey : roomsQueryKeys . room ( room . _id ) } ) ;
35+ void queryClient . invalidateQueries ( { queryKey : subscriptionsQueryKeys . subscription ( room . _id ) } ) ;
36+ void queryClient . invalidateQueries ( { queryKey : roomsQueryKeys . roomReference ( reference , room . t , userId ) } ) ;
37+ } ) ;
38+
39+ useEffect ( ( ) => {
40+ // Invalidate room and subscription queries when unmounting (invite accepted or rejected)
41+ return ( ) => invalidateQueries ( ) ;
42+ } , [ invalidateQueries ] ) ;
43+
2844 return (
2945 < RoomLayout
3046 { ...props }
0 commit comments