import React from 'react'; import { Modal, Avatar, Pagination } from 'antd'; import { AppstoreOutlined } from '@ant-design/icons'; import Styles from './styles.module.less'; const Records = (props) => { const { list, oakPagination } = props.data; const { pageSize, currentPage, total } = oakPagination || {}; const { t, revoke, setCurrentPage, setPageSize } = props.methods; const handleRevoke = (item) => { Modal.confirm({ title: t('revoke_confirm_title'), content: t('revoke_confirm_content', { appName: item.application?.name || t('unknown_app') }), okText: t('confirm'), cancelText: t('cancel'), okButtonProps: { danger: true }, onOk: () => { revoke(item); }, }); }; const formatDate = (date) => { if (!date) return '-'; return new Date(date).toLocaleString('zh-CN', { year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', }); }; function formateScope(scope) { if (!scope || scope.length === 0 || scope.includes('')) { return t('full_access'); } return scope.join(', '); } const getStatusTag = (item) => { if (item.token?.revokedAt) { return {t('status_revoked')}; } if (item.usageState === 'denied') { return {t('status_denied')}; } if (item.token?.refreshExpiresAt && new Date(item.token.refreshExpiresAt) < new Date()) { return {t('status_expired')}; } if (item.usageState === 'granted') { return {t('status_active')}; } if (item.usageState === 'revoked') { return {t('status_revoked')}; } return {t('status_unknown')}; }; const isRevokable = (item) => { return item.usageState === 'granted' && !item.token?.revokedAt; }; return (

{t('page_title')}

{t('page_description')}

{!list || list.length === 0 ? (
🔐

{t('no_records')}

) : (<>
{list.map((item) => { return (
} size={48} shape="square" className={Styles.appLogo}/>

{item.application?.name || t('unknown_app')}

{getStatusTag(item)}
{isRevokable(item) && ()}
{item.application?.description && (

{item.application?.description}

)}
{t('authorized_at')}: {formatDate(item.authorizedAt)}
{t('scope')}: {formateScope(item.code?.scope)}
{item.token?.lastUsedAt && (
{t('last_used_at')}: {formatDate(item.token.lastUsedAt)}
)} {/* {item.token?.accessExpiresAt && (
{t('access_expires_at')}: {formatDate(item.token.accessExpiresAt)}
)} */} {item.token?.revokedAt && (
{t('revoked_at')}: {formatDate(item.token.revokedAt)}
)}
); })}
{total && total > 0 && (
setCurrentPage(page)} onShowSizeChange={(current, size) => { setPageSize(size); setCurrentPage(1); }} showSizeChanger showQuickJumper showTotal={(total) => t('pagination_total', { total })} pageSizeOptions={['5', '10', '20', '50', '100']} className={Styles.pagination}/>
)} )}
); }; export default Records;