|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import React, { useMemo, useState } from 'react'; |
|
|
import { Empty } from '@douyinfe/semi-ui'; |
|
|
import CardTable from '../../common/ui/CardTable'; |
|
|
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'; |
|
|
import ResetPasskeyModal from './modals/ResetPasskeyModal'; |
|
|
import ResetTwoFAModal from './modals/ResetTwoFAModal'; |
|
|
|
|
|
const UsersTable = (usersData) => { |
|
|
const { |
|
|
users, |
|
|
loading, |
|
|
activePage, |
|
|
pageSize, |
|
|
userCount, |
|
|
compactMode, |
|
|
handlePageChange, |
|
|
handlePageSizeChange, |
|
|
handleRow, |
|
|
setEditingUser, |
|
|
setShowEditUser, |
|
|
manageUser, |
|
|
refresh, |
|
|
resetUserPasskey, |
|
|
resetUserTwoFA, |
|
|
t, |
|
|
} = usersData; |
|
|
|
|
|
|
|
|
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(''); |
|
|
const [showResetPasskeyModal, setShowResetPasskeyModal] = useState(false); |
|
|
const [showResetTwoFAModal, setShowResetTwoFAModal] = useState(false); |
|
|
|
|
|
|
|
|
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); |
|
|
}; |
|
|
|
|
|
const showResetPasskeyUserModal = (user) => { |
|
|
setModalUser(user); |
|
|
setShowResetPasskeyModal(true); |
|
|
}; |
|
|
|
|
|
const showResetTwoFAUserModal = (user) => { |
|
|
setModalUser(user); |
|
|
setShowResetTwoFAModal(true); |
|
|
}; |
|
|
|
|
|
|
|
|
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); |
|
|
}; |
|
|
|
|
|
const handleResetPasskeyConfirm = async () => { |
|
|
await resetUserPasskey(modalUser); |
|
|
setShowResetPasskeyModal(false); |
|
|
}; |
|
|
|
|
|
const handleResetTwoFAConfirm = async () => { |
|
|
await resetUserTwoFA(modalUser); |
|
|
setShowResetTwoFAModal(false); |
|
|
}; |
|
|
|
|
|
|
|
|
const columns = useMemo(() => { |
|
|
return getUsersColumns({ |
|
|
t, |
|
|
setEditingUser, |
|
|
setShowEditUser, |
|
|
showPromoteModal: showPromoteUserModal, |
|
|
showDemoteModal: showDemoteUserModal, |
|
|
showEnableDisableModal: showEnableDisableUserModal, |
|
|
showDeleteModal: showDeleteUserModal, |
|
|
showResetPasskeyModal: showResetPasskeyUserModal, |
|
|
showResetTwoFAModal: showResetTwoFAUserModal, |
|
|
}); |
|
|
}, [ |
|
|
t, |
|
|
setEditingUser, |
|
|
setShowEditUser, |
|
|
showPromoteUserModal, |
|
|
showDemoteUserModal, |
|
|
showEnableDisableUserModal, |
|
|
showDeleteUserModal, |
|
|
showResetPasskeyUserModal, |
|
|
showResetTwoFAUserModal, |
|
|
]); |
|
|
|
|
|
|
|
|
const tableColumns = useMemo(() => { |
|
|
return compactMode |
|
|
? columns.map((col) => { |
|
|
if (col.dataIndex === 'operate') { |
|
|
const { fixed, ...rest } = col; |
|
|
return rest; |
|
|
} |
|
|
return col; |
|
|
}) |
|
|
: columns; |
|
|
}, [compactMode, columns]); |
|
|
|
|
|
return ( |
|
|
<> |
|
|
<CardTable |
|
|
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, |
|
|
}} |
|
|
hidePagination={true} |
|
|
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} |
|
|
/> |
|
|
|
|
|
<ResetPasskeyModal |
|
|
visible={showResetPasskeyModal} |
|
|
onCancel={() => setShowResetPasskeyModal(false)} |
|
|
onConfirm={handleResetPasskeyConfirm} |
|
|
user={modalUser} |
|
|
t={t} |
|
|
/> |
|
|
|
|
|
<ResetTwoFAModal |
|
|
visible={showResetTwoFAModal} |
|
|
onCancel={() => setShowResetTwoFAModal(false)} |
|
|
onConfirm={handleResetTwoFAConfirm} |
|
|
user={modalUser} |
|
|
t={t} |
|
|
/> |
|
|
</> |
|
|
); |
|
|
}; |
|
|
|
|
|
export default UsersTable; |
|
|
|