CopyTokensModal.jsx 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 from 'react';
  16. import { Modal, Button, Space } from '@douyinfe/semi-ui';
  17. const CopyTokensModal = ({ visible, onCancel, selectedKeys, copyText, t }) => {
  18. // Handle copy with name and key format
  19. const handleCopyWithName = async () => {
  20. let content = '';
  21. for (let i = 0; i < selectedKeys.length; i++) {
  22. content += selectedKeys[i].name + ' sk-' + selectedKeys[i].key + '\n';
  23. }
  24. await copyText(content);
  25. onCancel();
  26. };
  27. // Handle copy with key only format
  28. const handleCopyKeyOnly = async () => {
  29. let content = '';
  30. for (let i = 0; i < selectedKeys.length; i++) {
  31. content += 'sk-' + selectedKeys[i].key + '\n';
  32. }
  33. await copyText(content);
  34. onCancel();
  35. };
  36. return (
  37. <Modal
  38. title={t('复制令牌')}
  39. icon={null}
  40. visible={visible}
  41. onCancel={onCancel}
  42. footer={
  43. <Space>
  44. <Button
  45. type='tertiary'
  46. onClick={handleCopyWithName}
  47. >
  48. {t('名称+密钥')}
  49. </Button>
  50. <Button
  51. onClick={handleCopyKeyOnly}
  52. >
  53. {t('仅密钥')}
  54. </Button>
  55. </Space>
  56. }
  57. >
  58. {t('请选择你的复制方式')}
  59. </Modal>
  60. );
  61. };
  62. export default CopyTokensModal;