import {
GenericTableHeaderCell,
GenericTable,
GenericTableHeader,
GenericTableRow,
GenericTableCell,
GenericTableBody,
GenericTableLoadingRow,
} from '@rocket.chat/ui-client';
import { useEndpoint, useRoute, useTranslation, useUserId } from '@rocket.chat/ui-contexts';
import { useQuery } from '@tanstack/react-query';
import { useCallback } from 'react';
import GenericNoResults from '../../../components/GenericNoResults';
import { useFormatDateAndTime } from '../../../hooks/useFormatDateAndTime';
const OAuthAppsTable = () => {
const t = useTranslation();
const formatDateAndTime = useFormatDateAndTime();
const uid = { uid: useUserId() || '' };
const getOauthApps = useEndpoint('GET', '/v1/oauth-apps.list');
const { data, isLoading, isSuccess } = useQuery({
queryKey: ['oauth-apps', { uid }],
queryFn: async () => {
const oauthApps = await getOauthApps(uid);
return oauthApps;
},
});
const router = useRoute('admin-oauth-apps');
const onClick = useCallback(
(_id: string) => (): void =>
router.push({
context: 'edit',
id: _id,
}),
[router],
);
const headers = (
<>
{t('Name')}
{t('Created_by')}
{t('Created_at')}
>
);
return (
<>
{isLoading && (
{headers}
)}
{isSuccess && data?.oauthApps.length === 0 && }
{isSuccess && data?.oauthApps.length > 0 && (
{headers}
{data?.oauthApps.map(({ _id, name, _createdAt, _createdBy: { username: createdBy } }) => (
{name}
{createdBy}
{formatDateAndTime(_createdAt)}
))}
)}
>
);
};
export default OAuthAppsTable;