Some checks failed
Create issues from TODOs / todos (push) Failing after 3s
Close inactive issues / close-issues (push) Has been cancelled
Deploy GitHub Pages / deploy-preview (push) Has been cancelled
CI / ⚙️ Variables Setup (push) Has been cancelled
CI / ⚙️ Test Guard (push) Has been cancelled
CI / 🚀 Notify external services - draft (push) Has been cancelled
CI / 📦 Build Packages (push) Has been cancelled
CI / 📦 Meteor Build (coverage) (push) Has been cancelled
CI / 📦 Meteor Build (production) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], fips) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Publish Docker Images (ghcr.io) (push) Has been cancelled
CI / 📦 Track Image Sizes (push) Has been cancelled
CI / 🔎 Code Check - Action Lint (push) Has been cancelled
CI / 🔎 Code Check (push) Has been cancelled
CI / 🔨 Test Storybook (push) Has been cancelled
CI / 🔨 Test Unit (push) Has been cancelled
CI / 🔨 Test API (CE) (push) Has been cancelled
CI / 🔨 Test API Livechat (CE) (push) Has been cancelled
CI / 🔨 Test UI (CE) (push) Has been cancelled
CI / 🔨 Test API (EE) (push) Has been cancelled
CI / 🔨 Test API Livechat (EE) (push) Has been cancelled
CI / 🔨 Test API Apps (deno-runtime - EE) (push) Has been cancelled
CI / 🔨 Test UI (EE) (push) Has been cancelled
CI / 🔨 Test API (FIPS) (push) Has been cancelled
CI / 🔨 Test API Livechat (FIPS) (push) Has been cancelled
CI / 🔨 Test UI (FIPS) (push) Has been cancelled
CI / 🔨 Test Federation Matrix (push) Has been cancelled
CI / 📊 Report Coverage (push) Has been cancelled
CI / ✅ Tests Done (push) Has been cancelled
CI / 🚀 Publish build assets (push) Has been cancelled
CI / 🚀 Publish Docker Images (DockerHub) (push) Has been cancelled
CI / 🚀 Notify external services (push) Has been cancelled
CI / Update Version Durability (push) Has been cancelled
Release / Release (push) Has been cancelled
Auto-close duplicate issues / auto-close-duplicates (push) Failing after 1s
Code scanning - action / CodeQL-Build (push) Failing after 2s
218 lines
6.1 KiB
TypeScript
218 lines
6.1 KiB
TypeScript
import type { IRole, IUser, Serialized } from '@rocket.chat/core-typings';
|
|
import { Pagination } from '@rocket.chat/fuselage';
|
|
import { useStableCallback, useBreakpoints } from '@rocket.chat/fuselage-hooks';
|
|
import type { DefaultUserInfo } from '@rocket.chat/rest-typings';
|
|
import {
|
|
GenericTable,
|
|
GenericTableHeader,
|
|
GenericTableHeaderCell,
|
|
GenericTableBody,
|
|
GenericTableLoadingTable,
|
|
} from '@rocket.chat/ui-client';
|
|
import type { usePagination, useSort } from '@rocket.chat/ui-client';
|
|
import type { TranslationKey } from '@rocket.chat/ui-contexts';
|
|
import { useRouter } from '@rocket.chat/ui-contexts';
|
|
import type { Dispatch, SetStateAction, MouseEvent, KeyboardEvent } from 'react';
|
|
import { useMemo } from 'react';
|
|
import { useTranslation } from 'react-i18next';
|
|
|
|
import UsersTableFilters from './UsersTableFilters';
|
|
import UsersTableRow from './UsersTableRow';
|
|
import GenericNoResults from '../../../../components/GenericNoResults';
|
|
import type { AdminUsersTab, UsersFilters, UsersTableSortingOption } from '../AdminUsersPage';
|
|
import { useShowVoipExtension } from '../useShowVoipExtension';
|
|
|
|
export type UsersTableProps = {
|
|
tab: AdminUsersTab;
|
|
roleData: { roles: Serialized<IRole>[] } | undefined;
|
|
users: Serialized<DefaultUserInfo>[];
|
|
total: number;
|
|
isLoading: boolean;
|
|
isError: boolean;
|
|
isSuccess: boolean;
|
|
onReload: () => void;
|
|
setUserFilters: Dispatch<SetStateAction<UsersFilters>>;
|
|
paginationData: ReturnType<typeof usePagination>;
|
|
sortData: ReturnType<typeof useSort<UsersTableSortingOption>>;
|
|
isSeatsCapExceeded: boolean;
|
|
};
|
|
|
|
const UsersTable = ({
|
|
users,
|
|
total,
|
|
isLoading,
|
|
isError,
|
|
isSuccess,
|
|
setUserFilters,
|
|
roleData,
|
|
tab,
|
|
onReload,
|
|
paginationData,
|
|
sortData,
|
|
isSeatsCapExceeded,
|
|
}: UsersTableProps) => {
|
|
const { t } = useTranslation();
|
|
const router = useRouter();
|
|
const breakpoints = useBreakpoints();
|
|
|
|
const isMobile = !breakpoints.includes('xl');
|
|
const isLaptop = !breakpoints.includes('xxl');
|
|
|
|
const showVoipExtension = useShowVoipExtension();
|
|
const { current, itemsPerPage, setCurrent, setItemsPerPage, ...paginationProps } = paginationData;
|
|
|
|
const isKeyboardEvent = (event: MouseEvent<HTMLElement> | KeyboardEvent<HTMLElement>): event is KeyboardEvent<HTMLElement> => {
|
|
return (event as KeyboardEvent<HTMLElement>).key !== undefined;
|
|
};
|
|
|
|
const handleClickOrKeyDown = useStableCallback((id: IUser['_id'], e: MouseEvent<HTMLElement> | KeyboardEvent<HTMLElement>): void => {
|
|
e.stopPropagation();
|
|
|
|
const keyboardSubmitKeys = ['Enter', ' '];
|
|
|
|
if (isKeyboardEvent(e) && !keyboardSubmitKeys.includes(e.key)) {
|
|
return;
|
|
}
|
|
|
|
router.navigate({
|
|
name: 'admin-users',
|
|
params: {
|
|
context: 'info',
|
|
id,
|
|
},
|
|
});
|
|
});
|
|
|
|
const headers = useMemo(
|
|
() => [
|
|
<GenericTableHeaderCell
|
|
key='name'
|
|
direction={sortData?.sortDirection}
|
|
active={sortData?.sortBy === 'name'}
|
|
onClick={sortData?.setSort}
|
|
sort='name'
|
|
>
|
|
{t('Name')}
|
|
</GenericTableHeaderCell>,
|
|
<GenericTableHeaderCell
|
|
key='username'
|
|
direction={sortData?.sortDirection}
|
|
active={sortData?.sortBy === 'username'}
|
|
onClick={sortData?.setSort}
|
|
sort='username'
|
|
>
|
|
{t('Username')}
|
|
</GenericTableHeaderCell>,
|
|
!isLaptop && (
|
|
<GenericTableHeaderCell
|
|
key='email'
|
|
direction={sortData?.sortDirection}
|
|
active={sortData?.sortBy === 'emails.address'}
|
|
onClick={sortData?.setSort}
|
|
sort='emails.address'
|
|
>
|
|
{t('Email')}
|
|
</GenericTableHeaderCell>
|
|
),
|
|
!isLaptop && <GenericTableHeaderCell key='roles'>{t('Roles')}</GenericTableHeaderCell>,
|
|
tab === 'all' && !isMobile && (
|
|
<GenericTableHeaderCell
|
|
key='status'
|
|
direction={sortData?.sortDirection}
|
|
active={sortData?.sortBy === 'status'}
|
|
onClick={sortData?.setSort}
|
|
sort='status'
|
|
>
|
|
{t('Registration_status')}
|
|
</GenericTableHeaderCell>
|
|
),
|
|
tab === 'pending' && !isMobile && (
|
|
<GenericTableHeaderCell
|
|
key='action'
|
|
direction={sortData?.sortDirection}
|
|
active={sortData?.sortBy === 'active'}
|
|
onClick={sortData?.setSort}
|
|
sort='active'
|
|
>
|
|
{t('Pending_action')}
|
|
</GenericTableHeaderCell>
|
|
),
|
|
tab === 'all' && showVoipExtension && (
|
|
<GenericTableHeaderCell
|
|
width='x180'
|
|
key='freeSwitchExtension'
|
|
direction={sortData?.sortDirection}
|
|
active={sortData?.sortBy === 'freeSwitchExtension'}
|
|
onClick={sortData?.setSort}
|
|
sort='freeSwitchExtension'
|
|
>
|
|
{t('Voice_call_extension')}
|
|
</GenericTableHeaderCell>
|
|
),
|
|
<GenericTableHeaderCell key='actions' width={tab === 'pending' ? 'x204' : 'x50'}>
|
|
{t('Actions')}
|
|
</GenericTableHeaderCell>,
|
|
],
|
|
[sortData, t, isLaptop, tab, isMobile, showVoipExtension],
|
|
);
|
|
|
|
return (
|
|
<>
|
|
<UsersTableFilters roleData={roleData} setUsersFilters={setUserFilters} />
|
|
{isLoading && (
|
|
<GenericTable>
|
|
<GenericTableHeader>{headers}</GenericTableHeader>
|
|
<GenericTableBody>
|
|
<GenericTableLoadingTable headerCells={5} />
|
|
</GenericTableBody>
|
|
</GenericTable>
|
|
)}
|
|
{isError && (
|
|
<GenericNoResults icon='warning' title={t('Something_went_wrong')} buttonTitle={t('Reload_page')} buttonAction={onReload} />
|
|
)}
|
|
|
|
{isSuccess && users.length === 0 && (
|
|
<GenericNoResults
|
|
icon='user'
|
|
title={t('Users_Table_Generic_No_users', { status: tab !== 'all' ? t(tab as TranslationKey) : '' })}
|
|
description={t(`Users_Table_no_${tab}_users_description`)}
|
|
/>
|
|
)}
|
|
|
|
{isSuccess && users.length > 0 && (
|
|
<>
|
|
<GenericTable>
|
|
<GenericTableHeader>{headers}</GenericTableHeader>
|
|
<GenericTableBody>
|
|
{users.map((user) => (
|
|
<UsersTableRow
|
|
key={user._id}
|
|
tab={tab}
|
|
user={user}
|
|
isMobile={isMobile}
|
|
isLaptop={isLaptop}
|
|
isSeatsCapExceeded={isSeatsCapExceeded}
|
|
showVoipExtension={showVoipExtension}
|
|
onReload={onReload}
|
|
onClick={handleClickOrKeyDown}
|
|
/>
|
|
))}
|
|
</GenericTableBody>
|
|
</GenericTable>
|
|
<Pagination
|
|
divider
|
|
current={current}
|
|
itemsPerPage={itemsPerPage}
|
|
count={total}
|
|
onSetItemsPerPage={setItemsPerPage}
|
|
onSetCurrent={setCurrent}
|
|
{...paginationProps}
|
|
/>
|
|
</>
|
|
)}
|
|
</>
|
|
);
|
|
};
|
|
|
|
export default UsersTable;
|