Skip to content
Snippets Groups Projects
Unverified Commit 00c787f8 authored by Filipe Marins's avatar Filipe Marins Committed by GitHub
Browse files

[FIX] Not allowed error in discussion room with a private parent channel (#26394)

parent 655a6fd7
No related branches found
No related tags found
No related merge requests found
import { IRoom } from '@rocket.chat/core-typings';
import { OperationResult } from '@rocket.chat/rest-typings';
import { useEndpoint } from '@rocket.chat/ui-contexts';
import { useQuery, UseQueryResult } from '@tanstack/react-query';
import { minutesToMilliseconds } from 'date-fns';
import type { Meteor } from 'meteor/meteor';
export const useRoomInfoEndpoint = (rid: IRoom['_id']): UseQueryResult<OperationResult<'GET', '/v1/rooms.info'>> => {
const getRoomInfo = useEndpoint('GET', '/v1/rooms.info');
return useQuery(['rooms/info', rid], () => getRoomInfo({ roomId: rid }), {
cacheTime: minutesToMilliseconds(15),
staleTime: minutesToMilliseconds(5),
retry: (count, error: Meteor.Error) => {
if (count > 2 || error.error === 'not-allowed') {
return false;
}
return true;
},
});
};
import type { IRoom } from '@rocket.chat/core-typings'; import type { IRoom } from '@rocket.chat/core-typings';
import React, { ReactElement, useMemo } from 'react'; import React, { ReactElement } from 'react';
import Header from '../../../components/Header'; import Header from '../../../components/Header';
import { AsyncStatePhase } from '../../../hooks/useAsyncState'; import { useRoomInfoEndpoint } from '../../../hooks/useRoomInfoEndpoint';
import { useEndpointData } from '../../../hooks/useEndpointData';
import ParentRoom from './ParentRoom'; import ParentRoom from './ParentRoom';
type ParentRoomWithEndpointDataProps = { type ParentRoomWithEndpointDataProps = {
...@@ -11,20 +10,17 @@ type ParentRoomWithEndpointDataProps = { ...@@ -11,20 +10,17 @@ type ParentRoomWithEndpointDataProps = {
}; };
const ParentRoomWithEndpointData = ({ rid }: ParentRoomWithEndpointDataProps): ReactElement | null => { const ParentRoomWithEndpointData = ({ rid }: ParentRoomWithEndpointDataProps): ReactElement | null => {
const { phase, value } = useEndpointData( const { data, isLoading, isError } = useRoomInfoEndpoint(rid);
'/v1/rooms.info',
useMemo(() => ({ roomId: rid }), [rid]),
);
if (AsyncStatePhase.LOADING === phase) { if (isLoading) {
return <Header.Tag.Skeleton />; return <Header.Tag.Skeleton />;
} }
if (AsyncStatePhase.REJECTED === phase || !value?.room) { if (isError || !data?.room) {
return null; return null;
} }
return <ParentRoom room={value.room} />; return <ParentRoom room={data.room} />;
}; };
export default ParentRoomWithEndpointData; export default ParentRoomWithEndpointData;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment