import { Icon, Margins, Pagination, Skeleton, Table, TableBody, TableCell, TableHead, TableRow, Tile } from '@rocket.chat/fuselage'; import { format } from 'date-fns'; import { useMemo, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { useChannelsList } from './useChannelsList'; import DownloadDataButton from '../../../../components/dashboards/DownloadDataButton'; import PeriodSelector from '../../../../components/dashboards/PeriodSelector'; import { usePeriodSelectorState } from '../../../../components/dashboards/usePeriodSelectorState'; import Growth from '../../../../components/dataView/Growth'; import EngagementDashboardCardFilter from '../EngagementDashboardCardFilter'; const ChannelsOverview = () => { const [period, periodSelectorProps] = usePeriodSelectorState('last 7 days', 'last 30 days', 'last 90 days'); const { t } = useTranslation(); const [current, setCurrent] = useState(0); const [itemsPerPage, setItemsPerPage] = useState<25 | 50 | 100>(25); const { data } = useChannelsList({ period, offset: current, count: itemsPerPage, }); const channels = useMemo(() => { if (!data) { return; } return data?.channels?.map(({ room: { t, name, usernames, ts, _updatedAt }, messages, diffFromLastWeek }) => ({ t, name: name || usernames?.join(' × '), createdAt: ts, updatedAt: _updatedAt, messagesCount: messages, messagesVariation: diffFromLastWeek, })); }, [data]); return ( <> data?.channels?.map(({ room: { t, name, usernames, ts, _updatedAt }, messages }) => [ t, name || usernames?.join(' × '), messages, _updatedAt, ts, ]) } />
{channels && !channels.length && ( {t('No_data_found')} )} {(!channels || channels.length) && ( # {t('Channel')} {t('Created')} {t('Last_active')} {t('Messages_sent')} {channels?.map(({ t, name, createdAt, updatedAt, messagesCount, messagesVariation }, i) => ( {i + 1}. {(t === 'd' && ) || (t === 'p' && ) || (t === 'c' && )} {name} {format(new Date(createdAt ?? new Date()), 'P')} {format(new Date(updatedAt ?? new Date()), 'P')} {messagesCount} {messagesVariation} ))} {!channels && Array.from({ length: 5 }, (_, i) => ( ))}
)} t('Items_per_page:')} showingResultsLabel={({ count, current, itemsPerPage }): string => t('Showing_results_of', { from: current + 1, to: Math.min(current + itemsPerPage, count), total: count }) } count={data?.total || 0} onSetItemsPerPage={setItemsPerPage} onSetCurrent={setCurrent} />
); }; export default ChannelsOverview;