diff --git a/apps/meteor/client/views/omnichannel/departments/ArchivedDepartmentsPageWithData.tsx b/apps/meteor/client/views/omnichannel/departments/ArchivedDepartmentsPageWithData.tsx index 8164a112d16a..e63bf39f3be9 100644 --- a/apps/meteor/client/views/omnichannel/departments/ArchivedDepartmentsPageWithData.tsx +++ b/apps/meteor/client/views/omnichannel/departments/ArchivedDepartmentsPageWithData.tsx @@ -3,7 +3,7 @@ import { useDebouncedValue } from '@rocket.chat/fuselage-hooks'; import { useEndpoint } from '@rocket.chat/ui-contexts'; import { useQuery } from '@tanstack/react-query'; import type { ReactElement } from 'react'; -import React, { useMemo, useState } from 'react'; +import React, { useState } from 'react'; import FilterByText from '../../../components/FilterByText'; import { usePagination } from '../../../components/GenericTable/hooks/usePagination'; @@ -13,27 +13,22 @@ import DepartmentsTable from './DepartmentsTable'; const ArchivedDepartmentsPageWithData = (): ReactElement => { const [text, setText] = useState(''); + const [debouncedText = ''] = useDebouncedValue(text, 500); const pagination = usePagination(); const sort = useSort<'name' | 'email' | 'active'>('name'); - const query = useDebouncedValue( - useMemo(() => { - return { - onlyMyDepartments: 'true' as const, - text, - sort: JSON.stringify({ [sort.sortBy]: sort.sortDirection === 'asc' ? 1 : -1 }), - ...(pagination.current && { offset: pagination.current }), - ...(pagination.itemsPerPage && { count: pagination.itemsPerPage }), - fields: JSON.stringify({ name: 1, username: 1, emails: 1, avatarETag: 1 }), - }; - }, [pagination, sort.sortBy, sort.sortDirection, text]), - 500, - ); - const getArchivedDepartments = useEndpoint('GET', '/v1/livechat/departments/archived'); - const { data, isLoading } = useQuery(['omnichannel', 'departments', 'archived', query], async () => getArchivedDepartments(query)); + const { data, isLoading } = useQuery(['omnichannel', 'departments', 'archived', debouncedText, pagination, sort], async () => + getArchivedDepartments({ + onlyMyDepartments: 'true' as const, + text, + sort: JSON.stringify({ [sort.sortBy]: sort.sortDirection === 'asc' ? 1 : -1 }), + ...(pagination.current && { offset: pagination.current }), + ...(pagination.itemsPerPage && { count: pagination.itemsPerPage }), + }), + ); const removeButton = (dep: Omit) => ;