Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,21 @@ type useQueryType = (
from: string;
to: string;
tags: any[];
itemsPerPage: 25 | 50 | 100;
current: number;
},
customFields: { [key: string]: string } | undefined,
[column, direction]: [string, 'asc' | 'desc'],
current: number,
itemsPerPage: 25 | 50 | 100,
) => GETLivechatRoomsParams;

const sortDir = (sortDir: 'asc' | 'desc'): 1 | -1 => (sortDir === 'asc' ? 1 : -1);

const currentChatQuery: useQueryType = (
{ guest, servedBy, department, status, from, to, tags, itemsPerPage, current },
{ guest, servedBy, department, status, from, to, tags },
customFields,
[column, direction],
current,
itemsPerPage,
) => {
const query: {
agents?: string[];
Expand Down Expand Up @@ -111,6 +113,18 @@ const currentChatQuery: useQueryType = (
const CurrentChatsRoute = (): ReactElement => {
const { sortBy, sortDirection, setSort } = useSort<'fname' | 'departmentId' | 'servedBy' | 'ts' | 'lm' | 'open'>('ts', 'desc');
const [customFields, setCustomFields] = useState<{ [key: string]: string }>();

const t = useTranslation();
const id = useRouteParameter('id');

const canViewCurrentChats = usePermission('view-livechat-current-chats');
const canRemoveClosedChats = usePermission('remove-closed-livechat-room');
const directoryRoute = useRoute('omnichannel-current-chats');

const { data: allCustomFields } = useAllCustomFields();

const { current, itemsPerPage, setItemsPerPage, setCurrent, ...paginationProps } = usePagination();

const [params, setParams] = useState({
guest: '',
fname: '',
Expand All @@ -120,31 +134,21 @@ const CurrentChatsRoute = (): ReactElement => {
from: '',
to: '',
current: 0,
itemsPerPage: 25 as 25 | 50 | 100,
tags: [] as string[],
});
const t = useTranslation();
const id = useRouteParameter('id');

const query = useMemo(
() => currentChatQuery(params, customFields, [sortBy, sortDirection]),
[customFields, params, sortBy, sortDirection],
);
const canViewCurrentChats = usePermission('view-livechat-current-chats');
const canRemoveClosedChats = usePermission('remove-closed-livechat-room');
const directoryRoute = useRoute('omnichannel-current-chats');

const result = useCurrentChats(query);

const { data: allCustomFields } = useAllCustomFields();

const { current, itemsPerPage, setItemsPerPage, setCurrent, ...paginationProps } = usePagination();

const hasCustomFields = useMemo(
() => !!allCustomFields?.customFields?.find((customField) => customField.scope === 'room'),
[allCustomFields],
);

const query = useMemo(
() => currentChatQuery(params, customFields, [sortBy, sortDirection], current, itemsPerPage),
[customFields, itemsPerPage, params, sortBy, sortDirection, current],
);

const result = useCurrentChats(query);

const onRowClick = useMutableCallback((_id) => {
directoryRoute.push({ id: _id });
});
Expand Down