import { useMediaQuery } from '@rocket.chat/fuselage-hooks'; import React, { useCallback } from 'react'; import FilterByText from '../../../components/FilterByText'; import GenericTable from '../../../components/GenericTable'; import { useRoute } from '../../../contexts/RouterContext'; import { useTranslation } from '../../../contexts/TranslationContext'; import UserRow from './UserRow'; function UsersTable({ params, onChangeParams, sort, onChangeSort, ...props }) { const t = useTranslation(); const usersRoute = useRoute('admin-users'); const onClick = useCallback( (username) => () => usersRoute.push({ context: 'info', id: username, }), [usersRoute], ); const onHeaderClick = useCallback( (id) => { const preparedSort = []; const [[sortBy, sortDirection]] = sort; if (sortBy === id) { preparedSort.push([id, sortDirection === 'asc' ? 'desc' : 'asc']); } else { preparedSort.push([id, 'asc']); } // // Special cases // If the sortable field is `name`, we should also add `usernames` if (id === 'name') { preparedSort.push(['usernames', sortDirection]); } // If the sortable field is `name`, we should also add `usernames` if (id === 'status') { preparedSort.push(['active', sortDirection === 'asc' ? 'desc' : 'asc']); } onChangeSort(preparedSort); }, [onChangeSort, sort], ); const mediaQuery = useMediaQuery('(min-width: 1024px)'); return ( {t('Name')} {mediaQuery && ( {t('Username')} )} {t('Email')} {mediaQuery && ( {t('Roles')} )} {t('Status')} } results={props.users} total={props.total} setParams={onChangeParams} params={params} renderFilter={({ onChange, ...props }) => } > {(props) => } ); } export default UsersTable;