import { useMediaQuery } from '@rocket.chat/fuselage-hooks'; import React, { useCallback, useState } 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(props) { const t = useTranslation(); const [params, setParams] = useState({ text: '', current: 0, itemsPerPage: 25 }); const [sort, setSort] = useState([ ['name', 'asc'], ['usernames', 'asc'], ]); 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']); } setSort(preparedSort); }, [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={setParams} params={params} renderFilter={({ onChange, ...props }) => ( )} > {(props) => } ); } export default UsersTable;