/*
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 .
For commercial licensing, please contact support@quantumnous.com
*/
import React from 'react';
import './admin-tokens.css';
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,
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 (
<>
setShowEnableDisable(false)}
onConfirm={handleEnableDisableConfirm}
token={modalToken}
action={enableDisableAction}
t={t}
/>
setShowDelete(false)}
onConfirm={handleDeleteConfirm}
token={modalToken}
t={t}
/>
setShowBatchAction(false)}
onConfirm={handleBatchConfirm}
action={batchAction}
count={selectedRowKeys.length}
t={t}
/>
}
type='type1'
actionsArea={
}
paginationArea={createCardProPagination({
showRange: false,
currentPage: activePage,
pageSize: pageSize,
total: tokenCount,
onPageChange: handlePageChange,
onPageSizeChange: handlePageSizeChange,
isMobile: isMobile,
t,
})}
t={t}
>
>
);
};
export default AdminTokensPage;