Skip to content

Commit

Permalink
same thing to ArchivedDepartmentsPageWithData
Browse files Browse the repository at this point in the history
  • Loading branch information
ggazzo committed Feb 17, 2023
1 parent 90c236f commit 0c76c54
Showing 1 changed file with 11 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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<ILivechatDepartment, '_updatedAt'>) => <ArchivedItemMenu dep={dep} />;

Expand Down

0 comments on commit 0c76c54

Please sign in to comment.