Initial import of weiyuan frontend
This commit is contained in:
@@ -0,0 +1,219 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import CardPro from '../../common/ui/CardPro';
|
||||
import AdminTokensTable from './AdminTokensTable';
|
||||
import AdminTokensActions from './AdminTokensActions';
|
||||
import AdminTokensFilters from './AdminTokensFilters';
|
||||
import AdminTokensDescription from './AdminTokensDescription';
|
||||
import AdminEditTokenModal from './modals/AdminEditTokenModal';
|
||||
import AdminEnableDisableTokenModal from './modals/AdminEnableDisableTokenModal';
|
||||
import AdminDeleteTokenModal from './modals/AdminDeleteTokenModal';
|
||||
import AdminBatchActionModal from './modals/AdminBatchActionModal';
|
||||
import { useAdminTokensData } from '../../../hooks/admin-tokens/useAdminTokensData';
|
||||
import { useIsMobile } from '../../../hooks/common/useIsMobile';
|
||||
import { createCardProPagination } from '../../../helpers/utils';
|
||||
|
||||
const AdminTokensPage = () => {
|
||||
const data = useAdminTokensData();
|
||||
const isMobile = useIsMobile();
|
||||
|
||||
const {
|
||||
tokens,
|
||||
loading,
|
||||
searching,
|
||||
activePage,
|
||||
pageSize,
|
||||
tokenCount,
|
||||
groupOptions,
|
||||
|
||||
selectedRowKeys,
|
||||
setSelectedRowKeys,
|
||||
|
||||
showEdit,
|
||||
editingToken,
|
||||
setEditingToken,
|
||||
setShowEdit,
|
||||
closeEdit,
|
||||
|
||||
showEnableDisable,
|
||||
setShowEnableDisable,
|
||||
enableDisableAction,
|
||||
setEnableDisableAction,
|
||||
showDelete,
|
||||
setShowDelete,
|
||||
showBatchAction,
|
||||
setShowBatchAction,
|
||||
batchAction,
|
||||
setBatchAction,
|
||||
modalToken,
|
||||
setModalToken,
|
||||
|
||||
formInitValues,
|
||||
setFormApi,
|
||||
|
||||
loadTokens,
|
||||
searchTokens,
|
||||
debouncedSearch,
|
||||
refresh,
|
||||
manageToken,
|
||||
batchManageTokens,
|
||||
handlePageChange,
|
||||
handlePageSizeChange,
|
||||
handleRow,
|
||||
|
||||
compactMode,
|
||||
setCompactMode,
|
||||
|
||||
t,
|
||||
} = data;
|
||||
|
||||
const handleBatchClick = (action) => {
|
||||
setBatchAction(action);
|
||||
setShowBatchAction(true);
|
||||
};
|
||||
|
||||
const handleBatchConfirm = async () => {
|
||||
await batchManageTokens(selectedRowKeys, batchAction);
|
||||
setShowBatchAction(false);
|
||||
};
|
||||
|
||||
const handleEnableDisableConfirm = async () => {
|
||||
if (!modalToken) return;
|
||||
await manageToken(modalToken.id, enableDisableAction);
|
||||
setShowEnableDisable(false);
|
||||
};
|
||||
|
||||
const handleDeleteConfirm = async () => {
|
||||
if (!modalToken) return;
|
||||
await manageToken(modalToken.id, 'delete');
|
||||
setShowDelete(false);
|
||||
};
|
||||
|
||||
const handleEditConfirm = async () => {
|
||||
closeEdit();
|
||||
await refresh();
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<AdminEditTokenModal
|
||||
visible={showEdit}
|
||||
onCancel={closeEdit}
|
||||
onConfirm={handleEditConfirm}
|
||||
token={editingToken}
|
||||
groupOptions={groupOptions}
|
||||
t={t}
|
||||
/>
|
||||
|
||||
<AdminEnableDisableTokenModal
|
||||
visible={showEnableDisable}
|
||||
onCancel={() => setShowEnableDisable(false)}
|
||||
onConfirm={handleEnableDisableConfirm}
|
||||
token={modalToken}
|
||||
action={enableDisableAction}
|
||||
t={t}
|
||||
/>
|
||||
|
||||
<AdminDeleteTokenModal
|
||||
visible={showDelete}
|
||||
onCancel={() => setShowDelete(false)}
|
||||
onConfirm={handleDeleteConfirm}
|
||||
token={modalToken}
|
||||
t={t}
|
||||
/>
|
||||
|
||||
<AdminBatchActionModal
|
||||
visible={showBatchAction}
|
||||
onCancel={() => setShowBatchAction(false)}
|
||||
onConfirm={handleBatchConfirm}
|
||||
action={batchAction}
|
||||
count={selectedRowKeys.length}
|
||||
t={t}
|
||||
/>
|
||||
|
||||
<CardPro
|
||||
type='type1'
|
||||
descriptionArea={
|
||||
<AdminTokensDescription
|
||||
compactMode={compactMode}
|
||||
setCompactMode={setCompactMode}
|
||||
t={t}
|
||||
/>
|
||||
}
|
||||
actionsArea={
|
||||
<div className='flex flex-col md:flex-row justify-between items-start md:items-center gap-2 w-full'>
|
||||
<AdminTokensActions
|
||||
selectedRowKeys={selectedRowKeys}
|
||||
onBatchAction={handleBatchClick}
|
||||
onRefresh={refresh}
|
||||
t={t}
|
||||
/>
|
||||
<AdminTokensFilters
|
||||
formInitValues={formInitValues}
|
||||
setFormApi={setFormApi}
|
||||
searchTokens={searchTokens}
|
||||
debouncedSearch={debouncedSearch}
|
||||
loadTokens={loadTokens}
|
||||
pageSize={pageSize}
|
||||
groupOptions={groupOptions}
|
||||
loading={loading}
|
||||
searching={searching}
|
||||
t={t}
|
||||
/>
|
||||
</div>
|
||||
}
|
||||
paginationArea={createCardProPagination({
|
||||
currentPage: activePage,
|
||||
pageSize: pageSize,
|
||||
total: tokenCount,
|
||||
onPageChange: handlePageChange,
|
||||
onPageSizeChange: handlePageSizeChange,
|
||||
isMobile: isMobile,
|
||||
t,
|
||||
})}
|
||||
t={t}
|
||||
>
|
||||
<AdminTokensTable
|
||||
tokens={tokens}
|
||||
loading={loading}
|
||||
activePage={activePage}
|
||||
pageSize={pageSize}
|
||||
tokenCount={tokenCount}
|
||||
compactMode={compactMode}
|
||||
selectedRowKeys={selectedRowKeys}
|
||||
setSelectedRowKeys={setSelectedRowKeys}
|
||||
handlePageChange={handlePageChange}
|
||||
handlePageSizeChange={handlePageSizeChange}
|
||||
handleRow={handleRow}
|
||||
setEditingToken={setEditingToken}
|
||||
setShowEdit={setShowEdit}
|
||||
setModalToken={setModalToken}
|
||||
setEnableDisableAction={setEnableDisableAction}
|
||||
setShowEnableDisable={setShowEnableDisable}
|
||||
setShowDelete={setShowDelete}
|
||||
t={t}
|
||||
/>
|
||||
</CardPro>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default AdminTokensPage;
|
||||
Reference in New Issue
Block a user