/* 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 { Trans } from 'react-i18next'; import { useEffectEvent } from '../../../../hooks/common/useEffectEvent'; import React, { useState, useEffect } from 'react'; import { Modal, Table, Tag, Spin } from '@/components/ui'; import { API, renderQuota, renderNumber, showError } from '../../../../helpers'; import TableEmpty from '../../../common/table/TableEmpty'; const InvitedUsersModal = ({ visible, onCancel, user, t }) => { const [invitedUsers, setInvitedUsers] = useState([]); const [loading, setLoading] = useState(false); const [total, setTotal] = useState(0); const onVisibilityChange = useEffectEvent(() => { if (visible && user) { fetchInvitedUsers(); } }); useEffect(() => onVisibilityChange(), [onVisibilityChange, visible, user]); const fetchInvitedUsers = async () => { if (!user?.id) return; setLoading(true); try { const res = await API.get(`/api/user/${user.id}/invitees`); if (res.data.success) { setInvitedUsers(res.data.data || []); setTotal(res.data.total || 0); } else { showError(res.data.message); } } catch (error) { showError(error.message); } finally { setLoading(false); } }; const columns = [ { title: 'ID', dataIndex: 'id', width: 80, }, { title: t('用户名'), dataIndex: 'username', render: (text, record) => { // Use display_name if available, otherwise fallback to username const displayName = record.display_name || text; const remark = record.remark; if (!remark) { return {displayName}; } return (
{displayName} {remark.length > 8 ? remark.slice(0, 8) + '...' : remark}
); }, }, { title: t('状态'), dataIndex: 'status', width: 100, render: (status, record) => { const isDeleted = record.DeletedAt !== null; if (isDeleted) { return ( {t('已注销')} ); } return status === 1 ? ( {t('已启用')} ) : ( {t('已禁用')} ); }, }, { title: t('剩余额度'), dataIndex: 'quota', width: 120, render: (quota) => renderQuota(quota, 2), }, { title: t('已用额度'), dataIndex: 'used_quota', width: 120, render: (used_quota) => renderQuota(used_quota, 2), }, { title: t('调用次数'), dataIndex: 'request_count', width: 100, render: (count) => renderNumber(count), }, { title: t('注册时间'), dataIndex: 'created_at', width: 160, render: (timestamp) => { const date = new Date(timestamp * 1000); return date.toLocaleString(); }, }, ]; return ( {t('邀请的用户')} {user && ( )} } visible={visible} onCancel={onCancel} footer={null} width={1000} bodyStyle={{ padding: '16px' }} > } style={{ maxHeight: '500px', overflowY: 'auto' }} /> ); }; export default InvitedUsersModal;