Skip to content

Commit 69fd39e

Browse files
committed
Test
1 parent 7e90e88 commit 69fd39e

File tree

6 files changed

+52
-22
lines changed

6 files changed

+52
-22
lines changed
Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,49 @@
1-
import type { IRoom } from '@rocket.chat/core-typings';
1+
import type { IRoom, ITeam, Serialized } from '@rocket.chat/core-typings';
22
import { useEndpoint, useUserId } from '@rocket.chat/ui-contexts';
3+
import type { UseQueryOptions } from '@tanstack/react-query';
34
import { useQuery } from '@tanstack/react-query';
45
import { minutesToMilliseconds } from 'date-fns';
56

67
import { roomsQueryKeys } from '../lib/queryKeys';
78

8-
export const useRoomInfoEndpoint = (rid: IRoom['_id']) => {
9+
type UseRoomInfoEndpointOptions<
10+
TData = Serialized<{
11+
room: IRoom | undefined;
12+
parent?: Pick<IRoom, '_id' | 'name' | 'fname' | 't' | 'prid' | 'u' | 'sidepanel'>;
13+
team?: Pick<ITeam, 'name' | 'roomId' | 'type' | '_id'>;
14+
}>,
15+
> = Omit<
16+
UseQueryOptions<
17+
Serialized<{
18+
room: IRoom | undefined;
19+
parent?: Pick<IRoom, '_id' | 'name' | 'fname' | 't' | 'prid' | 'u' | 'sidepanel'>;
20+
team?: Pick<ITeam, 'name' | 'roomId' | 'type' | '_id'>;
21+
}>,
22+
{ success: boolean; error: string },
23+
TData,
24+
ReturnType<typeof roomsQueryKeys.info>
25+
>,
26+
'queryKey' | 'queryFn'
27+
>;
28+
29+
export const useRoomInfoEndpoint = <
30+
TData = Serialized<{
31+
room: IRoom | undefined;
32+
parent?: Pick<IRoom, '_id' | 'name' | 'fname' | 't' | 'prid' | 'u' | 'sidepanel'>;
33+
team?: Pick<ITeam, 'name' | 'roomId' | 'type' | '_id'>;
34+
}>,
35+
>(
36+
rid: IRoom['_id'],
37+
options?: UseRoomInfoEndpointOptions<TData>,
38+
) => {
939
const getRoomInfo = useEndpoint('GET', '/v1/rooms.info');
1040
const uid = useUserId();
1141
return useQuery({
1242
queryKey: roomsQueryKeys.info(rid),
1343
queryFn: () => getRoomInfo({ roomId: rid }),
1444
gcTime: minutesToMilliseconds(15),
15-
16-
retry: (count, error: { success: boolean; error: string }) => {
17-
if (count > 2 || error.error === 'not-allowed') {
18-
return false;
19-
}
20-
return true;
21-
},
22-
45+
retry: (count, error: { success: boolean; error: string }) => count <= 2 && error.error !== 'not-allowed',
2346
enabled: !!uid,
47+
...options,
2448
});
2549
};

apps/meteor/client/omnichannel/hooks/useOmnichannelPrioritiesMenu.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { IRoom } from '@rocket.chat/core-typings';
12
import { LivechatPriorityWeight } from '@rocket.chat/core-typings';
23
import { useEffectEvent } from '@rocket.chat/fuselage-hooks';
34
import { useEndpoint } from '@rocket.chat/ui-contexts';
@@ -10,7 +11,7 @@ import { roomsQueryKeys } from '../../lib/queryKeys';
1011
import { dispatchToastMessage } from '../../lib/toast';
1112
import { PRIORITY_ICONS } from '../priorities/PriorityIcon';
1213

13-
export const useOmnichannelPrioritiesMenu = (rid: string) => {
14+
export const useOmnichannelPrioritiesMenu = (rid: IRoom['_id']) => {
1415
const { t } = useTranslation();
1516
const queryClient = useQueryClient();
1617
const updateRoomPriority = useEndpoint('POST', '/v1/livechat/room/:rid/priority', { rid });

apps/meteor/client/views/omnichannel/directory/chats/ChatInfo/ChatInfo.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ function ChatInfo({ id, route }: ChatInfoProps) {
5454
livechatData,
5555
source,
5656
queuedAt,
57-
} = room || { v: {} };
57+
} = room ?? {};
58+
console.log('Priority id:', priorityId);
5859

5960
const routePath = useRoute(route || 'omnichannel-directory');
6061
const canViewCustomFields = usePermission('view-livechat-room-customfields');

apps/meteor/client/views/omnichannel/directory/chats/ChatInfo/RoomEdit/RoomEditWithData.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function RoomEditWithData({ id: roomId, reload, reloadInfo, onClose }: RoomEditW
1919
const { data: room, isLoading: isRoomLoading, isError: isRoomError } = useOmnichannelRoomInfo(roomId);
2020
const { _id: visitorId } = room?.v ?? {};
2121

22-
const { data: visitor, isLoading: isVisitorLoading, isError: isVisitorError } = useVisitorInfo(visitorId, { enabled: !!visitorId });
22+
const { data: visitor, isLoading: isVisitorLoading, isError: isVisitorError } = useVisitorInfo(visitorId!, { enabled: !!visitorId });
2323

2424
if (isRoomLoading || isVisitorLoading) {
2525
return <FormSkeleton />;
Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1-
import type { IOmnichannelRoom, Serialized } from '@rocket.chat/core-typings';
1+
import type { IOmnichannelRoom, IRoom, Serialized } from '@rocket.chat/core-typings';
22

33
import { useRoomInfoEndpoint } from '../../../../hooks/useRoomInfoEndpoint';
44

5-
export const useOmnichannelRoomInfo = (roomId: string) => {
6-
const { data: roomData, ...props } = useRoomInfoEndpoint(roomId);
7-
const room = roomData?.room as Serialized<IOmnichannelRoom>;
5+
export const useOmnichannelRoomInfo = (rid: IRoom['_id']) => {
6+
const query = useRoomInfoEndpoint(rid, {
7+
select: (data) => {
8+
const newData = (data.room as Serialized<IOmnichannelRoom>) ?? null;
9+
console.log('useOmnichannelRoomInfo select', newData._id, 'priorityId', newData.priorityId);
10+
return newData;
11+
},
12+
});
813

9-
return {
10-
data: room,
11-
...props,
12-
};
14+
console.log('useOmnichannelRoomInfo data', query.data?._id, 'priorityId', query.data?.priorityId);
15+
16+
return query;
1317
};

apps/meteor/client/views/omnichannel/directory/utils/formatQueuedAt.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { IOmnichannelRoom, Serialized } from '@rocket.chat/core-typings';
22
import moment from 'moment';
33

4-
export const formatQueuedAt = (room: Serialized<IOmnichannelRoom>) => {
4+
export const formatQueuedAt = (room: Serialized<IOmnichannelRoom> | undefined) => {
55
const { servedBy, closedAt, open, queuedAt, ts } = room || {};
66
const queueStartedAt = queuedAt || ts;
77

0 commit comments

Comments
 (0)