import type { DeviceManagementSession, DeviceManagementPopulatedSession, Serialized } from '@rocket.chat/core-typings'; import { Box, Pagination, States, StatesAction, StatesActions, StatesIcon, StatesSubtitle, StatesTitle } from '@rocket.chat/fuselage'; import type { PaginatedResult } from '@rocket.chat/rest-typings'; import { GenericTable, GenericTableHeader, GenericTableBody, GenericTableLoadingTable } from '@rocket.chat/ui-client'; import type { UseQueryResult } from '@tanstack/react-query'; import type { ComponentProps, ReactElement } from 'react'; import { useTranslation } from 'react-i18next'; import GenericNoResults from '../../GenericNoResults/GenericNoResults'; // FIXME: this tight coupling with the query result is not ideal; it indicates visual components should not be tightly // coupled with data fetching logic. type DeviceManagementTableProps = UseQueryResult[] }>> & { headers: (ReactElement | false)[]; renderRow: (data: Serialized) => ReactElement; current?: ComponentProps['current']; itemsPerPage?: ComponentProps['itemsPerPage']; setCurrent?: ComponentProps['onSetCurrent']; setItemsPerPage?: ComponentProps['onSetItemsPerPage']; paginationProps?: Partial>; }; // TODO: Missing error state const DeviceManagementTable = ({ isPending, isError, error, isSuccess, data, refetch, headers, renderRow, current, itemsPerPage, setCurrent, setItemsPerPage, paginationProps, }: DeviceManagementTableProps): ReactElement => { const { t } = useTranslation(); if (isError) { return ( {t('Something_went_wrong')} {t('We_Could_not_retrive_any_data')} {error.message} {t('Retry')} ); } return ( <> {data?.sessions.length === 0 && isSuccess && } {data?.sessions && data.sessions.length > 0 && headers && {headers}} {isPending && } {isSuccess && data?.sessions && data.sessions.map(renderRow)} {isSuccess && ( )} ); }; export default DeviceManagementTable;