Files
Foxel/web/src/pages/UsersPage/components/RolesTable.tsx
shiyu c5e4b3ef43 feat: add user and role management pages with authentication settings
- Implemented AuthSettingsTab for managing authentication settings including user registration and default roles.
- Created UsersPage for managing users and roles, including user creation, editing, and deletion functionalities.
- Added components for user and role management: UserEditorDrawer, RoleEditorDrawer, UsersTable, RolesTable, and PathRuleEditorDrawer.
- Introduced QuickCreateRoleModal for quick role creation within user management.
- Implemented permission management within roles, including path rules and user assignments.
- Enhanced user experience with loading states and error handling in API interactions.
2026-02-01 19:25:17 +08:00

70 lines
1.8 KiB
TypeScript

import { LockOutlined } from '@ant-design/icons';
import { Button, Popconfirm, Space, Table, Tag } from 'antd';
import type { TableColumnsType } from 'antd';
import { memo, useMemo } from 'react';
import type { RoleInfo } from '../../../api/roles';
import { useI18n } from '../../../i18n';
export interface RolesTableProps {
data: RoleInfo[];
loading: boolean;
onEdit: (role: RoleInfo) => void;
onDelete: (role: RoleInfo) => void;
}
export const RolesTable = memo(function RolesTable({
data,
loading,
onEdit,
onDelete,
}: RolesTableProps) {
const { t } = useI18n();
const columns: TableColumnsType<RoleInfo> = useMemo(() => [
{
title: t('Role Name'),
dataIndex: 'name',
render: (value: string, rec: RoleInfo) => (
<Space>
<LockOutlined />
{value}
{rec.is_system && <Tag color="blue">{t('System')}</Tag>}
</Space>
),
},
{ title: t('Description'), dataIndex: 'description', render: (v: string | null) => v || '-' },
{
title: t('Created At'),
dataIndex: 'created_at',
width: 180,
render: (v: string) => new Date(v).toLocaleString(),
},
{
title: t('Actions'),
width: 160,
render: (_: any, rec: RoleInfo) => (
<Space size="small">
<Button size="small" onClick={() => onEdit(rec)}>{t('Edit')}</Button>
{!rec.is_system && (
<Popconfirm title={t('Confirm delete?')} onConfirm={() => onDelete(rec)}>
<Button size="small" danger>{t('Delete')}</Button>
</Popconfirm>
)}
</Space>
),
},
], [onDelete, onEdit, t]);
return (
<Table
rowKey="id"
dataSource={data}
columns={columns}
loading={loading}
pagination={false}
style={{ marginBottom: 0 }}
/>
);
});