mirror of
https://github.com/QuantumNous/new-api.git
synced 2026-04-19 20:58:38 +00:00
♻️ refactor(users): modularize UsersTable component into microcomponent architecture
BREAKING CHANGE: Removed standalone user edit routes (/console/user/edit, /console/user/edit/:id) - Decompose 673-line monolithic UsersTable.js into 8 specialized components - Extract column definitions to UsersColumnDefs.js with render functions - Create dedicated UsersActions.jsx for action buttons - Create UsersFilters.jsx for search and filtering logic - Create UsersDescription.jsx for description area - Extract all data management logic to useUsersData.js hook - Move AddUser.js and EditUser.js to users/modals/ folder as modal components - Create 4 new confirmation modal components (Promote, Demote, EnableDisable, Delete) - Implement pure UsersTable.jsx component for table rendering only - Create main container component users/index.jsx to compose all subcomponents - Update import paths in pages/User/index.js to use new modular structure - Remove obsolete EditUser imports and routes from App.js - Delete original monolithic files: UsersTable.js, AddUser.js, EditUser.js The new architecture follows the same modular pattern as tokens and redemptions modules: - Consistent file organization across all table modules - Better separation of concerns and maintainability - Enhanced reusability and testability - Unified modal management approach All existing functionality preserved with improved code organization.
This commit is contained in:
174
web/src/components/table/users/UsersTable.jsx
Normal file
174
web/src/components/table/users/UsersTable.jsx
Normal file
@@ -0,0 +1,174 @@
|
||||
import React, { useMemo, useState } from 'react';
|
||||
import { Table, Empty } from '@douyinfe/semi-ui';
|
||||
import {
|
||||
IllustrationNoResult,
|
||||
IllustrationNoResultDark
|
||||
} from '@douyinfe/semi-illustrations';
|
||||
import { getUsersColumns } from './UsersColumnDefs';
|
||||
import PromoteUserModal from './modals/PromoteUserModal';
|
||||
import DemoteUserModal from './modals/DemoteUserModal';
|
||||
import EnableDisableUserModal from './modals/EnableDisableUserModal';
|
||||
import DeleteUserModal from './modals/DeleteUserModal';
|
||||
|
||||
const UsersTable = (usersData) => {
|
||||
const {
|
||||
users,
|
||||
loading,
|
||||
activePage,
|
||||
pageSize,
|
||||
userCount,
|
||||
compactMode,
|
||||
handlePageChange,
|
||||
handlePageSizeChange,
|
||||
handleRow,
|
||||
setEditingUser,
|
||||
setShowEditUser,
|
||||
manageUser,
|
||||
refresh,
|
||||
t,
|
||||
} = usersData;
|
||||
|
||||
// Modal states
|
||||
const [showPromoteModal, setShowPromoteModal] = useState(false);
|
||||
const [showDemoteModal, setShowDemoteModal] = useState(false);
|
||||
const [showEnableDisableModal, setShowEnableDisableModal] = useState(false);
|
||||
const [showDeleteModal, setShowDeleteModal] = useState(false);
|
||||
const [modalUser, setModalUser] = useState(null);
|
||||
const [enableDisableAction, setEnableDisableAction] = useState('');
|
||||
|
||||
// Modal handlers
|
||||
const showPromoteUserModal = (user) => {
|
||||
setModalUser(user);
|
||||
setShowPromoteModal(true);
|
||||
};
|
||||
|
||||
const showDemoteUserModal = (user) => {
|
||||
setModalUser(user);
|
||||
setShowDemoteModal(true);
|
||||
};
|
||||
|
||||
const showEnableDisableUserModal = (user, action) => {
|
||||
setModalUser(user);
|
||||
setEnableDisableAction(action);
|
||||
setShowEnableDisableModal(true);
|
||||
};
|
||||
|
||||
const showDeleteUserModal = (user) => {
|
||||
setModalUser(user);
|
||||
setShowDeleteModal(true);
|
||||
};
|
||||
|
||||
// Modal confirm handlers
|
||||
const handlePromoteConfirm = () => {
|
||||
manageUser(modalUser.id, 'promote', modalUser);
|
||||
setShowPromoteModal(false);
|
||||
};
|
||||
|
||||
const handleDemoteConfirm = () => {
|
||||
manageUser(modalUser.id, 'demote', modalUser);
|
||||
setShowDemoteModal(false);
|
||||
};
|
||||
|
||||
const handleEnableDisableConfirm = () => {
|
||||
manageUser(modalUser.id, enableDisableAction, modalUser);
|
||||
setShowEnableDisableModal(false);
|
||||
};
|
||||
|
||||
// Get all columns
|
||||
const columns = useMemo(() => {
|
||||
return getUsersColumns({
|
||||
t,
|
||||
setEditingUser,
|
||||
setShowEditUser,
|
||||
showPromoteModal: showPromoteUserModal,
|
||||
showDemoteModal: showDemoteUserModal,
|
||||
showEnableDisableModal: showEnableDisableUserModal,
|
||||
showDeleteModal: showDeleteUserModal
|
||||
});
|
||||
}, [
|
||||
t,
|
||||
setEditingUser,
|
||||
setShowEditUser,
|
||||
]);
|
||||
|
||||
// Handle compact mode by removing fixed positioning
|
||||
const tableColumns = useMemo(() => {
|
||||
return compactMode ? columns.map(col => {
|
||||
if (col.dataIndex === 'operate') {
|
||||
const { fixed, ...rest } = col;
|
||||
return rest;
|
||||
}
|
||||
return col;
|
||||
}) : columns;
|
||||
}, [compactMode, columns]);
|
||||
|
||||
return (
|
||||
<>
|
||||
<Table
|
||||
columns={tableColumns}
|
||||
dataSource={users}
|
||||
scroll={compactMode ? undefined : { x: 'max-content' }}
|
||||
pagination={{
|
||||
currentPage: activePage,
|
||||
pageSize: pageSize,
|
||||
total: userCount,
|
||||
pageSizeOpts: [10, 20, 50, 100],
|
||||
showSizeChanger: true,
|
||||
onPageSizeChange: handlePageSizeChange,
|
||||
onPageChange: handlePageChange,
|
||||
}}
|
||||
loading={loading}
|
||||
onRow={handleRow}
|
||||
empty={
|
||||
<Empty
|
||||
image={<IllustrationNoResult style={{ width: 150, height: 150 }} />}
|
||||
darkModeImage={<IllustrationNoResultDark style={{ width: 150, height: 150 }} />}
|
||||
description={t('搜索无结果')}
|
||||
style={{ padding: 30 }}
|
||||
/>
|
||||
}
|
||||
className="overflow-hidden"
|
||||
size="middle"
|
||||
/>
|
||||
|
||||
{/* Modal components */}
|
||||
<PromoteUserModal
|
||||
visible={showPromoteModal}
|
||||
onCancel={() => setShowPromoteModal(false)}
|
||||
onConfirm={handlePromoteConfirm}
|
||||
user={modalUser}
|
||||
t={t}
|
||||
/>
|
||||
|
||||
<DemoteUserModal
|
||||
visible={showDemoteModal}
|
||||
onCancel={() => setShowDemoteModal(false)}
|
||||
onConfirm={handleDemoteConfirm}
|
||||
user={modalUser}
|
||||
t={t}
|
||||
/>
|
||||
|
||||
<EnableDisableUserModal
|
||||
visible={showEnableDisableModal}
|
||||
onCancel={() => setShowEnableDisableModal(false)}
|
||||
onConfirm={handleEnableDisableConfirm}
|
||||
user={modalUser}
|
||||
action={enableDisableAction}
|
||||
t={t}
|
||||
/>
|
||||
|
||||
<DeleteUserModal
|
||||
visible={showDeleteModal}
|
||||
onCancel={() => setShowDeleteModal(false)}
|
||||
user={modalUser}
|
||||
users={users}
|
||||
activePage={activePage}
|
||||
refresh={refresh}
|
||||
manageUser={manageUser}
|
||||
t={t}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default UsersTable;
|
||||
Reference in New Issue
Block a user