-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Expand file tree
/
Copy pathAgentEditWithData.tsx
More file actions
45 lines (36 loc) · 1.55 KB
/
AgentEditWithData.tsx
File metadata and controls
45 lines (36 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import type { ILivechatAgent } from '@rocket.chat/core-typings';
import { Box } from '@rocket.chat/fuselage';
import { ContextualbarSkeletonBody } from '@rocket.chat/ui-client';
import { useEndpoint } from '@rocket.chat/ui-contexts';
import { useQuery } from '@tanstack/react-query';
import type { ReactElement } from 'react';
import { useTranslation } from 'react-i18next';
import AgentEdit from './AgentEdit';
import { omnichannelQueryKeys } from '../../../lib/queryKeys';
const AgentEditWithData = ({ uid }: { uid: ILivechatAgent['_id'] }): ReactElement => {
const { t } = useTranslation();
const getAgentById = useEndpoint('GET', '/v1/livechat/users/:type/:_id', { type: 'agent', _id: uid });
const getAgentDepartments = useEndpoint('GET', '/v1/livechat/agents/:agentId/departments', { agentId: uid });
const { data, isPending, error } = useQuery({
queryKey: ['livechat-getAgentById', uid],
queryFn: async () => getAgentById(),
refetchOnWindowFocus: false,
});
const {
data: agentDepartments,
isPending: agentDepartmentsLoading,
error: agentsDepartmentsError,
} = useQuery({
queryKey: omnichannelQueryKeys.agentDepartments(uid),
queryFn: async () => getAgentDepartments(),
refetchOnWindowFocus: false,
});
if (isPending || agentDepartmentsLoading || !agentDepartments) {
return <ContextualbarSkeletonBody />;
}
if (error || agentsDepartmentsError || !data?.user) {
return <Box p={16}>{t('User_not_found')}</Box>;
}
return <AgentEdit agentData={data.user} agentDepartments={agentDepartments.departments} />;
};
export default AgentEditWithData;