Files
monkey-ai-web/src/components/table/users/modals/InvitedUsersModal.jsx
T

171 lines
4.7 KiB
React
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*
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, { 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);
useEffect(() => {
if (visible && user) {
fetchInvitedUsers();
}
}, [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 <span>{displayName}</span>;
}
return (
<div className='flex items-center gap-1'>
<span>{displayName}</span>
<Tag color='white' shape='circle' className='!text-xs'>
{remark.length > 8 ? remark.slice(0, 8) + '...' : remark}
</Tag>
</div>
);
},
},
{
title: t('状态'),
dataIndex: 'status',
width: 100,
render: (status, record) => {
const isDeleted = record.DeletedAt !== null;
if (isDeleted) {
return (
<Tag color='red' shape='circle' size='small'>
{t('已注销')}
</Tag>
);
}
return status === 1 ? (
<Tag color='green' shape='circle' size='small'>
{t('已启用')}
</Tag>
) : (
<Tag color='red' shape='circle' size='small'>
{t('已禁用')}
</Tag>
);
},
},
{
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 (
<Modal
title={
<div>
<span>{t('邀请的用户')}</span>
{user && (
<span className='ml-2 text-gray-500 text-sm'>
{user.display_name || user.username} {t('邀请了')} {total}{' '}
{t('位用户')}
</span>
)}
</div>
}
visible={visible}
onCancel={onCancel}
footer={null}
width={1000}
bodyStyle={{ padding: '16px' }}
>
<Spin spinning={loading}>
<Table
// 列宽合计 ~680px 且无横向滚动,390px 下只露出 ID+用户名,
// 其余 5 列要靠盲拖,且 iOS 上滚动条不可见
scroll={{ x: 'max-content' }}
columns={columns}
dataSource={invitedUsers}
pagination={false}
size='small'
empty={<TableEmpty />}
style={{ maxHeight: '500px', overflowY: 'auto' }}
/>
</Spin>
</Modal>
);
};
export default InvitedUsersModal;