feat: resource-group-management
This commit is contained in:
1 parent
d518efb843
commit
5fd1025340
7 files changed
+181
-78
No files matched your search
@@ -935,5 +935,6 @@
|
||||
"Failed to update user resource group": "更新用户资源组失败",
|
||||
"Failed to load simple resource groups": "获取简易资源组失败",
|
||||
"Failed to load resource group detail": "获取资源组详情失败",
|
||||
"Resource Group Detail": "资源组详情"
|
||||
"Resource Group Detail": "资源组详情",
|
||||
"Current display time is UTC time": "当前显示时间为UTC时间"
|
||||
}
|
||||
@@ -46,6 +46,19 @@ const isValidUrl = (url: string) => {
|
||||
}
|
||||
};
|
||||
|
||||
// Helper function to validate domain format
|
||||
const isValidDomain = (url: string) => {
|
||||
if (!url) return false;
|
||||
try {
|
||||
const parsed = new URL(url);
|
||||
const hostname = parsed.hostname;
|
||||
const domainRegex = /^(?:(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,})$/;
|
||||
return domainRegex.test(hostname);
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
const validateServiceForm = (data: MCPServiceFormData, t: any) => {
|
||||
const errors: Record<string, string> = {};
|
||||
|
||||
@@ -65,6 +78,8 @@ const validateServiceForm = (data: MCPServiceFormData, t: any) => {
|
||||
errors.base_url = t("API Endpoint is required");
|
||||
} else if (!isValidUrl(data.base_url)) {
|
||||
errors.base_url = t("API Endpoint must be a valid HTTP/HTTPS URL");
|
||||
} else if (!isValidDomain(data.base_url)) {
|
||||
errors.base_url = t("API Endpoint must contain a valid domain name");
|
||||
}
|
||||
|
||||
if (!data.short_description?.trim()) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import React, { useEffect, useState } from "react";
|
||||
import React, { useEffect, useState, useMemo } from "react";
|
||||
import {
|
||||
Button,
|
||||
Card,
|
||||
@@ -78,6 +78,12 @@ const GroupServiceTable: React.FC<GroupServiceTableProps> = ({
|
||||
const urlGroupId = searchParams.get('groupId');
|
||||
const currentGroupId = propGroupId || urlGroupId || null;
|
||||
|
||||
// 使用 useMemo 计算 showOptions,确保响应式更新
|
||||
const showOptions = useMemo(() => {
|
||||
if (!resourceGroupDetail) return false;
|
||||
return !['allow-all', 'deny-all'].includes(resourceGroupDetail.id);
|
||||
}, [resourceGroupDetail]);
|
||||
|
||||
const getResourceGroup = async (groupId: string) => {
|
||||
const response = await fetchResourceGroupDetail(groupId);
|
||||
if (response) {
|
||||
@@ -100,7 +106,7 @@ const GroupServiceTable: React.FC<GroupServiceTableProps> = ({
|
||||
{resourceGroupDetail?.name}
|
||||
</h2>
|
||||
<div className="flex gap-2 h-[32px]">
|
||||
{!['allow-all', 'deny-all'].includes(resourceGroupDetail?.id || '') && currentGroupId && <>
|
||||
{showOptions && currentGroupId && <>
|
||||
<Button
|
||||
isIconOnly
|
||||
size="sm"
|
||||
@@ -126,22 +132,27 @@ const GroupServiceTable: React.FC<GroupServiceTableProps> = ({
|
||||
</CardHeader>
|
||||
<Divider />
|
||||
<CardBody className="px-6 py-6">
|
||||
<div className="flex flex-col sm:flex-row gap-4 mb-6">
|
||||
<div className="flex-1">
|
||||
<Button
|
||||
color="primary"
|
||||
onPress={onAddService}
|
||||
startContent={<Plus size={16} />}
|
||||
size="sm"
|
||||
>
|
||||
{t("Add Server")}
|
||||
</Button>
|
||||
</div>
|
||||
{
|
||||
showOptions && (<>
|
||||
<div className="flex flex-col sm:flex-row gap-4 mb-6">
|
||||
<div className="flex-1">
|
||||
<Button
|
||||
color="primary"
|
||||
onPress={onAddService}
|
||||
startContent={<Plus size={16} />}
|
||||
size="sm"
|
||||
>
|
||||
{t("Add Server")}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<div className="flex gap-2"></div>
|
||||
</div>
|
||||
<div className="flex gap-2"></div>
|
||||
</div>
|
||||
</>)
|
||||
}
|
||||
|
||||
<Table
|
||||
key={`table-${showOptions}`}
|
||||
aria-label="Group services table"
|
||||
removeWrapper
|
||||
classNames={{
|
||||
@@ -167,7 +178,7 @@ const GroupServiceTable: React.FC<GroupServiceTableProps> = ({
|
||||
<TableColumn>{t("API Endpoint")}</TableColumn>
|
||||
<TableColumn>{t("Status")}</TableColumn>
|
||||
<TableColumn>{t("Pricing")}</TableColumn>
|
||||
<TableColumn className="w-20">{t("Actions")}</TableColumn>
|
||||
<TableColumn className={showOptions ? "w-20" : "hidden"}>{t("Actions")}</TableColumn>
|
||||
</TableHeader>
|
||||
<TableBody
|
||||
items={services}
|
||||
@@ -175,54 +186,58 @@ const GroupServiceTable: React.FC<GroupServiceTableProps> = ({
|
||||
loadingContent={<Spinner />}
|
||||
emptyContent={t("No services in this group")}
|
||||
>
|
||||
{(service) => (
|
||||
<TableRow key={service.id}>
|
||||
<TableCell>
|
||||
<span className="text-sm">{service.name}</span>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<span className="text-sm">{service.base_url}</span>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<Chip
|
||||
className="capitalize"
|
||||
color={service.enabled ? "success" : "danger"}
|
||||
size="sm"
|
||||
variant="flat"
|
||||
>
|
||||
{t(service.enabled ? "Published" : "Unpublished")}
|
||||
</Chip>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<div className="flex flex-col gap-1">
|
||||
<Price
|
||||
price={service.price}
|
||||
charge_type={service.charge_type}
|
||||
input_token_price={service.input_token_price}
|
||||
output_token_price={service.output_token_price}
|
||||
/>
|
||||
</div>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<Tooltip
|
||||
content={t("Remove")}
|
||||
color="danger"
|
||||
closeDelay={0}
|
||||
disableAnimation
|
||||
>
|
||||
<Button
|
||||
isIconOnly
|
||||
{(service) => {
|
||||
// 在渲染函数内部使用 showOptions,确保使用最新值
|
||||
const cellClassName = showOptions ? "" : "hidden";
|
||||
return (
|
||||
<TableRow key={service.id}>
|
||||
<TableCell>
|
||||
<span className="text-sm">{service.name}</span>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<span className="text-sm">{service.base_url}</span>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<Chip
|
||||
className="capitalize"
|
||||
color={service.enabled ? "success" : "danger"}
|
||||
size="sm"
|
||||
variant="light"
|
||||
color="danger"
|
||||
onPress={() => onRemoveService(service.id)}
|
||||
variant="flat"
|
||||
>
|
||||
<Trash2 className="w-4 h-4" />
|
||||
</Button>
|
||||
</Tooltip>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
)}
|
||||
{t(service.enabled ? "Published" : "Unpublished")}
|
||||
</Chip>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<div className="flex flex-col gap-1">
|
||||
<Price
|
||||
price={service.price}
|
||||
charge_type={service.charge_type}
|
||||
input_token_price={service.input_token_price}
|
||||
output_token_price={service.output_token_price}
|
||||
/>
|
||||
</div>
|
||||
</TableCell>
|
||||
<TableCell className={cellClassName}>
|
||||
<Tooltip
|
||||
content={t("Remove")}
|
||||
color="danger"
|
||||
closeDelay={0}
|
||||
disableAnimation
|
||||
>
|
||||
<Button
|
||||
isIconOnly
|
||||
size="sm"
|
||||
variant="light"
|
||||
color="danger"
|
||||
onPress={() => onRemoveService(service.id)}
|
||||
>
|
||||
<Trash2 className="w-4 h-4" />
|
||||
</Button>
|
||||
</Tooltip>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
);
|
||||
}}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</CardBody>
|
||||
|
||||
@@ -10,11 +10,12 @@ import {
|
||||
TableCell,
|
||||
Pagination,
|
||||
Chip,
|
||||
Spinner
|
||||
Spinner,
|
||||
Tooltip
|
||||
} from '@nextui-org/react';
|
||||
import { useTranslation } from '@/shared/lib/useTranslation';
|
||||
import { PaymentState, RevenueRecord } from '@/types/revenue';
|
||||
import { Calendar, CreditCard } from 'lucide-react';
|
||||
import { Calendar, CreditCard, HelpCircle } from 'lucide-react';
|
||||
import { formatCurrency } from '@/shared/utils/currency';
|
||||
|
||||
interface RevenueTableProps {
|
||||
@@ -122,7 +123,19 @@ export const RevenueTable: React.FC<RevenueTableProps> = ({
|
||||
<TableHeader>
|
||||
<TableColumn>{t('Account (Email)')}</TableColumn>
|
||||
<TableColumn>{t('Recharge Amount')}</TableColumn>
|
||||
<TableColumn>{t('Recharge Time')}</TableColumn>
|
||||
<TableColumn>
|
||||
<div className="flex items-center gap-1">
|
||||
<span>{t('Recharge Time')}</span>
|
||||
<Tooltip
|
||||
content={t("Current display time is UTC time")}
|
||||
color="default"
|
||||
closeDelay={0}
|
||||
disableAnimation
|
||||
>
|
||||
<HelpCircle className="w-4 h-4" />
|
||||
</Tooltip>
|
||||
</div>
|
||||
</TableColumn>
|
||||
<TableColumn>{t('Payment Method')}</TableColumn>
|
||||
<TableColumn>{t('Transaction ID')}</TableColumn>
|
||||
<TableColumn>{t('Status')}</TableColumn>
|
||||
|
||||
@@ -17,7 +17,7 @@ import {
|
||||
} from "@nextui-org/react";
|
||||
import { useTranslation } from "@/shared/lib/useTranslation";
|
||||
import { User } from "@/types/user";
|
||||
import { Trash2, CreditCard } from "lucide-react";
|
||||
import { Trash2, CreditCard, Calendar, HelpCircle } from "lucide-react";
|
||||
import { AdminRechargeModal } from "@/components/user-management/AdminRechargeModal";
|
||||
import { fetchSimpleResourceGroups, updateUserResourceGroup } from "@/api/resourceGroup.api";
|
||||
import toast from "react-hot-toast";
|
||||
@@ -97,12 +97,23 @@ export const UserTable: React.FC<UserTableProps> = ({
|
||||
fetchUsers();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const formatDate = (dateString: string) => {
|
||||
return (
|
||||
<div className="flex items-center gap-1">
|
||||
<Calendar className="w-3 h-3 text-gray-500" />
|
||||
<span className="text-sm text-gray-600">
|
||||
{new Date(dateString).toLocaleString()}
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
// 初始加载简易资源组列表
|
||||
useEffect(() => {
|
||||
loadSimpleResourceGroups();
|
||||
}, [loadSimpleResourceGroups]);
|
||||
|
||||
|
||||
// 等待用户数据或资源组数据加载
|
||||
if ((loading && users.length === 0) || groupsLoading) {
|
||||
return (
|
||||
@@ -124,7 +135,19 @@ export const UserTable: React.FC<UserTableProps> = ({
|
||||
<TableHeader>
|
||||
<TableColumn>{t("Email")}</TableColumn>
|
||||
<TableColumn width={250}>{t("Resource Group")}</TableColumn>
|
||||
<TableColumn>{t("Register Date")}</TableColumn>
|
||||
<TableColumn>
|
||||
<div className="flex items-center gap-1">
|
||||
<span>{t("Register Date")}</span>
|
||||
<Tooltip
|
||||
content={t("Current display time is UTC time")}
|
||||
color="default"
|
||||
closeDelay={0}
|
||||
disableAnimation
|
||||
>
|
||||
<HelpCircle className="w-4 h-4" />
|
||||
</Tooltip>
|
||||
</div>
|
||||
</TableColumn>
|
||||
<TableColumn>{t("Balance")}</TableColumn>
|
||||
<TableColumn>{t("Actions")}</TableColumn>
|
||||
</TableHeader>
|
||||
@@ -161,7 +184,7 @@ export const UserTable: React.FC<UserTableProps> = ({
|
||||
)}
|
||||
</Select>
|
||||
</TableCell>
|
||||
<TableCell>{user.created_at || "-"}</TableCell>
|
||||
<TableCell>{formatDate(user.created_at)}</TableCell>
|
||||
<TableCell>{user.balance.toFixed(2) || "-"}</TableCell>
|
||||
|
||||
<TableCell>
|
||||
|
||||
@@ -14,9 +14,10 @@ import {
|
||||
Pagination,
|
||||
} from "@nextui-org/react";
|
||||
import { useTranslation } from "@/shared/lib/useTranslation";
|
||||
import { Plus, SquareArrowOutUpRight, Trash2 } from "lucide-react";
|
||||
import { Calendar, Plus, Trash2, HelpCircle, Eye } from "lucide-react";
|
||||
import { MCPServiceFormData } from "@/shared/types/mcp-service";
|
||||
import toast from "react-hot-toast";
|
||||
|
||||
import { GetMCPResourceGroupsParams } from "@/services/mcpService";
|
||||
import DeleteServerModal from "@/components/resource-group/DeleteServerModal";
|
||||
import { McpAddGroupModal } from "../modal/McpAddGroup";
|
||||
@@ -97,6 +98,18 @@ const ResourceGroup: React.FC<ResourceGroupProps> = ({
|
||||
const onAddService = () => {
|
||||
setIsAddMcpGroupModalOpen(true);
|
||||
}
|
||||
|
||||
const formatDate = (dateString: string) => {
|
||||
return (
|
||||
<div className="flex items-center gap-1">
|
||||
<Calendar className="w-3 h-3 text-gray-500" />
|
||||
<span className="text-sm text-gray-600">
|
||||
{new Date(dateString).toLocaleString()}
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
// 保存 MCP 服务
|
||||
const handleSaveMcpServer = async (serverIds: string[]) => {
|
||||
if (!formData?.id) return;
|
||||
@@ -138,7 +151,7 @@ const ResourceGroup: React.FC<ResourceGroupProps> = ({
|
||||
const { pageSize, keyword } = resourceGroupsParams.current;
|
||||
loadResourceGroups(page, pageSize, keyword);
|
||||
}
|
||||
|
||||
|
||||
const openResourceGroupPage = (group: ResourceGroup) => {
|
||||
setResourceGroupDetailId(group.id);
|
||||
setIsResourceGroupDetailModalOpen(true);
|
||||
@@ -192,7 +205,19 @@ const ResourceGroup: React.FC<ResourceGroupProps> = ({
|
||||
>
|
||||
<TableHeader>
|
||||
<TableColumn>{t("Group Name")}</TableColumn>
|
||||
<TableColumn>{t("Added Time")}</TableColumn>
|
||||
<TableColumn>
|
||||
<div className="flex items-center gap-1">
|
||||
<span>{t("Added Time")}</span>
|
||||
<Tooltip
|
||||
content={t("Current display time is UTC time")}
|
||||
color="default"
|
||||
closeDelay={0}
|
||||
disableAnimation
|
||||
>
|
||||
<HelpCircle className="w-4 h-4" />
|
||||
</Tooltip>
|
||||
</div>
|
||||
</TableColumn>
|
||||
<TableColumn className="w-20">{t("Actions")}</TableColumn>
|
||||
</TableHeader>
|
||||
<TableBody
|
||||
@@ -207,7 +232,7 @@ const ResourceGroup: React.FC<ResourceGroupProps> = ({
|
||||
<span className="text-sm">{group.name}</span>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<span className="text-sm">{group.join_at}</span>
|
||||
{formatDate(group.join_at)}
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<div className="relative flex items-center gap-2">
|
||||
@@ -224,7 +249,7 @@ const ResourceGroup: React.FC<ResourceGroupProps> = ({
|
||||
color="primary"
|
||||
onPress={() => openResourceGroupPage(group)}
|
||||
>
|
||||
<SquareArrowOutUpRight className="w-4 h-4" />
|
||||
<Eye className="w-4 h-4" />
|
||||
</Button>
|
||||
</Tooltip>
|
||||
<Tooltip
|
||||
|
||||
@@ -16,7 +16,7 @@ import {
|
||||
} from "@nextui-org/react";
|
||||
import { useTranslation } from "@/shared/lib/useTranslation";
|
||||
import { EnabledEnum, MCPService } from "@/shared/types/mcp-service";
|
||||
import { Trash2, PencilIcon } from "lucide-react";
|
||||
import { Trash2, PencilIcon, Calendar } from "lucide-react";
|
||||
import { Price } from "@/shared/components/marketplace/Price";
|
||||
import { MdOutlineUnpublished, MdOutlineCheckCircle } from "react-icons/md";
|
||||
import { withComponentInjection } from "@/shared/hooks/useComponentInjection";
|
||||
@@ -78,7 +78,16 @@ const BaseServiceTable: React.FC<ServiceTableProps> = ({
|
||||
},
|
||||
[onToggleStatus]
|
||||
);
|
||||
|
||||
const formatDate = (dateString: string) => {
|
||||
return (
|
||||
<div className="flex items-center gap-1">
|
||||
<Calendar className="w-3 h-3 text-gray-500" />
|
||||
<span className="text-sm text-gray-600">
|
||||
{new Date(dateString).toLocaleString()}
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
if (loading && services.length === 0) {
|
||||
return (
|
||||
<div className="flex justify-center items-center h-64">
|
||||
@@ -117,6 +126,7 @@ const BaseServiceTable: React.FC<ServiceTableProps> = ({
|
||||
<TableColumn hidden={!columns.includes("pricing")}>
|
||||
{t("Pricing")}
|
||||
</TableColumn>
|
||||
<TableColumn>{t("Created_at")}</TableColumn>
|
||||
<TableColumn className="w-20">{t("Actions")}</TableColumn>
|
||||
</TableHeader>
|
||||
<TableBody
|
||||
@@ -153,6 +163,7 @@ const BaseServiceTable: React.FC<ServiceTableProps> = ({
|
||||
/>
|
||||
</div>
|
||||
</TableCell>
|
||||
<TableCell>{formatDate(service.created_at)}</TableCell>
|
||||
<TableCell>
|
||||
<div className="relative flex items-center gap-2">
|
||||
<Tooltip content={t("Edit")} closeDelay={0} disableAnimation>
|
||||
|
||||
Reference in new issue
Block a user