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
152 lines
4.9 KiB
TypeScript
152 lines
4.9 KiB
TypeScript
import { Box, Pagination } from '@rocket.chat/fuselage';
|
|
import { useDebouncedValue } from '@rocket.chat/fuselage-hooks';
|
|
import { UserAvatar } from '@rocket.chat/ui-avatar';
|
|
import {
|
|
GenericTable,
|
|
GenericTableBody,
|
|
GenericTableCell,
|
|
GenericTableHeader,
|
|
GenericTableHeaderCell,
|
|
GenericTableLoadingTable,
|
|
GenericTableRow,
|
|
usePagination,
|
|
useSort,
|
|
} from '@rocket.chat/ui-client';
|
|
import { useTranslation, useEndpoint } from '@rocket.chat/ui-contexts';
|
|
import { hashKey, useQuery } from '@tanstack/react-query';
|
|
import { useMemo, useState } from 'react';
|
|
|
|
import AddManager from './AddManager';
|
|
import RemoveManagerButton from './RemoveManagerButton';
|
|
import FilterByText from '../../../components/FilterByText';
|
|
import GenericError from '../../../components/GenericError';
|
|
import GenericNoResults from '../../../components/GenericNoResults/GenericNoResults';
|
|
import { links } from '../../../lib/links';
|
|
import { omnichannelQueryKeys } from '../../../lib/queryKeys';
|
|
|
|
const ManagersTable = () => {
|
|
const t = useTranslation();
|
|
|
|
const [text, setText] = useState('');
|
|
|
|
const { sortBy, sortDirection, setSort } = useSort<'name' | 'username' | 'emails.address'>('name');
|
|
|
|
const { current, itemsPerPage, setItemsPerPage: onSetItemsPerPage, setCurrent: onSetCurrent, ...paginationProps } = usePagination();
|
|
|
|
const query = useDebouncedValue(
|
|
useMemo(
|
|
() => ({
|
|
text,
|
|
sort: `{ "${sortBy}": ${sortDirection === 'asc' ? 1 : -1} }`,
|
|
count: itemsPerPage,
|
|
offset: current,
|
|
}),
|
|
[text, sortBy, sortDirection, itemsPerPage, current],
|
|
),
|
|
500,
|
|
);
|
|
|
|
const getManagers = useEndpoint('GET', '/v1/livechat/users/manager');
|
|
const { data, isLoading, isSuccess, isError, refetch } = useQuery({
|
|
queryKey: omnichannelQueryKeys.managers(query),
|
|
queryFn: async () => getManagers(query),
|
|
});
|
|
|
|
const [defaultQuery] = useState(hashKey([query]));
|
|
const queryHasChanged = defaultQuery !== hashKey([query]);
|
|
|
|
const headers = (
|
|
<>
|
|
<GenericTableHeaderCell key='name' direction={sortDirection} active={sortBy === 'name'} onClick={setSort} sort='name'>
|
|
{t('Name')}
|
|
</GenericTableHeaderCell>
|
|
<GenericTableHeaderCell key='username' direction={sortDirection} active={sortBy === 'username'} onClick={setSort} sort='username'>
|
|
{t('Username')}
|
|
</GenericTableHeaderCell>
|
|
<GenericTableHeaderCell
|
|
key='email'
|
|
direction={sortDirection}
|
|
active={sortBy === 'emails.address'}
|
|
onClick={setSort}
|
|
sort='emails.address'
|
|
>
|
|
{t('Email')}
|
|
</GenericTableHeaderCell>
|
|
<GenericTableHeaderCell key='remove' width='x60'>
|
|
{t('Remove')}
|
|
</GenericTableHeaderCell>
|
|
</>
|
|
);
|
|
|
|
return (
|
|
<>
|
|
<AddManager />
|
|
{((isSuccess && data?.users.length > 0) || queryHasChanged) && (
|
|
<FilterByText value={text} onChange={(event) => setText(event.target.value)} />
|
|
)}
|
|
{isLoading && (
|
|
<GenericTable aria-busy={isLoading} aria-label={t('Managers')}>
|
|
<GenericTableHeader>{headers}</GenericTableHeader>
|
|
<GenericTableBody>
|
|
<GenericTableLoadingTable headerCells={4} />
|
|
</GenericTableBody>
|
|
</GenericTable>
|
|
)}
|
|
{isSuccess && data.users.length === 0 && (
|
|
<GenericNoResults
|
|
icon='shield'
|
|
title={t('No_managers_yet')}
|
|
description={t('No_managers_yet_description')}
|
|
linkHref={links.go.omnichannelDocs}
|
|
linkText={t('Learn_more_about_managers')}
|
|
/>
|
|
)}
|
|
{isSuccess && data.users.length > 0 && (
|
|
<>
|
|
<GenericTable aria-busy={isLoading} aria-label={t('Managers')}>
|
|
<GenericTableHeader>{headers}</GenericTableHeader>
|
|
<GenericTableBody>
|
|
{data.users.map((user) => (
|
|
<GenericTableRow key={user._id} tabIndex={0}>
|
|
<GenericTableCell withTruncatedText>
|
|
<Box display='flex' alignItems='center'>
|
|
<UserAvatar size='x28' username={user.username || ''} etag={user.avatarETag} />
|
|
<Box display='flex' withTruncatedText marginInline={8}>
|
|
<Box display='flex' flexDirection='column' alignSelf='center' withTruncatedText>
|
|
<Box fontScale='p2m' withTruncatedText color='default'>
|
|
{user.name || user.username}
|
|
</Box>
|
|
</Box>
|
|
</Box>
|
|
</Box>
|
|
</GenericTableCell>
|
|
<GenericTableCell>
|
|
<Box fontScale='p2m' withTruncatedText color='hint'>
|
|
{user.username}
|
|
</Box>
|
|
<Box marginInline={4} />
|
|
</GenericTableCell>
|
|
<GenericTableCell withTruncatedText>{user.emails?.length && user.emails[0].address}</GenericTableCell>
|
|
<RemoveManagerButton _id={user._id} />
|
|
</GenericTableRow>
|
|
))}
|
|
</GenericTableBody>
|
|
</GenericTable>
|
|
<Pagination
|
|
divider
|
|
current={current}
|
|
itemsPerPage={itemsPerPage}
|
|
count={data.total || 0}
|
|
onSetItemsPerPage={onSetItemsPerPage}
|
|
onSetCurrent={onSetCurrent}
|
|
{...paginationProps}
|
|
/>
|
|
</>
|
|
)}
|
|
{isError && <GenericError buttonAction={refetch} />}
|
|
</>
|
|
);
|
|
};
|
|
|
|
export default ManagersTable;
|