RedemptionsTable.jsx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*
  2. Copyright (C) 2025 QuantumNous
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU Affero General Public License as
  5. published by the Free Software Foundation, either version 3 of the
  6. License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Affero General Public License for more details.
  11. You should have received a copy of the GNU Affero General Public License
  12. along with this program. If not, see <https://www.gnu.org/licenses/>.
  13. For commercial licensing, please contact support@quantumnous.com
  14. */
  15. import React, { useMemo, useState } from 'react';
  16. import { Empty } from '@douyinfe/semi-ui';
  17. import CardTable from '../../common/ui/CardTable.js';
  18. import {
  19. IllustrationNoResult,
  20. IllustrationNoResultDark
  21. } from '@douyinfe/semi-illustrations';
  22. import { getRedemptionsColumns, isExpired } from './RedemptionsColumnDefs';
  23. import DeleteRedemptionModal from './modals/DeleteRedemptionModal';
  24. const RedemptionsTable = (redemptionsData) => {
  25. const {
  26. redemptions,
  27. loading,
  28. activePage,
  29. pageSize,
  30. tokenCount,
  31. compactMode,
  32. handlePageChange,
  33. rowSelection,
  34. handleRow,
  35. manageRedemption,
  36. copyText,
  37. setEditingRedemption,
  38. setShowEdit,
  39. refresh,
  40. t,
  41. } = redemptionsData;
  42. // Modal states
  43. const [showDeleteModal, setShowDeleteModal] = useState(false);
  44. const [deletingRecord, setDeletingRecord] = useState(null);
  45. // Handle show delete modal
  46. const showDeleteRedemptionModal = (record) => {
  47. setDeletingRecord(record);
  48. setShowDeleteModal(true);
  49. };
  50. // Get all columns
  51. const columns = useMemo(() => {
  52. return getRedemptionsColumns({
  53. t,
  54. manageRedemption,
  55. copyText,
  56. setEditingRedemption,
  57. setShowEdit,
  58. refresh,
  59. redemptions,
  60. activePage,
  61. showDeleteRedemptionModal
  62. });
  63. }, [
  64. t,
  65. manageRedemption,
  66. copyText,
  67. setEditingRedemption,
  68. setShowEdit,
  69. refresh,
  70. redemptions,
  71. activePage,
  72. showDeleteRedemptionModal,
  73. ]);
  74. // Handle compact mode by removing fixed positioning
  75. const tableColumns = useMemo(() => {
  76. return compactMode ? columns.map(col => {
  77. if (col.dataIndex === 'operate') {
  78. const { fixed, ...rest } = col;
  79. return rest;
  80. }
  81. return col;
  82. }) : columns;
  83. }, [compactMode, columns]);
  84. return (
  85. <>
  86. <CardTable
  87. columns={tableColumns}
  88. dataSource={redemptions}
  89. scroll={compactMode ? undefined : { x: 'max-content' }}
  90. pagination={{
  91. currentPage: activePage,
  92. pageSize: pageSize,
  93. total: tokenCount,
  94. showSizeChanger: true,
  95. pageSizeOptions: [10, 20, 50, 100],
  96. onPageSizeChange: redemptionsData.handlePageSizeChange,
  97. onPageChange: handlePageChange,
  98. }}
  99. loading={loading}
  100. rowSelection={rowSelection}
  101. onRow={handleRow}
  102. empty={
  103. <Empty
  104. image={<IllustrationNoResult style={{ width: 150, height: 150 }} />}
  105. darkModeImage={<IllustrationNoResultDark style={{ width: 150, height: 150 }} />}
  106. description={t('搜索无结果')}
  107. style={{ padding: 30 }}
  108. />
  109. }
  110. className="rounded-xl overflow-hidden"
  111. size="middle"
  112. />
  113. <DeleteRedemptionModal
  114. visible={showDeleteModal}
  115. onCancel={() => setShowDeleteModal(false)}
  116. record={deletingRecord}
  117. manageRedemption={manageRedemption}
  118. refresh={refresh}
  119. redemptions={redemptions}
  120. activePage={activePage}
  121. t={t}
  122. />
  123. </>
  124. );
  125. };
  126. export default RedemptionsTable;