/* * @Author: ZhaoYing * @Date: 2026-02-03 17:51:08 * @Last Modified by: ZhaoYing * @Last Modified time: 2026-02-25 15:44:54 */ /** * User Management Page * Manages users with create, enable/disable, and password reset capabilities */ import React, { useRef } from 'react'; import { Button, Space, App } from 'antd'; import { useTranslation } from 'react-i18next'; import type { ColumnsType } from 'antd/es/table'; import CreateModal from './components/CreateModal'; import type { CreateModalRef, User, ResetPasswordModalRef } from './types' import Table, { type TableRef } from '@/components/Table' import StatusTag from '@/components/StatusTag' import { deleteUser, enableUser, getUserListUrl } from '@/api/user' import ResetPasswordModal from './components/ResetPasswordModal' import { formatDateTime } from '@/utils/format'; const UserManagement: React.FC = () => { const { t } = useTranslation(); const { message, modal } = App.useApp(); const userFormRef = useRef(null); const resetPasswordModalRef = useRef(null); const tableRef = useRef(null); /** Open create user modal */ const handleCreate = () => { userFormRef.current?.handleOpen(); } /** Reset user password */ const handleResetPassword = (user: User) => { resetPasswordModalRef.current?.handleOpen(user); }; /** Refresh table data */ const refreshTable = () => { tableRef.current?.loadData() } /** Enable/disable user */ const handleChangeStatus = async (record: User) => { modal.confirm({ title: t(`user.${record.is_active ? 'disabled' : 'enabled'}Confirm`), okText: t('common.confirm'), cancelText: t('common.cancel'), okType: 'danger', onOk: () => { const res = record.is_active ? deleteUser(record.id) : enableUser(record.id); res.then(() => { message.success(t(`user.${record.is_active ? 'disabled' : 'enabled'}ConfirmSuccess`)); refreshTable(); }) }, }) }; /** Table column configuration */ const columns: ColumnsType = [ { title: t('user.userId'), dataIndex: 'id', key: 'id', fixed: 'left', }, { title: <>{t('user.username')}
({t(`user.subUsername`)})
, dataIndex: 'email', key: 'email', }, { title: t('user.displayName'), dataIndex: 'username', key: 'username', }, { title: t('user.role'), dataIndex: 'is_superuser', key: 'is_superuser', render: (isSuperuser: boolean) => isSuperuser ? t('user.superuser') : t('user.normalUser'), }, { title: t('user.status'), dataIndex: 'is_active', key: 'is_active', render: (isActive: boolean) => ( ), }, { title: t('user.createTime'), dataIndex: 'created_at', key: 'created_at', render: (createdAt: string) => formatDateTime(createdAt, 'YYYY-MM-DD HH:mm:ss'), }, { title: t('user.lastLoginTime'), dataIndex: 'last_login_at', key: 'last_login_at', render: (lastLoginAt: string) => lastLoginAt ? formatDateTime(lastLoginAt, 'YYYY-MM-DD HH:mm:ss') : '-', }, { title: t('common.operation'), key: 'action', fixed: 'right', render: (_, record) => ( {record.is_active && } ), }, ]; return (
); }; export default UserManagement;