Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4b373d143f | ||
|
|
8529ac2e60 | ||
|
|
7f47841fdc | ||
|
|
f5b45af30a | ||
|
|
851d45a573 | ||
|
|
b7a10ca678 | ||
|
|
8f0796c031 | ||
|
|
721a2be32b | ||
|
|
1fbb6711f2 | ||
|
|
d18adf035b | ||
|
|
2fd6272bbd | ||
|
|
470d53cad6 | ||
|
|
f2b61bae7d | ||
|
|
588f2770b7 | ||
|
|
ad743d6ab7 | ||
|
|
6145d0b005 | ||
|
|
d147fcb070 | ||
|
|
6196b93e97 | ||
|
|
b51933d625 | ||
|
|
40ff118798 | ||
|
|
d470677abe | ||
|
|
6eac3c6100 | ||
|
|
d22513730a | ||
|
|
613cece94b | ||
|
|
5cd1c12323 | ||
|
|
dcf73b25bf | ||
|
|
64a67e9c8d | ||
|
|
b6160af3c5 | ||
|
|
2ea41dfb75 | ||
|
|
cbcc419f0b | ||
|
|
687949beb2 | ||
|
|
fedaa5f5df | ||
|
|
c272c87e1f | ||
|
|
8a052ff910 | ||
|
|
d1c7a4b8c0 | ||
|
|
1a104338e8 | ||
|
|
5dd47b2d01 | ||
|
|
a28de60b1c | ||
|
|
e4a807b2a0 | ||
|
|
d0e7ed2771 | ||
|
|
05c0088f1b | ||
|
|
7f66cfd21e | ||
|
|
05b48f3656 | ||
|
|
07fe83b7b5 | ||
|
|
5fa1cd741e | ||
|
|
3e1d986c1c | ||
|
|
2cf95fd1c1 | ||
|
|
09b6811391 | ||
|
|
08d326dc1f | ||
|
|
fb23d62fb2 | ||
|
|
79400146ea | ||
|
|
503b3bf078 | ||
|
|
eb4ecff6ed | ||
|
|
7f8947f070 | ||
|
|
6dca9b08cc | ||
|
|
06034cf46e | ||
|
|
ffdf931cad | ||
|
|
24e59f18d0 | ||
|
|
5a538863b1 | ||
|
|
f468fe270f | ||
|
|
4cc8b87de5 | ||
|
|
f6e0130035 | ||
|
|
d351afb732 | ||
|
|
fab064975d | ||
|
|
30a06d74d6 | ||
|
|
6f882845c2 | ||
|
|
33d66e7d3b | ||
|
|
5654f83644 | ||
|
|
b7c67cc44f | ||
|
|
6d15420b08 | ||
|
|
32562b9c25 | ||
|
|
5469eca450 | ||
|
|
94fd46c8ca | ||
|
|
ffc09b7b83 | ||
|
|
f4bd572fff | ||
|
|
57bd964d22 | ||
|
|
3c4e2be1dd | ||
|
|
aac3a187d1 | ||
|
|
c0ec39f1d6 | ||
|
|
22fa608220 | ||
|
|
e20dacde6b | ||
|
|
fef2e2a1f7 | ||
|
|
3cb1cca751 | ||
|
|
71807c0c67 | ||
|
|
14e6b5c23b | ||
|
|
64d5b2abfc | ||
|
|
fdbb077293 | ||
|
|
10809113f4 | ||
|
|
f592178d83 | ||
|
|
db9a5d571c | ||
|
|
1ebac24a3b | ||
|
|
875a7bf906 | ||
|
|
bf79191194 | ||
|
|
24ee3078d8 | ||
|
|
302277bad2 | ||
|
|
6724801d60 | ||
|
|
51338373e7 | ||
|
|
aa2fd609c6 | ||
|
|
46bdf470c8 | ||
|
|
6b758c3acd | ||
|
|
1589d6ef0a | ||
|
|
d55cc3e216 | ||
|
|
e1c59da804 | ||
|
|
60c9698cdd | ||
|
|
11de1de3b1 | ||
|
|
c16bab66ee | ||
|
|
ec3bef1cae | ||
|
|
060bcf7f73 | ||
|
|
8394afe581 | ||
|
|
85140f8bdc | ||
|
|
595994de8c | ||
|
|
ff725d766f | ||
|
|
c7bbd0589c | ||
|
|
cbfc4310b5 | ||
|
|
6f83fc7a88 | ||
|
|
714e19a4fc | ||
|
|
64d559dd31 | ||
|
|
50637087ae | ||
|
|
d9fe780665 | ||
|
|
fa23805b5c | ||
|
|
9d5d1ce2c5 | ||
|
|
d6dea1f1e8 | ||
|
|
f9c8a74849 | ||
|
|
915a2bcf9e | ||
|
|
b23662d76a | ||
|
|
77ca12045d | ||
|
|
4f27baf93a | ||
|
|
88325a0ba9 | ||
|
|
276817e624 | ||
|
|
3a622c452a | ||
|
|
e26e6a7f24 | ||
|
|
4d590bdb80 | ||
|
|
2ee39124b0 | ||
|
|
20f09ce044 | ||
|
|
65128b1d2a | ||
|
|
cb93e5c5aa | ||
|
|
5ce7cc4a2a | ||
|
|
6d33d99d94 | ||
|
|
15fe7b4aff | ||
|
|
8f340cb3d5 | ||
|
|
dab04242e6 | ||
|
|
a1740ab227 | ||
|
|
ae57e5b431 | ||
|
|
8abc7469cd | ||
|
|
2309de4025 | ||
|
|
06b71995f3 | ||
|
|
c675b273a8 | ||
|
|
52c135a7c6 | ||
|
|
fbb06d3c53 | ||
|
|
2c5c28c74f | ||
|
|
ab04738aff | ||
|
|
1eb0e23971 | ||
|
|
0ae8a4037d | ||
|
|
a0c2bfe9a6 | ||
|
|
5fa4d25e44 | ||
|
|
9f55110fb3 | ||
|
|
5fd1025340 | ||
|
|
01cbdbe5b0 | ||
|
|
a744f5a6c4 | ||
|
|
0e58492387 | ||
|
|
d518efb843 | ||
|
|
8fabe93710 | ||
|
|
924bee4a96 | ||
|
|
2dcd42a546 | ||
|
|
f416f4c278 | ||
|
|
1b6d3bc5bd | ||
|
|
5d30306ad7 | ||
|
|
127327e226 | ||
|
|
c82718e155 | ||
|
|
6ad1e01814 | ||
|
|
1c6773a95b | ||
|
|
b74a042f75 | ||
|
|
c5a020c65c | ||
|
|
61004e4686 | ||
|
|
ff870630fa | ||
|
|
1da7e2a618 | ||
|
|
de4b1bef32 | ||
|
|
f5ba03ca33 | ||
|
|
b00fca810d | ||
|
|
132f26e565 | ||
|
|
c5854a1d6f | ||
|
|
d0caf957fe | ||
|
|
fc3f633141 | ||
|
|
ada170e525 | ||
|
|
95ec31d5c0 | ||
|
|
a6242af7b1 | ||
|
|
028de0338e | ||
|
|
e6a197e709 | ||
|
|
61a313d8ff | ||
|
|
bbe94deedb | ||
|
|
5c90b8e1ca | ||
|
|
23f3c07d6b | ||
|
|
27f76d5cf0 | ||
|
|
732fefeb7e | ||
|
|
6fb71a48fe | ||
|
|
3daa8eaec1 | ||
|
|
811618d8e6 | ||
|
|
67819ad4d6 | ||
|
|
6405713314 | ||
|
|
60a6318663 | ||
|
|
3e83446a2c | ||
|
|
d725e9d896 | ||
|
|
68c4b2fcc2 | ||
|
|
96db00418c | ||
|
|
2def6457fe | ||
|
|
b9123d68a0 | ||
|
|
ebbf9b22da | ||
|
|
eace543d74 | ||
|
|
73cd1a01a0 | ||
|
|
8186b4c0b5 | ||
|
|
5023e4494c | ||
|
|
e2d360d5de | ||
|
|
948046948a | ||
|
|
4e3fd1afaf | ||
|
|
e2ae502b48 | ||
|
|
6561435a38 | ||
|
|
1846aafc1e | ||
|
|
54654b386d | ||
|
|
755d48a2f8 | ||
|
|
284880a170 | ||
|
|
950b516081 | ||
|
|
0088a7b447 | ||
|
|
19f646c318 | ||
|
|
115ac5caf7 | ||
|
|
798082934e | ||
|
|
a017b0fa93 | ||
|
|
877dbb6a4e | ||
|
|
523265e550 | ||
|
|
5d2db84d75 | ||
|
|
4826859152 | ||
|
|
92f8b68f0e | ||
|
|
87a4b6e2de |
No files matched your search
+17
-2
@@ -6,7 +6,7 @@ MYSQL_PASSWORD=mysql_ZTdhRB
|
|||||||
MYSQL_DB=xpack
|
MYSQL_DB=xpack
|
||||||
|
|
||||||
# 服务端口配置
|
# 服务端口配置
|
||||||
API_PORT=8000
|
API_PORT=8002
|
||||||
ADMIN_PORT=8001
|
ADMIN_PORT=8001
|
||||||
|
|
||||||
# 调试配置
|
# 调试配置
|
||||||
@@ -24,4 +24,19 @@ RABBITMQ_HOST=xpack-rabbitmq
|
|||||||
RABBITMQ_PORT=5672
|
RABBITMQ_PORT=5672
|
||||||
RABBITMQ_USER=rabbitmq
|
RABBITMQ_USER=rabbitmq
|
||||||
RABBITMQ_PASSWORD=rabbitmq_Gs123dA
|
RABBITMQ_PASSWORD=rabbitmq_Gs123dA
|
||||||
RABBITMQ_VHOST=/
|
RABBITMQ_VHOST=/
|
||||||
|
|
||||||
|
# Billing queue / retry settings
|
||||||
|
BILLING_QUEUE_NAME=billing.api.calls
|
||||||
|
# Max retry attempts (excluding initial consumption)
|
||||||
|
BILLING_RETRY_TIMES=3
|
||||||
|
# Base delay seconds for exponential backoff: base * 2^retry_count
|
||||||
|
BILLING_RETRY_BASE_DELAY_SECONDS=30
|
||||||
|
# Max delay seconds cap
|
||||||
|
BILLING_RETRY_MAX_DELAY_SECONDS=1800
|
||||||
|
|
||||||
|
# Payment config encryption key (Base64-encoded 32-byte random value for AES-GCM)
|
||||||
|
# Quick generation: python -c "import os,base64; print(base64.b64encode(os.urandom(32)).decode())"
|
||||||
|
PAYMENT_CONFIG_SECRET_KEY=uyyhfMJ+xpEE+IC5mPigpscekkR2ucz6Sj7sHYLhJQA=
|
||||||
|
# Optional: key ID used to support key rotation identification
|
||||||
|
PAYMENT_CONFIG_KEY_ID=default
|
||||||
@@ -20,7 +20,7 @@ jobs:
|
|||||||
node-version: '22.16'
|
node-version: '22.16'
|
||||||
- name: Pnpm install and build
|
- name: Pnpm install and build
|
||||||
run: |
|
run: |
|
||||||
npm install -g pnpm
|
npm install -g pnpm@9
|
||||||
./scripts/frontend_build.sh
|
./scripts/frontend_build.sh
|
||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v3
|
uses: docker/setup-buildx-action@v3
|
||||||
@@ -43,4 +43,4 @@ jobs:
|
|||||||
QINIU_BUCKET: ${{ secrets.QINIU_BUCKET }}
|
QINIU_BUCKET: ${{ secrets.QINIU_BUCKET }}
|
||||||
QINIU_NAME: ${{ secrets.QINIU_NAME }}
|
QINIU_NAME: ${{ secrets.QINIU_NAME }}
|
||||||
run: cd scripts && ./docker_publish.sh ${{ secrets.DOCKER_USERNAME }} upload_qiniu
|
run: cd scripts && ./docker_publish.sh ${{ secrets.DOCKER_USERNAME }} upload_qiniu
|
||||||
|
|
||||||
@@ -42,3 +42,6 @@ local_settings.py
|
|||||||
/.secrets
|
/.secrets
|
||||||
/uploads/
|
/uploads/
|
||||||
/.vercel/
|
/.vercel/
|
||||||
|
|
||||||
|
# Local deployment data
|
||||||
|
mysql-data/
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
/mcp.json
|
||||||
@@ -343,3 +343,46 @@ For details, please see the [LICENSE](./LICENSE) file.
|
|||||||
- [XRoute](https://xroute.ai): The Unified Interface For LLMs, provides better prices, better throughput, and no subscription.
|
- [XRoute](https://xroute.ai): The Unified Interface For LLMs, provides better prices, better throughput, and no subscription.
|
||||||
|
|
||||||
- [MemU](https://github.com/NevaMind-AI/memU): MemU is an open-source memory framework for AI companions
|
- [MemU](https://github.com/NevaMind-AI/memU): MemU is an open-source memory framework for AI companions
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 国内镜像部署(本项目维护,随 Release 更新)
|
||||||
|
|
||||||
|
镜像已双渠道发布,任选其一拉取:
|
||||||
|
|
||||||
|
- 公网:`gitea.88531.cn/jinghui/xpack-mcp-market:v1.5.1`、`jpccr.ccs.tencentyun.com/jinghui/xpack-mcp-market:v1.5.1`
|
||||||
|
- 内网:`192.168.68.19:3200/jinghui/xpack-mcp-market:v1.5.1`
|
||||||
|
|
||||||
|
### 方式一:docker-compose(推荐,带齐全部服务参数)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git clone http://192.168.68.19:3200/jinghui/xpack-mcp.git && cd xpack-mcp
|
||||||
|
|
||||||
|
# 1) 把 docker-compose.yml 中 xpack-mcp-market 服务的 image 改为公网镜像:
|
||||||
|
# image: xpackai/xpack-mcp-market:zhcn
|
||||||
|
# → image: gitea.88531.cn/jinghui/xpack-mcp-market:v1.5.1
|
||||||
|
|
||||||
|
# 2) 准备环境变量(支付渠道加密密钥,必须改掉示例值)
|
||||||
|
cp .env.example .env && vim .env # 修改 PAYMENT_CONFIG_SECRET_KEY 为自己的 32 字节随机串
|
||||||
|
|
||||||
|
docker compose up -d # 启动 mysql/redis/rabbitmq/market 四个容器
|
||||||
|
```
|
||||||
|
|
||||||
|
注意事项:
|
||||||
|
- `PAYMENT_CONFIG_SECRET_KEY` 缺失时 compose 会直接报错拒绝启动(`.env` 不可删);
|
||||||
|
- 数据库账号、Redis 密码、RabbitMQ 密码在 compose 里已固定,改任何一项都要同步改应用配置;
|
||||||
|
- 数据目录 `./mysql-data` 与容器网络 `172.101.0.0/24` 不要与已有环境冲突。
|
||||||
|
|
||||||
|
### 方式二:docker run(主站单容器)
|
||||||
|
|
||||||
|
前置:MySQL 8.0.37 / Redis 7.2.4 / RabbitMQ 4.1.2 已就绪,且容器与依赖服务同一网络(应用默认按主机名 `xpack-mysql`、`xpack-redis`、`xpack-rabbitmq` 连接)。
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker run -d --name xpack-mcp-market \
|
||||||
|
--restart always --privileged \
|
||||||
|
-p 8010:80 \
|
||||||
|
-e PAYMENT_CONFIG_SECRET_KEY='<32字节随机串>' \
|
||||||
|
-e PAYMENT_CONFIG_KEY_ID=default \
|
||||||
|
--network <依赖服务所在网络> \
|
||||||
|
gitea.88531.cn/jinghui/xpack-mcp-market:v1.5.1
|
||||||
|
```
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
version: '3'
|
||||||
|
services:
|
||||||
|
xpack-mysql:
|
||||||
|
image: mysql:8.0.37
|
||||||
|
privileged: true
|
||||||
|
restart: always
|
||||||
|
container_name: xpack-mysql
|
||||||
|
hostname: xpack-mysql
|
||||||
|
command:
|
||||||
|
- "--character-set-server=utf8mb4"
|
||||||
|
- "--collation-server=utf8mb4_unicode_ci"
|
||||||
|
ports:
|
||||||
|
- "33306:3306"
|
||||||
|
environment:
|
||||||
|
- MYSQL_ROOT_PASSWORD=mysql_ZTdhRB
|
||||||
|
- MYSQL_DATABASE=xpack
|
||||||
|
volumes:
|
||||||
|
- /vol3/1000/HD3/docker/xpack-mcp/mysql-data:/var/lib/mysql
|
||||||
|
networks:
|
||||||
|
- xpack
|
||||||
|
xpack-mcp-market:
|
||||||
|
image: xpackai/xpack-mcp-market:zhcn
|
||||||
|
container_name: xpack-mcp-market
|
||||||
|
privileged: true
|
||||||
|
restart: always
|
||||||
|
environment:
|
||||||
|
# AES-256-GCM key protecting payment channel config (epay merchant key, stripe secret).
|
||||||
|
# Lives here rather than in the image so the sample key shipped in .env.example
|
||||||
|
# can never decrypt this deployment's config.
|
||||||
|
- PAYMENT_CONFIG_SECRET_KEY=${PAYMENT_CONFIG_SECRET_KEY:?PAYMENT_CONFIG_SECRET_KEY not set - copy .env.example to .env}
|
||||||
|
- PAYMENT_CONFIG_KEY_ID=default
|
||||||
|
networks:
|
||||||
|
- xpack
|
||||||
|
ports:
|
||||||
|
- "8010:80"
|
||||||
|
depends_on:
|
||||||
|
- xpack-mysql
|
||||||
|
- xpack-redis
|
||||||
|
- xpack-rabbitmq
|
||||||
|
xpack-redis:
|
||||||
|
container_name: xpack-redis
|
||||||
|
image: redis:7.2.4
|
||||||
|
hostname: xpack-redis
|
||||||
|
privileged: true
|
||||||
|
restart: always
|
||||||
|
command:
|
||||||
|
- bash
|
||||||
|
- -c
|
||||||
|
- "redis-server --protected-mode yes --logfile redis.log --appendonly no --port 6379 --requirepass redis_6sJZDm"
|
||||||
|
networks:
|
||||||
|
- xpack
|
||||||
|
xpack-rabbitmq:
|
||||||
|
container_name: xpack-rabbitmq
|
||||||
|
image: rabbitmq:4.1.2-alpine
|
||||||
|
privileged: true
|
||||||
|
restart: always
|
||||||
|
environment:
|
||||||
|
- RABBITMQ_DEFAULT_USER=rabbitmq
|
||||||
|
- RABBITMQ_DEFAULT_PASS=rabbitmq_Gs123dA
|
||||||
|
networks:
|
||||||
|
- xpack
|
||||||
|
networks:
|
||||||
|
xpack:
|
||||||
|
driver: bridge
|
||||||
|
ipam:
|
||||||
|
driver: default
|
||||||
|
config:
|
||||||
|
- subnet: 172.101.0.0/24
|
||||||
+1
-1
@@ -9,7 +9,7 @@
|
|||||||
!.yarn/plugins
|
!.yarn/plugins
|
||||||
!.yarn/releases
|
!.yarn/releases
|
||||||
!.yarn/versions
|
!.yarn/versions
|
||||||
|
/pnpm-lock.yaml
|
||||||
# testing
|
# testing
|
||||||
/coverage
|
/coverage
|
||||||
|
|
||||||
|
|||||||
@@ -1,57 +0,0 @@
|
|||||||
/** @type {import('next').NextConfig} */
|
|
||||||
const nextConfig = {
|
|
||||||
reactStrictMode: false,
|
|
||||||
// Enable SSR
|
|
||||||
output: "standalone",
|
|
||||||
|
|
||||||
// Optimize images
|
|
||||||
images: {
|
|
||||||
domains: [],
|
|
||||||
unoptimized: false, // Enable image optimization for SSR
|
|
||||||
},
|
|
||||||
|
|
||||||
// Webpack configuration
|
|
||||||
webpack: (config) => {
|
|
||||||
return config;
|
|
||||||
},
|
|
||||||
|
|
||||||
// Redirect configuration
|
|
||||||
async redirects() {
|
|
||||||
return [];
|
|
||||||
},
|
|
||||||
async rewrites() {
|
|
||||||
return [
|
|
||||||
// {
|
|
||||||
// source: "/api/:path*",
|
|
||||||
// destination: `${process.env.NEXT_PUBLIC_API_URL || "http://127.0.0.1:8001"}/api/:path*`,
|
|
||||||
// },
|
|
||||||
{
|
|
||||||
source: "/uploads/:path*",
|
|
||||||
destination: `${
|
|
||||||
process.env.NEXT_PUBLIC_API_URL || "http://127.0.0.1:8001"
|
|
||||||
}/uploads/:path*`,
|
|
||||||
},
|
|
||||||
];
|
|
||||||
},
|
|
||||||
|
|
||||||
// Headers for better performance
|
|
||||||
async headers() {
|
|
||||||
return [
|
|
||||||
{
|
|
||||||
source: "/(.*)",
|
|
||||||
headers: [
|
|
||||||
{
|
|
||||||
key: "X-Content-Type-Options",
|
|
||||||
value: "nosniff",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
key: "X-XSS-Protection",
|
|
||||||
value: "1; mode=block",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
];
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = nextConfig;
|
|
||||||
@@ -1,10 +1,15 @@
|
|||||||
import type { NextConfig } from "next";
|
import type { NextConfig } from "next";
|
||||||
|
|
||||||
const nextConfig: NextConfig = {
|
const nextConfig: NextConfig = {
|
||||||
|
reactStrictMode: false,
|
||||||
|
output: "standalone",
|
||||||
|
|
||||||
experimental: {
|
experimental: {
|
||||||
optimizePackageImports: ["@nextui-org/react"],
|
optimizePackageImports: ["@nextui-org/react"],
|
||||||
},
|
},
|
||||||
|
|
||||||
transpilePackages: ["@nextui-org/react", "@nextui-org/theme"],
|
transpilePackages: ["@nextui-org/react", "@nextui-org/theme"],
|
||||||
|
|
||||||
images: {
|
images: {
|
||||||
remotePatterns: [
|
remotePatterns: [
|
||||||
{
|
{
|
||||||
@@ -12,6 +17,42 @@ const nextConfig: NextConfig = {
|
|||||||
hostname: "**",
|
hostname: "**",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
unoptimized: false,
|
||||||
|
},
|
||||||
|
|
||||||
|
// Redirect configuration
|
||||||
|
async redirects() {
|
||||||
|
return [];
|
||||||
|
},
|
||||||
|
|
||||||
|
async rewrites() {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
source: "/uploads/:path*",
|
||||||
|
destination: `${
|
||||||
|
process.env.NEXT_PUBLIC_API_URL || "http://127.0.0.1:8001"
|
||||||
|
}/uploads/:path*`,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
},
|
||||||
|
|
||||||
|
// Headers for better performance
|
||||||
|
async headers() {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
source: "/(.*)",
|
||||||
|
headers: [
|
||||||
|
{
|
||||||
|
key: "X-Content-Type-Options",
|
||||||
|
value: "nosniff",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: "X-XSS-Protection",
|
||||||
|
value: "1; mode=block",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
];
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@hookform/resolvers": "^3.3.4",
|
"@hookform/resolvers": "^3.3.4",
|
||||||
"@iconify/react": "^5.0.2",
|
"@iconify/react": "^5.0.2",
|
||||||
|
"@internationalized/date": "^3.10.1",
|
||||||
"@nextui-org/react": "^2.6.11",
|
"@nextui-org/react": "^2.6.11",
|
||||||
"@nextui-org/theme": "^2.4.5",
|
"@nextui-org/theme": "^2.4.5",
|
||||||
"@tailwindcss/typography": "^0.5.16",
|
"@tailwindcss/typography": "^0.5.16",
|
||||||
@@ -32,9 +33,9 @@
|
|||||||
"immer": "^10.0.3",
|
"immer": "^10.0.3",
|
||||||
"lottie-react": "^2.4.1",
|
"lottie-react": "^2.4.1",
|
||||||
"lucide-react": "^0.475.0",
|
"lucide-react": "^0.475.0",
|
||||||
"next": "^15.3.4",
|
"next": "^16.1.5",
|
||||||
"react": "^18.2.0",
|
"react": "^19.1.4",
|
||||||
"react-dom": "^18.2.0",
|
"react-dom": "^19.1.4",
|
||||||
"react-hook-form": "^7.49.3",
|
"react-hook-form": "^7.49.3",
|
||||||
"react-hot-toast": "^2.4.1",
|
"react-hot-toast": "^2.4.1",
|
||||||
"react-hover-video-player": "^10.0.2",
|
"react-hover-video-player": "^10.0.2",
|
||||||
@@ -49,12 +50,12 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^20.11.0",
|
"@types/node": "^20.11.0",
|
||||||
"@types/react": "^18.2.48",
|
"@types/react": "^18.3.18",
|
||||||
"@types/react-dom": "^18.2.18",
|
"@types/react-dom": "^18.3.5",
|
||||||
"@types/three": "^0.177.0",
|
"@types/three": "^0.177.0",
|
||||||
"autoprefixer": "^10.4.17",
|
"autoprefixer": "^10.4.17",
|
||||||
"eslint": "^8.56.0",
|
"eslint": "^8.56.0",
|
||||||
"eslint-config-next": "15.0.3",
|
"eslint-config-next": "16.1.5",
|
||||||
"postcss": "^8.4.33",
|
"postcss": "^8.4.33",
|
||||||
"tailwindcss": "^3.4.17",
|
"tailwindcss": "^3.4.17",
|
||||||
"typescript": "^5.3.3"
|
"typescript": "^5.3.3"
|
||||||
|
|||||||
Generated
-15888
File diff suppressed because it is too large.
Load diff
@@ -328,7 +328,7 @@
|
|||||||
"Current Balance": "Current Balance",
|
"Current Balance": "Current Balance",
|
||||||
"User recharged successfully": "User recharged successfully",
|
"User recharged successfully": "User recharged successfully",
|
||||||
"Please enter a valid amount": "Please enter a valid amount",
|
"Please enter a valid amount": "Please enter a valid amount",
|
||||||
"Minimum recharge amount is $1": "Minimum recharge amount is $1",
|
"Minimum recharge amount is ¥1": "Minimum recharge amount is ¥1",
|
||||||
"User not selected": "User not selected",
|
"User not selected": "User not selected",
|
||||||
"Recharge failed": "Recharge failed",
|
"Recharge failed": "Recharge failed",
|
||||||
"Network error, please try again": "Network error, please try again",
|
"Network error, please try again": "Network error, please try again",
|
||||||
@@ -380,7 +380,6 @@
|
|||||||
"Enter your password": "Enter your password",
|
"Enter your password": "Enter your password",
|
||||||
"Confirm your password": "Confirm your password",
|
"Confirm your password": "Confirm your password",
|
||||||
"Passwords do not match": "Passwords do not match",
|
"Passwords do not match": "Passwords do not match",
|
||||||
"Password must be at least 8 characters": "Password must be at least 8 characters",
|
|
||||||
"Registration successful": "Registration successful",
|
"Registration successful": "Registration successful",
|
||||||
"Registration failed": "Registration failed",
|
"Registration failed": "Registration failed",
|
||||||
"Email already exists": "Email already exists",
|
"Email already exists": "Email already exists",
|
||||||
@@ -484,7 +483,6 @@
|
|||||||
"Enter server ID": "Enter server ID",
|
"Enter server ID": "Enter server ID",
|
||||||
"Modifying the ID will affect the MCP access URL. Please modify with caution.": "Modifying the ID will affect the MCP access URL. Please modify with caution.",
|
"Modifying the ID will affect the MCP access URL. Please modify with caution.": "Modifying the ID will affect the MCP access URL. Please modify with caution.",
|
||||||
"You have modified the Server ID. This will affect the MCP access URL and may break existing integrations. Are you sure you want to continue?": "You have modified the Server ID. This will affect the MCP access URL and may break existing integrations. Are you sure you want to continue?",
|
"You have modified the Server ID. This will affect the MCP access URL and may break existing integrations. Are you sure you want to continue?": "You have modified the Server ID. This will affect the MCP access URL and may break existing integrations. Are you sure you want to continue?",
|
||||||
|
|
||||||
"The header name for the API key (e.g., X-API-Key, Authorization)": "The header name for the API key (e.g., X-API-Key, Authorization)",
|
"The header name for the API key (e.g., X-API-Key, Authorization)": "The header name for the API key (e.g., X-API-Key, Authorization)",
|
||||||
"Enter API key": "Enter API key",
|
"Enter API key": "Enter API key",
|
||||||
"Enter bearer token": "Enter bearer token",
|
"Enter bearer token": "Enter bearer token",
|
||||||
@@ -509,7 +507,7 @@
|
|||||||
"API Key Header Name": "API Key Header Name",
|
"API Key Header Name": "API Key Header Name",
|
||||||
"Secret Key format is incorrect, should start with sk_": "Secret Key format is incorrect, should start with sk_",
|
"Secret Key format is incorrect, should start with sk_": "Secret Key format is incorrect, should start with sk_",
|
||||||
"Webhook Secret format is incorrect, should start with whsec_": "Webhook Secret format is incorrect, should start with whsec_",
|
"Webhook Secret format is incorrect, should start with whsec_": "Webhook Secret format is incorrect, should start with whsec_",
|
||||||
"Password must be at least 8 characters long": "Password must be at least 8 characters long",
|
"Password must be at least 6 characters long": "Password must be at least 6 characters long",
|
||||||
"OAuth 2.0 Client Secret (optional, for server-side verification)": "OAuth 2.0 Client Secret (optional, for server-side verification)",
|
"OAuth 2.0 Client Secret (optional, for server-side verification)": "OAuth 2.0 Client Secret (optional, for server-side verification)",
|
||||||
"Authorized redirect URI configured in Google Cloud Console": "Authorized redirect URI configured in Google Cloud Console",
|
"Authorized redirect URI configured in Google Cloud Console": "Authorized redirect URI configured in Google Cloud Console",
|
||||||
"Webhook signing secret for verifying Stripe events": "Webhook signing secret for verifying Stripe events",
|
"Webhook signing secret for verifying Stripe events": "Webhook signing secret for verifying Stripe events",
|
||||||
@@ -774,7 +772,7 @@
|
|||||||
"Re-enter new password": "Re-enter new password",
|
"Re-enter new password": "Re-enter new password",
|
||||||
"Confirm new password": "Confirm new password",
|
"Confirm new password": "Confirm new password",
|
||||||
"New password and confirm password do not match": "New password and confirm password do not match",
|
"New password and confirm password do not match": "New password and confirm password do not match",
|
||||||
"New password must be at least 8 characters long": "New password must be at least 8 characters long",
|
"New password must be at least 6 characters long": "New password must be at least 6 characters long",
|
||||||
"New password and confirm password must be the same": "New password and confirm password must be the same",
|
"New password and confirm password must be the same": "New password and confirm password must be the same",
|
||||||
"New Password": "New Password",
|
"New Password": "New Password",
|
||||||
"Confirm New Password": "Confirm New Password",
|
"Confirm New Password": "Confirm New Password",
|
||||||
@@ -877,5 +875,32 @@
|
|||||||
"Email is required": "Email is required",
|
"Email is required": "Email is required",
|
||||||
"No servers available": "No servers available",
|
"No servers available": "No servers available",
|
||||||
"(Deleted)": "(Deleted)",
|
"(Deleted)": "(Deleted)",
|
||||||
"Transport Type": "Transport Type"
|
"Transport Type": "Transport Type",
|
||||||
}
|
"Server ID must be less than 255 characters": "Server ID must be less than 255 characters",
|
||||||
|
"Server Name must be less than 255 characters": "Server Name must be less than 255 characters",
|
||||||
|
"API Endpoint must be a valid HTTP/HTTPS URL": "API Endpoint must be a valid HTTP/HTTPS URL",
|
||||||
|
"Server ID is required": "Server ID is required",
|
||||||
|
"Short description is required": "Short description is required",
|
||||||
|
"Auth Key Name": "Auth Key Name",
|
||||||
|
"Search by email": "Search by email",
|
||||||
|
"Search by service name": "Search by service name",
|
||||||
|
"Select Date Range": "Select Date Range",
|
||||||
|
"Resource group name \"{{name}}\" is reserved and cannot be used": "Resource group name \"{{name}}\" is reserved and cannot be used",
|
||||||
|
"Resource group name \"{{name}}\" already exists": "Resource group name \"{{name}}\" already exists",
|
||||||
|
"Auth key name \"{{name}}\" already exists": "Auth key name \"{{name}}\" already exists",
|
||||||
|
"Start date must be before end date": "Start date must be before end date",
|
||||||
|
"Start date cannot be earlier than 30 days ago": "Start date cannot be earlier than 30 days ago",
|
||||||
|
"Resource Groups": "Resource Groups",
|
||||||
|
"Daily call limit per user": "Daily call limit per user",
|
||||||
|
"Max calls per user per day (Beijing time). Leave blank or 0 for unlimited": "Max calls per user per day (Beijing time). Leave blank or 0 for unlimited",
|
||||||
|
"e.g. 50": "e.g. 50",
|
||||||
|
"Free Call Limits": "Free Call Limits",
|
||||||
|
"Global daily call cap for free services": "Global daily call cap for free services",
|
||||||
|
"Platform-wide daily call limit per user": "Platform-wide daily call limit per user",
|
||||||
|
"Applies to every free service, leave blank or 0 for unlimited": "Applies to every free service, leave blank or 0 for unlimited",
|
||||||
|
"If a service also has its own limit, the smaller number wins": "If a service also has its own limit, the smaller number wins",
|
||||||
|
"Example 100": "Example 100",
|
||||||
|
"Enter a non-negative integer": "Enter a non-negative integer",
|
||||||
|
"Free call limit saved": "Free call limit saved",
|
||||||
|
"Failed to save free call limit": "Failed to save free call limit"
|
||||||
|
}
|
||||||
@@ -300,6 +300,7 @@
|
|||||||
"Overview and analytics": "概览和分析",
|
"Overview and analytics": "概览和分析",
|
||||||
"Manage MCP servers and API tools": "管理MCP服务及API工具",
|
"Manage MCP servers and API tools": "管理MCP服务及API工具",
|
||||||
"Manage registered users": "管理注册用户",
|
"Manage registered users": "管理注册用户",
|
||||||
|
"Manage resource groups": "管理资源组",
|
||||||
"View user recharge history": "查看用户充值历史",
|
"View user recharge history": "查看用户充值历史",
|
||||||
"Configure payment channels": "配置支付渠道",
|
"Configure payment channels": "配置支付渠道",
|
||||||
"Platform basic configuration": "平台基础配置",
|
"Platform basic configuration": "平台基础配置",
|
||||||
@@ -329,7 +330,7 @@
|
|||||||
"Current Balance": "当前余额",
|
"Current Balance": "当前余额",
|
||||||
"User recharged successfully": "用户充值成功",
|
"User recharged successfully": "用户充值成功",
|
||||||
"Please enter a valid amount": "请输入有效金额",
|
"Please enter a valid amount": "请输入有效金额",
|
||||||
"Minimum recharge amount is $1": "最低充值金额为 $1",
|
"Minimum recharge amount is ¥1": "最低充值金额为 ¥1",
|
||||||
"User not selected": "未选择用户",
|
"User not selected": "未选择用户",
|
||||||
"Recharge failed": "充值失败",
|
"Recharge failed": "充值失败",
|
||||||
"Network error, please try again": "网络错误,请重试",
|
"Network error, please try again": "网络错误,请重试",
|
||||||
@@ -381,7 +382,6 @@
|
|||||||
"Enter your password": "请输入密码",
|
"Enter your password": "请输入密码",
|
||||||
"Confirm your password": "请确认密码",
|
"Confirm your password": "请确认密码",
|
||||||
"Passwords do not match": "密码不匹配",
|
"Passwords do not match": "密码不匹配",
|
||||||
"Password must be at least 8 characters": "密码至少需要8个字符",
|
|
||||||
"Registration successful": "注册成功",
|
"Registration successful": "注册成功",
|
||||||
"Registration failed": "注册失败",
|
"Registration failed": "注册失败",
|
||||||
"Email already exists": "邮箱已存在",
|
"Email already exists": "邮箱已存在",
|
||||||
@@ -485,7 +485,6 @@
|
|||||||
"Enter server ID": "输入服务器ID",
|
"Enter server ID": "输入服务器ID",
|
||||||
"Modifying the ID will affect the MCP access URL. Please modify with caution.": "修改ID会影响MCP的访问地址,需要谨慎修改。",
|
"Modifying the ID will affect the MCP access URL. Please modify with caution.": "修改ID会影响MCP的访问地址,需要谨慎修改。",
|
||||||
"You have modified the Server ID. This will affect the MCP access URL and may break existing integrations. Are you sure you want to continue?": "您已修改了服务器ID。这将影响MCP访问地址,可能会破坏现有的集成。您确定要继续吗?",
|
"You have modified the Server ID. This will affect the MCP access URL and may break existing integrations. Are you sure you want to continue?": "您已修改了服务器ID。这将影响MCP访问地址,可能会破坏现有的集成。您确定要继续吗?",
|
||||||
|
|
||||||
"The header name for the API key (e.g., X-API-Key, Authorization)": "API密钥的头部名称(例如:X-API-Key, Authorization)",
|
"The header name for the API key (e.g., X-API-Key, Authorization)": "API密钥的头部名称(例如:X-API-Key, Authorization)",
|
||||||
"Enter API key": "输入API密钥",
|
"Enter API key": "输入API密钥",
|
||||||
"Enter bearer token": "输入Bearer令牌",
|
"Enter bearer token": "输入Bearer令牌",
|
||||||
@@ -510,7 +509,7 @@
|
|||||||
"API Key Header Name": "API密钥头部名称",
|
"API Key Header Name": "API密钥头部名称",
|
||||||
"Secret Key format is incorrect, should start with sk_": "密钥格式不正确,应以sk_开头",
|
"Secret Key format is incorrect, should start with sk_": "密钥格式不正确,应以sk_开头",
|
||||||
"Webhook Secret format is incorrect, should start with whsec_": "Webhook密钥格式不正确,应以whsec_开头",
|
"Webhook Secret format is incorrect, should start with whsec_": "Webhook密钥格式不正确,应以whsec_开头",
|
||||||
"Password must be at least 8 characters long": "密码至少需要8个字符",
|
"Password must be at least 6 characters long": "密码至少需要6个字符",
|
||||||
"OAuth 2.0 Client Secret (optional, for server-side verification)": "OAuth 2.0 客户端密钥(可选,用于服务端验证)",
|
"OAuth 2.0 Client Secret (optional, for server-side verification)": "OAuth 2.0 客户端密钥(可选,用于服务端验证)",
|
||||||
"Authorized redirect URI configured in Google Cloud Console": "在Google Cloud Console中配置的授权重定向URI",
|
"Authorized redirect URI configured in Google Cloud Console": "在Google Cloud Console中配置的授权重定向URI",
|
||||||
"Webhook signing secret for verifying Stripe events": "用于验证Stripe事件的Webhook签名密钥",
|
"Webhook signing secret for verifying Stripe events": "用于验证Stripe事件的Webhook签名密钥",
|
||||||
@@ -625,6 +624,8 @@
|
|||||||
"MCP Config": "MCP配置",
|
"MCP Config": "MCP配置",
|
||||||
"Copy full config": "复制完整配置",
|
"Copy full config": "复制完整配置",
|
||||||
"Analytics": "分析",
|
"Analytics": "分析",
|
||||||
|
"Resource Group": "资源组",
|
||||||
|
"Manage Your Resource Groups": "管理您的资源组",
|
||||||
"Times": "次",
|
"Times": "次",
|
||||||
"No analytics data available": "无可用分析数据",
|
"No analytics data available": "无可用分析数据",
|
||||||
"Delete Auth Key": "删除认证密钥",
|
"Delete Auth Key": "删除认证密钥",
|
||||||
@@ -776,7 +777,7 @@
|
|||||||
"Re-enter new password": "重新输入新密码",
|
"Re-enter new password": "重新输入新密码",
|
||||||
"Confirm new password": "确认新密码",
|
"Confirm new password": "确认新密码",
|
||||||
"New password and confirm password do not match": "新密码和确认密码不匹配",
|
"New password and confirm password do not match": "新密码和确认密码不匹配",
|
||||||
"New password must be at least 8 characters long": "新密码至少需要8个字符",
|
"New password must be at least 6 characters long": "新密码至少需要6个字符",
|
||||||
"New password and confirm password must be the same": "新密码和确认密码必须相同",
|
"New password and confirm password must be the same": "新密码和确认密码必须相同",
|
||||||
"New Password": "新密码",
|
"New Password": "新密码",
|
||||||
"Confirm New Password": "确认新密码",
|
"Confirm New Password": "确认新密码",
|
||||||
@@ -879,5 +880,100 @@
|
|||||||
"Email is required": "邮箱为必填项",
|
"Email is required": "邮箱为必填项",
|
||||||
"No servers available": "没有可用服务",
|
"No servers available": "没有可用服务",
|
||||||
"(Deleted)": "(已删除)",
|
"(Deleted)": "(已删除)",
|
||||||
"Transport Type": "传输方式"
|
"Transport Type": "传输方式",
|
||||||
}
|
"Server ID must be less than 255 characters": "Server ID 必须少于255个字符",
|
||||||
|
"Server Name must be less than 255 characters": "Server Name 必须少于255个字符",
|
||||||
|
"API Endpoint must be a valid HTTP/HTTPS URL": "API Endpoint 必须是一个有效的HTTP/HTTPS URL",
|
||||||
|
"Server ID is required": "Server ID 为必填项",
|
||||||
|
"Short description is required": "简短描述为必填项",
|
||||||
|
"Add": "添加",
|
||||||
|
"Add to Groups": "添加到资源组",
|
||||||
|
"Group Name": "资源组名称",
|
||||||
|
"No resource groups available": "没有可用资源组",
|
||||||
|
"Failed to load group services": "加载资源组服务失败",
|
||||||
|
"Resource group deleted successfully": "资源组删除成功",
|
||||||
|
"Added Time": "添加时间",
|
||||||
|
"No services in this group": "此资源组没有服务",
|
||||||
|
"Open Resource Group Page": "打开资源组页面",
|
||||||
|
"Remove": "删除",
|
||||||
|
"Confirm Remove": "确认删除",
|
||||||
|
"Are you sure you want to remove this \"{{name}}\" mcp server from \"{{groupName}}\" resource group?": "您确定要从 \"{{groupName}}\" 资源组中移除 \"{{name}}\" MCP 服务吗?",
|
||||||
|
"Users associated with this resource group will not be able to call the removed MCP server": "与该资源组关联的用户将无法调用已移除的 MCP 服务",
|
||||||
|
"You don't have permission to access this MCP server.": "您没有权限访问此 MCP 服务。",
|
||||||
|
"Failed to load resource groups": "加载资源组失败",
|
||||||
|
"Failed to delete resource group": "删除资源组失败",
|
||||||
|
"Failed to add service to group": "添加服务到资源组失败",
|
||||||
|
"Resource group created successfully": "资源组创建成功",
|
||||||
|
"Resource group updated successfully": "资源组更新成功",
|
||||||
|
"Services added successfully": "服务添加成功",
|
||||||
|
"Service removed successfully": "服务移除成功",
|
||||||
|
"Select resource group": "选择资源组",
|
||||||
|
"Manage your resource group. Each user has a resource group and can only access resources within their resource group": "管理您的资源组。每个用户都有一个资源组,并且只能访问其资源组内的资源",
|
||||||
|
"Please select a group to view services": "请选择一个资源组来查看服务",
|
||||||
|
"Are you sure you want to remove this \"{{name}}\" Resource Group?": "您确定要删除这个 \"{{name}}\" 资源组吗?",
|
||||||
|
"The bound users have been transferred to the following resource group": "与该资源组关联的用户已转移至以下资源组",
|
||||||
|
"Service Name": "服务名称",
|
||||||
|
"Group List": "资源组列表",
|
||||||
|
"No groups found": "没有找到资源组",
|
||||||
|
"No more groups": "没有更多资源组",
|
||||||
|
"Are you sure you want to delete this item? This action cannot be undone.": "您确定要删除这个项目吗?此操作无法撤销。",
|
||||||
|
"Create New Resource Group": "创建新资源组",
|
||||||
|
"Edit Resource Group": "编辑资源组",
|
||||||
|
"Edit Resource Group Name": "编辑资源组名称",
|
||||||
|
"Set as default": "设置为默认",
|
||||||
|
"Automatically bind default resource groups when adding users": "添加用户时自动绑定默认资源组",
|
||||||
|
"Add MCP Server": "添加 MCP 服务",
|
||||||
|
"No MCP services available": "没有可用的 MCP 服务",
|
||||||
|
"Resource Groups": "资源组",
|
||||||
|
"Resource Group Name": "资源组名称",
|
||||||
|
"Failed to remove service from group": "从资源组中移除服务失败",
|
||||||
|
"Failed to update resource group": "更新资源组失败",
|
||||||
|
"Failed to create resource group": "创建资源组失败",
|
||||||
|
"Failed to fetch simple mcp services": "获取简易MCP服务失败",
|
||||||
|
"Failed to fetch group services": "获取资源组服务失败",
|
||||||
|
"Failed to update user resource group": "更新用户资源组失败",
|
||||||
|
"Failed to load simple resource groups": "获取简易资源组失败",
|
||||||
|
"Failed to load resource group detail": "获取资源组详情失败",
|
||||||
|
"Resource Group Detail": "资源组详情",
|
||||||
|
"Current display time is UTC time": "当前显示时间为UTC时间",
|
||||||
|
"View Resource Group Detail": "查看资源组详情",
|
||||||
|
"Configure tags bar display": "配置标签栏显示",
|
||||||
|
"Failed to load orders": "加载订单失败",
|
||||||
|
"Transaction Time": "交易时间",
|
||||||
|
"All": "全部",
|
||||||
|
"Purchase": "消费",
|
||||||
|
"No orders found": "无订单",
|
||||||
|
"Account Balance": "账户余额",
|
||||||
|
"View your balance and transaction history": "查看您的余额和交易历史",
|
||||||
|
"Display tags bar": "显示标签栏",
|
||||||
|
"Front end displays tags bar and allows users to filter products based on tags.": "前端显示标签栏,允许用户根据标签过滤产品。",
|
||||||
|
"Tags Bar": "标签栏",
|
||||||
|
"Auth Key Name": "认证密钥名称",
|
||||||
|
"Search by email": "按邮箱搜索",
|
||||||
|
"Search by service name": "按服务名称搜索",
|
||||||
|
"Select Date Range": "选择日期范围",
|
||||||
|
"Resource group name \"{{name}}\" is reserved and cannot be used": "资源组名称 \"{{name}}\" 是保留名称,不能使用",
|
||||||
|
"Resource group name \"{{name}}\" already exists": "资源组名称 \"{{name}}\" 已存在",
|
||||||
|
"Auth key name \"{{name}}\" already exists": "认证密钥 \"{{name}}\" 已存在",
|
||||||
|
"Start date must be before end date": "开始日期必须早于结束日期",
|
||||||
|
"Start date cannot be earlier than 30 days ago": "开始日期不能早于30天前",
|
||||||
|
"Daily call limit per user": "每用户每日调用上限",
|
||||||
|
"Max calls per user per day (Beijing time). Leave blank or 0 for unlimited": "每个用户每天最多调用次数(北京时间)。留空或填 0 表示不限",
|
||||||
|
"e.g. 50": "如 50",
|
||||||
|
"Free Call Limits": "免费调用限制",
|
||||||
|
"Global daily call cap for free services": "免费服务的全局每日调用上限",
|
||||||
|
"Platform-wide daily call limit per user": "全站每用户每日调用上限",
|
||||||
|
"Applies to every free service, leave blank or 0 for unlimited": "对所有免费服务生效,留空或填 0 表示不限",
|
||||||
|
"If a service also has its own limit, the smaller number wins": "若单个服务也设置了上限,两者取更小值",
|
||||||
|
"Example 100": "如 100",
|
||||||
|
"Enter a non-negative integer": "请输入非负整数",
|
||||||
|
"Free call limit saved": "免费调用上限已保存",
|
||||||
|
"Failed to save free call limit": "保存免费调用上限失败",
|
||||||
|
"Publish MCP Service": "发布 MCP 服务",
|
||||||
|
"Submit your own MCP service": "提交你的 MCP 服务并上架市场",
|
||||||
|
"My Submissions": "我的提交记录",
|
||||||
|
"No submissions yet": "还没有提交记录",
|
||||||
|
"Pending Review": "待审核",
|
||||||
|
"Approved": "已通过",
|
||||||
|
"Rejected": "已拒绝"
|
||||||
|
}
|
||||||
@@ -67,9 +67,26 @@ export interface AdminAnalyticsResponse
|
|||||||
/**
|
/**
|
||||||
* Get admin analytics data
|
* Get admin analytics data
|
||||||
* Headers: { Authorization: string }
|
* Headers: { Authorization: string }
|
||||||
|
* @param start_time - Start time timestamp (seconds)
|
||||||
|
* @param end_time - End time timestamp (seconds)
|
||||||
*/
|
*/
|
||||||
export async function getAdminAnalytics(): Promise<AdminAnalyticsResponse> {
|
export async function getAdminAnalytics(
|
||||||
return fetchAdminAPI<AdminAnalyticsData>("/api/admin/stats/analytics", {
|
start_time?: number,
|
||||||
|
end_time?: number
|
||||||
|
): Promise<AdminAnalyticsResponse> {
|
||||||
|
const params = new URLSearchParams();
|
||||||
|
|
||||||
|
if (start_time !== undefined) {
|
||||||
|
params.append('start', start_time.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (end_time !== undefined) {
|
||||||
|
params.append('end', end_time.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
const url = `/api/admin/stats/analytics${params.toString() ? `?${params.toString()}` : ''}`;
|
||||||
|
|
||||||
|
return fetchAdminAPI<AdminAnalyticsData>(url, {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
}) as unknown as AdminAnalyticsResponse;
|
}) as unknown as AdminAnalyticsResponse;
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,305 @@
|
|||||||
|
import { SimpleMcpService } from "@/components/resource-group/AddMcpServerModal";
|
||||||
|
import { GroupService } from "@/components/resource-group/GroupServiceTable";
|
||||||
|
import { fetchAdminAPI } from "@/rpc/admin-api";
|
||||||
|
import { toast } from "react-hot-toast";
|
||||||
|
import i18n from "@/shared/lib/i18n";
|
||||||
|
|
||||||
|
export interface ResourceGroupResponse {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
description: string;
|
||||||
|
is_default: boolean;
|
||||||
|
service_count: number;
|
||||||
|
create_at: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ResourceGroupDetailResponse {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
description: string;
|
||||||
|
is_default: boolean;
|
||||||
|
update_at: number;
|
||||||
|
create_at: string;
|
||||||
|
}
|
||||||
|
export interface ResourceGroupListResponse {
|
||||||
|
data: ResourceGroupResponse[];
|
||||||
|
total: number;
|
||||||
|
page: number;
|
||||||
|
page_size: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface GroupServiceListResponse {
|
||||||
|
data: GroupService[];
|
||||||
|
total: number;
|
||||||
|
page: number;
|
||||||
|
page_size: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SimpleMcpServiceListResponse {
|
||||||
|
data: SimpleMcpService[];
|
||||||
|
total: number;
|
||||||
|
page: number;
|
||||||
|
page_size: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export const fetchResourceGroupDetail = async (groupId: string): Promise<ResourceGroupDetailResponse | null> => {
|
||||||
|
try {
|
||||||
|
const response = await fetchAdminAPI<ResourceGroupDetailResponse>(`/api/resource_group/info?id=${groupId}`);
|
||||||
|
if (!response.success) {
|
||||||
|
toast.error(response.error_message || i18n.t("Failed to load resource group detail"));
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return response.data || null;
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error fetching resource group detail:", error);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* 获取资源组列表
|
||||||
|
*/
|
||||||
|
export const fetchResourceGroups = async (page: number, page_size: number, keyword: string): Promise<ResourceGroupListResponse> => {
|
||||||
|
try {
|
||||||
|
const response = await fetchAdminAPI<ResourceGroupResponse[]>(`/api/resource_group/list?page=${page}&page_size=${page_size}&keyword=${keyword}`);
|
||||||
|
if (!response.success) {
|
||||||
|
toast.error(response.error_message || i18n.t("Failed to load resource groups"));
|
||||||
|
return {
|
||||||
|
data: [],
|
||||||
|
total: 0,
|
||||||
|
page,
|
||||||
|
page_size,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
data: response.data || [],
|
||||||
|
total: response.page?.total || 0,
|
||||||
|
page: response.page?.page || page,
|
||||||
|
page_size: response.page?.page_size || page_size,
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error fetching auth keys:", error);
|
||||||
|
return {
|
||||||
|
data: [],
|
||||||
|
total: 0,
|
||||||
|
page,
|
||||||
|
page_size,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* 获取简易资源组列表
|
||||||
|
*/
|
||||||
|
export const fetchSimpleResourceGroups = async (): Promise<{ id: string, name: string }[]> => {
|
||||||
|
try {
|
||||||
|
const response = await fetchAdminAPI<{ id: string, name: string }[]>(`/api/resource_group/list/simple`);
|
||||||
|
if (!response.success) {
|
||||||
|
toast.error(response.error_message || i18n.t("Failed to load simple resource groups"));
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
return response.data || []
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error fetching auth keys:", error);
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改用户资源组
|
||||||
|
*/
|
||||||
|
export const updateUserResourceGroup = async (userId: string, resourceGroupId: string): Promise<boolean> => {
|
||||||
|
try {
|
||||||
|
const response = await fetchAdminAPI<boolean>(`/api/user_manager/resource_group`, {
|
||||||
|
method: "PUT",
|
||||||
|
body: { user_id: userId, resource_group: resourceGroupId } as unknown as BodyInit,
|
||||||
|
});
|
||||||
|
if (!response.success) {
|
||||||
|
toast.error(response.error_message || i18n.t("Failed to update user resource group"));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error updating user resource group:", error);
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取指定资源组下的服务列表
|
||||||
|
*/
|
||||||
|
export const fetchGroupServices = async (id: string,page: number, page_size: number, keyword: string): Promise<GroupServiceListResponse> => {
|
||||||
|
try {
|
||||||
|
const response = await fetchAdminAPI<GroupService[]>(`/api/resource_group/service/list?id=${id}&page=${page}&page_size=${page_size}&keyword=${keyword}`);
|
||||||
|
if (!response.success) {
|
||||||
|
toast.error(response.error_message || i18n.t("Failed to fetch group services"));
|
||||||
|
return {
|
||||||
|
data: [],
|
||||||
|
total: 0,
|
||||||
|
page,
|
||||||
|
page_size,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
data: response.data || [],
|
||||||
|
total: response.page?.total || 0,
|
||||||
|
page: response.page?.page || page,
|
||||||
|
page_size: response.page?.page_size || page_size,
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error fetching auth keys:", error);
|
||||||
|
return {
|
||||||
|
data: [],
|
||||||
|
total: 0,
|
||||||
|
page,
|
||||||
|
page_size,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取简易指定资源组下的服务列表
|
||||||
|
*/
|
||||||
|
export const fetchSimpleMcpServices = async (id: string): Promise<SimpleMcpService[]> => {
|
||||||
|
try {
|
||||||
|
const response = await fetchAdminAPI<SimpleMcpService[]>(`/api/resource_group/service/list/unbind?id=${id}`);
|
||||||
|
if (!response.success) {
|
||||||
|
toast.error(response.error_message || i18n.t("Failed to fetch simple mcp services"));
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
return response.data || []
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error fetching auth keys:", error);
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建资源组
|
||||||
|
*/
|
||||||
|
export const createResourceGroup = async (name: string, isDefault: boolean): Promise<{success: boolean, id: string}> => {
|
||||||
|
try {
|
||||||
|
const response = await fetchAdminAPI<{id: string}>(`/api/resource_group`, {
|
||||||
|
method: "POST",
|
||||||
|
body: { name: name, is_default: isDefault } as unknown as BodyInit,
|
||||||
|
});
|
||||||
|
if (!response.success) {
|
||||||
|
const errorMsg = response.error_message
|
||||||
|
if (errorMsg?.endsWith('already exists')) {
|
||||||
|
toast.error(i18n.t(errorMsg, { name: name }));
|
||||||
|
} else if(errorMsg?.endsWith('cannot be used')) {
|
||||||
|
toast.error(i18n.t(errorMsg, { name: name }));
|
||||||
|
} else {
|
||||||
|
toast.error(errorMsg || i18n.t("Failed to create resource group"));
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
id: "",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
id: response.data?.id || "",
|
||||||
|
};
|
||||||
|
} catch {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
id: "",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新资源组
|
||||||
|
*/
|
||||||
|
export const updateResourceGroup = async (
|
||||||
|
groupId: string,
|
||||||
|
name: string,
|
||||||
|
isDefault: boolean
|
||||||
|
): Promise<boolean> => {
|
||||||
|
try {
|
||||||
|
const response = await fetchAdminAPI<boolean>(`/api/resource_group?id=${groupId}`, {
|
||||||
|
method: "PUT",
|
||||||
|
body: { name: name, is_default: isDefault } as unknown as BodyInit,
|
||||||
|
});
|
||||||
|
if (!response.success) {
|
||||||
|
const errorMsg = response.error_message
|
||||||
|
if (errorMsg?.endsWith('already exists')) {
|
||||||
|
toast.error(i18n.t(errorMsg, { name: name }));
|
||||||
|
} else if(errorMsg?.endsWith('cannot be used')) {
|
||||||
|
toast.error(i18n.t(errorMsg, { name: name }));
|
||||||
|
} else {
|
||||||
|
toast.error(errorMsg || i18n.t("Failed to update resource group"));
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} catch {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除资源组
|
||||||
|
*/
|
||||||
|
export const deleteResourceGroup = async (
|
||||||
|
groupId: string,
|
||||||
|
transferToGroupId: string
|
||||||
|
): Promise<boolean> => {
|
||||||
|
try {
|
||||||
|
const response = await fetchAdminAPI<boolean>(`/api/resource_group?id=${groupId}&migrate_id=${transferToGroupId}`, {
|
||||||
|
method: "DELETE"
|
||||||
|
});
|
||||||
|
if (!response.success) {
|
||||||
|
toast.error(response.error_message || i18n.t("Failed to delete resource group"));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} catch {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从资源组中移除服务
|
||||||
|
*/
|
||||||
|
export const removeServiceFromGroup = async (
|
||||||
|
groupId: string,
|
||||||
|
serviceIds: string[]
|
||||||
|
): Promise<boolean> => {
|
||||||
|
try {
|
||||||
|
const response = await fetchAdminAPI<boolean>(`/api/resource_group/service?id=${groupId}`, {
|
||||||
|
method: "DELETE",
|
||||||
|
body: { services: serviceIds } as unknown as BodyInit,
|
||||||
|
});
|
||||||
|
if (!response.success) {
|
||||||
|
toast.error(response.error_message || i18n.t("Failed to remove service from group"));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} catch {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加服务到资源组
|
||||||
|
*/
|
||||||
|
export const addServiceToGroup = async (
|
||||||
|
groupId: string,
|
||||||
|
services: string[]
|
||||||
|
): Promise<boolean> => {
|
||||||
|
try {
|
||||||
|
const response = await fetchAdminAPI<boolean>(`/api/resource_group/service?id=${groupId}`, {
|
||||||
|
method: "PUT",
|
||||||
|
body: { services: services } as unknown as BodyInit,
|
||||||
|
});
|
||||||
|
if (!response.success) {
|
||||||
|
toast.error(response.error_message || i18n.t("Failed to add service to group"));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} catch {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
@@ -12,7 +12,7 @@ export async function revalidatePlatformConfig() {
|
|||||||
revalidatePath("/", "layout");
|
revalidatePath("/", "layout");
|
||||||
|
|
||||||
// Revalidate host-specific cache tag
|
// Revalidate host-specific cache tag
|
||||||
revalidateTag(`platform-config-${host}`);
|
revalidateTag(`platform-config-${host}`, 'max');
|
||||||
|
|
||||||
console.info(
|
console.info(
|
||||||
`Platform config cache revalidated for host: platform-config-${host}`
|
`Platform config cache revalidated for host: platform-config-${host}`
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
"use client";
|
||||||
|
import React from "react";
|
||||||
|
import { SubmissionsManagement } from "@/components/console/SubmissionsManagement";
|
||||||
|
|
||||||
|
export default function AdminSubmissionsPage() {
|
||||||
|
return <SubmissionsManagement />;
|
||||||
|
}
|
||||||
@@ -1,13 +1,14 @@
|
|||||||
input::placeholder,
|
/* Import theme styles */
|
||||||
textarea::placeholder {
|
@import "../styles/themes.css";
|
||||||
--nextui-foreground-500: 240 5.03% 64.9%;
|
|
||||||
}
|
|
||||||
@tailwind base;
|
@tailwind base;
|
||||||
@tailwind components;
|
@tailwind components;
|
||||||
@tailwind utilities;
|
@tailwind utilities;
|
||||||
|
|
||||||
/* Import theme styles */
|
input::placeholder,
|
||||||
@import "../styles/themes.css";
|
textarea::placeholder {
|
||||||
|
--nextui-foreground-500: 240 5.03% 64.9%;
|
||||||
|
}
|
||||||
|
|
||||||
html,
|
html,
|
||||||
body {
|
body {
|
||||||
|
|||||||
@@ -27,12 +27,12 @@ export default async function RootLayout({
|
|||||||
const platformConfig = await getCachedPlatformConfig();
|
const platformConfig = await getCachedPlatformConfig();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<html lang="en" suppressHydrationWarning data-color-mode="light">
|
<html lang="zh-CN" suppressHydrationWarning data-color-mode="light">
|
||||||
<head>
|
<head>
|
||||||
<script
|
<script
|
||||||
dangerouslySetInnerHTML={{
|
dangerouslySetInnerHTML={{
|
||||||
__html: `
|
__html: `
|
||||||
window.localStorage.setItem("i18nextLng", "${platformConfig?.platform?.language || "en"}");
|
window.localStorage.setItem("i18nextLng", "${platformConfig?.platform?.language || "zh-CN"}");
|
||||||
`,
|
`,
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -0,0 +1,260 @@
|
|||||||
|
"use client";
|
||||||
|
import React, { useEffect, useState } from "react";
|
||||||
|
import { fetchAPI } from "@/shared/rpc/common-function";
|
||||||
|
import { useSharedStore } from "@/shared/store/share";
|
||||||
|
|
||||||
|
type SubType = "mcp";
|
||||||
|
|
||||||
|
type SubRecord = {
|
||||||
|
id: string;
|
||||||
|
type: string;
|
||||||
|
name: string;
|
||||||
|
status: string;
|
||||||
|
created_at?: string | null;
|
||||||
|
review_note?: string | null;
|
||||||
|
};
|
||||||
|
|
||||||
|
const TYPE_LABEL: Record<string, string> = {
|
||||||
|
mcp: "MCP 服务",
|
||||||
|
};
|
||||||
|
|
||||||
|
const STATUS_LABEL: Record<string, { text: string; cls: string }> = {
|
||||||
|
pending: { text: "待审核", cls: "bg-yellow-100 text-yellow-800" },
|
||||||
|
approved: { text: "已通过", cls: "bg-green-100 text-green-800" },
|
||||||
|
rejected: { text: "已拒绝", cls: "bg-red-100 text-red-700" },
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function SubmitPage() {
|
||||||
|
// 网页登录态存在 zustand store(XPack_Shared),localStorage["user_token"] 只有扩展侧栏才会写,
|
||||||
|
// 用 store 判断才不会把已登录用户误判为未登录
|
||||||
|
const user_token = useSharedStore((s: any) => s.user_token);
|
||||||
|
const type: SubType = "mcp";
|
||||||
|
const [name, setName] = useState("");
|
||||||
|
const [desc, setDesc] = useState("");
|
||||||
|
const [file, setFile] = useState<File | null>(null);
|
||||||
|
const [baseUrl, setBaseUrl] = useState("");
|
||||||
|
const [serviceType, setServiceType] = useState("openapi");
|
||||||
|
const [tags, setTags] = useState("");
|
||||||
|
const [chargeType, setChargeType] = useState<"free" | "paid">("free");
|
||||||
|
const [price, setPrice] = useState("");
|
||||||
|
const [freeDailyLimit, setFreeDailyLimit] = useState("");
|
||||||
|
const [msg, setMsg] = useState<{ ok: boolean; text: string } | null>(null);
|
||||||
|
const [submitting, setSubmitting] = useState(false);
|
||||||
|
const [subs, setSubs] = useState<SubRecord[]>([]);
|
||||||
|
const [loggedIn, setLoggedIn] = useState<boolean | null>(null);
|
||||||
|
|
||||||
|
const loadSubs = async () => {
|
||||||
|
if (typeof window === "undefined") return;
|
||||||
|
try {
|
||||||
|
const d = await fetchAPI<{ success: boolean; data?: SubRecord[] }>(
|
||||||
|
"/api/submission/submissions",
|
||||||
|
{ method: "GET" }
|
||||||
|
);
|
||||||
|
if (d?.success && Array.isArray(d.data)) {
|
||||||
|
setLoggedIn(true);
|
||||||
|
setSubs(d.data);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
/* 网络异常按未登录处理,不影响提交表单 */
|
||||||
|
}
|
||||||
|
setLoggedIn(false);
|
||||||
|
setSubs([]);
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
loadSubs();
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const handleSubmit = async (e: React.FormEvent) => {
|
||||||
|
e.preventDefault();
|
||||||
|
setMsg(null);
|
||||||
|
|
||||||
|
if (typeof window !== "undefined" && !user_token) {
|
||||||
|
setMsg({ ok: false, text: "请先登录后再提交(右上角登录)" });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (type === "mcp" && !baseUrl.trim()) {
|
||||||
|
setMsg({ ok: false, text: "MCP 服务必须填写服务地址 base_url" });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setSubmitting(true);
|
||||||
|
try {
|
||||||
|
const fd = new FormData();
|
||||||
|
fd.append("type", type);
|
||||||
|
fd.append("name", name);
|
||||||
|
if (desc) fd.append("description", desc);
|
||||||
|
if (file) fd.append("file", file);
|
||||||
|
if (type === "mcp") {
|
||||||
|
fd.append("base_url", baseUrl.trim());
|
||||||
|
fd.append("service_type", serviceType);
|
||||||
|
if (tags.trim()) fd.append("tags", tags.trim());
|
||||||
|
fd.append("charge_type", chargeType);
|
||||||
|
if (chargeType === "paid" && price) fd.append("price", price);
|
||||||
|
if (chargeType === "free" && freeDailyLimit) fd.append("free_daily_limit", freeDailyLimit);
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = await fetchAPI<{ success: boolean; error_message?: string; data?: { id: string; status: string } }>(
|
||||||
|
"/api/submission/submission",
|
||||||
|
{ method: "POST", body: fd }
|
||||||
|
);
|
||||||
|
if (data?.success) {
|
||||||
|
setMsg({ ok: true, text: "提交成功,等待管理员审核。审核通过后将自动上架到市场。" });
|
||||||
|
setName(""); setDesc(""); setFile(null); setBaseUrl(""); setTags("");
|
||||||
|
loadSubs();
|
||||||
|
} else {
|
||||||
|
setMsg({ ok: false, text: data?.error_message || "提交失败,请稍后重试" });
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
setMsg({ ok: false, text: "提交失败:" + (err as Error).message });
|
||||||
|
} finally {
|
||||||
|
setSubmitting(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const inputCls = "border p-2 w-full rounded";
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="max-w-xl mx-auto p-6">
|
||||||
|
<div className="flex items-center justify-between mb-4">
|
||||||
|
<h1 className="text-2xl font-bold">上传 MCP 服务</h1>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<form onSubmit={handleSubmit} className="space-y-4">
|
||||||
|
<input value={name} onChange={(e) => setName(e.target.value)} placeholder="名称" className={inputCls} required />
|
||||||
|
<textarea value={desc} onChange={(e) => setDesc(e.target.value)} placeholder="描述" className={inputCls} rows={3} />
|
||||||
|
|
||||||
|
{type === "mcp" && (
|
||||||
|
<div className="space-y-3 border rounded p-3 bg-gray-50">
|
||||||
|
<div>
|
||||||
|
<label className="block text-sm font-medium mb-1">服务地址 base_url *</label>
|
||||||
|
<input
|
||||||
|
value={baseUrl}
|
||||||
|
onChange={(e) => setBaseUrl(e.target.value)}
|
||||||
|
placeholder="http://192.168.1.10:8020"
|
||||||
|
className={inputCls}
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label className="block text-sm font-medium mb-1">服务类型</label>
|
||||||
|
<select value={serviceType} onChange={(e) => setServiceType(e.target.value)} className={inputCls}>
|
||||||
|
<option value="openapi">openapi(HTTP 接口)</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label className="block text-sm font-medium mb-1">标签(逗号分隔)</label>
|
||||||
|
<input value={tags} onChange={(e) => setTags(e.target.value)} placeholder="工具, 搜索, 免费" className={inputCls} />
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label className="block text-sm font-medium mb-1">计费方式</label>
|
||||||
|
<select
|
||||||
|
value={chargeType}
|
||||||
|
onChange={(e) => setChargeType(e.target.value as "free" | "paid")}
|
||||||
|
className={inputCls}
|
||||||
|
>
|
||||||
|
<option value="free">免费</option>
|
||||||
|
<option value="paid">按次付费</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
{chargeType === "paid" ? (
|
||||||
|
<div>
|
||||||
|
<label className="block text-sm font-medium mb-1">单价(元/次)</label>
|
||||||
|
<input
|
||||||
|
type="number" step="0.01" min="0"
|
||||||
|
value={price}
|
||||||
|
onChange={(e) => setPrice(e.target.value)}
|
||||||
|
placeholder="0.10"
|
||||||
|
className={inputCls}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<div>
|
||||||
|
<label className="block text-sm font-medium mb-1">每日免费次数(留空 = 不限)</label>
|
||||||
|
<input
|
||||||
|
type="number" min="1"
|
||||||
|
value={freeDailyLimit}
|
||||||
|
onChange={(e) => setFreeDailyLimit(e.target.value)}
|
||||||
|
placeholder="100"
|
||||||
|
className={inputCls}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
<div>
|
||||||
|
<label className="block text-sm font-medium mb-1">
|
||||||
|
OpenAPI 规范文件(.json,用于自动生成工具列表)
|
||||||
|
</label>
|
||||||
|
<input type="file" onChange={(e) => setFile(e.target.files?.[0] || null)} className={inputCls} />
|
||||||
|
<p className="text-xs text-gray-500 mt-1">
|
||||||
|
上传后审核通过会自动生成工具;不上传则上架后需在服务管理里手动添加工具。
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<button
|
||||||
|
type="submit"
|
||||||
|
disabled={submitting}
|
||||||
|
className="bg-blue-600 text-white px-4 py-2 rounded disabled:opacity-50"
|
||||||
|
>
|
||||||
|
{submitting ? "提交中..." : "提交"}
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
{msg && (
|
||||||
|
<pre className={`mt-4 text-sm whitespace-pre-wrap ${msg.ok ? "text-green-700" : "text-red-600"}`}>
|
||||||
|
{msg.text}
|
||||||
|
</pre>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{loggedIn === false && (
|
||||||
|
<p className="mt-6 text-sm text-gray-500">
|
||||||
|
登录后可提交服务并查看审核状态。
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{loggedIn && (
|
||||||
|
<div className="mt-8 border rounded p-4 bg-white">
|
||||||
|
<h2 className="text-lg font-semibold mb-3">我的提交记录</h2>
|
||||||
|
{subs.length === 0 ? (
|
||||||
|
<p className="text-sm text-gray-500">还没有提交记录</p>
|
||||||
|
) : (
|
||||||
|
<ul className="space-y-2">
|
||||||
|
{subs.map((s) => {
|
||||||
|
const st = STATUS_LABEL[s.status] || {
|
||||||
|
text: s.status,
|
||||||
|
cls: "bg-gray-100 text-gray-600",
|
||||||
|
};
|
||||||
|
return (
|
||||||
|
<li key={s.id} className="border rounded p-3 text-sm">
|
||||||
|
<div className="flex items-center justify-between gap-2">
|
||||||
|
<span className="font-medium truncate">{s.name}</span>
|
||||||
|
<span
|
||||||
|
className={`px-2 py-0.5 rounded text-xs whitespace-nowrap ${st.cls}`}
|
||||||
|
>
|
||||||
|
{st.text}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div className="text-xs text-gray-500 mt-1 flex flex-wrap gap-x-4">
|
||||||
|
<span>{TYPE_LABEL[s.type] || s.type}</span>
|
||||||
|
{s.created_at && (
|
||||||
|
<span>{new Date(s.created_at).toLocaleString("zh-CN")}</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
{s.review_note && (
|
||||||
|
<div className="text-xs text-orange-600 mt-1">
|
||||||
|
审核备注:{s.review_note}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</li>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</ul>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -48,8 +48,8 @@ export const ChangePasswordModal: React.FC<ChangePasswordModalProps> = ({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newPassword.length < 8) {
|
if (newPassword.length < 6) {
|
||||||
toast.error(t("Password must be at least 8 characters long"));
|
toast.error(t("Password must be at least 6 characters long"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,7 +73,7 @@ export const ChangePasswordModal: React.FC<ChangePasswordModalProps> = ({
|
|||||||
newPassword.trim() !== "" &&
|
newPassword.trim() !== "" &&
|
||||||
confirmPassword.trim() !== "" &&
|
confirmPassword.trim() !== "" &&
|
||||||
newPassword === confirmPassword &&
|
newPassword === confirmPassword &&
|
||||||
newPassword.length >= 8;
|
newPassword.length >= 6;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal isOpen={isOpen} onClose={handleClose} size="md">
|
<Modal isOpen={isOpen} onClose={handleClose} size="md">
|
||||||
@@ -90,7 +90,7 @@ export const ChangePasswordModal: React.FC<ChangePasswordModalProps> = ({
|
|||||||
type={showNewPassword ? "text" : "password"}
|
type={showNewPassword ? "text" : "password"}
|
||||||
value={newPassword}
|
value={newPassword}
|
||||||
onChange={(e) => setNewPassword(e.target.value)}
|
onChange={(e) => setNewPassword(e.target.value)}
|
||||||
description={t("Password must be at least 8 characters long")}
|
description={t("Password must be at least 6 characters long")}
|
||||||
endContent={
|
endContent={
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
|
|||||||
@@ -14,12 +14,12 @@ const formSchema = z.object({
|
|||||||
.string()
|
.string()
|
||||||
.min(1, "Password is required")
|
.min(1, "Password is required")
|
||||||
.max(100, "Password is too long")
|
.max(100, "Password is too long")
|
||||||
.min(8, "Password must be at least 8 characters"),
|
.min(6, "Password must be at least 6 characters"),
|
||||||
confirmPassword: z
|
confirmPassword: z
|
||||||
.string()
|
.string()
|
||||||
.min(1, "Confirm password is required")
|
.min(1, "Confirm password is required")
|
||||||
.max(100, "Confirm password is too long")
|
.max(100, "Confirm password is too long")
|
||||||
.min(8, "Confirm password must be at least 8 characters"),
|
.min(6, "Confirm password must be at least 6 characters"),
|
||||||
});
|
});
|
||||||
type FormData = z.infer<typeof formSchema>;
|
type FormData = z.infer<typeof formSchema>;
|
||||||
|
|
||||||
@@ -61,7 +61,7 @@ export const AdminConfigForm: React.FC<AdminConfigFormProps> = ({ onSave }) => {
|
|||||||
{...field}
|
{...field}
|
||||||
label={t("Administrator Password")}
|
label={t("Administrator Password")}
|
||||||
placeholder={t("Enter administrator password")}
|
placeholder={t("Enter administrator password")}
|
||||||
description={t("Password must be at least 8 characters long")}
|
description={t("Password must be at least 6 characters long")}
|
||||||
isInvalid={!!errors.password}
|
isInvalid={!!errors.password}
|
||||||
errorMessage={errors.password?.message}
|
errorMessage={errors.password?.message}
|
||||||
type={showPassword ? "text" : "password"}
|
type={showPassword ? "text" : "password"}
|
||||||
|
|||||||
@@ -10,7 +10,9 @@ import {
|
|||||||
Listbox,
|
Listbox,
|
||||||
ListboxItem,
|
ListboxItem,
|
||||||
Skeleton,
|
Skeleton,
|
||||||
|
DateRangePicker
|
||||||
} from "@nextui-org/react";
|
} from "@nextui-org/react";
|
||||||
|
import { parseDate } from "@internationalized/date";
|
||||||
import { useTranslation } from "@/shared/lib/useTranslation";
|
import { useTranslation } from "@/shared/lib/useTranslation";
|
||||||
import {
|
import {
|
||||||
LineChart,
|
LineChart,
|
||||||
@@ -60,9 +62,9 @@ const transformToChartData = (
|
|||||||
userRegDay?.stats_day || payDay?.stats_day || callDay?.stats_day;
|
userRegDay?.stats_day || payDay?.stats_day || callDay?.stats_day;
|
||||||
const formattedDate = rawDate
|
const formattedDate = rawDate
|
||||||
? new Date(rawDate).toLocaleDateString("en-US", {
|
? new Date(rawDate).toLocaleDateString("en-US", {
|
||||||
month: "short",
|
month: "short",
|
||||||
day: "numeric",
|
day: "numeric",
|
||||||
})
|
})
|
||||||
: `Day ${i + 1}`;
|
: `Day ${i + 1}`;
|
||||||
|
|
||||||
chartData.push({
|
chartData.push({
|
||||||
@@ -99,12 +101,114 @@ const ConsoleStats: React.FC = () => {
|
|||||||
);
|
);
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
|
|
||||||
// Fetch analytics data on component mount
|
// 日期范围状态 - 默认最近30天
|
||||||
|
const [dateRange, setDateRange] = useState<any>(() => {
|
||||||
|
const today = new Date();
|
||||||
|
const thirtyDaysAgo = new Date();
|
||||||
|
thirtyDaysAgo.setDate(today.getDate() - 29);
|
||||||
|
|
||||||
|
// 格式化为 YYYY-MM-DD
|
||||||
|
const formatDate = (date: Date) => {
|
||||||
|
const year = date.getFullYear();
|
||||||
|
const month = String(date.getMonth() + 1).padStart(2, '0');
|
||||||
|
const day = String(date.getDate()).padStart(2, '0');
|
||||||
|
return `${year}-${month}-${day}`;
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
start: parseDate(formatDate(thirtyDaysAgo)),
|
||||||
|
end: parseDate(formatDate(today)),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
// 计算最早可选日期(30天前)
|
||||||
|
const minValue = useMemo(() => {
|
||||||
|
const date = new Date();
|
||||||
|
date.setDate(date.getDate() - 30);
|
||||||
|
const year = date.getFullYear();
|
||||||
|
const month = String(date.getMonth() + 1).padStart(2, '0');
|
||||||
|
const day = String(date.getDate()).padStart(2, '0');
|
||||||
|
return parseDate(`${year}-${month}-${day}`);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
// 计算最大可选日期(今天)
|
||||||
|
const maxValue = useMemo(() => {
|
||||||
|
const date = new Date();
|
||||||
|
const year = date.getFullYear();
|
||||||
|
const month = String(date.getMonth() + 1).padStart(2, '0');
|
||||||
|
const day = String(date.getDate()).padStart(2, '0');
|
||||||
|
return parseDate(`${year}-${month}-${day}`);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
// 校验:开始日期必须早于结束日期,且不能早于30天前
|
||||||
|
const dateValidation = useMemo(() => {
|
||||||
|
if (!dateRange?.start || !dateRange?.end) {
|
||||||
|
return { isInvalid: false, error: "" };
|
||||||
|
}
|
||||||
|
|
||||||
|
const start = dateRange.start;
|
||||||
|
const end = dateRange.end;
|
||||||
|
const minDate = minValue;
|
||||||
|
|
||||||
|
// 检查开始日期是否早于30天前
|
||||||
|
const isStartTooEarly =
|
||||||
|
start.year < minDate.year ||
|
||||||
|
(start.year === minDate.year && start.month < minDate.month) ||
|
||||||
|
(start.year === minDate.year && start.month === minDate.month && start.day < minDate.day);
|
||||||
|
|
||||||
|
if (isStartTooEarly) {
|
||||||
|
return {
|
||||||
|
isInvalid: true,
|
||||||
|
error: t("Start date cannot be earlier than 30 days ago")
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查开始日期是否晚于结束日期
|
||||||
|
const isEndBeforeStart =
|
||||||
|
start.year > end.year ||
|
||||||
|
(start.year === end.year && start.month > end.month) ||
|
||||||
|
(start.year === end.year && start.month === end.month && start.day >= end.day);
|
||||||
|
|
||||||
|
if (isEndBeforeStart) {
|
||||||
|
return {
|
||||||
|
isInvalid: true,
|
||||||
|
error: t("Start date must be before end date")
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return { isInvalid: false, error: "" };
|
||||||
|
}, [dateRange, minValue, t]);
|
||||||
|
|
||||||
|
// 错误消息
|
||||||
|
const errorMessage = dateValidation.error;
|
||||||
|
const isInvalidDateRange = dateValidation.isInvalid;
|
||||||
|
|
||||||
|
// Fetch analytics data on component mount and when date range changes
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchData = async () => {
|
const fetchData = async () => {
|
||||||
|
if (!dateRange?.start || !dateRange?.end) return;
|
||||||
|
|
||||||
|
// 如果日期范围无效,不发送请求
|
||||||
|
if (isInvalidDateRange) {
|
||||||
|
setLoading(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
const response = await getAdminAnalytics();
|
|
||||||
|
// parseDate 返回的对象有 year, month, day 属性
|
||||||
|
const start = dateRange.start;
|
||||||
|
const end = dateRange.end;
|
||||||
|
|
||||||
|
// 转换日期为时间戳(秒)
|
||||||
|
const startDateTime = new Date(start.year, start.month - 1, start.day, 0, 0, 0);
|
||||||
|
const startTime = Math.floor(startDateTime.getTime() / 1000);
|
||||||
|
|
||||||
|
const endDateTime = new Date(end.year, end.month - 1, end.day, 23, 59, 59);
|
||||||
|
const endTime = Math.floor(endDateTime.getTime() / 1000);
|
||||||
|
|
||||||
|
const response = await getAdminAnalytics(startTime, endTime);
|
||||||
|
|
||||||
if (response.success) {
|
if (response.success) {
|
||||||
setAnalyticsData(response.data);
|
setAnalyticsData(response.data);
|
||||||
@@ -113,14 +217,15 @@ const ConsoleStats: React.FC = () => {
|
|||||||
response.error_message || "Failed to load analytics data"
|
response.error_message || "Failed to load analytics data"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch {
|
||||||
|
toast.error("Failed to load analytics data");
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
fetchData();
|
fetchData();
|
||||||
}, []);
|
}, [dateRange, isInvalidDateRange]);
|
||||||
|
|
||||||
// Transform API data to chart format
|
// Transform API data to chart format
|
||||||
const chartData = useMemo<ChartDataItem[]>(() => {
|
const chartData = useMemo<ChartDataItem[]>(() => {
|
||||||
@@ -128,9 +233,9 @@ const ConsoleStats: React.FC = () => {
|
|||||||
return transformToChartData(analyticsData);
|
return transformToChartData(analyticsData);
|
||||||
}, [analyticsData]);
|
}, [analyticsData]);
|
||||||
|
|
||||||
// Format revenue as currency (USD by default)
|
// Format revenue as currency (CNY by default)
|
||||||
const formatCurrency = (value: number, currency: string = "USD") =>
|
const formatCurrency = (value: number, currency: string = "CNY") =>
|
||||||
new Intl.NumberFormat("en-US", { style: "currency", currency }).format(
|
new Intl.NumberFormat("zh-CN", { style: "currency", currency }).format(
|
||||||
value
|
value
|
||||||
);
|
);
|
||||||
if (loading) {
|
if (loading) {
|
||||||
@@ -156,6 +261,24 @@ const ConsoleStats: React.FC = () => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="space-y-6">
|
<div className="space-y-6">
|
||||||
|
{/* 日期范围选择器 */}
|
||||||
|
<div className="flex justify-end">
|
||||||
|
<DateRangePicker
|
||||||
|
label={t("Select Date Range")}
|
||||||
|
value={dateRange}
|
||||||
|
onChange={setDateRange}
|
||||||
|
minValue={minValue}
|
||||||
|
maxValue={maxValue}
|
||||||
|
isInvalid={isInvalidDateRange}
|
||||||
|
errorMessage={errorMessage}
|
||||||
|
onKeyDown={(e) => e.preventDefault()}
|
||||||
|
onKeyUp={(e) => e.preventDefault()}
|
||||||
|
className="w-[250px]"
|
||||||
|
visibleMonths={2}
|
||||||
|
granularity="day"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
{/* Charts with Tabs */}
|
{/* Charts with Tabs */}
|
||||||
<Card shadow="none" className="border-1">
|
<Card shadow="none" className="border-1">
|
||||||
<CardHeader className="p-0 flex items-center justify-between">
|
<CardHeader className="p-0 flex items-center justify-between">
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import UserManagement from "@/components/user-management/UserManagement";
|
|||||||
import RevenueManagement from "@/components/revenue-management/RevenueManagement";
|
import RevenueManagement from "@/components/revenue-management/RevenueManagement";
|
||||||
import ConsoleSidebar from "./Sidebar";
|
import ConsoleSidebar from "./Sidebar";
|
||||||
import { withComponentInjection } from "@/shared/hooks/useComponentInjection";
|
import { withComponentInjection } from "@/shared/hooks/useComponentInjection";
|
||||||
import { DollarSign, Home, ServerIcon, Users } from "lucide-react";
|
import { Boxes, DollarSign, Home, Inbox, ServerIcon, Users } from "lucide-react";
|
||||||
import OnboardingWelcome, { REQUIRED_TASK_KEYS } from "./OnboardingWelcome";
|
import OnboardingWelcome, { REQUIRED_TASK_KEYS } from "./OnboardingWelcome";
|
||||||
import ConsoleStats from "./ConsoleStats";
|
import ConsoleStats from "./ConsoleStats";
|
||||||
import SystemSettingsModal from "./SystemSettingsModal";
|
import SystemSettingsModal from "./SystemSettingsModal";
|
||||||
@@ -23,6 +23,8 @@ import {
|
|||||||
TaskStatusEnum,
|
TaskStatusEnum,
|
||||||
updateAdminOnboardingTasks,
|
updateAdminOnboardingTasks,
|
||||||
} from "@/api/onboard.api";
|
} from "@/api/onboard.api";
|
||||||
|
import ResourceGroupManagement from "../resource-group/resourceGroup";
|
||||||
|
import { SubmissionsManagement } from "./SubmissionsManagement";
|
||||||
|
|
||||||
const ConsoleContent: React.FC = () => {
|
const ConsoleContent: React.FC = () => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
@@ -36,9 +38,13 @@ const ConsoleContent: React.FC = () => {
|
|||||||
const tabFromUrl = searchParams.get("tab") as TabKey;
|
const tabFromUrl = searchParams.get("tab") as TabKey;
|
||||||
if (
|
if (
|
||||||
tabFromUrl &&
|
tabFromUrl &&
|
||||||
["mcp-services", "user-management", "revenue-management"].includes(
|
[
|
||||||
tabFromUrl
|
"mcp-services",
|
||||||
)
|
"user-management",
|
||||||
|
"revenue-management",
|
||||||
|
"resource-group",
|
||||||
|
"submissions",
|
||||||
|
].includes(tabFromUrl)
|
||||||
) {
|
) {
|
||||||
return tabFromUrl;
|
return tabFromUrl;
|
||||||
}
|
}
|
||||||
@@ -68,12 +74,24 @@ const ConsoleContent: React.FC = () => {
|
|||||||
label: t("MCP"),
|
label: t("MCP"),
|
||||||
description: t("Manage MCP servers and API tools"),
|
description: t("Manage MCP servers and API tools"),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
key: TabKey.SUBMISSIONS,
|
||||||
|
icon: <Inbox size={18} />,
|
||||||
|
label: t("Submissions"),
|
||||||
|
description: t("Review user submissions and publish to marketplace"),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
key: TabKey.USER_MANAGEMENT,
|
key: TabKey.USER_MANAGEMENT,
|
||||||
icon: <Users size={18} />,
|
icon: <Users size={18} />,
|
||||||
label: t("User"),
|
label: t("User"),
|
||||||
description: t("Manage registered users"),
|
description: t("Manage registered users"),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
key: TabKey.RESOURCE_GROUP,
|
||||||
|
icon: <Boxes size={18} />,
|
||||||
|
label: t("Resource Group"),
|
||||||
|
description: t("Manage resource groups"),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
key: TabKey.REVENUE_MANAGEMENT,
|
key: TabKey.REVENUE_MANAGEMENT,
|
||||||
icon: <DollarSign size={18} />,
|
icon: <DollarSign size={18} />,
|
||||||
@@ -206,6 +224,12 @@ const ConsoleContent: React.FC = () => {
|
|||||||
switch (activeTab) {
|
switch (activeTab) {
|
||||||
case TabKey.MCP_SERVICES:
|
case TabKey.MCP_SERVICES:
|
||||||
return <MCPServicesManagement />;
|
return <MCPServicesManagement />;
|
||||||
|
case TabKey.SUBMISSIONS:
|
||||||
|
return (
|
||||||
|
<div className="h-full overflow-auto">
|
||||||
|
<SubmissionsManagement />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
case TabKey.USER_MANAGEMENT:
|
case TabKey.USER_MANAGEMENT:
|
||||||
return (
|
return (
|
||||||
<div className="h-full overflow-auto">
|
<div className="h-full overflow-auto">
|
||||||
@@ -218,6 +242,12 @@ const ConsoleContent: React.FC = () => {
|
|||||||
<RevenueManagement />
|
<RevenueManagement />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
case TabKey.RESOURCE_GROUP:
|
||||||
|
return (
|
||||||
|
<div className="h-full overflow-auto">
|
||||||
|
<ResourceGroupManagement />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
default:
|
default:
|
||||||
return showOnboarding ? (
|
return showOnboarding ? (
|
||||||
<OnboardingWelcome
|
<OnboardingWelcome
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import React from "react";
|
|||||||
import { StripeConfigForm } from "../payment/StripeConfigForm";
|
import { StripeConfigForm } from "../payment/StripeConfigForm";
|
||||||
import { AlipayConfigForm } from "../payment/AlipayConfigForm";
|
import { AlipayConfigForm } from "../payment/AlipayConfigForm";
|
||||||
import { WechatConfigForm } from "../payment/WechatConfigForm";
|
import { WechatConfigForm } from "../payment/WechatConfigForm";
|
||||||
|
import { EpayConfigForm } from "../payment/EpayConfigForm";
|
||||||
import { usePaymentChannelManagement } from "@/hooks/usePaymentChannelManagement";
|
import { usePaymentChannelManagement } from "@/hooks/usePaymentChannelManagement";
|
||||||
|
|
||||||
interface PaymentChannelsContentProps {
|
interface PaymentChannelsContentProps {
|
||||||
@@ -17,12 +18,15 @@ export const PaymentChannelsContent: React.FC<PaymentChannelsContentProps> = ({
|
|||||||
stripeConfig,
|
stripeConfig,
|
||||||
alipayConfig,
|
alipayConfig,
|
||||||
wechatConfig,
|
wechatConfig,
|
||||||
|
epayConfig,
|
||||||
isWechatSaving,
|
isWechatSaving,
|
||||||
isStripeSaving,
|
isStripeSaving,
|
||||||
isAlipaySaving,
|
isAlipaySaving,
|
||||||
|
isEpaySaving,
|
||||||
saveStripeConfig,
|
saveStripeConfig,
|
||||||
saveAlipayConfig,
|
saveAlipayConfig,
|
||||||
saveWechatConfig,
|
saveWechatConfig,
|
||||||
|
saveEpayConfig,
|
||||||
enableChannel,
|
enableChannel,
|
||||||
disableChannel,
|
disableChannel,
|
||||||
} = usePaymentChannelManagement();
|
} = usePaymentChannelManagement();
|
||||||
@@ -38,6 +42,15 @@ export const PaymentChannelsContent: React.FC<PaymentChannelsContentProps> = ({
|
|||||||
isLoading={isStripeSaving}
|
isLoading={isStripeSaving}
|
||||||
labelPlacement={labelPlacement}
|
labelPlacement={labelPlacement}
|
||||||
/>
|
/>
|
||||||
|
{/* epay (易支付) configuration */}
|
||||||
|
<EpayConfigForm
|
||||||
|
config={epayConfig}
|
||||||
|
onSave={saveEpayConfig}
|
||||||
|
onEnable={enableChannel}
|
||||||
|
onDisable={disableChannel}
|
||||||
|
isLoading={isEpaySaving}
|
||||||
|
labelPlacement={labelPlacement}
|
||||||
|
/>
|
||||||
{/* coming soon */}
|
{/* coming soon */}
|
||||||
{/* alipay configuration */}
|
{/* alipay configuration */}
|
||||||
{/* <AlipayConfigForm
|
{/* <AlipayConfigForm
|
||||||
|
|||||||
@@ -0,0 +1,173 @@
|
|||||||
|
"use client";
|
||||||
|
import React, { useEffect, useState } from "react";
|
||||||
|
import { fetchAdminAPI } from "@/rpc/admin-api";
|
||||||
|
|
||||||
|
interface Metadata {
|
||||||
|
base_url?: string;
|
||||||
|
service_type?: string;
|
||||||
|
tags?: string;
|
||||||
|
charge_type?: string;
|
||||||
|
price?: number;
|
||||||
|
free_daily_limit?: number | null;
|
||||||
|
published_service_id?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Submission {
|
||||||
|
id: string;
|
||||||
|
user_id: string;
|
||||||
|
type: string;
|
||||||
|
name: string;
|
||||||
|
description?: string;
|
||||||
|
file_path?: string;
|
||||||
|
metadata_json?: Metadata | null;
|
||||||
|
status: string;
|
||||||
|
created_at?: string;
|
||||||
|
review_note?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const statusColor: Record<string, string> = {
|
||||||
|
pending: "bg-yellow-100 text-yellow-800",
|
||||||
|
approved: "bg-green-100 text-green-800",
|
||||||
|
rejected: "bg-red-100 text-red-800",
|
||||||
|
};
|
||||||
|
|
||||||
|
export function SubmissionsManagement() {
|
||||||
|
const [subs, setSubs] = useState<Submission[]>([]);
|
||||||
|
const [filter, setFilter] = useState<string>("");
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
const [error, setError] = useState("");
|
||||||
|
const [rejectNote, setRejectNote] = useState<Record<string, string>>({});
|
||||||
|
|
||||||
|
const load = async () => {
|
||||||
|
setLoading(true);
|
||||||
|
setError("");
|
||||||
|
try {
|
||||||
|
const qs = filter ? `?status=${filter}` : "";
|
||||||
|
// fetchAdminAPI<T> already returns the { success, error_message, data } envelope
|
||||||
|
const response = await fetchAdminAPI<Submission[]>(
|
||||||
|
`/api/submission/admin/submissions${qs}`
|
||||||
|
);
|
||||||
|
if (response?.success === false) {
|
||||||
|
setError(response.error_message || "加载失败");
|
||||||
|
setSubs([]);
|
||||||
|
} else if (response?.data) {
|
||||||
|
setSubs(response.data);
|
||||||
|
} else {
|
||||||
|
setSubs([]);
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
setError("加载失败:" + (err as Error).message);
|
||||||
|
setSubs([]);
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => { load(); }, [filter]);
|
||||||
|
|
||||||
|
const act = async (id: string, action: "approve" | "reject") => {
|
||||||
|
const body: RequestInit =
|
||||||
|
action === "approve"
|
||||||
|
? { method: "PUT" }
|
||||||
|
: {
|
||||||
|
method: "PUT",
|
||||||
|
headers: { "Content-Type": "application/json" },
|
||||||
|
body: JSON.stringify({ note: rejectNote[id] || "" }),
|
||||||
|
};
|
||||||
|
await fetchAdminAPI(`/api/submission/admin/submission/${id}/${action}`, body);
|
||||||
|
load();
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="max-w-6xl mx-auto p-6">
|
||||||
|
<div className="flex items-center justify-between mb-4">
|
||||||
|
<h1 className="text-2xl font-bold">投稿审核</h1>
|
||||||
|
<select value={filter} onChange={(e) => setFilter(e.target.value)} className="border p-2">
|
||||||
|
<option value="">全部</option>
|
||||||
|
<option value="pending">待审核</option>
|
||||||
|
<option value="approved">已通过</option>
|
||||||
|
<option value="rejected">已拒绝</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{error && <div className="mb-4 p-3 bg-red-50 text-red-700 rounded">{error}</div>}
|
||||||
|
{loading && <div className="mb-4 text-gray-500">加载中...</div>}
|
||||||
|
{!loading && !error && subs.length === 0 && (
|
||||||
|
<div className="mb-4 text-gray-500">暂无提交记录</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<div className="space-y-4">
|
||||||
|
{subs.map((s) => {
|
||||||
|
const meta = s.metadata_json || {};
|
||||||
|
return (
|
||||||
|
<div key={s.id} className="border rounded p-4 space-y-2">
|
||||||
|
<div className="flex items-center justify-between">
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<span className="font-semibold">{s.name}</span>
|
||||||
|
<span className="px-2 py-0.5 rounded text-xs">{s.type}</span>
|
||||||
|
<span className={`px-2 py-0.5 rounded text-xs ${statusColor[s.status] || "bg-gray-100"}`}>{s.status}</span>
|
||||||
|
</div>
|
||||||
|
<span className="text-sm text-gray-500">{s.created_at?.slice(0, 19).replace("T", " ")}</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{s.description && <p className="text-sm text-gray-700">{s.description}</p>}
|
||||||
|
|
||||||
|
{s.type === "mcp" && (meta.base_url || meta.tags || meta.charge_type) && (
|
||||||
|
<div className="text-sm text-gray-600 bg-gray-50 rounded p-2 space-y-1">
|
||||||
|
{meta.base_url && <div>服务地址:<code className="text-xs">{meta.base_url}</code></div>}
|
||||||
|
{meta.tags && <div>标签:{meta.tags}</div>}
|
||||||
|
<div>
|
||||||
|
计费:
|
||||||
|
{meta.charge_type === "paid"
|
||||||
|
? `按次付费 ¥${meta.price ?? 0}/次`
|
||||||
|
: `免费${meta.free_daily_limit ? `(每日 ${meta.free_daily_limit} 次)` : "(不限次)"}`}
|
||||||
|
</div>
|
||||||
|
{meta.published_service_id && (
|
||||||
|
<div className="text-green-700">
|
||||||
|
已上架市场,服务 ID:<code className="text-xs">{meta.published_service_id}</code>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{s.file_path && (
|
||||||
|
<div className="text-sm text-gray-500">
|
||||||
|
附件:<code className="text-xs">{s.file_path}</code>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{s.review_note && (
|
||||||
|
<div className="text-sm text-gray-600">审核备注:{s.review_note}</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{s.status === "pending" ? (
|
||||||
|
<div className="space-y-2">
|
||||||
|
<input
|
||||||
|
value={rejectNote[s.id] || ""}
|
||||||
|
onChange={(e) => setRejectNote({ ...rejectNote, [s.id]: e.target.value })}
|
||||||
|
placeholder="拒绝原因(可选)"
|
||||||
|
className="border p-2 w-full text-sm"
|
||||||
|
/>
|
||||||
|
<div className="flex gap-2">
|
||||||
|
<button
|
||||||
|
onClick={() => act(s.id, "approve")}
|
||||||
|
className="bg-green-600 text-white px-3 py-1 rounded text-sm"
|
||||||
|
>
|
||||||
|
通过(自动上架)
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
onClick={() => act(s.id, "reject")}
|
||||||
|
className="bg-red-600 text-white px-3 py-1 rounded text-sm"
|
||||||
|
>
|
||||||
|
拒绝
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -26,6 +26,7 @@ import {
|
|||||||
Captions,
|
Captions,
|
||||||
Code,
|
Code,
|
||||||
CreditCard,
|
CreditCard,
|
||||||
|
Gauge,
|
||||||
GhostIcon,
|
GhostIcon,
|
||||||
GlobeIcon,
|
GlobeIcon,
|
||||||
LockIcon,
|
LockIcon,
|
||||||
@@ -34,6 +35,7 @@ import {
|
|||||||
Palette,
|
Palette,
|
||||||
SquareMenu,
|
SquareMenu,
|
||||||
TableOfContents,
|
TableOfContents,
|
||||||
|
Tags,
|
||||||
Trello,
|
Trello,
|
||||||
XIcon,
|
XIcon,
|
||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
@@ -161,6 +163,12 @@ const SystemSettingsModal: React.FC<SystemSettingsModalProps> = ({
|
|||||||
icon: <SquareMenu size={16} />,
|
icon: <SquareMenu size={16} />,
|
||||||
description: "Configure site navigation and menus",
|
description: "Configure site navigation and menus",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
key: SettingModalTab.TAGS_BAR,
|
||||||
|
label: "Tags Bar",
|
||||||
|
icon: <Tags size={16} />,
|
||||||
|
description: "Configure tags bar display",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
key: SettingModalTab.FAQ,
|
key: SettingModalTab.FAQ,
|
||||||
label: "FAQ",
|
label: "FAQ",
|
||||||
@@ -174,6 +182,12 @@ const SystemSettingsModal: React.FC<SystemSettingsModalProps> = ({
|
|||||||
icon: <CreditCard size={16} />,
|
icon: <CreditCard size={16} />,
|
||||||
description: "Configure payment channels",
|
description: "Configure payment channels",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
key: SettingModalTab.FREE_QUOTA,
|
||||||
|
label: "Free Call Limits",
|
||||||
|
icon: <Gauge size={16} />,
|
||||||
|
description: "Global daily call cap for free services",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
key: SettingModalTab.XPACK_EXPLORE,
|
key: SettingModalTab.XPACK_EXPLORE,
|
||||||
label: "XPack Explore",
|
label: "XPack Explore",
|
||||||
@@ -240,6 +254,7 @@ const SystemSettingsModal: React.FC<SystemSettingsModalProps> = ({
|
|||||||
items: groupItems([
|
items: groupItems([
|
||||||
SettingModalTab.THEME,
|
SettingModalTab.THEME,
|
||||||
SettingModalTab.NAVIGATION,
|
SettingModalTab.NAVIGATION,
|
||||||
|
SettingModalTab.TAGS_BAR,
|
||||||
SettingModalTab.FAQ,
|
SettingModalTab.FAQ,
|
||||||
]),
|
]),
|
||||||
},
|
},
|
||||||
@@ -248,6 +263,7 @@ const SystemSettingsModal: React.FC<SystemSettingsModalProps> = ({
|
|||||||
title: "Business",
|
title: "Business",
|
||||||
items: groupItems([
|
items: groupItems([
|
||||||
SettingModalTab.PAYMENT,
|
SettingModalTab.PAYMENT,
|
||||||
|
SettingModalTab.FREE_QUOTA,
|
||||||
SettingModalTab.XPACK_EXPLORE,
|
SettingModalTab.XPACK_EXPLORE,
|
||||||
]),
|
]),
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -31,6 +31,8 @@ import { AdminConfig, EmailConfig } from "@/types/system";
|
|||||||
import { LoginSettingsContent } from "./LoginSettingsContent";
|
import { LoginSettingsContent } from "./LoginSettingsContent";
|
||||||
import { EmailConfigForm } from "@/components/system-setting/EmailConfigForm";
|
import { EmailConfigForm } from "@/components/system-setting/EmailConfigForm";
|
||||||
import { LanguageSetting } from "@/components/system-setting/LanguageSetting";
|
import { LanguageSetting } from "@/components/system-setting/LanguageSetting";
|
||||||
|
import { FreeQuotaSettings } from "@/components/system-setting/FreeQuotaSettings";
|
||||||
|
import { TagsBarSetting } from "../system-setting/TagsBarSetting";
|
||||||
|
|
||||||
interface SystemSettingsRightContentProps {
|
interface SystemSettingsRightContentProps {
|
||||||
filteredKeys: string[];
|
filteredKeys: string[];
|
||||||
@@ -201,6 +203,13 @@ const SystemSettingsRightContent: React.FC<SystemSettingsRightContentProps> = ({
|
|||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{section.key === "tagsBar" && (
|
||||||
|
<TagsBarSetting
|
||||||
|
isEnabled={!!platformConfig.tag_bar_display}
|
||||||
|
onSave={onSavePlatformConfig}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
{section.key === "faq" && (
|
{section.key === "faq" && (
|
||||||
<FaqSettings
|
<FaqSettings
|
||||||
onSave={saveFaqConfig}
|
onSave={saveFaqConfig}
|
||||||
@@ -213,6 +222,8 @@ const SystemSettingsRightContent: React.FC<SystemSettingsRightContentProps> = ({
|
|||||||
<PaymentChannelsContent labelPlacement="outside" />
|
<PaymentChannelsContent labelPlacement="outside" />
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{section.key === "free-quota" && <FreeQuotaSettings />}
|
||||||
|
|
||||||
{section.key === "xpack-explore" && (
|
{section.key === "xpack-explore" && (
|
||||||
<ExplorePanel
|
<ExplorePanel
|
||||||
isEnabled={!!platformConfig.is_showcased}
|
isEnabled={!!platformConfig.is_showcased}
|
||||||
|
|||||||
@@ -5,9 +5,11 @@ export enum SettingModalTab {
|
|||||||
BRANDING = "branding",
|
BRANDING = "branding",
|
||||||
THEME = "theme",
|
THEME = "theme",
|
||||||
PAYMENT = "payment",
|
PAYMENT = "payment",
|
||||||
|
FREE_QUOTA = "free-quota",
|
||||||
CODE_INJECTION = "code-injection",
|
CODE_INJECTION = "code-injection",
|
||||||
XPACK_EXPLORE = "xpack-explore",
|
XPACK_EXPLORE = "xpack-explore",
|
||||||
NAVIGATION = "navigation",
|
NAVIGATION = "navigation",
|
||||||
|
TAGS_BAR = "tagsBar",
|
||||||
FAQ = "faq",
|
FAQ = "faq",
|
||||||
CHANGE_PASSWORD = "change-password",
|
CHANGE_PASSWORD = "change-password",
|
||||||
EMAIL_LOGIN_SETTINGS = "email-login-settings",
|
EMAIL_LOGIN_SETTINGS = "email-login-settings",
|
||||||
|
|||||||
@@ -7,11 +7,13 @@ import { useTranslation } from "@/shared/lib/useTranslation";
|
|||||||
interface CustomDomainPanelProps {
|
interface CustomDomainPanelProps {
|
||||||
domain: string;
|
domain: string;
|
||||||
setDomain: (domain: string) => void;
|
setDomain: (domain: string) => void;
|
||||||
|
onValidationChange?: (isValid: boolean) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const CustomDomainPanel: React.FC<CustomDomainPanelProps> = ({
|
const CustomDomainPanel: React.FC<CustomDomainPanelProps> = ({
|
||||||
domain,
|
domain,
|
||||||
setDomain,
|
setDomain,
|
||||||
|
onValidationChange,
|
||||||
}) => {
|
}) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const [validationError, setValidationError] = useState<string | undefined>();
|
const [validationError, setValidationError] = useState<string | undefined>();
|
||||||
@@ -24,7 +26,7 @@ const CustomDomainPanel: React.FC<CustomDomainPanelProps> = ({
|
|||||||
|
|
||||||
// Basic domain format validation ,like www.example.com
|
// Basic domain format validation ,like www.example.com
|
||||||
const domainRegex =
|
const domainRegex =
|
||||||
/(?=.{1,255}$)(?:(?!-)[a-zA-Z0-9-]{1,63}(?<!-)\.)+[a-zA-Z]{2,}/;
|
/^(?:(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,})$/;
|
||||||
if (!domainRegex.test(value)) {
|
if (!domainRegex.test(value)) {
|
||||||
return t("Please enter a valid domain");
|
return t("Please enter a valid domain");
|
||||||
}
|
}
|
||||||
@@ -34,6 +36,17 @@ const CustomDomainPanel: React.FC<CustomDomainPanelProps> = ({
|
|||||||
const handleBlur = () => {
|
const handleBlur = () => {
|
||||||
const error = validateDomain(domain);
|
const error = validateDomain(domain);
|
||||||
setValidationError(error);
|
setValidationError(error);
|
||||||
|
// 通知父组件校验状态
|
||||||
|
onValidationChange?.(!error);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
|
const value = e.target.value;
|
||||||
|
setDomain(value);
|
||||||
|
// 实时校验
|
||||||
|
const error = validateDomain(value);
|
||||||
|
setValidationError(error);
|
||||||
|
onValidationChange?.(!error);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -48,7 +61,7 @@ const CustomDomainPanel: React.FC<CustomDomainPanelProps> = ({
|
|||||||
label={t("Domain")}
|
label={t("Domain")}
|
||||||
placeholder={t("Enter your full domain name (e.g., www.example.com)")}
|
placeholder={t("Enter your full domain name (e.g., www.example.com)")}
|
||||||
value={domain}
|
value={domain}
|
||||||
onChange={(e) => setDomain(e.target.value)}
|
onChange={handleChange}
|
||||||
onBlur={handleBlur}
|
onBlur={handleBlur}
|
||||||
isInvalid={!!validationError}
|
isInvalid={!!validationError}
|
||||||
errorMessage={validationError}
|
errorMessage={validationError}
|
||||||
|
|||||||
@@ -36,6 +36,8 @@ const DomainActivationPanel: React.FC<DomainActivationPanelProps> = ({
|
|||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
const [domain, setDomain] = useState(config.domain || "");
|
const [domain, setDomain] = useState(config.domain || "");
|
||||||
|
const [isValidDomain, setIsValidDomain] = useState(false);
|
||||||
|
|
||||||
const handleActivate = async () => {
|
const handleActivate = async () => {
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
try {
|
try {
|
||||||
@@ -54,7 +56,11 @@ const DomainActivationPanel: React.FC<DomainActivationPanelProps> = ({
|
|||||||
<ModalContent>
|
<ModalContent>
|
||||||
<ModalHeader>{t("Set Custom Domain")}</ModalHeader>
|
<ModalHeader>{t("Set Custom Domain")}</ModalHeader>
|
||||||
<ModalBody className="flex flex-col gap-4">
|
<ModalBody className="flex flex-col gap-4">
|
||||||
<CustomDomainPanel domain={domain} setDomain={setDomain} />
|
<CustomDomainPanel
|
||||||
|
domain={domain}
|
||||||
|
setDomain={setDomain}
|
||||||
|
onValidationChange={setIsValidDomain}
|
||||||
|
/>
|
||||||
<DNSRecordsPanel
|
<DNSRecordsPanel
|
||||||
cnameTarget={`${config.subdomain || ""}${process.env.NEXT_PUBLIC_DOMAIN_HOST || ""}`}
|
cnameTarget={`${config.subdomain || ""}${process.env.NEXT_PUBLIC_DOMAIN_HOST || ""}`}
|
||||||
apexATarget={config.cname_a_ip}
|
apexATarget={config.cname_a_ip}
|
||||||
@@ -67,7 +73,7 @@ const DomainActivationPanel: React.FC<DomainActivationPanelProps> = ({
|
|||||||
</h3>
|
</h3>
|
||||||
<Button
|
<Button
|
||||||
color="primary"
|
color="primary"
|
||||||
isDisabled={!domain}
|
isDisabled={!domain || !isValidDomain}
|
||||||
isLoading={isLoading}
|
isLoading={isLoading}
|
||||||
onPress={handleActivate}
|
onPress={handleActivate}
|
||||||
size="sm"
|
size="sm"
|
||||||
|
|||||||
@@ -64,7 +64,12 @@ export const APIKeyModal = ({
|
|||||||
|
|
||||||
if (!response.success) {
|
if (!response.success) {
|
||||||
console.error("Error creating auth key:", response.error_message);
|
console.error("Error creating auth key:", response.error_message);
|
||||||
toast.error(t("Failed to create auth key"));
|
const errorMsg = response.error_message
|
||||||
|
if (errorMsg?.endsWith('already exists')) {
|
||||||
|
toast.error(t(errorMsg, { name: keyName }));
|
||||||
|
} else {
|
||||||
|
toast.error(t("Failed to create auth key"));
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,7 +84,12 @@ export const APIKeyModal = ({
|
|||||||
|
|
||||||
if (!response.success) {
|
if (!response.success) {
|
||||||
console.error("Error updating auth key:", response.error_message);
|
console.error("Error updating auth key:", response.error_message);
|
||||||
toast.error(t("Failed to update auth key"));
|
const errorMsg = response.error_message
|
||||||
|
if (errorMsg?.endsWith('already exists')) {
|
||||||
|
toast.error(t(errorMsg, { name: keyName }));
|
||||||
|
} else {
|
||||||
|
toast.error(t("Failed to update auth key"));
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,6 +100,7 @@ export const APIKeyModal = ({
|
|||||||
toast.success(t("Auth key updated successfully"));
|
toast.success(t("Auth key updated successfully"));
|
||||||
onClose();
|
onClose();
|
||||||
}
|
}
|
||||||
|
setName('')
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error creating/updating auth key:", error);
|
console.error("Error creating/updating auth key:", error);
|
||||||
toast.error(t("Failed to create/update auth key"));
|
toast.error(t("Failed to create/update auth key"));
|
||||||
|
|||||||
@@ -0,0 +1,388 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import React, { useState, useCallback, useRef, useEffect } from "react";
|
||||||
|
import {
|
||||||
|
Table,
|
||||||
|
TableHeader,
|
||||||
|
TableColumn,
|
||||||
|
TableBody,
|
||||||
|
TableRow,
|
||||||
|
TableCell,
|
||||||
|
Button,
|
||||||
|
Pagination,
|
||||||
|
Tooltip,
|
||||||
|
Spinner,
|
||||||
|
Chip,
|
||||||
|
Dropdown,
|
||||||
|
DropdownTrigger,
|
||||||
|
DropdownMenu,
|
||||||
|
DropdownItem,
|
||||||
|
} from "@nextui-org/react";
|
||||||
|
import { useTranslation } from "@/shared/lib/useTranslation";
|
||||||
|
import { Calendar, HelpCircle, Filter } from "lucide-react";
|
||||||
|
import { fetchAPI } from "@/shared/rpc/common-function";
|
||||||
|
import i18n from "@/shared/lib/i18n";
|
||||||
|
import { toast } from "react-hot-toast";
|
||||||
|
import { fetchAdminAPI } from "@/rpc/admin-api";
|
||||||
|
|
||||||
|
export interface OrderItem {
|
||||||
|
id: string;
|
||||||
|
amount: string;
|
||||||
|
balance: string;
|
||||||
|
order_id: string;
|
||||||
|
// 支付类型,stripe默认值
|
||||||
|
payment_type: string;
|
||||||
|
// 支付状态,0=未支付,1=已支付,2=支付失败
|
||||||
|
payment_state: number;
|
||||||
|
description: string;
|
||||||
|
// 充值时间
|
||||||
|
create_at: string;
|
||||||
|
// 交易时间,确认订单时间,只有充值完成后才有
|
||||||
|
confirm_at: string;
|
||||||
|
// 订单类型,充值(recharge),消费(purchase),退款(refund),冲正(reversal)
|
||||||
|
order_type: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface AccountBalanceTableProps {
|
||||||
|
userId?: string;
|
||||||
|
source?: "client" | "admin";
|
||||||
|
}
|
||||||
|
|
||||||
|
const AccountBalanceTable: React.FC<AccountBalanceTableProps> = ({ userId, source }) => {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
|
||||||
|
const [items, setItems] = useState<OrderItem[]>([]);
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
const [pagination, setPagination] = useState({
|
||||||
|
page: 1,
|
||||||
|
pageSize: 10,
|
||||||
|
total: 0,
|
||||||
|
});
|
||||||
|
const [selectedType, setSelectedType] = useState<string>("all");
|
||||||
|
const [selectedStatus, setSelectedStatus] = useState<string>("all");
|
||||||
|
const resourceGroupsParams = useRef({
|
||||||
|
page: 1,
|
||||||
|
pageSize: 10,
|
||||||
|
keyword: "",
|
||||||
|
orderType: "",
|
||||||
|
status: "",
|
||||||
|
});
|
||||||
|
|
||||||
|
const pages = Math.ceil(pagination.total / pagination.pageSize);
|
||||||
|
const currentPage = Number(pagination.page);
|
||||||
|
|
||||||
|
const fetchOrders = useCallback(
|
||||||
|
async (
|
||||||
|
page: number,
|
||||||
|
page_size: number,
|
||||||
|
order_type?: string,
|
||||||
|
status?: string
|
||||||
|
): Promise<{ data: OrderItem[]; total: number; page: number; page_size: number }> => {
|
||||||
|
try {
|
||||||
|
const params = new URLSearchParams({
|
||||||
|
page: page.toString(),
|
||||||
|
page_size: page_size.toString(),
|
||||||
|
});
|
||||||
|
if (order_type) params.append("order_type", order_type);
|
||||||
|
if (status) params.append("status", status);
|
||||||
|
if (userId) params.append("user_id", userId);
|
||||||
|
|
||||||
|
// 根据是否有 userId 来决定使用哪个 API
|
||||||
|
const apiUrl = userId
|
||||||
|
? `/api/order/list/by_user?${params.toString()}`
|
||||||
|
: `/api/user/order/list?${params.toString()}`;
|
||||||
|
|
||||||
|
const response = source === "client" ? await fetchAPI<OrderItem[]>(apiUrl) : await fetchAdminAPI<OrderItem[]>(apiUrl);
|
||||||
|
if (!response.success) {
|
||||||
|
toast.error(response.error_message || i18n.t("Failed to load orders"));
|
||||||
|
return {
|
||||||
|
data: [],
|
||||||
|
total: 0,
|
||||||
|
page,
|
||||||
|
page_size,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
data: response.data || [],
|
||||||
|
total: response.page?.total || 0,
|
||||||
|
page: response.page?.page || page,
|
||||||
|
page_size: response.page?.page_size || page_size,
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error fetching orders:", error);
|
||||||
|
return {
|
||||||
|
data: [],
|
||||||
|
total: 0,
|
||||||
|
page,
|
||||||
|
page_size,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[userId]
|
||||||
|
);
|
||||||
|
|
||||||
|
const loadOrders = useCallback(
|
||||||
|
async (
|
||||||
|
page: number = 1,
|
||||||
|
pageSize: number = 10,
|
||||||
|
keyword: string = "",
|
||||||
|
orderType: string = "",
|
||||||
|
status: string = ""
|
||||||
|
) => {
|
||||||
|
setLoading(true);
|
||||||
|
try {
|
||||||
|
const response = await fetchOrders(
|
||||||
|
page,
|
||||||
|
pageSize,
|
||||||
|
orderType || undefined,
|
||||||
|
status || undefined
|
||||||
|
);
|
||||||
|
setItems(response.data);
|
||||||
|
setPagination({
|
||||||
|
page: response.page,
|
||||||
|
pageSize: response.page_size,
|
||||||
|
total: response.total,
|
||||||
|
});
|
||||||
|
resourceGroupsParams.current = {
|
||||||
|
page: response.page,
|
||||||
|
pageSize: response.page_size,
|
||||||
|
keyword,
|
||||||
|
orderType,
|
||||||
|
status,
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
console.error(t("Failed to load orders"), error);
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[fetchOrders]
|
||||||
|
);
|
||||||
|
|
||||||
|
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>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
// 格式化金额,带正负号和人民币符号
|
||||||
|
const formatAmount = (amount: string | number): string => {
|
||||||
|
const numAmount = typeof amount === 'string' ? parseFloat(amount) : amount;
|
||||||
|
if (isNaN(numAmount)) return '¥0.00';
|
||||||
|
const absAmount = Math.abs(numAmount).toFixed(2);
|
||||||
|
if (numAmount > 0) {
|
||||||
|
return `+¥${absAmount}`;
|
||||||
|
} else if (numAmount < 0) {
|
||||||
|
return `-¥${absAmount}`;
|
||||||
|
}
|
||||||
|
return `¥${absAmount}`;
|
||||||
|
};
|
||||||
|
|
||||||
|
// 格式化余额,只显示人民币符号,不带正负号
|
||||||
|
const formatBalance = (balance: string | number): string => {
|
||||||
|
const numBalance = typeof balance === 'string' ? parseFloat(balance) : balance;
|
||||||
|
if (isNaN(numBalance)) return '¥0.00';
|
||||||
|
|
||||||
|
return `¥${Math.abs(numBalance).toFixed(2)}`;
|
||||||
|
};
|
||||||
|
|
||||||
|
const getStatusColor = (status: number) => {
|
||||||
|
switch (status) {
|
||||||
|
case 1:
|
||||||
|
return "success";
|
||||||
|
case 2:
|
||||||
|
return "danger";
|
||||||
|
default:
|
||||||
|
return "warning";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const onPageChange = (page: number) => {
|
||||||
|
const { pageSize, orderType, status } = resourceGroupsParams.current;
|
||||||
|
loadOrders(page, pageSize, "", orderType, status);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleTypeChange = (value: string) => {
|
||||||
|
setSelectedType(value);
|
||||||
|
const orderType = value === "all" ? "" : value;
|
||||||
|
const { status } = resourceGroupsParams.current;
|
||||||
|
loadOrders(1, pagination.pageSize, "", orderType, status);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleStatusChange = (value: string) => {
|
||||||
|
setSelectedStatus(value);
|
||||||
|
const status = value === "all" ? "" : value;
|
||||||
|
const { orderType } = resourceGroupsParams.current;
|
||||||
|
loadOrders(1, pagination.pageSize, "", orderType, status);
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
loadOrders(1, 10, "");
|
||||||
|
}, [loadOrders]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="space-y-4">
|
||||||
|
<Table
|
||||||
|
aria-label="Orders table"
|
||||||
|
classNames={{
|
||||||
|
wrapper: "min-h-[400px]",
|
||||||
|
}}
|
||||||
|
removeWrapper
|
||||||
|
>
|
||||||
|
<TableHeader>
|
||||||
|
<TableColumn>
|
||||||
|
<div className="flex items-center gap-1">
|
||||||
|
<span>{t("Transaction Time")}</span>
|
||||||
|
</div>
|
||||||
|
</TableColumn>
|
||||||
|
<TableColumn>
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<span>{t("Type")}</span>
|
||||||
|
<Dropdown>
|
||||||
|
<DropdownTrigger>
|
||||||
|
<Button
|
||||||
|
isIconOnly
|
||||||
|
size="sm"
|
||||||
|
variant="light"
|
||||||
|
aria-label="Filter by type"
|
||||||
|
>
|
||||||
|
<Filter
|
||||||
|
className={`w-4 h-4 ${
|
||||||
|
selectedType !== "all" ? "text-primary" : ""
|
||||||
|
}`}
|
||||||
|
/>
|
||||||
|
</Button>
|
||||||
|
</DropdownTrigger>
|
||||||
|
<DropdownMenu
|
||||||
|
aria-label="Type filter"
|
||||||
|
selectionMode="single"
|
||||||
|
selectedKeys={[selectedType]}
|
||||||
|
onSelectionChange={(keys) => {
|
||||||
|
const selected = Array.from(keys)[0] as string;
|
||||||
|
handleTypeChange(selected);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<DropdownItem key="all">{t("All")}</DropdownItem>
|
||||||
|
<DropdownItem key="recharge">{t("Recharge")}</DropdownItem>
|
||||||
|
<DropdownItem key="purchase">{t("Purchase")}</DropdownItem>
|
||||||
|
</DropdownMenu>
|
||||||
|
</Dropdown>
|
||||||
|
</div>
|
||||||
|
</TableColumn>
|
||||||
|
<TableColumn>{t("Description")}</TableColumn>
|
||||||
|
<TableColumn>{t("Amount")}</TableColumn>
|
||||||
|
<TableColumn>{t("Balance")}</TableColumn>
|
||||||
|
<TableColumn>
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<span>{t("Status")}</span>
|
||||||
|
<Dropdown>
|
||||||
|
<DropdownTrigger>
|
||||||
|
<Button
|
||||||
|
isIconOnly
|
||||||
|
size="sm"
|
||||||
|
variant="light"
|
||||||
|
aria-label="Filter by status"
|
||||||
|
>
|
||||||
|
<Filter
|
||||||
|
className={`w-4 h-4 ${
|
||||||
|
selectedStatus !== "all" ? "text-primary" : ""
|
||||||
|
}`}
|
||||||
|
/>
|
||||||
|
</Button>
|
||||||
|
</DropdownTrigger>
|
||||||
|
<DropdownMenu
|
||||||
|
aria-label="Status filter"
|
||||||
|
selectionMode="single"
|
||||||
|
selectedKeys={[selectedStatus]}
|
||||||
|
onSelectionChange={(keys) => {
|
||||||
|
const selected = Array.from(keys)[0] as string;
|
||||||
|
handleStatusChange(selected);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<DropdownItem key="all">{t("All")}</DropdownItem>
|
||||||
|
<DropdownItem key="0">{t("Pending")}</DropdownItem>
|
||||||
|
<DropdownItem key="1">{t("Completed")}</DropdownItem>
|
||||||
|
<DropdownItem key="2">{t("Failed")}</DropdownItem>
|
||||||
|
</DropdownMenu>
|
||||||
|
</Dropdown>
|
||||||
|
</div>
|
||||||
|
</TableColumn>
|
||||||
|
</TableHeader>
|
||||||
|
<TableBody
|
||||||
|
items={items}
|
||||||
|
isLoading={loading}
|
||||||
|
loadingContent={<Spinner />}
|
||||||
|
emptyContent={t("No orders found")}
|
||||||
|
>
|
||||||
|
{(order) => (
|
||||||
|
<TableRow key={order.id}>
|
||||||
|
<TableCell>{formatDate(order.payment_state === 0 ? order.create_at : order.confirm_at)}</TableCell>
|
||||||
|
<TableCell>
|
||||||
|
<span
|
||||||
|
className={
|
||||||
|
order.order_type === "recharge"
|
||||||
|
? "text-green-500"
|
||||||
|
: "text-red-500"
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{
|
||||||
|
order.order_type === "recharge" ? t("Recharge") : t("Purchase")
|
||||||
|
}
|
||||||
|
</span>
|
||||||
|
</TableCell>
|
||||||
|
<TableCell>{order.description}</TableCell>
|
||||||
|
<TableCell>
|
||||||
|
<span
|
||||||
|
className={
|
||||||
|
order.order_type === "recharge"
|
||||||
|
? "text-green-500"
|
||||||
|
: "text-red-500"
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{formatAmount(order.amount)}
|
||||||
|
</span>
|
||||||
|
</TableCell>
|
||||||
|
<TableCell>{formatBalance(order.balance)}</TableCell>
|
||||||
|
<TableCell>
|
||||||
|
<Chip
|
||||||
|
className="capitalize"
|
||||||
|
color={getStatusColor(order.payment_state)}
|
||||||
|
size="sm"
|
||||||
|
variant="flat"
|
||||||
|
>
|
||||||
|
{t(
|
||||||
|
order.payment_state === 1
|
||||||
|
? "Completed"
|
||||||
|
: order.payment_state === 2
|
||||||
|
? "Failed"
|
||||||
|
: "Pending"
|
||||||
|
)}
|
||||||
|
</Chip>
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
)}
|
||||||
|
</TableBody>
|
||||||
|
</Table>
|
||||||
|
|
||||||
|
{pages > 1 && (
|
||||||
|
<div className="flex w-full justify-center">
|
||||||
|
<Pagination
|
||||||
|
showControls
|
||||||
|
color="primary"
|
||||||
|
variant="light"
|
||||||
|
page={currentPage}
|
||||||
|
total={pages}
|
||||||
|
onChange={onPageChange}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default AccountBalanceTable;
|
||||||
@@ -53,6 +53,10 @@ const OverviewPage: React.FC = () => {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetchApiKeys();
|
fetchApiKeys();
|
||||||
|
if (sessionStorage.getItem('create_new_authorization')) {
|
||||||
|
handleNewKey();
|
||||||
|
sessionStorage.removeItem('create_new_authorization');
|
||||||
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
// create new auth key
|
// create new auth key
|
||||||
|
|||||||
@@ -11,8 +11,9 @@ import { formatCurrency } from "@/shared/utils/currency";
|
|||||||
// Import dashboard content components
|
// Import dashboard content components
|
||||||
import DashboardOverview from "@/components/dashboard/DashboardOverview";
|
import DashboardOverview from "@/components/dashboard/DashboardOverview";
|
||||||
import WalletManagement from "@/components/wallet/WalletManagement";
|
import WalletManagement from "@/components/wallet/WalletManagement";
|
||||||
import { Home, Key, Wallet } from "lucide-react";
|
import UserAccountBalance from "@/components/dashboard/UserAccountBalance";
|
||||||
import { Avatar, Card, CardBody, Button, Divider } from "@nextui-org/react";
|
import { Home, Key, Wallet, Rocket } from "lucide-react";
|
||||||
|
import { Avatar, Card, CardBody, Button, Divider, Link } from "@nextui-org/react";
|
||||||
import { RechargeModal } from "@/shared/components/modal/RechargeModal";
|
import { RechargeModal } from "@/shared/components/modal/RechargeModal";
|
||||||
import { useTranslation } from "@/shared/lib/useTranslation";
|
import { useTranslation } from "@/shared/lib/useTranslation";
|
||||||
import { ChangePasswordModal } from "@/components/common/ChangePasswordModal";
|
import { ChangePasswordModal } from "@/components/common/ChangePasswordModal";
|
||||||
@@ -41,7 +42,7 @@ const DashboardContent: React.FC = () => {
|
|||||||
const [isRechargeModalOpen, setIsRechargeModalOpen] = useState(false);
|
const [isRechargeModalOpen, setIsRechargeModalOpen] = useState(false);
|
||||||
const getInitialTab = (): TabKey => {
|
const getInitialTab = (): TabKey => {
|
||||||
const tabFromUrl = searchParams.get("tab") as TabKey;
|
const tabFromUrl = searchParams.get("tab") as TabKey;
|
||||||
if (tabFromUrl && [TabKey.OVERVIEW, TabKey.WALLET].includes(tabFromUrl)) {
|
if (tabFromUrl && [TabKey.OVERVIEW, TabKey.WALLET, TabKey.USER_ACCOUNT].includes(tabFromUrl)) {
|
||||||
return tabFromUrl;
|
return tabFromUrl;
|
||||||
}
|
}
|
||||||
return TabKey.OVERVIEW;
|
return TabKey.OVERVIEW;
|
||||||
@@ -91,9 +92,20 @@ const DashboardContent: React.FC = () => {
|
|||||||
label: "Dashboard",
|
label: "Dashboard",
|
||||||
description: "Manage your integration and auth key",
|
description: "Manage your integration and auth key",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
key: "publish-service",
|
||||||
|
icon: <Rocket className="w-5 h-5" />,
|
||||||
|
label: "Publish MCP Service",
|
||||||
|
description: "Submit your own MCP service",
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const handleTabNavigate = (tab: TabKey | string) => {
|
const handleTabNavigate = (tab: TabKey | string) => {
|
||||||
|
// 发布 MCP 服务:跳转到独立提交页
|
||||||
|
if (tab === "publish-service") {
|
||||||
|
router.push("/submit");
|
||||||
|
return;
|
||||||
|
}
|
||||||
setActiveTab(tab as TabKey);
|
setActiveTab(tab as TabKey);
|
||||||
// update url params
|
// update url params
|
||||||
if (tab === TabKey.OVERVIEW) {
|
if (tab === TabKey.OVERVIEW) {
|
||||||
@@ -158,8 +170,15 @@ const DashboardContent: React.FC = () => {
|
|||||||
<Wallet size={16} />
|
<Wallet size={16} />
|
||||||
<span>
|
<span>
|
||||||
{t("Balance: {{amount}}", {
|
{t("Balance: {{amount}}", {
|
||||||
amount: formatCurrency(user?.wallet?.balance || 0),
|
amount: "",
|
||||||
})}
|
}).replace("{{amount}}", "")}
|
||||||
|
<Link
|
||||||
|
href="#"
|
||||||
|
className="text-xs cursor-pointer"
|
||||||
|
onPress={() => handleTabNavigate(TabKey.USER_ACCOUNT)}
|
||||||
|
>
|
||||||
|
{formatCurrency(user?.wallet?.balance || 0)}
|
||||||
|
</Link>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -187,6 +206,7 @@ const DashboardContent: React.FC = () => {
|
|||||||
{activeTab === TabKey.WALLET && (
|
{activeTab === TabKey.WALLET && (
|
||||||
<WalletManagement onRecharge={() => setIsRechargeModalOpen(true)} />
|
<WalletManagement onRecharge={() => setIsRechargeModalOpen(true)} />
|
||||||
)}
|
)}
|
||||||
|
{activeTab === TabKey.USER_ACCOUNT && <UserAccountBalance />}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import React from "react";
|
||||||
|
import { useTranslation } from "@/shared/lib/useTranslation";
|
||||||
|
import DashboardDemoContent from "@/shared/components/DashboardDemoContent";
|
||||||
|
import AccountBalanceTable from "./AccountBalanceTable";
|
||||||
|
|
||||||
|
const UserAccountBalance: React.FC = () => {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<DashboardDemoContent
|
||||||
|
title={t("Account Balance")}
|
||||||
|
description={t("View your balance and transaction history")}
|
||||||
|
>
|
||||||
|
<div className="space-y-6 w-full">
|
||||||
|
<AccountBalanceTable source="client" />
|
||||||
|
</div>
|
||||||
|
</DashboardDemoContent>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default UserAccountBalance;
|
||||||
@@ -4,12 +4,19 @@ import React, { useState, useEffect } from "react";
|
|||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
import { HeroSection } from "../../shared/components/marketplace/HeroSection";
|
import { HeroSection } from "../../shared/components/marketplace/HeroSection";
|
||||||
import { ServiceListSection } from "@/shared/components/marketplace/ServiceListSection";
|
import { ServiceListSection } from "@/shared/components/marketplace/ServiceListSection";
|
||||||
|
import { TagFilter } from "@/shared/components/marketplace/TagFilter";
|
||||||
import { ServiceData } from "@/shared/types/marketplace";
|
import { ServiceData } from "@/shared/types/marketplace";
|
||||||
import { fetchServices } from "@/services/marketplaceService";
|
import { fetchServices } from "@/services/marketplaceService";
|
||||||
import { Spinner } from "@nextui-org/react";
|
import { Spinner } from "@nextui-org/react";
|
||||||
|
import { ThemeType } from "@/shared/types/system";
|
||||||
|
|
||||||
interface MarketplaceMainProps {
|
interface MarketplaceMainProps {
|
||||||
initialServices: ServiceData[];
|
initialServices: ServiceData[];
|
||||||
|
availableTags: string[];
|
||||||
|
isTagBarDisplay: boolean;
|
||||||
|
selectedTag: string;
|
||||||
|
setSelectedTag: (tag: string) => void;
|
||||||
|
currentTheme: ThemeType;
|
||||||
initialTotal: number;
|
initialTotal: number;
|
||||||
initialPage: number;
|
initialPage: number;
|
||||||
initialSearch: string;
|
initialSearch: string;
|
||||||
@@ -19,6 +26,11 @@ interface MarketplaceMainProps {
|
|||||||
|
|
||||||
export const MarketplaceMain: React.FC<MarketplaceMainProps> = ({
|
export const MarketplaceMain: React.FC<MarketplaceMainProps> = ({
|
||||||
initialServices,
|
initialServices,
|
||||||
|
availableTags,
|
||||||
|
isTagBarDisplay,
|
||||||
|
selectedTag,
|
||||||
|
setSelectedTag,
|
||||||
|
currentTheme,
|
||||||
initialTotal,
|
initialTotal,
|
||||||
initialPage,
|
initialPage,
|
||||||
initialSearch,
|
initialSearch,
|
||||||
@@ -33,16 +45,18 @@ export const MarketplaceMain: React.FC<MarketplaceMainProps> = ({
|
|||||||
const [total, setTotal] = useState(initialTotal);
|
const [total, setTotal] = useState(initialTotal);
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
|
|
||||||
|
|
||||||
// load services data
|
// load services data
|
||||||
const loadServices = async (page: number, search: string) => {
|
const loadServices = async (page: number, search: string, tag: string = "ALL") => {
|
||||||
try {
|
try {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
const result = await fetchServices({
|
const result = await fetchServices({
|
||||||
page,
|
page,
|
||||||
page_size: pageSize,
|
page_size: pageSize,
|
||||||
keyword: search,
|
keyword: search,
|
||||||
|
// 如果需要,可以在这里添加tag参数传递给API
|
||||||
|
tag: tag !== "ALL" ? tag : undefined,
|
||||||
});
|
});
|
||||||
|
|
||||||
setServices(result.data.services);
|
setServices(result.data.services);
|
||||||
setTotal(result.page.total);
|
setTotal(result.page.total);
|
||||||
setCurrentPage(page);
|
setCurrentPage(page);
|
||||||
@@ -79,13 +93,20 @@ export const MarketplaceMain: React.FC<MarketplaceMainProps> = ({
|
|||||||
// when page number changes, reload
|
// when page number changes, reload
|
||||||
const handlePageChange = (page: number) => {
|
const handlePageChange = (page: number) => {
|
||||||
updateURL(page, searchQuery);
|
updateURL(page, searchQuery);
|
||||||
loadServices(page, searchQuery);
|
loadServices(page, searchQuery, selectedTag);
|
||||||
};
|
};
|
||||||
|
|
||||||
// handle search submit
|
// handle search submit
|
||||||
const handleSearch = () => {
|
const handleSearch = () => {
|
||||||
updateURL(1, searchQuery);
|
updateURL(1, searchQuery);
|
||||||
loadServices(1, searchQuery);
|
loadServices(1, searchQuery, selectedTag);
|
||||||
|
};
|
||||||
|
|
||||||
|
// handle tag change
|
||||||
|
const handleTagChange = (tag: string) => {
|
||||||
|
setSelectedTag(tag);
|
||||||
|
setCurrentPage(1);
|
||||||
|
loadServices(1, searchQuery, tag);
|
||||||
};
|
};
|
||||||
|
|
||||||
// if there is an error, show error message
|
// if there is an error, show error message
|
||||||
@@ -102,9 +123,25 @@ export const MarketplaceMain: React.FC<MarketplaceMainProps> = ({
|
|||||||
{/* Hero Section */}
|
{/* Hero Section */}
|
||||||
<HeroSection
|
<HeroSection
|
||||||
searchQuery={searchQuery}
|
searchQuery={searchQuery}
|
||||||
|
isTagBarDisplay={isTagBarDisplay}
|
||||||
onSearchChange={setSearchQuery}
|
onSearchChange={setSearchQuery}
|
||||||
onSearch={handleSearch}
|
onSearch={handleSearch}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
{/* filter section */}
|
||||||
|
{
|
||||||
|
isTagBarDisplay && (
|
||||||
|
<>
|
||||||
|
<TagFilter
|
||||||
|
theme={currentTheme}
|
||||||
|
tags={availableTags}
|
||||||
|
selectedTag={selectedTag}
|
||||||
|
onTagChange={handleTagChange}
|
||||||
|
maxWidthPercent={80}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
{/* Server List Section */}
|
{/* Server List Section */}
|
||||||
{loading ? (
|
{loading ? (
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import React, { useState, useCallback, useEffect } from "react";
|
import React, { useState, useCallback, useEffect, useRef } from "react";
|
||||||
import { useSearchParams } from "next/navigation";
|
import { useSearchParams } from "next/navigation";
|
||||||
import { useMCPServicesList } from "@/hooks/useMCPServicesList";
|
import { useMCPServicesList } from "@/hooks/useMCPServicesList";
|
||||||
import { MCPService, MCPServiceFormData } from "@/shared/types/mcp-service";
|
import { MCPService, MCPServiceFormData } from "@/shared/types/mcp-service";
|
||||||
@@ -12,6 +12,8 @@ import { DeleteConfirmModal } from "@/shared/components/modal/DeleteConfirmModal
|
|||||||
import DashboardDemoContent from "@/shared/components/DashboardDemoContent";
|
import DashboardDemoContent from "@/shared/components/DashboardDemoContent";
|
||||||
import { ServiceTable } from "@/shared/components/mcp-services/ServiceTable";
|
import { ServiceTable } from "@/shared/components/mcp-services/ServiceTable";
|
||||||
import { OpenAPIGeneratorModal } from "@/shared/components/mcp-services/OpenAPIGeneratorModal";
|
import { OpenAPIGeneratorModal } from "@/shared/components/mcp-services/OpenAPIGeneratorModal";
|
||||||
|
import { Input } from "@nextui-org/react";
|
||||||
|
import { Search } from "lucide-react";
|
||||||
|
|
||||||
type ViewMode = "list" | "edit" | "create";
|
type ViewMode = "list" | "edit" | "create";
|
||||||
|
|
||||||
@@ -30,9 +32,24 @@ export const MCPServicesManagement: React.FC = () => {
|
|||||||
toggleServiceStatus,
|
toggleServiceStatus,
|
||||||
parseOpenAPIDocument,
|
parseOpenAPIDocument,
|
||||||
loadServices,
|
loadServices,
|
||||||
|
setSearchTerm,
|
||||||
|
setStatusFilter,
|
||||||
} = useMCPServicesList();
|
} = useMCPServicesList();
|
||||||
const [addServiceType, setAddServiceType] = useState<string | null>(null);
|
const [addServiceType, setAddServiceType] = useState<string | null>(null);
|
||||||
|
|
||||||
|
// 搜索相关状态
|
||||||
|
const [searchValue, setSearchValue] = useState('');
|
||||||
|
const searchTimerRef = useRef<NodeJS.Timeout | null>(null);
|
||||||
|
|
||||||
|
// 清理定时器
|
||||||
|
useEffect(() => {
|
||||||
|
return () => {
|
||||||
|
if (searchTimerRef.current) {
|
||||||
|
clearTimeout(searchTimerRef.current);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
// Get initial state from URL
|
// Get initial state from URL
|
||||||
const getInitialViewMode = (): ViewMode => {
|
const getInitialViewMode = (): ViewMode => {
|
||||||
const mode = searchParams.get("mode") as ViewMode;
|
const mode = searchParams.get("mode") as ViewMode;
|
||||||
@@ -190,6 +207,26 @@ export const MCPServicesManagement: React.FC = () => {
|
|||||||
setServiceToDelete(null);
|
setServiceToDelete(null);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
// 处理搜索 - 使用防抖
|
||||||
|
const handleSearchChange = useCallback((value: string) => {
|
||||||
|
setSearchValue(value);
|
||||||
|
|
||||||
|
// 清除之前的定时器
|
||||||
|
if (searchTimerRef.current) {
|
||||||
|
clearTimeout(searchTimerRef.current);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 设置新的定时器,500ms 后触发搜索
|
||||||
|
searchTimerRef.current = setTimeout(() => {
|
||||||
|
setSearchTerm(value);
|
||||||
|
}, 500);
|
||||||
|
}, [setSearchTerm]);
|
||||||
|
|
||||||
|
// 处理状态筛选
|
||||||
|
const handleStatusFilterChange = useCallback((status: string) => {
|
||||||
|
setStatusFilter(status);
|
||||||
|
}, [setStatusFilter]);
|
||||||
|
|
||||||
// Render edit page if in edit/create mode
|
// Render edit page if in edit/create mode
|
||||||
if (viewMode === "edit" || viewMode === "create") {
|
if (viewMode === "edit" || viewMode === "create") {
|
||||||
return (
|
return (
|
||||||
@@ -214,8 +251,27 @@ export const MCPServicesManagement: React.FC = () => {
|
|||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<div className="space-y-6 w-full">
|
<div className="space-y-6 w-full">
|
||||||
{/* comming soon:Filters and Actions */}
|
{/* Filters and Actions */}
|
||||||
<ServiceFiltersBar onAddService={handleCreateService} />
|
<div className="flex justify-between items-center gap-4">
|
||||||
|
<ServiceFiltersBar onAddService={handleCreateService} />
|
||||||
|
|
||||||
|
{/* 搜索框 - 右侧 */}
|
||||||
|
<Input
|
||||||
|
isClearable
|
||||||
|
className="w-full sm:max-w-[400px]"
|
||||||
|
placeholder={t('Search by service name')}
|
||||||
|
startContent={<Search className="w-4 h-4" />}
|
||||||
|
value={searchValue}
|
||||||
|
onClear={() => {
|
||||||
|
setSearchValue('');
|
||||||
|
if (searchTimerRef.current) {
|
||||||
|
clearTimeout(searchTimerRef.current);
|
||||||
|
}
|
||||||
|
setSearchTerm('');
|
||||||
|
}}
|
||||||
|
onValueChange={handleSearchChange}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
{/* Servers Table */}
|
{/* Servers Table */}
|
||||||
<ServiceTable
|
<ServiceTable
|
||||||
@@ -226,6 +282,7 @@ export const MCPServicesManagement: React.FC = () => {
|
|||||||
onDelete={handleDeleteService}
|
onDelete={handleDeleteService}
|
||||||
onToggleStatus={handleToggleStatus}
|
onToggleStatus={handleToggleStatus}
|
||||||
onPageChange={onPageChange}
|
onPageChange={onPageChange}
|
||||||
|
onStatusFilterChange={handleStatusFilterChange}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{/* Modals */}
|
{/* Modals */}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import { ToolsTab } from "@/shared/components/mcp-services/ToolsTab";
|
|||||||
import { OpenAPIGeneratorModal } from "@/shared/components/mcp-services/OpenAPIGeneratorModal";
|
import { OpenAPIGeneratorModal } from "@/shared/components/mcp-services/OpenAPIGeneratorModal";
|
||||||
import { ChargeType } from "@/shared/types/marketplace";
|
import { ChargeType } from "@/shared/types/marketplace";
|
||||||
import { withComponentInjection } from "@/shared/hooks/useComponentInjection";
|
import { withComponentInjection } from "@/shared/hooks/useComponentInjection";
|
||||||
|
import ResourceGroup from "@/shared/components/mcp-services/ResourceGroup";
|
||||||
|
|
||||||
const _DefaultFormData: MCPServiceFormData = {
|
const _DefaultFormData: MCPServiceFormData = {
|
||||||
id: "",
|
id: "",
|
||||||
@@ -29,11 +30,72 @@ const _DefaultFormData: MCPServiceFormData = {
|
|||||||
auth_token: "",
|
auth_token: "",
|
||||||
charge_type: ChargeType.Free,
|
charge_type: ChargeType.Free,
|
||||||
price: "",
|
price: "",
|
||||||
|
free_daily_limit: "",
|
||||||
enabled: 0,
|
enabled: 0,
|
||||||
tags: [],
|
tags: [],
|
||||||
apis: [],
|
apis: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Helper function to validate URL
|
||||||
|
const isValidUrl = (url: string) => {
|
||||||
|
if (!url) return false;
|
||||||
|
try {
|
||||||
|
const parsed = new URL(url);
|
||||||
|
return parsed.protocol === "http:" || parsed.protocol === "https:";
|
||||||
|
} catch {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Helper function to validate domain format (allow domain or IP address including LAN IPs)
|
||||||
|
const isValidDomain = (url: string) => {
|
||||||
|
if (!url) return false;
|
||||||
|
try {
|
||||||
|
const parsed = new URL(url);
|
||||||
|
const hostname = parsed.hostname;
|
||||||
|
// Allow IPv4 addresses (including private/lan IPs like 192.168.x.x, 10.x.x.x, 172.x.x.x)
|
||||||
|
const ipv4Regex = /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
|
||||||
|
if (ipv4Regex.test(hostname)) return true;
|
||||||
|
// Allow IPv6 (simplified)
|
||||||
|
if (hostname.includes(":")) return true;
|
||||||
|
// Domain format
|
||||||
|
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> = {};
|
||||||
|
|
||||||
|
if (!data.slug_name?.trim()) {
|
||||||
|
errors.slug_name = t("Server ID is required");
|
||||||
|
} else if (data.slug_name.length > 255) {
|
||||||
|
errors.slug_name = t("Server ID must be less than 255 characters");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!data.name?.trim()) {
|
||||||
|
errors.name = t("Server name is required");
|
||||||
|
} else if (data.name.length > 255) {
|
||||||
|
errors.name = t("Server Name must be less than 255 characters");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!data.base_url?.trim()) {
|
||||||
|
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()) {
|
||||||
|
errors.short_description = t("Short description is required");
|
||||||
|
}
|
||||||
|
|
||||||
|
return errors;
|
||||||
|
};
|
||||||
|
|
||||||
interface ServiceEditPageProps {
|
interface ServiceEditPageProps {
|
||||||
serviceId?: string;
|
serviceId?: string;
|
||||||
onSave: (data: MCPServiceFormData, isDraft?: boolean) => void;
|
onSave: (data: MCPServiceFormData, isDraft?: boolean) => void;
|
||||||
@@ -59,6 +121,9 @@ const BaseServiceEditPage: React.FC<ServiceEditPageProps> = ({
|
|||||||
getServiceDetail,
|
getServiceDetail,
|
||||||
clearServiceDetail,
|
clearServiceDetail,
|
||||||
parseOpenAPIDocumentForUpdate,
|
parseOpenAPIDocumentForUpdate,
|
||||||
|
fetchMCPResourceGroups,
|
||||||
|
deleteResourceGroup,
|
||||||
|
addServiceToGroup,
|
||||||
updateLoading,
|
updateLoading,
|
||||||
} = useMCPServiceDetail();
|
} = useMCPServiceDetail();
|
||||||
const [isSaving, setIsSaving] = useState(false);
|
const [isSaving, setIsSaving] = useState(false);
|
||||||
@@ -193,24 +258,41 @@ const BaseServiceEditPage: React.FC<ServiceEditPageProps> = ({
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Helper function to validate price string
|
||||||
|
const isValidPrice = (priceStr: string | undefined): boolean => {
|
||||||
|
if (!priceStr || priceStr.trim() === "") {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const numValue = parseFloat(priceStr);
|
||||||
|
return !isNaN(numValue) && numValue >= 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
const validationErrors = validateServiceForm(formData, t);
|
||||||
|
|
||||||
const isFormValid = () => {
|
const isFormValid = () => {
|
||||||
const hasBasicInfo =
|
if (Object.keys(validationErrors).length > 0) {
|
||||||
formData.name.trim() &&
|
return false;
|
||||||
formData.short_description?.trim() &&
|
}
|
||||||
formData.slug_name?.trim() &&
|
|
||||||
formData.base_url?.trim();
|
|
||||||
|
|
||||||
// if free, no need to validate price
|
// if free, no need to validate price
|
||||||
if (formData.charge_type === ChargeType.Free) {
|
if (formData.charge_type === ChargeType.Free) {
|
||||||
return hasBasicInfo;
|
return true;
|
||||||
|
}
|
||||||
|
// if PerCall, validate price
|
||||||
|
if (formData.charge_type === ChargeType.PerCall) {
|
||||||
|
return isValidPrice(formData.price);
|
||||||
|
}
|
||||||
|
|
||||||
|
// if PerToken, validate both input and output token prices
|
||||||
|
if (formData.charge_type === ChargeType.PerToken) {
|
||||||
|
return (
|
||||||
|
isValidPrice(formData.input_token_price) &&
|
||||||
|
isValidPrice(formData.output_token_price)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// if paid, need to validate price
|
// if paid, need to validate price
|
||||||
return (
|
return formData.price !== undefined && formData.price.trim() !== "";
|
||||||
hasBasicInfo &&
|
|
||||||
formData.price !== undefined &&
|
|
||||||
formData.price.trim() !== ""
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -299,6 +381,7 @@ const BaseServiceEditPage: React.FC<ServiceEditPageProps> = ({
|
|||||||
onInputChange={handleInputChange}
|
onInputChange={handleInputChange}
|
||||||
onAddTag={handleAddTag}
|
onAddTag={handleAddTag}
|
||||||
onRemoveTag={handleRemoveTag}
|
onRemoveTag={handleRemoveTag}
|
||||||
|
errors={validationErrors}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="w-[400px] max-w-[1/2]">
|
<div className="w-[400px] max-w-[1/2]">
|
||||||
@@ -324,6 +407,16 @@ const BaseServiceEditPage: React.FC<ServiceEditPageProps> = ({
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</Tab>
|
</Tab>
|
||||||
|
<Tab key="ResourceGroups" title={t("Resource Groups")}>
|
||||||
|
<div className="pt-2 h-full">
|
||||||
|
<ResourceGroup
|
||||||
|
formData={formData}
|
||||||
|
deleteResourceGroup={deleteResourceGroup}
|
||||||
|
fetchMCPResourceGroups={fetchMCPResourceGroups}
|
||||||
|
addServiceToGroup={addServiceToGroup}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</Tab>
|
||||||
</Tabs>
|
</Tabs>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,234 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import React, { useEffect, useState } from "react";
|
||||||
|
import { Input, Button, AccordionItem, Accordion, Switch } from "@nextui-org/react";
|
||||||
|
import { Eye, EyeOff } from "lucide-react";
|
||||||
|
import { EpayChannelConfig } from "@/types/payment";
|
||||||
|
import { useTranslation } from "@/shared/lib/useTranslation";
|
||||||
|
|
||||||
|
interface EpayConfigFormProps {
|
||||||
|
config: EpayChannelConfig;
|
||||||
|
onSave: (config: EpayChannelConfig) => void;
|
||||||
|
onEnable: (channelId: string) => Promise<boolean>;
|
||||||
|
onDisable: (channelId: string) => Promise<boolean>;
|
||||||
|
isLoading?: boolean;
|
||||||
|
labelPlacement?: "outside" | "inside";
|
||||||
|
}
|
||||||
|
|
||||||
|
export const EpayConfigForm: React.FC<EpayConfigFormProps> = ({
|
||||||
|
config,
|
||||||
|
onSave,
|
||||||
|
onEnable,
|
||||||
|
onDisable,
|
||||||
|
isLoading = false,
|
||||||
|
labelPlacement = "inside",
|
||||||
|
}) => {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const [formData, setFormData] = useState<EpayChannelConfig>(config);
|
||||||
|
const [showKey, setShowKey] = useState(false);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setFormData(config);
|
||||||
|
}, [config]);
|
||||||
|
|
||||||
|
const handleInputChange = (field: keyof EpayChannelConfig, value: string | boolean) => {
|
||||||
|
setFormData((prev) => ({ ...prev, [field]: value }));
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleEnableDisable = async (value: boolean) => {
|
||||||
|
const result = value ? await onEnable("epay") : await onDisable("epay");
|
||||||
|
if (result) {
|
||||||
|
setFormData((prev) => ({ ...prev, is_enabled: value }));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleSave = () => onSave(formData);
|
||||||
|
|
||||||
|
const isFormValid =
|
||||||
|
!!formData?.gateway?.trim() && !!formData?.pid?.trim() && !!formData?.key?.trim();
|
||||||
|
|
||||||
|
const panelContent = () => (
|
||||||
|
<>
|
||||||
|
<div className={`flex flex-col gap-4 ${formData.is_enabled ? "" : "hidden"}`}>
|
||||||
|
<Input
|
||||||
|
label={t("Gateway URL")}
|
||||||
|
placeholder="https://pay.example.com"
|
||||||
|
description={t("Epay gateway base address, no trailing slash")}
|
||||||
|
value={formData.gateway || ""}
|
||||||
|
onChange={(e) => handleInputChange("gateway", e.target.value)}
|
||||||
|
isRequired
|
||||||
|
autoComplete="off"
|
||||||
|
isDisabled={!formData.is_enabled}
|
||||||
|
labelPlacement="outside"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Input
|
||||||
|
label={t("Merchant ID (pid)")}
|
||||||
|
placeholder={t("Enter Merchant ID")}
|
||||||
|
description={t("Numeric merchant id issued by the epay platform")}
|
||||||
|
value={formData.pid || ""}
|
||||||
|
onChange={(e) => handleInputChange("pid", e.target.value)}
|
||||||
|
isRequired
|
||||||
|
autoComplete="off"
|
||||||
|
isDisabled={!formData.is_enabled}
|
||||||
|
labelPlacement="outside"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Input
|
||||||
|
label={t("Merchant Key (key)")}
|
||||||
|
placeholder={t("Enter Merchant Key")}
|
||||||
|
description={t("Used to sign requests and verify notifications, 32 characters")}
|
||||||
|
value={formData.key || ""}
|
||||||
|
onChange={(e) => handleInputChange("key", e.target.value)}
|
||||||
|
type={showKey ? "text" : "password"}
|
||||||
|
isRequired
|
||||||
|
autoComplete="off"
|
||||||
|
isDisabled={!formData.is_enabled}
|
||||||
|
labelPlacement="outside"
|
||||||
|
endContent={
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => setShowKey(!showKey)}
|
||||||
|
className="focus:outline-none"
|
||||||
|
>
|
||||||
|
{showKey ? (
|
||||||
|
<EyeOff className="w-4 h-4 text-gray-400" />
|
||||||
|
) : (
|
||||||
|
<Eye className="w-4 h-4 text-gray-400" />
|
||||||
|
)}
|
||||||
|
</button>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div className="flex flex-col gap-1">
|
||||||
|
<label className="text-sm font-medium">{t("Payment Method")}</label>
|
||||||
|
<select
|
||||||
|
className="w-full px-3 py-2 text-sm border border-gray-300 rounded-md bg-white focus:outline-none focus:ring-2 focus:ring-primary-500 disabled:opacity-50 disabled:cursor-not-allowed"
|
||||||
|
value={formData.pay_type || ""}
|
||||||
|
disabled={!formData.is_enabled}
|
||||||
|
onChange={(e) => handleInputChange("pay_type", e.target.value)}
|
||||||
|
>
|
||||||
|
<option value="">{t("Let customer choose at checkout")}</option>
|
||||||
|
<option value="alipay">{t("Alipay")}</option>
|
||||||
|
<option value="wxpay">{t("WeChat Pay")}</option>
|
||||||
|
<option value="qqpay">{t("QQ Wallet")}</option>
|
||||||
|
</select>
|
||||||
|
<span className="text-xs text-gray-500">
|
||||||
|
{t("Leave empty to show the gateway cashier with all methods")}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Input
|
||||||
|
label={t("Exchange Rate")}
|
||||||
|
placeholder="1"
|
||||||
|
description={t(
|
||||||
|
"CNY charged per 1 balance unit. Default 1 means 1:1. e.g. 7 means a $10 recharge bills ¥70"
|
||||||
|
)}
|
||||||
|
value={String(formData.exchange_rate ?? 1)}
|
||||||
|
onChange={(e) => handleInputChange("exchange_rate", e.target.value)}
|
||||||
|
type="number"
|
||||||
|
min="0"
|
||||||
|
step="0.01"
|
||||||
|
autoComplete="off"
|
||||||
|
isDisabled={!formData.is_enabled}
|
||||||
|
labelPlacement="outside"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Input
|
||||||
|
label={t("Notify URL (optional)")}
|
||||||
|
placeholder={t("Auto derived from the site URL when empty")}
|
||||||
|
description={t(
|
||||||
|
"Async payment notification address that the gateway can reach from the internet"
|
||||||
|
)}
|
||||||
|
value={formData.notify_url || ""}
|
||||||
|
onChange={(e) => handleInputChange("notify_url", e.target.value)}
|
||||||
|
autoComplete="off"
|
||||||
|
isDisabled={!formData.is_enabled}
|
||||||
|
labelPlacement="outside"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Input
|
||||||
|
label={t("Return URL (optional)")}
|
||||||
|
placeholder={t("Auto derived when empty")}
|
||||||
|
description={t("Page opened after the customer finishes paying")}
|
||||||
|
value={formData.return_url || ""}
|
||||||
|
onChange={(e) => handleInputChange("return_url", e.target.value)}
|
||||||
|
autoComplete="off"
|
||||||
|
isDisabled={!formData.is_enabled}
|
||||||
|
labelPlacement="outside"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{formData.is_enabled && (
|
||||||
|
<div className="flex gap-3 py-4">
|
||||||
|
<Button
|
||||||
|
color="primary"
|
||||||
|
variant="solid"
|
||||||
|
onPress={handleSave}
|
||||||
|
isLoading={isLoading}
|
||||||
|
isDisabled={!isFormValid}
|
||||||
|
size="sm"
|
||||||
|
>
|
||||||
|
{t("Save")}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
|
||||||
|
if (labelPlacement === "outside") {
|
||||||
|
return (
|
||||||
|
<div className="flex flex-col gap-4">
|
||||||
|
<div className="flex items-center justify-between p-4 bg-gray-50 rounded-lg">
|
||||||
|
<div className="flex flex-col gap-1">
|
||||||
|
<span className="text-sm font-medium">{t("Enable Epay Payment")}</span>
|
||||||
|
<span className="text-xs text-gray-500">
|
||||||
|
{t("Alipay / WeChat Pay through your own epay gateway")}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<Switch
|
||||||
|
isSelected={formData.is_enabled || false}
|
||||||
|
onValueChange={handleEnableDisable}
|
||||||
|
color="primary"
|
||||||
|
size="sm"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
{panelContent()}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Accordion
|
||||||
|
variant="splitted"
|
||||||
|
itemClasses={{ base: "shadow-none border-1" }}
|
||||||
|
defaultExpandedKeys={["epay-config"]}
|
||||||
|
className="px-0"
|
||||||
|
>
|
||||||
|
<AccordionItem
|
||||||
|
key="epay-config"
|
||||||
|
title={
|
||||||
|
<div className="flex flex-col justify-between">
|
||||||
|
<div className="flex items-center justify-between w-full">
|
||||||
|
<div>
|
||||||
|
<h3 className="text-lg font-semibold">{t("Epay Configuration")}</h3>
|
||||||
|
<p className="text-sm text-gray-500">
|
||||||
|
{t("Configure your epay (Epay) gateway")}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<Switch
|
||||||
|
isSelected={formData.is_enabled || false}
|
||||||
|
onValueChange={handleEnableDisable}
|
||||||
|
size="sm"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{panelContent()}
|
||||||
|
</AccordionItem>
|
||||||
|
</Accordion>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default EpayConfigForm;
|
||||||
@@ -66,8 +66,8 @@ export const StripeConfigForm: React.FC<StripeConfigFormProps> = ({
|
|||||||
onSave(formData);
|
onSave(formData);
|
||||||
};
|
};
|
||||||
|
|
||||||
const isFormValid =
|
const isFormValid =
|
||||||
formData.secret.trim() !== "" && formData.webhook_secret.trim() !== "";
|
formData?.secret?.trim() !== "" && formData?.webhook_secret?.trim() !== "";
|
||||||
|
|
||||||
const panelContent = () => {
|
const panelContent = () => {
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -0,0 +1,175 @@
|
|||||||
|
import {
|
||||||
|
Button,
|
||||||
|
Modal,
|
||||||
|
ModalBody,
|
||||||
|
ModalContent,
|
||||||
|
ModalFooter,
|
||||||
|
ModalHeader,
|
||||||
|
Table,
|
||||||
|
TableHeader,
|
||||||
|
TableColumn,
|
||||||
|
TableBody,
|
||||||
|
TableRow,
|
||||||
|
TableCell,
|
||||||
|
Chip,
|
||||||
|
Spinner,
|
||||||
|
} from "@nextui-org/react";
|
||||||
|
import { useState, useEffect, useCallback } from "react";
|
||||||
|
import { useTranslation } from "@/shared/lib/useTranslation";
|
||||||
|
import { ChargeType } from "@/shared/types/marketplace";
|
||||||
|
import { fetchSimpleMcpServices } from "@/api/resourceGroup.api";
|
||||||
|
import { Price } from "@/shared/components/marketplace/Price";
|
||||||
|
|
||||||
|
interface AddMcpServerModalProps {
|
||||||
|
isOpen: boolean;
|
||||||
|
onClose: () => void;
|
||||||
|
onSaveMcpServer: (serverIds: string[]) => Promise<void>;
|
||||||
|
id: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SimpleMcpService {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
base_url: string;
|
||||||
|
charge_type: ChargeType;
|
||||||
|
price: string;
|
||||||
|
enabled: boolean;
|
||||||
|
input_token_price?: string;
|
||||||
|
output_token_price?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const AddMcpServerModal: React.FC<AddMcpServerModalProps> = ({
|
||||||
|
isOpen,
|
||||||
|
onClose,
|
||||||
|
onSaveMcpServer,
|
||||||
|
id,
|
||||||
|
}) => {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
const [services, setServices] = useState<SimpleMcpService[]>([]);
|
||||||
|
const [selectedKeys, setSelectedKeys] = useState<Set<string>>(new Set());
|
||||||
|
|
||||||
|
// 加载服务列表
|
||||||
|
const loadServices = useCallback(async (id: string) => {
|
||||||
|
setLoading(true);
|
||||||
|
try {
|
||||||
|
const response = await fetchSimpleMcpServices(id);
|
||||||
|
setServices(response);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Failed to load MCP services:", error);
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
// 当模态框打开时加载数据
|
||||||
|
useEffect(() => {
|
||||||
|
if (isOpen) {
|
||||||
|
setSelectedKeys(new Set());
|
||||||
|
loadServices(id);
|
||||||
|
}
|
||||||
|
}, [isOpen, loadServices]);
|
||||||
|
|
||||||
|
// 处理保存
|
||||||
|
const handleSave = async () => {
|
||||||
|
const serverIds = typeof selectedKeys === 'string' && selectedKeys === 'all' ? services.map((service) => service.id) : Array.from(selectedKeys);
|
||||||
|
if (serverIds.length === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setIsLoading(true);
|
||||||
|
try {
|
||||||
|
await onSaveMcpServer(serverIds);
|
||||||
|
onClose();
|
||||||
|
} finally {
|
||||||
|
setIsLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Modal isOpen={isOpen} onClose={onClose} size="5xl" scrollBehavior="inside">
|
||||||
|
<ModalContent>
|
||||||
|
{() => (
|
||||||
|
<>
|
||||||
|
<ModalHeader className="flex flex-col gap-1">
|
||||||
|
{t("Add MCP Server")}
|
||||||
|
</ModalHeader>
|
||||||
|
<ModalBody>
|
||||||
|
<Table
|
||||||
|
aria-label="MCP services selection table"
|
||||||
|
selectionMode="multiple"
|
||||||
|
selectedKeys={selectedKeys}
|
||||||
|
onSelectionChange={(keys) => setSelectedKeys(keys as Set<string>)}
|
||||||
|
removeWrapper
|
||||||
|
classNames={{
|
||||||
|
wrapper: "min-h-[400px]",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<TableHeader>
|
||||||
|
<TableColumn>{t("Service Name")}</TableColumn>
|
||||||
|
<TableColumn>{t("API Endpoint")}</TableColumn>
|
||||||
|
<TableColumn>{t("Status")}</TableColumn>
|
||||||
|
<TableColumn>{t("Pricing")}</TableColumn>
|
||||||
|
</TableHeader>
|
||||||
|
<TableBody
|
||||||
|
items={services}
|
||||||
|
isLoading={loading}
|
||||||
|
loadingContent={<Spinner />}
|
||||||
|
emptyContent={t("No MCP services available")}
|
||||||
|
>
|
||||||
|
{(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>
|
||||||
|
<Price
|
||||||
|
price={service.price}
|
||||||
|
charge_type={service.charge_type}
|
||||||
|
input_token_price={service.input_token_price}
|
||||||
|
output_token_price={service.output_token_price}
|
||||||
|
/>
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
)}
|
||||||
|
</TableBody>
|
||||||
|
</Table>
|
||||||
|
</ModalBody>
|
||||||
|
<ModalFooter>
|
||||||
|
<Button
|
||||||
|
color="danger"
|
||||||
|
variant="light"
|
||||||
|
onPress={onClose}
|
||||||
|
isDisabled={isLoading}
|
||||||
|
>
|
||||||
|
{t("Close")}
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
color="primary"
|
||||||
|
onPress={handleSave}
|
||||||
|
isLoading={isLoading}
|
||||||
|
isDisabled={selectedKeys.size === 0}
|
||||||
|
>
|
||||||
|
{t("Add")}
|
||||||
|
</Button>
|
||||||
|
</ModalFooter>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</ModalContent>
|
||||||
|
</Modal>
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -0,0 +1,105 @@
|
|||||||
|
import { Button, Input, Modal, ModalBody, ModalContent, ModalFooter, ModalHeader, Switch } from "@nextui-org/react"
|
||||||
|
import { useState, useEffect } from "react";
|
||||||
|
import { useTranslation } from "@/shared/lib/useTranslation";
|
||||||
|
interface AddServerModalProps {
|
||||||
|
isOpen: boolean;
|
||||||
|
onClose: () => void;
|
||||||
|
name: string;
|
||||||
|
id: string;
|
||||||
|
onSaveServer: (name: string, isDefault: boolean) => Promise<void>;
|
||||||
|
type: "add" | "edit";
|
||||||
|
isDefault: boolean;
|
||||||
|
}
|
||||||
|
export const AddServerModal: React.FC<AddServerModalProps> = ({
|
||||||
|
isOpen,
|
||||||
|
onClose,
|
||||||
|
name,
|
||||||
|
id,
|
||||||
|
onSaveServer,
|
||||||
|
type,
|
||||||
|
isDefault,
|
||||||
|
}) => {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const [serverName, setServerName] = useState(name);
|
||||||
|
const [isEnabledState, setIsEnabledState] = useState(isDefault);
|
||||||
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
|
|
||||||
|
// 当 name prop 或 isOpen 变化时,更新内部状态
|
||||||
|
useEffect(() => {
|
||||||
|
if (isOpen) {
|
||||||
|
setServerName(name);
|
||||||
|
setIsEnabledState(isDefault);
|
||||||
|
setIsLoading(false); // 重置 loading 状态
|
||||||
|
}
|
||||||
|
}, [name, isOpen, isDefault]);
|
||||||
|
|
||||||
|
// 处理保存
|
||||||
|
const handleSave = async () => {
|
||||||
|
setIsLoading(true);
|
||||||
|
try {
|
||||||
|
await onSaveServer(serverName, isEnabledState);
|
||||||
|
} finally {
|
||||||
|
setIsLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
return (
|
||||||
|
<Modal isOpen={isOpen} onClose={onClose} size="2xl">
|
||||||
|
<ModalContent>
|
||||||
|
{() => (
|
||||||
|
<>
|
||||||
|
<ModalHeader className="flex flex-col gap-1">
|
||||||
|
{type === "add" ? t("Create New Resource Group") : t("Edit Resource Group")}
|
||||||
|
</ModalHeader>
|
||||||
|
<ModalBody>
|
||||||
|
{
|
||||||
|
!['allow-all', 'deny-all'].includes(id) && <>
|
||||||
|
<Input
|
||||||
|
label={t("Resource Group Name")}
|
||||||
|
value={serverName}
|
||||||
|
placeholder={t("Edit Resource Group Name")}
|
||||||
|
onChange={(e) => setServerName(e.target.value)}
|
||||||
|
maxLength={255}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
}
|
||||||
|
<div className="flex items-center justify-between p-4 bg-gray-50 rounded-lg">
|
||||||
|
<div className="flex flex-col gap-1">
|
||||||
|
<span className="text-sm font-medium">
|
||||||
|
{t("Set as default")}
|
||||||
|
</span>
|
||||||
|
<span className="text-xs text-gray-500">
|
||||||
|
{t("Automatically bind default resource groups when adding users")}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<Switch
|
||||||
|
isSelected={isEnabledState || false}
|
||||||
|
onValueChange={setIsEnabledState}
|
||||||
|
color="primary"
|
||||||
|
size="sm"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</ModalBody>
|
||||||
|
<ModalFooter>
|
||||||
|
<Button
|
||||||
|
color="danger"
|
||||||
|
variant="light"
|
||||||
|
onPress={onClose}
|
||||||
|
isDisabled={isLoading}
|
||||||
|
>
|
||||||
|
{t("Cancel")}
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
color="primary"
|
||||||
|
onPress={handleSave}
|
||||||
|
isLoading={isLoading}
|
||||||
|
>
|
||||||
|
{t("Save")}
|
||||||
|
</Button>
|
||||||
|
</ModalFooter>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
|
||||||
|
</ModalContent>
|
||||||
|
</Modal>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,94 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import React, { useState } from "react";
|
||||||
|
import {
|
||||||
|
Modal,
|
||||||
|
ModalContent,
|
||||||
|
ModalHeader,
|
||||||
|
ModalBody,
|
||||||
|
ModalFooter,
|
||||||
|
Button,
|
||||||
|
Alert,
|
||||||
|
} from "@nextui-org/react";
|
||||||
|
import { useTranslation } from "@/shared/lib/useTranslation";
|
||||||
|
|
||||||
|
interface DeleteServerModalProps {
|
||||||
|
isOpen: boolean;
|
||||||
|
onClose: () => void;
|
||||||
|
onConfirm: () => void | Promise<void>;
|
||||||
|
title?: string | React.ReactNode;
|
||||||
|
description?: string | React.ReactNode;
|
||||||
|
alertDescription?: string;
|
||||||
|
customAlertContent?: React.ReactNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const DeleteServerModal: React.FC<DeleteServerModalProps> = ({
|
||||||
|
isOpen,
|
||||||
|
onClose,
|
||||||
|
onConfirm,
|
||||||
|
title,
|
||||||
|
description,
|
||||||
|
alertDescription,
|
||||||
|
customAlertContent,
|
||||||
|
}) => {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
|
|
||||||
|
const handleConfirm = async () => {
|
||||||
|
setIsLoading(true);
|
||||||
|
try {
|
||||||
|
await onConfirm();
|
||||||
|
} finally {
|
||||||
|
setIsLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const defaultTitle = t("Confirm Delete");
|
||||||
|
const defaultDescription = t("Are you sure you want to delete this item? This action cannot be undone.");
|
||||||
|
const defaultAlertDescription= t("This action cannot be undone.");
|
||||||
|
return (
|
||||||
|
<Modal isOpen={isOpen} onClose={onClose} size="xl">
|
||||||
|
<ModalContent>
|
||||||
|
{() => (
|
||||||
|
<>
|
||||||
|
<ModalHeader className="flex flex-col gap-1">
|
||||||
|
{title || defaultTitle}
|
||||||
|
</ModalHeader>
|
||||||
|
<ModalBody>
|
||||||
|
<div className="space-y-4">
|
||||||
|
{/* Description */}
|
||||||
|
<div className="text-default-600">
|
||||||
|
{description || defaultDescription}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Warning message */}
|
||||||
|
<Alert title={alertDescription || defaultAlertDescription} color="danger" classNames={{mainWrapper: "w-[calc(100%-60px)]"}}>
|
||||||
|
{customAlertContent && customAlertContent}
|
||||||
|
</Alert>
|
||||||
|
</div>
|
||||||
|
</ModalBody>
|
||||||
|
<ModalFooter>
|
||||||
|
<Button
|
||||||
|
color="default"
|
||||||
|
variant="light"
|
||||||
|
onPress={onClose}
|
||||||
|
isDisabled={isLoading}
|
||||||
|
>
|
||||||
|
{t("Cancel")}
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
color="danger"
|
||||||
|
onPress={handleConfirm}
|
||||||
|
isLoading={isLoading}
|
||||||
|
>
|
||||||
|
{t("Remove")}
|
||||||
|
</Button>
|
||||||
|
</ModalFooter>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</ModalContent>
|
||||||
|
</Modal >
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default DeleteServerModal;
|
||||||
@@ -0,0 +1,162 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import React, { useRef, useCallback, useEffect } from "react";
|
||||||
|
import { Button, Card, CardBody, CardHeader, Chip, Divider, Listbox, ListboxItem, Spinner } from "@nextui-org/react";
|
||||||
|
import { useTranslation } from "@/shared/lib/useTranslation";
|
||||||
|
import { Plus } from "lucide-react";
|
||||||
|
|
||||||
|
// 资源组类型定义
|
||||||
|
export interface ResourceGroup {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
description?: string;
|
||||||
|
isDefault?: boolean;
|
||||||
|
serviceCount?: number;
|
||||||
|
createdAt?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface GroupListProps {
|
||||||
|
groups: ResourceGroup[];
|
||||||
|
selectedGroup: ResourceGroup | null;
|
||||||
|
onSelectGroup: (group: ResourceGroup) => void;
|
||||||
|
onCreateGroup: () => void;
|
||||||
|
onLoadMore?: () => void;
|
||||||
|
hasMore?: boolean;
|
||||||
|
loading?: boolean;
|
||||||
|
shouldScrollToTop?: boolean;
|
||||||
|
onScrolledToTop?: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
const GroupList: React.FC<GroupListProps> = ({
|
||||||
|
groups,
|
||||||
|
selectedGroup,
|
||||||
|
onSelectGroup,
|
||||||
|
onCreateGroup,
|
||||||
|
onLoadMore,
|
||||||
|
hasMore = false,
|
||||||
|
loading = false,
|
||||||
|
shouldScrollToTop = false,
|
||||||
|
onScrolledToTop,
|
||||||
|
}) => {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const scrollRef = useRef<HTMLDivElement>(null);
|
||||||
|
const observerRef = useRef<IntersectionObserver | null>(null);
|
||||||
|
const loadMoreTriggerRef = useRef<HTMLDivElement>(null);
|
||||||
|
const hasLoadedMoreRef = useRef(false);
|
||||||
|
|
||||||
|
// 使用 IntersectionObserver 监听滚动到底部
|
||||||
|
const handleObserver = useCallback(
|
||||||
|
(entries: IntersectionObserverEntry[]) => {
|
||||||
|
const [target] = entries;
|
||||||
|
if (target.isIntersecting && hasMore && !loading && onLoadMore) {
|
||||||
|
hasLoadedMoreRef.current = true; // 标记已触发过加载更多
|
||||||
|
onLoadMore();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[hasMore, loading, onLoadMore]
|
||||||
|
);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const element = loadMoreTriggerRef.current;
|
||||||
|
if (!element || !onLoadMore) return;
|
||||||
|
|
||||||
|
// 创建 IntersectionObserver
|
||||||
|
observerRef.current = new IntersectionObserver(handleObserver, {
|
||||||
|
root: scrollRef.current,
|
||||||
|
rootMargin: "100px", // 提前 100px 触发加载
|
||||||
|
threshold: 0.1,
|
||||||
|
});
|
||||||
|
|
||||||
|
observerRef.current.observe(element);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
if (observerRef.current && element) {
|
||||||
|
observerRef.current.unobserve(element);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}, [handleObserver, onLoadMore]);
|
||||||
|
|
||||||
|
// 监听 shouldScrollToTop 变化,滚动到顶部
|
||||||
|
useEffect(() => {
|
||||||
|
if (shouldScrollToTop && scrollRef.current) {
|
||||||
|
scrollRef.current.scrollTo({ top: 0, behavior: 'smooth' });
|
||||||
|
// 通知父组件已完成滚动
|
||||||
|
onScrolledToTop?.();
|
||||||
|
}
|
||||||
|
}, [shouldScrollToTop, onScrolledToTop]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="min-w-[300px] w-[300px] bg-default-100/50 h-full">
|
||||||
|
<Card shadow="none"
|
||||||
|
radius="none"
|
||||||
|
className="bg-transparent flex flex-col h-full">
|
||||||
|
<CardHeader className="flex justify-between items-center px-6 py-4">
|
||||||
|
<h2 className="text-xl font-semibold text-gray-900">{t("Group List")}</h2>
|
||||||
|
<Button
|
||||||
|
size="sm"
|
||||||
|
color="primary"
|
||||||
|
startContent={<Plus size={16} />}
|
||||||
|
onPress={onCreateGroup}
|
||||||
|
>
|
||||||
|
{t("New")}
|
||||||
|
</Button>
|
||||||
|
</CardHeader>
|
||||||
|
<Divider />
|
||||||
|
<CardBody className="flex-grow p-0">
|
||||||
|
<div ref={scrollRef} className="overflow-y-auto h-full px-4 py-4">
|
||||||
|
<Listbox
|
||||||
|
aria-label="Group list"
|
||||||
|
items={groups || []}
|
||||||
|
emptyContent={loading ? <></> : <div className="flex items-center justify-center h-full">{t("No groups found")}</div>}
|
||||||
|
selectionMode="single"
|
||||||
|
selectedKeys={selectedGroup ? [selectedGroup.id] : []}
|
||||||
|
onSelectionChange={(keys) => {
|
||||||
|
const selectedId = Array.from(keys)[0];
|
||||||
|
const selectedKey = (groups || []).find(
|
||||||
|
(k) => k.id === selectedId
|
||||||
|
);
|
||||||
|
if (selectedKey) onSelectGroup(selectedKey);
|
||||||
|
}}
|
||||||
|
itemClasses={{
|
||||||
|
title: "text-md font-medium",
|
||||||
|
base: "bg-white p-6 transition-colors border-1 data-[selected=true]:focus:bg-primary-50 data-[selected=true]:data-[hover=true]:bg-primary-50 data-[selected=true]:border-primary-500 data-[selected=true]:bg-primary-50 data-[hover=true]:bg-default/50 data-[selectable=true]:focus:bg-default/50 [&>span]:w-full",
|
||||||
|
}}
|
||||||
|
classNames={{
|
||||||
|
list: "gap-4",
|
||||||
|
}}
|
||||||
|
hideSelectedIcon
|
||||||
|
>
|
||||||
|
{(group) => (
|
||||||
|
<ListboxItem key={group.id} textValue={group.name}>
|
||||||
|
<div className="flex items-center gap-2 w-full overflow-hidden">
|
||||||
|
<span className="truncate flex-1 min-w-0">{group.name}</span>
|
||||||
|
{group.isDefault && (
|
||||||
|
<Chip size="sm" color="warning" variant="flat" className="shrink-0 ml-auto">
|
||||||
|
{t("Default")}
|
||||||
|
</Chip>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</ListboxItem>
|
||||||
|
)}
|
||||||
|
</Listbox>
|
||||||
|
|
||||||
|
{/* 加载更多触发器 */}
|
||||||
|
{onLoadMore && (
|
||||||
|
<div ref={loadMoreTriggerRef} className="py-4 flex justify-center">
|
||||||
|
{loading && hasMore && (
|
||||||
|
<Spinner size="sm" color="primary" />
|
||||||
|
)}
|
||||||
|
{!hasMore && groups.length > 0 && hasLoadedMoreRef.current && (
|
||||||
|
<p className="text-sm text-default-400">{t("No more groups")}</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</CardBody>
|
||||||
|
</Card>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default GroupList;
|
||||||
|
|
||||||
@@ -0,0 +1,252 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import React, { useEffect, useState, useMemo } from "react";
|
||||||
|
import {
|
||||||
|
Button,
|
||||||
|
Card,
|
||||||
|
Chip,
|
||||||
|
Table,
|
||||||
|
TableHeader,
|
||||||
|
TableColumn,
|
||||||
|
TableBody,
|
||||||
|
TableRow,
|
||||||
|
TableCell,
|
||||||
|
Tooltip,
|
||||||
|
Spinner,
|
||||||
|
Divider,
|
||||||
|
CardHeader,
|
||||||
|
CardBody,
|
||||||
|
Pagination,
|
||||||
|
} from "@nextui-org/react";
|
||||||
|
import { useTranslation } from "@/shared/lib/useTranslation";
|
||||||
|
import { Plus, Trash2, Edit2 } from "lucide-react";
|
||||||
|
import { Price } from "@/shared/components/marketplace/Price";
|
||||||
|
import { ChargeType } from "@/shared/types/marketplace";
|
||||||
|
import { fetchResourceGroupDetail, ResourceGroupDetailResponse } from "@/api/resourceGroup.api";
|
||||||
|
import { useSearchParams } from "next/navigation";
|
||||||
|
|
||||||
|
// 组内服务类型定义
|
||||||
|
export interface GroupService {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
base_url: string;
|
||||||
|
charge_type: ChargeType;
|
||||||
|
price: string;
|
||||||
|
enabled: boolean;
|
||||||
|
slug_name?: string;
|
||||||
|
input_token_price?: string;
|
||||||
|
output_token_price?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface GroupServiceTableProps {
|
||||||
|
groupId?: string; // 可选,因为可能从 URL 获取
|
||||||
|
services: GroupService[];
|
||||||
|
loading?: boolean;
|
||||||
|
pagination: {
|
||||||
|
page: number;
|
||||||
|
pageSize: number;
|
||||||
|
total: number;
|
||||||
|
};
|
||||||
|
onPageChange: (page: number) => void;
|
||||||
|
onAddService: () => void;
|
||||||
|
onRemoveService: (serviceId: string) => void;
|
||||||
|
onEditGroup: (groupId: string) => void;
|
||||||
|
onDeleteGroup: (groupId: string) => void;
|
||||||
|
refreshTrigger?: number; // 用于触发刷新
|
||||||
|
}
|
||||||
|
|
||||||
|
const GroupServiceTable: React.FC<GroupServiceTableProps> = ({
|
||||||
|
groupId: propGroupId,
|
||||||
|
services,
|
||||||
|
loading = false,
|
||||||
|
pagination,
|
||||||
|
onPageChange,
|
||||||
|
onAddService,
|
||||||
|
onRemoveService,
|
||||||
|
onEditGroup,
|
||||||
|
onDeleteGroup,
|
||||||
|
refreshTrigger,
|
||||||
|
}) => {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const searchParams = useSearchParams();
|
||||||
|
|
||||||
|
const pages = Math.ceil(pagination.total / pagination.pageSize);
|
||||||
|
const currentPage = pagination.page;
|
||||||
|
const [resourceGroupDetail, setResourceGroupDetail] = useState<ResourceGroupDetailResponse | null>(null);
|
||||||
|
|
||||||
|
// 优先使用 props 传入的 groupId,如果没有则从 URL 参数获取
|
||||||
|
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) {
|
||||||
|
setResourceGroupDetail(response);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (currentGroupId) {
|
||||||
|
getResourceGroup(currentGroupId);
|
||||||
|
}
|
||||||
|
}, [currentGroupId, refreshTrigger]); // 当 refreshTrigger 变化时也会刷新
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Card className="flex-1" radius="none" shadow="sm">
|
||||||
|
<CardHeader className="px-6 py-4">
|
||||||
|
<div className="flex justify-between items-center w-full">
|
||||||
|
<h2 className="text-xl font-semibold text-gray-900 truncate" title={resourceGroupDetail?.name}>
|
||||||
|
{resourceGroupDetail?.name}
|
||||||
|
</h2>
|
||||||
|
<div className="flex gap-2 h-[32px]">
|
||||||
|
{currentGroupId && <>
|
||||||
|
<Button
|
||||||
|
isIconOnly
|
||||||
|
size="sm"
|
||||||
|
variant="bordered"
|
||||||
|
onPress={() => onEditGroup(currentGroupId)}
|
||||||
|
>
|
||||||
|
<Edit2 size={18} />
|
||||||
|
</Button></>
|
||||||
|
}
|
||||||
|
{showOptions && currentGroupId && <>
|
||||||
|
<Button
|
||||||
|
isIconOnly
|
||||||
|
size="sm"
|
||||||
|
variant="bordered"
|
||||||
|
color="danger"
|
||||||
|
onPress={() => onDeleteGroup(currentGroupId)}
|
||||||
|
>
|
||||||
|
<Trash2 size={18} />
|
||||||
|
</Button></>
|
||||||
|
}
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</CardHeader>
|
||||||
|
<Divider />
|
||||||
|
<CardBody className="px-6 py-6">
|
||||||
|
{
|
||||||
|
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>
|
||||||
|
</>)
|
||||||
|
}
|
||||||
|
|
||||||
|
<Table
|
||||||
|
key={`table-${showOptions}`}
|
||||||
|
aria-label="Group services table"
|
||||||
|
removeWrapper
|
||||||
|
classNames={{
|
||||||
|
wrapper: "min-h-[400px]",
|
||||||
|
}}
|
||||||
|
bottomContent={
|
||||||
|
pages > 1 ? (
|
||||||
|
<div className="flex w-full justify-center">
|
||||||
|
<Pagination
|
||||||
|
showControls
|
||||||
|
variant="light"
|
||||||
|
color="primary"
|
||||||
|
page={currentPage}
|
||||||
|
total={pages}
|
||||||
|
onChange={onPageChange}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
) : null
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<TableHeader>
|
||||||
|
<TableColumn>{t("Service Name")}</TableColumn>
|
||||||
|
<TableColumn>{t("API Endpoint")}</TableColumn>
|
||||||
|
<TableColumn>{t("Status")}</TableColumn>
|
||||||
|
<TableColumn>{t("Pricing")}</TableColumn>
|
||||||
|
<TableColumn className={showOptions ? "w-20" : "hidden"}>{t("Actions")}</TableColumn>
|
||||||
|
</TableHeader>
|
||||||
|
<TableBody
|
||||||
|
items={services}
|
||||||
|
isLoading={loading}
|
||||||
|
loadingContent={<Spinner />}
|
||||||
|
emptyContent={t("No services in this group")}
|
||||||
|
>
|
||||||
|
{(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="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 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>
|
||||||
|
</Card>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default GroupServiceTable;
|
||||||
|
|
||||||
@@ -0,0 +1,354 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import React, { useState, useEffect } from "react";
|
||||||
|
import { useTranslation } from "@/shared/lib/useTranslation";
|
||||||
|
import DashboardDemoContent from "@/shared/components/DashboardDemoContent";
|
||||||
|
import GroupList, { ResourceGroup } from "./GroupList";
|
||||||
|
import GroupServiceTable, { GroupService } from "./GroupServiceTable";
|
||||||
|
import { AddServerModal } from "./AddServerModal";
|
||||||
|
import { DeleteServerModal } from "./DeleteServerModal";
|
||||||
|
import { Divider, Select, SelectItem } from "@nextui-org/react";
|
||||||
|
import { useResourceGroups } from "@/hooks/useResourceGroups";
|
||||||
|
import { AddMcpServerModal } from "./AddMcpServerModal";
|
||||||
|
import toast from "react-hot-toast";
|
||||||
|
|
||||||
|
const ResourceGroupManagement: React.FC = () => {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
|
||||||
|
// 使用自定义 Hook 管理资源组
|
||||||
|
const {
|
||||||
|
groups,
|
||||||
|
simpleResourceGroups,
|
||||||
|
loadSimpleResourceGroups,
|
||||||
|
groupServices,
|
||||||
|
serviceTablePagination,
|
||||||
|
serviceTableParams,
|
||||||
|
loading,
|
||||||
|
servicesLoading,
|
||||||
|
hasMore,
|
||||||
|
shouldScrollToTop,
|
||||||
|
setShouldScrollToTop,
|
||||||
|
loadGroupServices,
|
||||||
|
loadMoreGroups,
|
||||||
|
handleServicePageChange,
|
||||||
|
handleAddServiceToGroup,
|
||||||
|
handleCreateGroup: createGroup,
|
||||||
|
handleUpdateGroup: updateGroup,
|
||||||
|
handleDeleteGroup: deleteGroup,
|
||||||
|
handleRemoveService: removeService,
|
||||||
|
} = useResourceGroups();
|
||||||
|
|
||||||
|
// 当前选中的资源组
|
||||||
|
const [selectedGroup, setSelectedGroup] = useState<ResourceGroup | null>(null);
|
||||||
|
|
||||||
|
// 删除组确认模态框
|
||||||
|
const [isDeleteGroupModalOpen, setIsDeleteGroupModalOpen] = useState(false);
|
||||||
|
const [groupToDelete, setGroupToDelete] = useState<ResourceGroup | null>(null);
|
||||||
|
const [transferToGroupId, setTransferToGroupId] = useState<string | null>(null);
|
||||||
|
const [simpleResourceGroupsLoading, setSimpleResourceGroupsLoading] = useState(false);
|
||||||
|
|
||||||
|
// 删除服务确认模态框
|
||||||
|
const [isDeleteServiceModalOpen, setIsDeleteServiceModalOpen] = useState(false);
|
||||||
|
const [serviceToDelete, setServiceToDelete] = useState<GroupService | null>(null);
|
||||||
|
|
||||||
|
// 创建/编辑组模态框
|
||||||
|
const [isGroupModalOpen, setIsGroupModalOpen] = useState(false);
|
||||||
|
const [editingGroup, setEditingGroup] = useState<ResourceGroup | null>(null);
|
||||||
|
|
||||||
|
// 添加 MCP 服务模态框
|
||||||
|
const [isAddMcpServerModalOpen, setIsAddMcpServerModalOpen] = useState(false);
|
||||||
|
|
||||||
|
// 刷新触发器,用于触发 GroupServiceTable 刷新
|
||||||
|
const [refreshTrigger, setRefreshTrigger] = useState(0);
|
||||||
|
const [newGroupId, setNewGroupId] = useState<string | null>(null);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 保存 MCP 服务
|
||||||
|
* @param serverIds 服务ID列表
|
||||||
|
* @returns 是否保存成功
|
||||||
|
*/
|
||||||
|
const handleSaveMcpServer = async (serverIds: string[]) => {
|
||||||
|
if (!selectedGroup) return;
|
||||||
|
|
||||||
|
const success = await handleAddServiceToGroup(selectedGroup.id, serverIds);
|
||||||
|
if (success) {
|
||||||
|
setIsAddMcpServerModalOpen(false);
|
||||||
|
await loadGroupServices(selectedGroup.id, 1, serviceTableParams.current.pageSize, serviceTableParams.current.keyword);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 初始化选中第一个组,或在滚动到顶部时选中第一个
|
||||||
|
useEffect(() => {
|
||||||
|
if (groups.length > 0 && (shouldScrollToTop || !selectedGroup)) {
|
||||||
|
const index = shouldScrollToTop && newGroupId ? groups.findIndex((group) => group.id === newGroupId) : 0;
|
||||||
|
setSelectedGroup(groups[index]);
|
||||||
|
loadGroupServices(groups[index].id);
|
||||||
|
}
|
||||||
|
}, [groups, selectedGroup, loadGroupServices, shouldScrollToTop]);
|
||||||
|
|
||||||
|
// 选择组
|
||||||
|
const handleSelectGroup = (group: ResourceGroup) => {
|
||||||
|
setSelectedGroup(group);
|
||||||
|
loadGroupServices(group.id);
|
||||||
|
};
|
||||||
|
|
||||||
|
// 创建新组
|
||||||
|
const handleCreateGroup = () => {
|
||||||
|
setEditingGroup(null);
|
||||||
|
setIsGroupModalOpen(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
// 保存组(创建或编辑)
|
||||||
|
const handleSaveGroup = async (name: string, isDefault: boolean) => {
|
||||||
|
// 去除首尾空格
|
||||||
|
const trimmedName = name.trim();
|
||||||
|
|
||||||
|
let success = false;
|
||||||
|
|
||||||
|
if (editingGroup) {
|
||||||
|
// 编辑现有组
|
||||||
|
success = await updateGroup(editingGroup.id, trimmedName, isDefault);
|
||||||
|
if (success && selectedGroup?.id === editingGroup.id) {
|
||||||
|
setSelectedGroup({ ...selectedGroup, name: trimmedName, isDefault });
|
||||||
|
// 触发 GroupServiceTable 刷新
|
||||||
|
setRefreshTrigger(prev => prev + 1);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 创建新组
|
||||||
|
const newGroupId = await createGroup(trimmedName, isDefault);
|
||||||
|
success = !!newGroupId;
|
||||||
|
if (newGroupId) {
|
||||||
|
setNewGroupId(newGroupId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (success) {
|
||||||
|
setIsGroupModalOpen(false);
|
||||||
|
setEditingGroup(null);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 编辑组
|
||||||
|
const handleEditGroup = (groupId: string) => {
|
||||||
|
const group = groups.find((g) => g.id === groupId);
|
||||||
|
if (group) {
|
||||||
|
setEditingGroup(group);
|
||||||
|
setIsGroupModalOpen(true);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 删除组
|
||||||
|
const handleDeleteGroup = async (groupId: string) => {
|
||||||
|
const group = groups.find((g) => g.id === groupId);
|
||||||
|
if (group) {
|
||||||
|
setSimpleResourceGroupsLoading(true);
|
||||||
|
const simpleResourceGroups = await loadSimpleResourceGroups();
|
||||||
|
setTransferToGroupId(simpleResourceGroups.filter((group) => group.id !== groupId)[0].id);
|
||||||
|
setSimpleResourceGroupsLoading(false);
|
||||||
|
setGroupToDelete(group);
|
||||||
|
setIsDeleteGroupModalOpen(true);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 确认删除组
|
||||||
|
const handleConfirmDeleteGroup = async () => {
|
||||||
|
if (groupToDelete && transferToGroupId) {
|
||||||
|
// 在删除前找到要选中的目标组
|
||||||
|
let targetGroup: ResourceGroup | null = null;
|
||||||
|
if (selectedGroup?.id === groupToDelete.id) {
|
||||||
|
const currentIndex = groups.findIndex((g) => g.id === groupToDelete.id);
|
||||||
|
if (currentIndex !== -1) {
|
||||||
|
// 优先选择上一个,如果没有上一个则选择下一个
|
||||||
|
if (currentIndex > 0) {
|
||||||
|
targetGroup = groups[currentIndex - 1];
|
||||||
|
} else if (currentIndex < groups.length - 1) {
|
||||||
|
targetGroup = groups[currentIndex + 1];
|
||||||
|
}
|
||||||
|
// 如果既没有上一个也没有下一个(只有一个元素),targetGroup 保持为 null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const success = await deleteGroup(groupToDelete.id, transferToGroupId);
|
||||||
|
|
||||||
|
if (success) {
|
||||||
|
// 等待列表刷新后选中目标组
|
||||||
|
setTimeout(() => {
|
||||||
|
if (groups.length === 0) {
|
||||||
|
// 删除后没有任何资源组了
|
||||||
|
setSelectedGroup(null);
|
||||||
|
} else if (targetGroup) {
|
||||||
|
// 在新列表中找到目标组(因为列表已经刷新了)
|
||||||
|
const newTarget = groups.find((g) => g.id === targetGroup.id);
|
||||||
|
if (newTarget) {
|
||||||
|
setSelectedGroup(newTarget);
|
||||||
|
loadGroupServices(newTarget.id);
|
||||||
|
} else {
|
||||||
|
// 如果目标组不存在了,选择第一个
|
||||||
|
setSelectedGroup(groups[0]);
|
||||||
|
loadGroupServices(groups[0].id);
|
||||||
|
}
|
||||||
|
} else if (selectedGroup?.id === groupToDelete.id) {
|
||||||
|
// 如果删除的是当前选中的组,且没有找到目标组(理论上不应该发生)
|
||||||
|
setSelectedGroup(groups[0]);
|
||||||
|
loadGroupServices(groups[0].id);
|
||||||
|
}
|
||||||
|
// 如果删除的不是当前选中的组,保持原有选中状态
|
||||||
|
}, 200);
|
||||||
|
|
||||||
|
setIsDeleteGroupModalOpen(false);
|
||||||
|
setGroupToDelete(null);
|
||||||
|
setTransferToGroupId(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 添加服务到组
|
||||||
|
const handleAddService = () => {
|
||||||
|
setIsAddMcpServerModalOpen(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
// 从组中移除服务
|
||||||
|
const handleRemoveService = (serviceId: string) => {
|
||||||
|
const service = groupServices.find((s) => s.id === serviceId);
|
||||||
|
if (service) {
|
||||||
|
setServiceToDelete(service);
|
||||||
|
setIsDeleteServiceModalOpen(true);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 确认删除服务
|
||||||
|
const handleConfirmDeleteService = async () => {
|
||||||
|
if (serviceToDelete && selectedGroup) {
|
||||||
|
const success = await removeService(selectedGroup.id, serviceToDelete.id);
|
||||||
|
|
||||||
|
if (success) {
|
||||||
|
setIsDeleteServiceModalOpen(false);
|
||||||
|
setServiceToDelete(null);
|
||||||
|
await loadGroupServices(selectedGroup.id, 1, serviceTableParams.current.pageSize, serviceTableParams.current.keyword);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<DashboardDemoContent
|
||||||
|
title={t("Resource Group")}
|
||||||
|
description={t("Manage your resource group. Each user has a resource group and can only access resources within their resource group")}
|
||||||
|
>
|
||||||
|
<div className="flex border-1 border-gray-200 rounded-lg items-stretch overflow-hidden h-full">
|
||||||
|
{/* 左侧组列表 */}
|
||||||
|
<GroupList
|
||||||
|
groups={groups}
|
||||||
|
selectedGroup={selectedGroup}
|
||||||
|
onSelectGroup={handleSelectGroup}
|
||||||
|
onCreateGroup={handleCreateGroup}
|
||||||
|
onLoadMore={loadMoreGroups}
|
||||||
|
hasMore={hasMore}
|
||||||
|
loading={loading}
|
||||||
|
shouldScrollToTop={shouldScrollToTop}
|
||||||
|
onScrolledToTop={() => setShouldScrollToTop(false)}
|
||||||
|
/>
|
||||||
|
<Divider orientation="vertical" className="h-auto" />
|
||||||
|
{/* 右侧服务列表 */}
|
||||||
|
{selectedGroup ? (
|
||||||
|
<GroupServiceTable
|
||||||
|
groupId={selectedGroup.id}
|
||||||
|
services={groupServices}
|
||||||
|
loading={servicesLoading}
|
||||||
|
pagination={serviceTablePagination}
|
||||||
|
onPageChange={(page) => handleServicePageChange(selectedGroup.id, page)}
|
||||||
|
onAddService={handleAddService}
|
||||||
|
onRemoveService={handleRemoveService}
|
||||||
|
onEditGroup={handleEditGroup}
|
||||||
|
onDeleteGroup={handleDeleteGroup}
|
||||||
|
refreshTrigger={refreshTrigger}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<div className="flex-1 flex items-center justify-center text-default-400">
|
||||||
|
{t("Please select a group to view services")}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* 删除资源组模态框 */}
|
||||||
|
<DeleteServerModal
|
||||||
|
isOpen={isDeleteGroupModalOpen}
|
||||||
|
onClose={() => {
|
||||||
|
setIsDeleteGroupModalOpen(false);
|
||||||
|
setGroupToDelete(null);
|
||||||
|
setTransferToGroupId(null);
|
||||||
|
}}
|
||||||
|
onConfirm={handleConfirmDeleteGroup}
|
||||||
|
title={t("Confirm Remove")}
|
||||||
|
description={t(
|
||||||
|
'Are you sure you want to remove this "{{name}}" Resource Group?',
|
||||||
|
{
|
||||||
|
name: groupToDelete?.name || "",
|
||||||
|
}
|
||||||
|
)}
|
||||||
|
alertDescription={t("The bound users have been transferred to the following resource group")}
|
||||||
|
customAlertContent={<div className="w-full mt-[10px]">
|
||||||
|
<Select
|
||||||
|
placeholder={t("Select resource group")}
|
||||||
|
isLoading={simpleResourceGroupsLoading}
|
||||||
|
selectedKeys={transferToGroupId ? [transferToGroupId] : simpleResourceGroups.length > 0 ? [simpleResourceGroups.filter((group) => group.id !== groupToDelete?.id)[0].id] : []}
|
||||||
|
onSelectionChange={(keys) => {
|
||||||
|
const selectedKey = Array.from(keys)[0] as string;
|
||||||
|
if (selectedKey) {
|
||||||
|
setTransferToGroupId(selectedKey);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
labelPlacement="outside"
|
||||||
|
>
|
||||||
|
{simpleResourceGroups.filter((group) => group.id !== groupToDelete?.id).map((group) => (
|
||||||
|
<SelectItem key={group.id} value={group.id}>
|
||||||
|
{group.name}
|
||||||
|
</SelectItem>
|
||||||
|
))}
|
||||||
|
</Select>
|
||||||
|
</div>}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{/* 删除服务模态框 */}
|
||||||
|
<DeleteServerModal
|
||||||
|
isOpen={isDeleteServiceModalOpen}
|
||||||
|
onClose={() => {
|
||||||
|
setIsDeleteServiceModalOpen(false);
|
||||||
|
setServiceToDelete(null);
|
||||||
|
}}
|
||||||
|
onConfirm={handleConfirmDeleteService}
|
||||||
|
title={t("Confirm Remove")}
|
||||||
|
description={t(
|
||||||
|
'Are you sure you want to remove this "{{name}}" mcp server from "{{groupName}}" resource group?',
|
||||||
|
{
|
||||||
|
name: serviceToDelete?.name || "",
|
||||||
|
groupName: selectedGroup?.name || "",
|
||||||
|
}
|
||||||
|
)}
|
||||||
|
alertDescription={t("Users associated with this resource group will not be able to call the removed MCP server")}
|
||||||
|
/>
|
||||||
|
{/* 创建/编辑组模态框 */}
|
||||||
|
<AddServerModal
|
||||||
|
isOpen={isGroupModalOpen}
|
||||||
|
onClose={() => {
|
||||||
|
setIsGroupModalOpen(false);
|
||||||
|
setEditingGroup(null);
|
||||||
|
}}
|
||||||
|
name={editingGroup?.name || ""}
|
||||||
|
id={editingGroup?.id || ""}
|
||||||
|
isDefault={editingGroup?.isDefault || false}
|
||||||
|
onSaveServer={handleSaveGroup}
|
||||||
|
type={editingGroup ? "edit" : "add"}
|
||||||
|
/>
|
||||||
|
<AddMcpServerModal
|
||||||
|
id={selectedGroup?.id || ""}
|
||||||
|
isOpen={isAddMcpServerModalOpen}
|
||||||
|
onClose={() => {
|
||||||
|
setIsAddMcpServerModalOpen(false);
|
||||||
|
}}
|
||||||
|
onSaveMcpServer={handleSaveMcpServer}
|
||||||
|
/>
|
||||||
|
</DashboardDemoContent>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ResourceGroupManagement;
|
||||||
@@ -1,13 +1,52 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import React from "react";
|
import React, { useState, useRef, useEffect } from "react";
|
||||||
import { RevenueTable } from "./RevenueTable";
|
import { RevenueTable } from "./RevenueTable";
|
||||||
import DashboardDemoContent from "@/shared/components/DashboardDemoContent";
|
import DashboardDemoContent from "@/shared/components/DashboardDemoContent";
|
||||||
import { useRevenueManagement } from "@/hooks/useRevenueManagement";
|
import { useRevenueManagement } from "@/hooks/useRevenueManagement";
|
||||||
|
import { Input } from "@nextui-org/react";
|
||||||
|
import { Search } from "lucide-react";
|
||||||
|
import { useTranslation } from "@/shared/lib/useTranslation";
|
||||||
|
|
||||||
const RevenueManagement: React.FC = () => {
|
const RevenueManagement: React.FC = () => {
|
||||||
|
const { t } = useTranslation();
|
||||||
// use custom hook to manage revenue data
|
// use custom hook to manage revenue data
|
||||||
const { records, loading, pagination, setPage } = useRevenueManagement();
|
const {
|
||||||
|
records,
|
||||||
|
loading,
|
||||||
|
pagination,
|
||||||
|
setPage,
|
||||||
|
setSearch,
|
||||||
|
setPaymentType,
|
||||||
|
setSort
|
||||||
|
} = useRevenueManagement();
|
||||||
|
|
||||||
|
const [searchValue, setSearchValue] = useState('');
|
||||||
|
const searchTimerRef = useRef<NodeJS.Timeout | null>(null);
|
||||||
|
|
||||||
|
// 清理定时器
|
||||||
|
useEffect(() => {
|
||||||
|
return () => {
|
||||||
|
if (searchTimerRef.current) {
|
||||||
|
clearTimeout(searchTimerRef.current);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
// 处理搜索 - 使用防抖
|
||||||
|
const handleSearchChange = (value: string) => {
|
||||||
|
setSearchValue(value);
|
||||||
|
|
||||||
|
// 清除之前的定时器
|
||||||
|
if (searchTimerRef.current) {
|
||||||
|
clearTimeout(searchTimerRef.current);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 设置新的定时器,500ms 后触发搜索
|
||||||
|
searchTimerRef.current = setTimeout(() => {
|
||||||
|
setSearch(value);
|
||||||
|
}, 500);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DashboardDemoContent
|
<DashboardDemoContent
|
||||||
@@ -15,13 +54,24 @@ const RevenueManagement: React.FC = () => {
|
|||||||
description="Monitor platform revenue and view user recharge history"
|
description="Monitor platform revenue and view user recharge history"
|
||||||
>
|
>
|
||||||
<div className="space-y-6 w-full">
|
<div className="space-y-6 w-full">
|
||||||
{/* comming soon:Filters */}
|
{/* 搜索框 - 右上角 */}
|
||||||
{/* <RevenueFiltersBar
|
<div className="flex justify-end items-center gap-4">
|
||||||
searchQuery={searchQuery}
|
<Input
|
||||||
onSearchChange={setSearch}
|
isClearable
|
||||||
statusFilter={statusFilter}
|
className="w-full sm:max-w-[400px]"
|
||||||
onStatusChange={setStatus}
|
placeholder={t('Search by email')}
|
||||||
/> */}
|
startContent={<Search className="w-4 h-4" />}
|
||||||
|
value={searchValue}
|
||||||
|
onClear={() => {
|
||||||
|
setSearchValue('');
|
||||||
|
if (searchTimerRef.current) {
|
||||||
|
clearTimeout(searchTimerRef.current);
|
||||||
|
}
|
||||||
|
setSearch('');
|
||||||
|
}}
|
||||||
|
onValueChange={handleSearchChange}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
{/* Revenue Table */}
|
{/* Revenue Table */}
|
||||||
<RevenueTable
|
<RevenueTable
|
||||||
@@ -29,6 +79,8 @@ const RevenueManagement: React.FC = () => {
|
|||||||
loading={loading}
|
loading={loading}
|
||||||
pagination={pagination}
|
pagination={pagination}
|
||||||
onPageChange={setPage}
|
onPageChange={setPage}
|
||||||
|
onPaymentTypeChange={setPaymentType}
|
||||||
|
onSortChange={setSort}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</DashboardDemoContent>
|
</DashboardDemoContent>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import React from 'react';
|
import React, { useState } from 'react';
|
||||||
import {
|
import {
|
||||||
Table,
|
Table,
|
||||||
TableHeader,
|
TableHeader,
|
||||||
@@ -10,11 +10,17 @@ import {
|
|||||||
TableCell,
|
TableCell,
|
||||||
Pagination,
|
Pagination,
|
||||||
Chip,
|
Chip,
|
||||||
Spinner
|
Spinner,
|
||||||
|
Tooltip,
|
||||||
|
Dropdown,
|
||||||
|
DropdownTrigger,
|
||||||
|
DropdownMenu,
|
||||||
|
DropdownItem,
|
||||||
|
Button
|
||||||
} from '@nextui-org/react';
|
} from '@nextui-org/react';
|
||||||
import { useTranslation } from '@/shared/lib/useTranslation';
|
import { useTranslation } from '@/shared/lib/useTranslation';
|
||||||
import { PaymentState, RevenueRecord } from '@/types/revenue';
|
import { PaymentState, RevenueRecord } from '@/types/revenue';
|
||||||
import { Calendar, CreditCard } from 'lucide-react';
|
import { Calendar, CreditCard, HelpCircle, Filter, ArrowUpDown, ArrowUp, ArrowDown } from 'lucide-react';
|
||||||
import { formatCurrency } from '@/shared/utils/currency';
|
import { formatCurrency } from '@/shared/utils/currency';
|
||||||
|
|
||||||
interface RevenueTableProps {
|
interface RevenueTableProps {
|
||||||
@@ -26,6 +32,8 @@ interface RevenueTableProps {
|
|||||||
total: number;
|
total: number;
|
||||||
};
|
};
|
||||||
onPageChange: (page: number) => void;
|
onPageChange: (page: number) => void;
|
||||||
|
onPaymentTypeChange?: (paymentType: string) => void;
|
||||||
|
onSortChange?: (field: string | undefined, order: 'asc' | 'desc' | undefined) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const RevenueTable: React.FC<RevenueTableProps> = ({
|
export const RevenueTable: React.FC<RevenueTableProps> = ({
|
||||||
@@ -33,8 +41,12 @@ export const RevenueTable: React.FC<RevenueTableProps> = ({
|
|||||||
loading = false,
|
loading = false,
|
||||||
pagination,
|
pagination,
|
||||||
onPageChange,
|
onPageChange,
|
||||||
|
onPaymentTypeChange,
|
||||||
|
onSortChange,
|
||||||
}) => {
|
}) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
const [selectedPaymentType, setSelectedPaymentType] = useState('all');
|
||||||
|
const [sortState, setSortState] = useState<'none' | 'desc' | 'asc'>('none');
|
||||||
|
|
||||||
const pages = Math.ceil(pagination.total / pagination.pageSize);
|
const pages = Math.ceil(pagination.total / pagination.pageSize);
|
||||||
const currentPage = pagination.page;
|
const currentPage = pagination.page;
|
||||||
@@ -91,6 +103,35 @@ export const RevenueTable: React.FC<RevenueTableProps> = ({
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 处理付款方式筛选
|
||||||
|
const handlePaymentTypeChange = (type: string) => {
|
||||||
|
setSelectedPaymentType(type);
|
||||||
|
onPaymentTypeChange?.(type);
|
||||||
|
};
|
||||||
|
|
||||||
|
// 处理排序
|
||||||
|
const handleSortClick = () => {
|
||||||
|
let newSortState: 'none' | 'desc' | 'asc';
|
||||||
|
if (sortState === 'none') {
|
||||||
|
newSortState = 'desc';
|
||||||
|
onSortChange?.('amount', 'desc');
|
||||||
|
} else if (sortState === 'desc') {
|
||||||
|
newSortState = 'asc';
|
||||||
|
onSortChange?.('amount', 'asc');
|
||||||
|
} else {
|
||||||
|
newSortState = 'none';
|
||||||
|
onSortChange?.(undefined, undefined);
|
||||||
|
}
|
||||||
|
setSortState(newSortState);
|
||||||
|
};
|
||||||
|
|
||||||
|
// 获取排序图标
|
||||||
|
const getSortIcon = () => {
|
||||||
|
if (sortState === 'desc') return <ArrowDown className="w-4 h-4" />;
|
||||||
|
if (sortState === 'asc') return <ArrowUp className="w-4 h-4" />;
|
||||||
|
return <ArrowUpDown className="w-4 h-4" />;
|
||||||
|
};
|
||||||
|
|
||||||
if (loading) {
|
if (loading) {
|
||||||
return (
|
return (
|
||||||
<div className="flex justify-center items-center h-64">
|
<div className="flex justify-center items-center h-64">
|
||||||
@@ -121,9 +162,68 @@ export const RevenueTable: React.FC<RevenueTableProps> = ({
|
|||||||
>
|
>
|
||||||
<TableHeader>
|
<TableHeader>
|
||||||
<TableColumn>{t('Account (Email)')}</TableColumn>
|
<TableColumn>{t('Account (Email)')}</TableColumn>
|
||||||
<TableColumn>{t('Recharge Amount')}</TableColumn>
|
<TableColumn>
|
||||||
<TableColumn>{t('Recharge Time')}</TableColumn>
|
<div className="flex items-center gap-2">
|
||||||
<TableColumn>{t('Payment Method')}</TableColumn>
|
<span>{t('Recharge Amount')}</span>
|
||||||
|
<Button
|
||||||
|
isIconOnly
|
||||||
|
size="sm"
|
||||||
|
variant="light"
|
||||||
|
onPress={handleSortClick}
|
||||||
|
className="min-w-unit-6 w-6 h-6"
|
||||||
|
>
|
||||||
|
{getSortIcon()}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</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>
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<span>{t('Payment Method')}</span>
|
||||||
|
<Dropdown>
|
||||||
|
<DropdownTrigger>
|
||||||
|
<Button
|
||||||
|
isIconOnly
|
||||||
|
size="sm"
|
||||||
|
variant="light"
|
||||||
|
aria-label="Filter by payment method"
|
||||||
|
className="min-w-unit-6 w-6 h-6"
|
||||||
|
>
|
||||||
|
<Filter
|
||||||
|
className={`w-4 h-4 ${
|
||||||
|
selectedPaymentType !== 'all' ? 'text-primary' : ''
|
||||||
|
}`}
|
||||||
|
/>
|
||||||
|
</Button>
|
||||||
|
</DropdownTrigger>
|
||||||
|
<DropdownMenu
|
||||||
|
aria-label="Payment method filter"
|
||||||
|
selectionMode="single"
|
||||||
|
selectedKeys={[selectedPaymentType]}
|
||||||
|
onSelectionChange={(keys) => {
|
||||||
|
const selected = Array.from(keys)[0] as string;
|
||||||
|
handlePaymentTypeChange(selected);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<DropdownItem key="all">{t('All')}</DropdownItem>
|
||||||
|
<DropdownItem key="stripe">Stripe</DropdownItem>
|
||||||
|
<DropdownItem key="platform">Platform</DropdownItem>
|
||||||
|
</DropdownMenu>
|
||||||
|
</Dropdown>
|
||||||
|
</div>
|
||||||
|
</TableColumn>
|
||||||
<TableColumn>{t('Transaction ID')}</TableColumn>
|
<TableColumn>{t('Transaction ID')}</TableColumn>
|
||||||
<TableColumn>{t('Status')}</TableColumn>
|
<TableColumn>{t('Status')}</TableColumn>
|
||||||
</TableHeader>
|
</TableHeader>
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ export const AdminConfigForm: React.FC<AdminConfigFormProps> = ({
|
|||||||
formData.username.trim() !== "" &&
|
formData.username.trim() !== "" &&
|
||||||
formData.password?.trim() !== "" &&
|
formData.password?.trim() !== "" &&
|
||||||
formData.password === confirmPassword &&
|
formData.password === confirmPassword &&
|
||||||
formData.password?.length >= 8;
|
formData.password?.length >= 6;
|
||||||
|
|
||||||
const passwordsMatch = formData.password === confirmPassword;
|
const passwordsMatch = formData.password === confirmPassword;
|
||||||
|
|
||||||
@@ -86,7 +86,7 @@ export const AdminConfigForm: React.FC<AdminConfigFormProps> = ({
|
|||||||
<Input
|
<Input
|
||||||
label={t("Administrator Password")}
|
label={t("Administrator Password")}
|
||||||
placeholder={t("Enter administrator password")}
|
placeholder={t("Enter administrator password")}
|
||||||
description={t("Password must be at least 8 characters long")}
|
description={t("Password must be at least 6 characters long")}
|
||||||
value={formData.password}
|
value={formData.password}
|
||||||
onChange={(e) => handleInputChange("password", e.target.value)}
|
onChange={(e) => handleInputChange("password", e.target.value)}
|
||||||
type={showPassword ? "text" : "password"}
|
type={showPassword ? "text" : "password"}
|
||||||
@@ -106,13 +106,13 @@ export const AdminConfigForm: React.FC<AdminConfigFormProps> = ({
|
|||||||
isRequired
|
isRequired
|
||||||
autoComplete="new-password"
|
autoComplete="new-password"
|
||||||
color={
|
color={
|
||||||
formData.password?.length > 0 && formData.password?.length < 8
|
formData.password?.length > 0 && formData.password?.length < 6
|
||||||
? "danger"
|
? "danger"
|
||||||
: "default"
|
: "default"
|
||||||
}
|
}
|
||||||
errorMessage={
|
errorMessage={
|
||||||
formData.password?.length > 0 && formData.password?.length < 8
|
formData.password?.length > 0 && formData.password?.length < 6
|
||||||
? t("Password must be at least 8 characters")
|
? t("Password must be at least 6 characters")
|
||||||
: ""
|
: ""
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -0,0 +1,111 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import React, { useEffect, useState } from "react";
|
||||||
|
import { Button, Input } from "@nextui-org/react";
|
||||||
|
import { fetchAdminAPI } from "@/rpc/admin-api";
|
||||||
|
import { useTranslation } from "@/shared/lib/useTranslation";
|
||||||
|
import toast from "react-hot-toast";
|
||||||
|
|
||||||
|
interface FreeQuotaResponse {
|
||||||
|
free_global_daily_limit: number | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Platform-wide daily call cap for free services.
|
||||||
|
*
|
||||||
|
* Stored in sys_config under free_global_daily_limit. The billing service takes
|
||||||
|
* the smaller of this value and any per-service limit, so a service with no
|
||||||
|
* limit of its own still inherits this one.
|
||||||
|
*/
|
||||||
|
export const FreeQuotaSettings: React.FC = () => {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const [value, setValue] = useState<string>("");
|
||||||
|
const [loading, setLoading] = useState<boolean>(true);
|
||||||
|
const [saving, setSaving] = useState<boolean>(false);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
let mounted = true;
|
||||||
|
(async () => {
|
||||||
|
const res = await fetchAdminAPI<FreeQuotaResponse>(
|
||||||
|
"/api/sysconfig/free-quota",
|
||||||
|
{ method: "GET" }
|
||||||
|
);
|
||||||
|
if (!mounted) return;
|
||||||
|
if (res.success) {
|
||||||
|
const n = res.data?.free_global_daily_limit;
|
||||||
|
setValue(n && n > 0 ? String(n) : "");
|
||||||
|
} else if (res.error_message) {
|
||||||
|
toast.error(res.error_message);
|
||||||
|
}
|
||||||
|
setLoading(false);
|
||||||
|
})();
|
||||||
|
return () => {
|
||||||
|
mounted = false;
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const handleSave = async () => {
|
||||||
|
const raw = value.trim();
|
||||||
|
let payload: number | null = null;
|
||||||
|
if (raw !== "") {
|
||||||
|
const n = Number(raw);
|
||||||
|
if (!Number.isInteger(n) || n < 0) {
|
||||||
|
toast.error(t("Enter a non-negative integer"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
payload = n;
|
||||||
|
}
|
||||||
|
|
||||||
|
setSaving(true);
|
||||||
|
const res = await fetchAdminAPI<FreeQuotaResponse>(
|
||||||
|
"/api/sysconfig/free-quota",
|
||||||
|
{ method: "PUT", body: { free_global_daily_limit: payload } as unknown as BodyInit }
|
||||||
|
);
|
||||||
|
setSaving(false);
|
||||||
|
|
||||||
|
if (res.success) {
|
||||||
|
const n = res.data?.free_global_daily_limit;
|
||||||
|
setValue(n && n > 0 ? String(n) : "");
|
||||||
|
toast.success(t("Free call limit saved"));
|
||||||
|
} else {
|
||||||
|
toast.error(res.error_message || t("Failed to save free call limit"));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="space-y-4">
|
||||||
|
<Input
|
||||||
|
type="number"
|
||||||
|
min={0}
|
||||||
|
step={1}
|
||||||
|
labelPlacement="outside"
|
||||||
|
label={t("Platform-wide daily call limit per user")}
|
||||||
|
placeholder={t("Example 100")}
|
||||||
|
value={value}
|
||||||
|
isDisabled={loading || saving}
|
||||||
|
onValueChange={setValue}
|
||||||
|
description={t(
|
||||||
|
"Applies to every free service, leave blank or 0 for unlimited"
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<p className="text-xs text-default-400">
|
||||||
|
{t("If a service also has its own limit, the smaller number wins")}
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<div className="flex gap-3 py-4">
|
||||||
|
<Button
|
||||||
|
color="primary"
|
||||||
|
variant="solid"
|
||||||
|
onPress={handleSave}
|
||||||
|
isLoading={saving}
|
||||||
|
size="sm"
|
||||||
|
>
|
||||||
|
{t("Save")}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default FreeQuotaSettings;
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import React from "react";
|
||||||
|
import { Switch } from "@nextui-org/react";
|
||||||
|
import { useTranslation } from "@/shared/lib/useTranslation";
|
||||||
|
|
||||||
|
export type TagsBarSettingConfig = {
|
||||||
|
tag_bar_display: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
interface TagsBarSettingProps {
|
||||||
|
isEnabled: boolean;
|
||||||
|
onSave: (config: TagsBarSettingConfig) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const TagsBarSetting: React.FC<TagsBarSettingProps> = ({
|
||||||
|
isEnabled,
|
||||||
|
onSave,
|
||||||
|
}) => {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="space-y-4">
|
||||||
|
<div className="flex flex-col gap-4">
|
||||||
|
{/* showcase in xpack */}
|
||||||
|
<div className="flex items-center justify-between p-4 bg-gray-50 rounded-lg">
|
||||||
|
<div className="flex flex-col gap-1">
|
||||||
|
<span className="text-sm font-medium">
|
||||||
|
{t("Display tags bar")}
|
||||||
|
</span>
|
||||||
|
<span className="text-xs text-gray-500">
|
||||||
|
{t(
|
||||||
|
"Front end displays tags bar and allows users to filter products based on tags."
|
||||||
|
)}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<Switch
|
||||||
|
isSelected={isEnabled}
|
||||||
|
onValueChange={(value) => {
|
||||||
|
onSave({
|
||||||
|
tag_bar_display: value
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
color="primary"
|
||||||
|
size="sm"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -18,6 +18,7 @@ import { useTranslation } from "react-i18next";
|
|||||||
import { sanitizeMCPServerName } from "@/shared/utils/mcp";
|
import { sanitizeMCPServerName } from "@/shared/utils/mcp";
|
||||||
import { useNavigationItems } from "@/shared/providers/ConfigProvider";
|
import { useNavigationItems } from "@/shared/providers/ConfigProvider";
|
||||||
import { withComponentInjection } from "@/shared/hooks/useComponentInjection";
|
import { withComponentInjection } from "@/shared/hooks/useComponentInjection";
|
||||||
|
import { useSharedStore } from "@/shared/store/share";
|
||||||
|
|
||||||
interface ProductDetailThemeSelectorProps {
|
interface ProductDetailThemeSelectorProps {
|
||||||
product: ServiceData;
|
product: ServiceData;
|
||||||
@@ -36,8 +37,13 @@ const BasicProductDetailThemeSelector: React.FC<
|
|||||||
platformConfig.mcp_server_prefix || process.env.NEXT_PUBLIC_MCP_URL || "";
|
platformConfig.mcp_server_prefix || process.env.NEXT_PUBLIC_MCP_URL || "";
|
||||||
const [url, setUrl] = useState<string>("");
|
const [url, setUrl] = useState<string>("");
|
||||||
const [mcpName, setMcpName] = useState<string>("");
|
const [mcpName, setMcpName] = useState<string>("");
|
||||||
|
const [can_invoke, setCanInvoke] = useState<boolean>(false);
|
||||||
|
const [visitor, setVisitor] = useState<boolean>(false);
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const configNavigation = useNavigationItems() || NavigationItems;
|
const configNavigation = useNavigationItems() || NavigationItems;
|
||||||
|
|
||||||
|
// 使用 Zustand hook 正确订阅 user 状态
|
||||||
|
const user = useSharedStore((state) => state.user);
|
||||||
|
|
||||||
const navigationItems = [
|
const navigationItems = [
|
||||||
...configNavigation,
|
...configNavigation,
|
||||||
@@ -56,6 +62,24 @@ const BasicProductDetailThemeSelector: React.FC<
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setMcpName(sanitizeMCPServerName(product.name));
|
setMcpName(sanitizeMCPServerName(product.name));
|
||||||
}, [product.name]);
|
}, [product.name]);
|
||||||
|
useEffect(() => {
|
||||||
|
if (user) {
|
||||||
|
if (user?.allow_all) {
|
||||||
|
setCanInvoke(true)
|
||||||
|
} else {
|
||||||
|
const serviceId = product.id
|
||||||
|
const allowIds = user.service_ids
|
||||||
|
if (!allowIds?.includes(serviceId)) {
|
||||||
|
setCanInvoke(false)
|
||||||
|
} else {
|
||||||
|
setCanInvoke(true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
setCanInvoke(true);
|
||||||
|
setVisitor(true);
|
||||||
|
}
|
||||||
|
}, [user, product.id]);
|
||||||
const getCodeContent = () => {
|
const getCodeContent = () => {
|
||||||
return `{
|
return `{
|
||||||
"mcpServers": {
|
"mcpServers": {
|
||||||
@@ -82,6 +106,8 @@ const BasicProductDetailThemeSelector: React.FC<
|
|||||||
case Theme.MODERN:
|
case Theme.MODERN:
|
||||||
return (
|
return (
|
||||||
<ModernDetail
|
<ModernDetail
|
||||||
|
can_invoke={can_invoke}
|
||||||
|
visitor={visitor}
|
||||||
product={product}
|
product={product}
|
||||||
breadcrumbs={breadcrumbs}
|
breadcrumbs={breadcrumbs}
|
||||||
url={url}
|
url={url}
|
||||||
@@ -93,6 +119,8 @@ const BasicProductDetailThemeSelector: React.FC<
|
|||||||
case Theme.CLASSIC:
|
case Theme.CLASSIC:
|
||||||
return (
|
return (
|
||||||
<ClassicDetail
|
<ClassicDetail
|
||||||
|
can_invoke={can_invoke}
|
||||||
|
visitor={visitor}
|
||||||
product={product}
|
product={product}
|
||||||
breadcrumbs={breadcrumbs}
|
breadcrumbs={breadcrumbs}
|
||||||
url={url}
|
url={url}
|
||||||
@@ -104,6 +132,8 @@ const BasicProductDetailThemeSelector: React.FC<
|
|||||||
case Theme.CREATIVE:
|
case Theme.CREATIVE:
|
||||||
return (
|
return (
|
||||||
<CreativeDetail
|
<CreativeDetail
|
||||||
|
can_invoke={can_invoke}
|
||||||
|
visitor={visitor}
|
||||||
product={product}
|
product={product}
|
||||||
breadcrumbs={breadcrumbs}
|
breadcrumbs={breadcrumbs}
|
||||||
url={url}
|
url={url}
|
||||||
@@ -115,6 +145,8 @@ const BasicProductDetailThemeSelector: React.FC<
|
|||||||
case Theme.TEMU:
|
case Theme.TEMU:
|
||||||
return (
|
return (
|
||||||
<TemuDetail
|
<TemuDetail
|
||||||
|
can_invoke={can_invoke}
|
||||||
|
visitor={visitor}
|
||||||
product={product}
|
product={product}
|
||||||
breadcrumbs={breadcrumbs}
|
breadcrumbs={breadcrumbs}
|
||||||
url={url}
|
url={url}
|
||||||
@@ -131,6 +163,8 @@ const BasicProductDetailThemeSelector: React.FC<
|
|||||||
<main className="flex-1">
|
<main className="flex-1">
|
||||||
<ProductDetailClient
|
<ProductDetailClient
|
||||||
product={product}
|
product={product}
|
||||||
|
can_invoke={can_invoke}
|
||||||
|
visitor={visitor}
|
||||||
mcpName={mcpName}
|
mcpName={mcpName}
|
||||||
url={url}
|
url={url}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import { Home as ClassicHome } from "./classic/Home";
|
|||||||
import { Home as CreativeHome } from "./creative/Home";
|
import { Home as CreativeHome } from "./creative/Home";
|
||||||
import { Home as TemuHome } from "./temu/Home";
|
import { Home as TemuHome } from "./temu/Home";
|
||||||
import { ServiceData } from "@/shared/types/marketplace";
|
import { ServiceData } from "@/shared/types/marketplace";
|
||||||
import { fetchServices } from "@/services/marketplaceService";
|
import { fetchServices, fetchTagsList } from "@/services/marketplaceService";
|
||||||
import { Navigation } from "@/shared/components/Navigation";
|
import { Navigation } from "@/shared/components/Navigation";
|
||||||
import { MarketplaceMain } from "../marketplace/Main";
|
import { MarketplaceMain } from "../marketplace/Main";
|
||||||
import { Footer } from "@/shared/components/Footer";
|
import { Footer } from "@/shared/components/Footer";
|
||||||
@@ -53,18 +53,36 @@ export const ThemeSelector: React.FC<ThemeSelectorProps> = ({
|
|||||||
const [currentPage, setCurrentPage] = useState(initialPage);
|
const [currentPage, setCurrentPage] = useState(initialPage);
|
||||||
const [total, setTotal] = useState(initialTotal);
|
const [total, setTotal] = useState(initialTotal);
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
|
const isTagBarDisplay = platformConfig.tag_bar_display || false;
|
||||||
|
// 可用的标签列表(这里可以从API获取或配置)
|
||||||
|
const [availableTags, setAvailableTags] = useState<string[]>([]);
|
||||||
|
const [selectedTag, setSelectedTag] = useState("ALL");
|
||||||
// search suggestion
|
// search suggestion
|
||||||
const searchSuggestions = ["Search MCP servers"];
|
const searchSuggestions = ["Search MCP servers"];
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const loadTagsList = async () => {
|
||||||
|
const tags = await fetchTagsList();
|
||||||
|
setAvailableTags(tags);
|
||||||
|
};
|
||||||
|
loadTagsList();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
// handle tag change
|
||||||
|
const handleTagChange = (tag: string) => {
|
||||||
|
setSelectedTag(tag);
|
||||||
|
setCurrentPage(1);
|
||||||
|
loadServices(1, searchQuery, tag);
|
||||||
|
};
|
||||||
// loading service data
|
// loading service data
|
||||||
const loadServices = async (page: number, search: string) => {
|
const loadServices = async (page: number, search: string, tag: string = "ALL") => {
|
||||||
try {
|
try {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
const result = await fetchServices({
|
const result = await fetchServices({
|
||||||
page,
|
page,
|
||||||
page_size: pageSize,
|
page_size: pageSize,
|
||||||
keyword: search,
|
keyword: search,
|
||||||
|
tag: tag !== "ALL" ? tag : undefined,
|
||||||
});
|
});
|
||||||
|
|
||||||
setServices(result.data.services);
|
setServices(result.data.services);
|
||||||
@@ -103,13 +121,13 @@ export const ThemeSelector: React.FC<ThemeSelectorProps> = ({
|
|||||||
// page change handler
|
// page change handler
|
||||||
const handlePageChange = (page: number) => {
|
const handlePageChange = (page: number) => {
|
||||||
updateURL(page, searchQuery);
|
updateURL(page, searchQuery);
|
||||||
loadServices(page, searchQuery);
|
loadServices(page, searchQuery, selectedTag);
|
||||||
};
|
};
|
||||||
|
|
||||||
// search submit handler
|
// search submit handler
|
||||||
const handleSearch = () => {
|
const handleSearch = () => {
|
||||||
updateURL(1, searchQuery);
|
updateURL(1, searchQuery);
|
||||||
loadServices(1, searchQuery);
|
loadServices(1, searchQuery, selectedTag);
|
||||||
};
|
};
|
||||||
|
|
||||||
// search input change handler
|
// search input change handler
|
||||||
@@ -122,6 +140,11 @@ export const ThemeSelector: React.FC<ThemeSelectorProps> = ({
|
|||||||
case Theme.MODERN:
|
case Theme.MODERN:
|
||||||
return (
|
return (
|
||||||
<ModernHome
|
<ModernHome
|
||||||
|
currentTheme={currentTheme}
|
||||||
|
selectedTag={selectedTag}
|
||||||
|
handleTagChange={handleTagChange}
|
||||||
|
isTagBarDisplay={isTagBarDisplay}
|
||||||
|
availableTags={availableTags}
|
||||||
searchQuery={searchQuery}
|
searchQuery={searchQuery}
|
||||||
services={services}
|
services={services}
|
||||||
currentPage={currentPage}
|
currentPage={currentPage}
|
||||||
@@ -139,6 +162,11 @@ export const ThemeSelector: React.FC<ThemeSelectorProps> = ({
|
|||||||
case Theme.CLASSIC:
|
case Theme.CLASSIC:
|
||||||
return (
|
return (
|
||||||
<ClassicHome
|
<ClassicHome
|
||||||
|
currentTheme={currentTheme}
|
||||||
|
selectedTag={selectedTag}
|
||||||
|
handleTagChange={handleTagChange}
|
||||||
|
isTagBarDisplay={isTagBarDisplay}
|
||||||
|
availableTags={availableTags}
|
||||||
searchQuery={searchQuery}
|
searchQuery={searchQuery}
|
||||||
services={services}
|
services={services}
|
||||||
currentPage={currentPage}
|
currentPage={currentPage}
|
||||||
@@ -156,6 +184,11 @@ export const ThemeSelector: React.FC<ThemeSelectorProps> = ({
|
|||||||
case Theme.CREATIVE:
|
case Theme.CREATIVE:
|
||||||
return (
|
return (
|
||||||
<CreativeHome
|
<CreativeHome
|
||||||
|
currentTheme={currentTheme}
|
||||||
|
selectedTag={selectedTag}
|
||||||
|
handleTagChange={handleTagChange}
|
||||||
|
isTagBarDisplay={isTagBarDisplay}
|
||||||
|
availableTags={availableTags}
|
||||||
searchQuery={searchQuery}
|
searchQuery={searchQuery}
|
||||||
services={services}
|
services={services}
|
||||||
currentPage={currentPage}
|
currentPage={currentPage}
|
||||||
@@ -173,6 +206,11 @@ export const ThemeSelector: React.FC<ThemeSelectorProps> = ({
|
|||||||
case Theme.TEMU:
|
case Theme.TEMU:
|
||||||
return (
|
return (
|
||||||
<TemuHome
|
<TemuHome
|
||||||
|
currentTheme={currentTheme}
|
||||||
|
selectedTag={selectedTag}
|
||||||
|
handleTagChange={handleTagChange}
|
||||||
|
isTagBarDisplay={isTagBarDisplay}
|
||||||
|
availableTags={availableTags}
|
||||||
searchQuery={searchQuery}
|
searchQuery={searchQuery}
|
||||||
services={services}
|
services={services}
|
||||||
currentPage={currentPage}
|
currentPage={currentPage}
|
||||||
@@ -194,6 +232,11 @@ export const ThemeSelector: React.FC<ThemeSelectorProps> = ({
|
|||||||
<Navigation items={navigationItems} />
|
<Navigation items={navigationItems} />
|
||||||
<main className="flex-1">
|
<main className="flex-1">
|
||||||
<MarketplaceMain
|
<MarketplaceMain
|
||||||
|
currentTheme={currentTheme}
|
||||||
|
selectedTag={selectedTag}
|
||||||
|
setSelectedTag={setSelectedTag}
|
||||||
|
isTagBarDisplay={isTagBarDisplay}
|
||||||
|
availableTags={availableTags}
|
||||||
initialServices={services}
|
initialServices={services}
|
||||||
initialTotal={total}
|
initialTotal={total}
|
||||||
initialPage={currentPage}
|
initialPage={currentPage}
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ import { NavigationItem } from "@/shared/components/Navigation";
|
|||||||
import { ServerConfig } from "@/shared/components/marketplace/ServerConfig";
|
import { ServerConfig } from "@/shared/components/marketplace/ServerConfig";
|
||||||
|
|
||||||
interface DetailProps {
|
interface DetailProps {
|
||||||
|
can_invoke?: boolean;
|
||||||
|
visitor?: boolean;
|
||||||
product: ServiceData;
|
product: ServiceData;
|
||||||
breadcrumbs?: {
|
breadcrumbs?: {
|
||||||
link: string;
|
link: string;
|
||||||
@@ -30,6 +32,8 @@ interface DetailProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const Detail: React.FC<DetailProps> = ({
|
export const Detail: React.FC<DetailProps> = ({
|
||||||
|
can_invoke,
|
||||||
|
visitor,
|
||||||
product,
|
product,
|
||||||
url,
|
url,
|
||||||
mcpName,
|
mcpName,
|
||||||
@@ -216,6 +220,8 @@ export const Detail: React.FC<DetailProps> = ({
|
|||||||
</div>
|
</div>
|
||||||
{/* Code Snippet */}
|
{/* Code Snippet */}
|
||||||
<ServerConfig
|
<ServerConfig
|
||||||
|
can_invoke={can_invoke}
|
||||||
|
visitor={visitor}
|
||||||
mcpName={mcpName}
|
mcpName={mcpName}
|
||||||
url={url}
|
url={url}
|
||||||
className="w-full max-w-2xl"
|
className="w-full max-w-2xl"
|
||||||
|
|||||||
@@ -24,11 +24,18 @@ import { Footer } from "./Footer";
|
|||||||
import { Navigation } from "./Navigation";
|
import { Navigation } from "./Navigation";
|
||||||
import { NavigationItem } from "@/shared/components/Navigation";
|
import { NavigationItem } from "@/shared/components/Navigation";
|
||||||
import { Faq } from "@/components/marketplace/Faq";
|
import { Faq } from "@/components/marketplace/Faq";
|
||||||
|
import { TagFilter } from "@/shared/components/marketplace/TagFilter";
|
||||||
|
import { ThemeType } from "@/shared/types/system";
|
||||||
|
|
||||||
interface HomeProps {
|
interface HomeProps {
|
||||||
// 状态
|
// 状态
|
||||||
searchQuery: string;
|
searchQuery: string;
|
||||||
services: ServiceData[];
|
services: ServiceData[];
|
||||||
|
isTagBarDisplay: boolean;
|
||||||
|
availableTags: string[];
|
||||||
|
selectedTag: string;
|
||||||
|
handleTagChange: (tag: string) => void;
|
||||||
|
currentTheme: ThemeType;
|
||||||
currentPage: number;
|
currentPage: number;
|
||||||
total: number;
|
total: number;
|
||||||
pageSize: number;
|
pageSize: number;
|
||||||
@@ -50,6 +57,11 @@ interface HomeProps {
|
|||||||
export const Home: React.FC<HomeProps> = ({
|
export const Home: React.FC<HomeProps> = ({
|
||||||
searchQuery,
|
searchQuery,
|
||||||
services,
|
services,
|
||||||
|
isTagBarDisplay,
|
||||||
|
availableTags,
|
||||||
|
selectedTag,
|
||||||
|
handleTagChange,
|
||||||
|
currentTheme,
|
||||||
currentPage,
|
currentPage,
|
||||||
total,
|
total,
|
||||||
pageSize,
|
pageSize,
|
||||||
@@ -83,9 +95,9 @@ export const Home: React.FC<HomeProps> = ({
|
|||||||
<h1 className="text-4xl lg:text-5xl font-bold mb-6 text-slate-800">
|
<h1 className="text-4xl lg:text-5xl font-bold mb-6 text-slate-800">
|
||||||
{t(
|
{t(
|
||||||
platformConfig.headline ||
|
platformConfig.headline ||
|
||||||
platformConfig.name ||
|
platformConfig.name ||
|
||||||
_DefaultPlatformConfig.headline ||
|
_DefaultPlatformConfig.headline ||
|
||||||
""
|
""
|
||||||
)}
|
)}
|
||||||
</h1>
|
</h1>
|
||||||
|
|
||||||
@@ -93,8 +105,8 @@ export const Home: React.FC<HomeProps> = ({
|
|||||||
<p className="text-xl text-gray-600 max-w-3xl mx-auto leading-relaxed">
|
<p className="text-xl text-gray-600 max-w-3xl mx-auto leading-relaxed">
|
||||||
{t(
|
{t(
|
||||||
platformConfig.subheadline ||
|
platformConfig.subheadline ||
|
||||||
_DefaultPlatformConfig.subheadline ||
|
_DefaultPlatformConfig.subheadline ||
|
||||||
""
|
""
|
||||||
)}
|
)}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
@@ -140,6 +152,21 @@ export const Home: React.FC<HomeProps> = ({
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{/* filter section */}
|
||||||
|
{
|
||||||
|
isTagBarDisplay && (
|
||||||
|
<div className="pt-10">
|
||||||
|
<TagFilter
|
||||||
|
theme={currentTheme}
|
||||||
|
tags={availableTags}
|
||||||
|
selectedTag={selectedTag}
|
||||||
|
onTagChange={handleTagChange}
|
||||||
|
maxWidthPercent={80}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
{/* Server List Section */}
|
{/* Server List Section */}
|
||||||
{loading ? (
|
{loading ? (
|
||||||
<div className="mx-auto h-[200px] flex items-center justify-center">
|
<div className="mx-auto h-[200px] flex items-center justify-center">
|
||||||
@@ -148,7 +175,7 @@ export const Home: React.FC<HomeProps> = ({
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<div className="bg-gray-50 py-16">
|
<div className={`bg-gray-50 ${isTagBarDisplay ? 'py-10' : 'py-16'}`}>
|
||||||
<div className="mx-auto px-6 max-w-7xl">
|
<div className="mx-auto px-6 max-w-7xl">
|
||||||
{/* Server Grid */}
|
{/* Server Grid */}
|
||||||
<div className="flex flex-wrap justify-center gap-4 mb-12">
|
<div className="flex flex-wrap justify-center gap-4 mb-12">
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import React from "react";
|
import React, { useState, useEffect } from "react";
|
||||||
import { Button } from "@nextui-org/react";
|
import { Button } from "@nextui-org/react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
|
|
||||||
@@ -8,6 +8,7 @@ import { DynamicLogo } from "@/shared/components/DynamicLogo";
|
|||||||
import { useAuth } from "@/shared/lib/useAuth";
|
import { useAuth } from "@/shared/lib/useAuth";
|
||||||
import { NavigationItem } from "@/shared/components/Navigation";
|
import { NavigationItem } from "@/shared/components/Navigation";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
|
import { useSharedStore } from "@/shared/store/share";
|
||||||
|
|
||||||
interface NavigationProps {
|
interface NavigationProps {
|
||||||
items?: NavigationItem[];
|
items?: NavigationItem[];
|
||||||
@@ -17,6 +18,13 @@ export const Navigation: React.FC<NavigationProps> = ({ items }) => {
|
|||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { handleLogin } = useAuth();
|
const { handleLogin } = useAuth();
|
||||||
|
|
||||||
|
const [userToken, setUserToken] = useState<string | null>(null);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const userToken = useSharedStore?.getState?.().user_token
|
||||||
|
setUserToken(userToken);
|
||||||
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="fixed top-0 left-0 right-0 z-50">
|
<div className="fixed top-0 left-0 right-0 z-50">
|
||||||
{/* Classic Header */}
|
{/* Classic Header */}
|
||||||
@@ -26,21 +34,27 @@ export const Navigation: React.FC<NavigationProps> = ({ items }) => {
|
|||||||
<DynamicLogo alt="Platform Logo" className="h-[32px] text-white" />
|
<DynamicLogo alt="Platform Logo" className="h-[32px] text-white" />
|
||||||
</div>
|
</div>
|
||||||
<div className="flex space-x-2">
|
<div className="flex space-x-2">
|
||||||
<Button
|
{
|
||||||
onPress={handleLogin}
|
!userToken && (
|
||||||
variant="light"
|
<>
|
||||||
className="hidden sm:block text-white text-sm px-4 py-1 rounded-sm font-medium"
|
<Button
|
||||||
size="sm"
|
onPress={handleLogin}
|
||||||
>
|
variant="light"
|
||||||
<b className="text-md"> {t("Sign In")}</b>
|
className="hidden sm:block text-white text-sm px-4 py-1 rounded-sm font-medium"
|
||||||
</Button>
|
size="sm"
|
||||||
|
>
|
||||||
|
<b className="text-md"> {t("Sign In")}</b>
|
||||||
|
</Button>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
<Button
|
<Button
|
||||||
color="primary"
|
color="primary"
|
||||||
className="bg-red-600 hover:bg-red-700 text-white text-sm px-4 py-1 rounded-sm font-medium"
|
className="bg-red-600 hover:bg-red-700 text-white text-sm px-4 py-1 rounded-sm font-medium"
|
||||||
size="sm"
|
size="sm"
|
||||||
onPress={handleLogin}
|
onPress={handleLogin}
|
||||||
>
|
>
|
||||||
{t("Get Started")}
|
{userToken ? t("Dashboard") : t("Get Started")}
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ import { NavigationItem } from "@/shared/components/Navigation";
|
|||||||
import { ServerConfig } from "@/shared/components/marketplace/ServerConfig";
|
import { ServerConfig } from "@/shared/components/marketplace/ServerConfig";
|
||||||
|
|
||||||
interface DetailProps {
|
interface DetailProps {
|
||||||
|
can_invoke?: boolean;
|
||||||
|
visitor?: boolean;
|
||||||
product: ServiceData;
|
product: ServiceData;
|
||||||
breadcrumbs?: {
|
breadcrumbs?: {
|
||||||
link: string;
|
link: string;
|
||||||
@@ -29,6 +31,8 @@ interface DetailProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const Detail: React.FC<DetailProps> = ({
|
export const Detail: React.FC<DetailProps> = ({
|
||||||
|
can_invoke,
|
||||||
|
visitor,
|
||||||
product,
|
product,
|
||||||
breadcrumbs,
|
breadcrumbs,
|
||||||
url,
|
url,
|
||||||
@@ -176,6 +180,8 @@ export const Detail: React.FC<DetailProps> = ({
|
|||||||
</div>
|
</div>
|
||||||
{/* Code Snippet */}
|
{/* Code Snippet */}
|
||||||
<ServerConfig
|
<ServerConfig
|
||||||
|
can_invoke={can_invoke}
|
||||||
|
visitor={visitor}
|
||||||
mcpName={mcpName}
|
mcpName={mcpName}
|
||||||
url={url}
|
url={url}
|
||||||
className="w-full max-w-2xl"
|
className="w-full max-w-2xl"
|
||||||
|
|||||||
@@ -24,11 +24,18 @@ import { Footer } from "./Footer";
|
|||||||
import { Navigation } from "./Navigation";
|
import { Navigation } from "./Navigation";
|
||||||
import { NavigationItem } from "@/shared/components/Navigation";
|
import { NavigationItem } from "@/shared/components/Navigation";
|
||||||
import { Faq } from "@/components/marketplace/Faq";
|
import { Faq } from "@/components/marketplace/Faq";
|
||||||
|
import { TagFilter } from "@/shared/components/marketplace/TagFilter";
|
||||||
|
import { ThemeType } from "@/shared/types/system";
|
||||||
|
|
||||||
interface HomeProps {
|
interface HomeProps {
|
||||||
// 状态
|
// 状态
|
||||||
searchQuery: string;
|
searchQuery: string;
|
||||||
services: ServiceData[];
|
services: ServiceData[];
|
||||||
|
isTagBarDisplay: boolean;
|
||||||
|
availableTags: string[];
|
||||||
|
selectedTag: string;
|
||||||
|
handleTagChange: (tag: string) => void;
|
||||||
|
currentTheme: ThemeType;
|
||||||
currentPage: number;
|
currentPage: number;
|
||||||
total: number;
|
total: number;
|
||||||
pageSize: number;
|
pageSize: number;
|
||||||
@@ -50,6 +57,11 @@ interface HomeProps {
|
|||||||
export const Home: React.FC<HomeProps> = ({
|
export const Home: React.FC<HomeProps> = ({
|
||||||
searchQuery,
|
searchQuery,
|
||||||
services,
|
services,
|
||||||
|
isTagBarDisplay,
|
||||||
|
availableTags,
|
||||||
|
selectedTag,
|
||||||
|
handleTagChange,
|
||||||
|
currentTheme,
|
||||||
currentPage,
|
currentPage,
|
||||||
total,
|
total,
|
||||||
pageSize,
|
pageSize,
|
||||||
@@ -102,9 +114,9 @@ export const Home: React.FC<HomeProps> = ({
|
|||||||
<span className="bg-clip-text text-transparent bg-gradient-to-r from-pink-600 via-red-500 to-orange-600">
|
<span className="bg-clip-text text-transparent bg-gradient-to-r from-pink-600 via-red-500 to-orange-600">
|
||||||
{t(
|
{t(
|
||||||
platformConfig.headline ||
|
platformConfig.headline ||
|
||||||
platformConfig.name ||
|
platformConfig.name ||
|
||||||
_DefaultPlatformConfig.headline ||
|
_DefaultPlatformConfig.headline ||
|
||||||
""
|
""
|
||||||
)}
|
)}
|
||||||
</span>
|
</span>
|
||||||
</h1>
|
</h1>
|
||||||
@@ -113,8 +125,8 @@ export const Home: React.FC<HomeProps> = ({
|
|||||||
<p className="text-lg font-medium max-w-3xl mx-auto leading-relaxed text-gray-700">
|
<p className="text-lg font-medium max-w-3xl mx-auto leading-relaxed text-gray-700">
|
||||||
{t(
|
{t(
|
||||||
platformConfig.subheadline ||
|
platformConfig.subheadline ||
|
||||||
_DefaultPlatformConfig.subheadline ||
|
_DefaultPlatformConfig.subheadline ||
|
||||||
""
|
""
|
||||||
)}
|
)}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
@@ -166,6 +178,21 @@ export const Home: React.FC<HomeProps> = ({
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{/* filter section */}
|
||||||
|
{
|
||||||
|
isTagBarDisplay && (
|
||||||
|
<>
|
||||||
|
<TagFilter
|
||||||
|
theme={currentTheme}
|
||||||
|
tags={availableTags}
|
||||||
|
selectedTag={selectedTag}
|
||||||
|
onTagChange={handleTagChange}
|
||||||
|
maxWidthPercent={80}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
{/* Creative Server List Section */}
|
{/* Creative Server List Section */}
|
||||||
{loading ? (
|
{loading ? (
|
||||||
<div className="relative z-10 mx-auto h-[200px] flex items-center justify-center">
|
<div className="relative z-10 mx-auto h-[200px] flex items-center justify-center">
|
||||||
@@ -177,7 +204,7 @@ export const Home: React.FC<HomeProps> = ({
|
|||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<div className="relative z-10">
|
<div className="relative z-10">
|
||||||
<div className="relative mx-auto px-6 py-16 max-w-8xl">
|
<div className={`relative mx-auto px-6 ${isTagBarDisplay ? 'py-12' : 'py-16'} max-w-8xl`}>
|
||||||
{/* Creative Server Grid */}
|
{/* Creative Server Grid */}
|
||||||
<div className="flex flex-wrap justify-center gap-4 mb-12">
|
<div className="flex flex-wrap justify-center gap-4 mb-12">
|
||||||
{services.map((service, index) => {
|
{services.map((service, index) => {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import React from "react";
|
import React, { useEffect } from "react";
|
||||||
import { Button } from "@nextui-org/react";
|
import { Button } from "@nextui-org/react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
@@ -16,6 +16,7 @@ import { ArrowRightIcon } from "lucide-react";
|
|||||||
import { DynamicLogo } from "@/shared/components/DynamicLogo";
|
import { DynamicLogo } from "@/shared/components/DynamicLogo";
|
||||||
import { useAuth } from "@/shared/lib/useAuth";
|
import { useAuth } from "@/shared/lib/useAuth";
|
||||||
import { NavigationItem } from "@/shared/components/Navigation";
|
import { NavigationItem } from "@/shared/components/Navigation";
|
||||||
|
import { useSharedStore } from "@/shared/store/share";
|
||||||
|
|
||||||
interface NavigationProps {
|
interface NavigationProps {
|
||||||
items?: NavigationItem[];
|
items?: NavigationItem[];
|
||||||
@@ -26,6 +27,13 @@ export const Navigation: React.FC<NavigationProps> = ({ items }) => {
|
|||||||
const { handleLogin } = useAuth();
|
const { handleLogin } = useAuth();
|
||||||
const [isMenuOpen, setIsMenuOpen] = useState(false);
|
const [isMenuOpen, setIsMenuOpen] = useState(false);
|
||||||
|
|
||||||
|
const [userToken, setUserToken] = useState<string | null>(null);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const userToken = useSharedStore?.getState?.().user_token
|
||||||
|
setUserToken(userToken);
|
||||||
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{/* Creative Navigation */}
|
{/* Creative Navigation */}
|
||||||
@@ -65,16 +73,22 @@ export const Navigation: React.FC<NavigationProps> = ({ items }) => {
|
|||||||
</NavbarContent>
|
</NavbarContent>
|
||||||
<NavbarContent justify="end" className="items-center gap-2 sm:gap-4">
|
<NavbarContent justify="end" className="items-center gap-2 sm:gap-4">
|
||||||
<div className="hidden sm:flex gap-2">
|
<div className="hidden sm:flex gap-2">
|
||||||
<Button onPress={handleLogin} variant="light">
|
{
|
||||||
<b className="text-md"> {t("Sign In")}</b>
|
!userToken && (
|
||||||
</Button>
|
<>
|
||||||
|
<Button onPress={handleLogin} variant="light">
|
||||||
|
<b className="text-md"> {t("Sign In")}</b>
|
||||||
|
</Button>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
<Button
|
<Button
|
||||||
color="primary"
|
color="primary"
|
||||||
className="bg-gradient-to-r from-pink-500 via-red-500 to-orange-500 hover:from-pink-600 hover:via-red-600 hover:to-orange-600 text-white shadow-lg hover:shadow-xl transition-all duration-300 hover:scale-105 flex items-center justify-center gap-4 pr-1 h-[45px]"
|
className="bg-gradient-to-r from-pink-500 via-red-500 to-orange-500 hover:from-pink-600 hover:via-red-600 hover:to-orange-600 text-white shadow-lg hover:shadow-xl transition-all duration-300 hover:scale-105 flex items-center justify-center gap-4 pr-1 h-[45px]"
|
||||||
radius="full"
|
radius="full"
|
||||||
onPress={handleLogin}
|
onPress={handleLogin}
|
||||||
>
|
>
|
||||||
<b className="text-md">{t("Get Started")}</b>
|
<b className="text-md">{userToken ? t("Dashboard") : t("Get Started")}</b>
|
||||||
<div className="w-8 h-8 bg-white/20 flex items-center justify-center rounded-full">
|
<div className="w-8 h-8 bg-white/20 flex items-center justify-center rounded-full">
|
||||||
<ArrowRightIcon
|
<ArrowRightIcon
|
||||||
size={16}
|
size={16}
|
||||||
@@ -89,7 +103,7 @@ export const Navigation: React.FC<NavigationProps> = ({ items }) => {
|
|||||||
onPress={handleLogin}
|
onPress={handleLogin}
|
||||||
size="sm"
|
size="sm"
|
||||||
>
|
>
|
||||||
<b className="text-md">{t("Get Started")}</b>
|
<b className="text-md">{userToken ? t("Dashboard") : t("Get Started")}</b>
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</NavbarContent>
|
</NavbarContent>
|
||||||
@@ -101,7 +115,7 @@ export const Navigation: React.FC<NavigationProps> = ({ items }) => {
|
|||||||
radius="full"
|
radius="full"
|
||||||
onPress={handleLogin}
|
onPress={handleLogin}
|
||||||
>
|
>
|
||||||
<b className="text-md">{t("Get Started")}</b>
|
<b className="text-md">{userToken ? t("Dashboard") : t("Get Started")}</b>
|
||||||
<div className="w-8 h-8 bg-white/20 flex items-center justify-center rounded-full">
|
<div className="w-8 h-8 bg-white/20 flex items-center justify-center rounded-full">
|
||||||
<ArrowRightIcon
|
<ArrowRightIcon
|
||||||
size={16}
|
size={16}
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ const DefaultDemo: React.FC = () => {
|
|||||||
<span className="bg-blue-100 text-blue-800 px-2 py-1 rounded text-xs">
|
<span className="bg-blue-100 text-blue-800 px-2 py-1 rounded text-xs">
|
||||||
Beta
|
Beta
|
||||||
</span>
|
</span>
|
||||||
<span className="text-xs text-gray-500">$0.02 /Per Call</span>
|
<span className="text-xs text-gray-500">¥0.02 /Per Call</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -79,7 +79,7 @@ const DefaultDemo: React.FC = () => {
|
|||||||
<span className="bg-blue-100 text-blue-800 px-2 py-1 rounded text-xs">
|
<span className="bg-blue-100 text-blue-800 px-2 py-1 rounded text-xs">
|
||||||
Beta
|
Beta
|
||||||
</span>
|
</span>
|
||||||
<span className="text-xs text-gray-500">$0.02 /Per Call</span>
|
<span className="text-xs text-gray-500">¥0.02 /Per Call</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ import { NavigationItem } from "@/shared/components/Navigation";
|
|||||||
import { ServerConfig } from "@/shared/components/marketplace/ServerConfig";
|
import { ServerConfig } from "@/shared/components/marketplace/ServerConfig";
|
||||||
|
|
||||||
interface DetailProps {
|
interface DetailProps {
|
||||||
|
can_invoke?: boolean;
|
||||||
|
visitor?: boolean;
|
||||||
product: ServiceData;
|
product: ServiceData;
|
||||||
breadcrumbs?: {
|
breadcrumbs?: {
|
||||||
link: string;
|
link: string;
|
||||||
@@ -30,6 +32,8 @@ interface DetailProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const Detail: React.FC<DetailProps> = ({
|
export const Detail: React.FC<DetailProps> = ({
|
||||||
|
can_invoke,
|
||||||
|
visitor,
|
||||||
product,
|
product,
|
||||||
breadcrumbs,
|
breadcrumbs,
|
||||||
url,
|
url,
|
||||||
@@ -144,6 +148,8 @@ export const Detail: React.FC<DetailProps> = ({
|
|||||||
{/* Code Snippet */}
|
{/* Code Snippet */}
|
||||||
<ServerConfig
|
<ServerConfig
|
||||||
mcpName={mcpName}
|
mcpName={mcpName}
|
||||||
|
can_invoke={can_invoke}
|
||||||
|
visitor={visitor}
|
||||||
url={url}
|
url={url}
|
||||||
className="w-full max-w-2xl"
|
className="w-full max-w-2xl"
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -26,11 +26,18 @@ import { Navigation } from "./Navigation";
|
|||||||
import { Footer } from "./Footer";
|
import { Footer } from "./Footer";
|
||||||
import { NavigationItem } from "@/shared/components/Navigation";
|
import { NavigationItem } from "@/shared/components/Navigation";
|
||||||
import { Faq } from "@/components/marketplace/Faq";
|
import { Faq } from "@/components/marketplace/Faq";
|
||||||
|
import { TagFilter } from "@/shared/components/marketplace/TagFilter";
|
||||||
|
import { ThemeType } from "@/shared/types/system";
|
||||||
|
|
||||||
interface HomeProps {
|
interface HomeProps {
|
||||||
// 状态
|
// 状态
|
||||||
searchQuery: string;
|
searchQuery: string;
|
||||||
services: ServiceData[];
|
services: ServiceData[];
|
||||||
|
isTagBarDisplay: boolean;
|
||||||
|
availableTags: string[];
|
||||||
|
selectedTag: string;
|
||||||
|
handleTagChange: (tag: string) => void;
|
||||||
|
currentTheme: ThemeType;
|
||||||
currentPage: number;
|
currentPage: number;
|
||||||
total: number;
|
total: number;
|
||||||
pageSize: number;
|
pageSize: number;
|
||||||
@@ -52,6 +59,11 @@ interface HomeProps {
|
|||||||
export const Home: React.FC<HomeProps> = ({
|
export const Home: React.FC<HomeProps> = ({
|
||||||
searchQuery,
|
searchQuery,
|
||||||
services,
|
services,
|
||||||
|
isTagBarDisplay,
|
||||||
|
availableTags,
|
||||||
|
selectedTag,
|
||||||
|
handleTagChange,
|
||||||
|
currentTheme,
|
||||||
currentPage,
|
currentPage,
|
||||||
total,
|
total,
|
||||||
pageSize,
|
pageSize,
|
||||||
@@ -78,7 +90,7 @@ export const Home: React.FC<HomeProps> = ({
|
|||||||
<Navigation items={navItems} />
|
<Navigation items={navItems} />
|
||||||
{/* Modern Hero Section */}
|
{/* Modern Hero Section */}
|
||||||
<div className="pt-32">
|
<div className="pt-32">
|
||||||
<div className="mx-auto px-6 py-20 max-w-6xl">
|
<div className={`mx-auto px-6 max-w-6xl ${isTagBarDisplay ? 'py-16' : 'py-20'}`}>
|
||||||
<div className="text-center mb-16">
|
<div className="text-center mb-16">
|
||||||
{/* Modern Icon */}
|
{/* Modern Icon */}
|
||||||
<div className="flex justify-center mb-8">
|
<div className="flex justify-center mb-8">
|
||||||
@@ -91,9 +103,9 @@ export const Home: React.FC<HomeProps> = ({
|
|||||||
<h1 className="text-4xl lg:text-6xl font-bold mb-6 text-gray-900 leading-tight">
|
<h1 className="text-4xl lg:text-6xl font-bold mb-6 text-gray-900 leading-tight">
|
||||||
{t(
|
{t(
|
||||||
platformConfig.headline ||
|
platformConfig.headline ||
|
||||||
platformConfig.name ||
|
platformConfig.name ||
|
||||||
_DefaultPlatformConfig.headline ||
|
_DefaultPlatformConfig.headline ||
|
||||||
""
|
""
|
||||||
)}
|
)}
|
||||||
</h1>
|
</h1>
|
||||||
|
|
||||||
@@ -101,8 +113,8 @@ export const Home: React.FC<HomeProps> = ({
|
|||||||
<p className="text-lg text-gray-600 max-w-2xl mx-auto leading-relaxed">
|
<p className="text-lg text-gray-600 max-w-2xl mx-auto leading-relaxed">
|
||||||
{t(
|
{t(
|
||||||
platformConfig.subheadline ||
|
platformConfig.subheadline ||
|
||||||
_DefaultPlatformConfig.subheadline ||
|
_DefaultPlatformConfig.subheadline ||
|
||||||
""
|
""
|
||||||
)}
|
)}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
@@ -145,6 +157,21 @@ export const Home: React.FC<HomeProps> = ({
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{/* filter section */}
|
||||||
|
{
|
||||||
|
isTagBarDisplay && (
|
||||||
|
<>
|
||||||
|
<TagFilter
|
||||||
|
theme={currentTheme}
|
||||||
|
tags={availableTags}
|
||||||
|
selectedTag={selectedTag}
|
||||||
|
onTagChange={handleTagChange}
|
||||||
|
maxWidthPercent={80}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
<section>
|
<section>
|
||||||
{/* Server List Section */}
|
{/* Server List Section */}
|
||||||
{loading ? (
|
{loading ? (
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import React from "react";
|
import React, { useEffect } from "react";
|
||||||
import { Button } from "@nextui-org/react";
|
import { Button } from "@nextui-org/react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
@@ -16,6 +16,7 @@ import { ArrowRightIcon } from "lucide-react";
|
|||||||
import { DynamicLogo } from "@/shared/components/DynamicLogo";
|
import { DynamicLogo } from "@/shared/components/DynamicLogo";
|
||||||
import { useAuth } from "@/shared/lib/useAuth";
|
import { useAuth } from "@/shared/lib/useAuth";
|
||||||
import { NavigationItem } from "@/shared/components/Navigation";
|
import { NavigationItem } from "@/shared/components/Navigation";
|
||||||
|
import { useSharedStore } from "@/shared/store/share";
|
||||||
|
|
||||||
interface NavigationProps {
|
interface NavigationProps {
|
||||||
items?: NavigationItem[];
|
items?: NavigationItem[];
|
||||||
@@ -25,7 +26,12 @@ export const Navigation: React.FC<NavigationProps> = ({ items }) => {
|
|||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { handleLogin } = useAuth();
|
const { handleLogin } = useAuth();
|
||||||
const [isMenuOpen, setIsMenuOpen] = useState(false);
|
const [isMenuOpen, setIsMenuOpen] = useState(false);
|
||||||
|
const [userToken, setUserToken] = useState<string | null>(null);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const userToken = useSharedStore?.getState?.().user_token
|
||||||
|
setUserToken(userToken);
|
||||||
|
}, []);
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{/* Modern Navigation */}
|
{/* Modern Navigation */}
|
||||||
@@ -61,16 +67,22 @@ export const Navigation: React.FC<NavigationProps> = ({ items }) => {
|
|||||||
</NavbarContent>
|
</NavbarContent>
|
||||||
<NavbarContent justify="end" className="items-center gap-2 sm:gap-4">
|
<NavbarContent justify="end" className="items-center gap-2 sm:gap-4">
|
||||||
<div className="hidden sm:flex gap-2">
|
<div className="hidden sm:flex gap-2">
|
||||||
<Button onPress={handleLogin} variant="light">
|
{
|
||||||
<b className="text-md"> {t("Sign In")}</b>
|
!userToken && (
|
||||||
</Button>
|
<>
|
||||||
|
<Button onPress={handleLogin} variant="light">
|
||||||
|
<b className="text-md"> {t("Sign In")}</b>
|
||||||
|
</Button>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
<Button
|
<Button
|
||||||
color="primary"
|
color="primary"
|
||||||
className="bg-gradient-to-r from-blue-500 to-purple-600 text-white hover:from-blue-600 hover:to-purple-700 flex items-center justify-center gap-4 pr-1 h-[45px] shadow-lg"
|
className="bg-gradient-to-r from-blue-500 to-purple-600 text-white hover:from-blue-600 hover:to-purple-700 flex items-center justify-center gap-4 pr-1 h-[45px] shadow-lg"
|
||||||
radius="full"
|
radius="full"
|
||||||
onPress={handleLogin}
|
onPress={handleLogin}
|
||||||
>
|
>
|
||||||
<b className="text-md">{t("Get Started")}</b>
|
<b className="text-md">{userToken ? t("Dashboard") : t("Get Started")}</b>
|
||||||
<div className="w-8 h-8 bg-white/20 flex items-center justify-center rounded-full">
|
<div className="w-8 h-8 bg-white/20 flex items-center justify-center rounded-full">
|
||||||
<ArrowRightIcon
|
<ArrowRightIcon
|
||||||
size={16}
|
size={16}
|
||||||
@@ -85,7 +97,7 @@ export const Navigation: React.FC<NavigationProps> = ({ items }) => {
|
|||||||
onPress={handleLogin}
|
onPress={handleLogin}
|
||||||
size="sm"
|
size="sm"
|
||||||
>
|
>
|
||||||
<b className="text-md">{t("Get Started")}</b>
|
<b className="text-md">{userToken ? t("Dashboard") : t("Get Started")}</b>
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</NavbarContent>
|
</NavbarContent>
|
||||||
@@ -97,7 +109,7 @@ export const Navigation: React.FC<NavigationProps> = ({ items }) => {
|
|||||||
radius="full"
|
radius="full"
|
||||||
onPress={handleLogin}
|
onPress={handleLogin}
|
||||||
>
|
>
|
||||||
<b className="text-md">{t("Get Started")}</b>
|
<b className="text-md">{userToken ? t("Dashboard") : t("Get Started")}</b>
|
||||||
<div className="w-8 h-8 bg-white/20 flex items-center justify-center rounded-full">
|
<div className="w-8 h-8 bg-white/20 flex items-center justify-center rounded-full">
|
||||||
<ArrowRightIcon
|
<ArrowRightIcon
|
||||||
size={16}
|
size={16}
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ const TemuDemo: React.FC = () => {
|
|||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex items-center justify-between">
|
<div className="flex items-center justify-between">
|
||||||
<span className="text-xs font-bold text-orange-600">$9.99</span>
|
<span className="text-xs font-bold text-orange-600">¥9.99</span>
|
||||||
<div className="flex items-center gap-1">
|
<div className="flex items-center gap-1">
|
||||||
<Star className="w-2 h-2 text-yellow-400 fill-current" />
|
<Star className="w-2 h-2 text-yellow-400 fill-current" />
|
||||||
<span className="text-xs text-gray-500">4.8</span>
|
<span className="text-xs text-gray-500">4.8</span>
|
||||||
@@ -87,7 +87,7 @@ const TemuDemo: React.FC = () => {
|
|||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex items-center justify-between">
|
<div className="flex items-center justify-between">
|
||||||
<span className="text-xs font-bold text-orange-600">$14.99</span>
|
<span className="text-xs font-bold text-orange-600">¥14.99</span>
|
||||||
<div className="flex items-center gap-1">
|
<div className="flex items-center gap-1">
|
||||||
<Star className="w-2 h-2 text-yellow-400 fill-current" />
|
<Star className="w-2 h-2 text-yellow-400 fill-current" />
|
||||||
<span className="text-xs text-gray-500">4.9</span>
|
<span className="text-xs text-gray-500">4.9</span>
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ import { NavigationItem } from "@/shared/components/Navigation";
|
|||||||
import { ServerConfig } from "@/shared/components/marketplace/ServerConfig";
|
import { ServerConfig } from "@/shared/components/marketplace/ServerConfig";
|
||||||
|
|
||||||
interface DetailProps {
|
interface DetailProps {
|
||||||
|
can_invoke?: boolean;
|
||||||
|
visitor?: boolean;
|
||||||
product: ServiceData;
|
product: ServiceData;
|
||||||
breadcrumbs?: {
|
breadcrumbs?: {
|
||||||
link: string;
|
link: string;
|
||||||
@@ -29,6 +31,8 @@ interface DetailProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const Detail: React.FC<DetailProps> = ({
|
export const Detail: React.FC<DetailProps> = ({
|
||||||
|
can_invoke,
|
||||||
|
visitor,
|
||||||
product,
|
product,
|
||||||
breadcrumbs,
|
breadcrumbs,
|
||||||
url,
|
url,
|
||||||
@@ -163,6 +167,8 @@ export const Detail: React.FC<DetailProps> = ({
|
|||||||
<div className="p-6">
|
<div className="p-6">
|
||||||
{/* Code Snippet */}
|
{/* Code Snippet */}
|
||||||
<ServerConfig
|
<ServerConfig
|
||||||
|
can_invoke={can_invoke}
|
||||||
|
visitor={visitor}
|
||||||
mcpName={mcpName}
|
mcpName={mcpName}
|
||||||
url={url}
|
url={url}
|
||||||
className="w-full max-w-2xl"
|
className="w-full max-w-2xl"
|
||||||
|
|||||||
@@ -23,11 +23,18 @@ import { Footer } from "./Footer";
|
|||||||
import { Navigation } from "./Navigation";
|
import { Navigation } from "./Navigation";
|
||||||
import { NavigationItem } from "@/shared/components/Navigation";
|
import { NavigationItem } from "@/shared/components/Navigation";
|
||||||
import { Faq } from "@/components/marketplace/Faq";
|
import { Faq } from "@/components/marketplace/Faq";
|
||||||
|
import { TagFilter } from "@/shared/components/marketplace/TagFilter";
|
||||||
|
import { ThemeType } from "@/shared/types/system";
|
||||||
|
|
||||||
interface HomeProps {
|
interface HomeProps {
|
||||||
// 状态
|
// 状态
|
||||||
searchQuery: string;
|
searchQuery: string;
|
||||||
services: ServiceData[];
|
services: ServiceData[];
|
||||||
|
isTagBarDisplay: boolean;
|
||||||
|
availableTags: string[];
|
||||||
|
selectedTag: string;
|
||||||
|
handleTagChange: (tag: string) => void;
|
||||||
|
currentTheme: ThemeType;
|
||||||
currentPage: number;
|
currentPage: number;
|
||||||
total: number;
|
total: number;
|
||||||
pageSize: number;
|
pageSize: number;
|
||||||
@@ -49,6 +56,11 @@ interface HomeProps {
|
|||||||
export const Home: React.FC<HomeProps> = ({
|
export const Home: React.FC<HomeProps> = ({
|
||||||
searchQuery,
|
searchQuery,
|
||||||
services,
|
services,
|
||||||
|
isTagBarDisplay,
|
||||||
|
availableTags,
|
||||||
|
selectedTag,
|
||||||
|
handleTagChange,
|
||||||
|
currentTheme,
|
||||||
currentPage,
|
currentPage,
|
||||||
total,
|
total,
|
||||||
pageSize,
|
pageSize,
|
||||||
@@ -95,9 +107,9 @@ export const Home: React.FC<HomeProps> = ({
|
|||||||
<h1 className="text-4xl lg:text-6xl font-bold mb-6 text-white">
|
<h1 className="text-4xl lg:text-6xl font-bold mb-6 text-white">
|
||||||
{t(
|
{t(
|
||||||
platformConfig.headline ||
|
platformConfig.headline ||
|
||||||
platformConfig.name ||
|
platformConfig.name ||
|
||||||
_DefaultPlatformConfig.headline ||
|
_DefaultPlatformConfig.headline ||
|
||||||
""
|
""
|
||||||
)}
|
)}
|
||||||
</h1>
|
</h1>
|
||||||
|
|
||||||
@@ -105,8 +117,8 @@ export const Home: React.FC<HomeProps> = ({
|
|||||||
<p className="text-xl text-white/90 mb-8 max-w-2xl mx-auto">
|
<p className="text-xl text-white/90 mb-8 max-w-2xl mx-auto">
|
||||||
{t(
|
{t(
|
||||||
platformConfig.subheadline ||
|
platformConfig.subheadline ||
|
||||||
_DefaultPlatformConfig.subheadline ||
|
_DefaultPlatformConfig.subheadline ||
|
||||||
""
|
""
|
||||||
)}
|
)}
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
@@ -139,6 +151,21 @@ export const Home: React.FC<HomeProps> = ({
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{/* filter section */}
|
||||||
|
{
|
||||||
|
isTagBarDisplay && (
|
||||||
|
<div className="pt-12">
|
||||||
|
<TagFilter
|
||||||
|
theme={currentTheme}
|
||||||
|
tags={availableTags}
|
||||||
|
selectedTag={selectedTag}
|
||||||
|
onTagChange={handleTagChange}
|
||||||
|
maxWidthPercent={80}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
{/* Products Section */}
|
{/* Products Section */}
|
||||||
<div className="mx-auto px-6 py-12 max-w-7xl">
|
<div className="mx-auto px-6 py-12 max-w-7xl">
|
||||||
{/* Section Header */}
|
{/* Section Header */}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import React from "react";
|
import React, { useEffect } from "react";
|
||||||
import { Button } from "@nextui-org/react";
|
import { Button } from "@nextui-org/react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
@@ -16,6 +16,7 @@ import { DynamicLogo } from "@/shared/components/DynamicLogo";
|
|||||||
import { useAuth } from "@/shared/lib/useAuth";
|
import { useAuth } from "@/shared/lib/useAuth";
|
||||||
import { NavigationItem } from "@/shared/components/Navigation";
|
import { NavigationItem } from "@/shared/components/Navigation";
|
||||||
import { ArrowRightIcon } from "lucide-react";
|
import { ArrowRightIcon } from "lucide-react";
|
||||||
|
import { useSharedStore } from "@/shared/store/share";
|
||||||
|
|
||||||
interface NavigationProps {
|
interface NavigationProps {
|
||||||
items?: NavigationItem[];
|
items?: NavigationItem[];
|
||||||
@@ -26,6 +27,13 @@ export const Navigation: React.FC<NavigationProps> = ({ items }) => {
|
|||||||
const { handleLogin } = useAuth();
|
const { handleLogin } = useAuth();
|
||||||
const [isMenuOpen, setIsMenuOpen] = useState(false);
|
const [isMenuOpen, setIsMenuOpen] = useState(false);
|
||||||
|
|
||||||
|
const [userToken, setUserToken] = useState<string | null>(null);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const userToken = useSharedStore?.getState?.().user_token
|
||||||
|
setUserToken(userToken);
|
||||||
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{/* Temu Style Navigation */}
|
{/* Temu Style Navigation */}
|
||||||
@@ -64,15 +72,21 @@ export const Navigation: React.FC<NavigationProps> = ({ items }) => {
|
|||||||
</NavbarContent>
|
</NavbarContent>
|
||||||
<NavbarContent justify="end" className="items-center gap-2 sm:gap-4">
|
<NavbarContent justify="end" className="items-center gap-2 sm:gap-4">
|
||||||
<div className="hidden sm:flex items-center gap-2">
|
<div className="hidden sm:flex items-center gap-2">
|
||||||
<Button onPress={handleLogin} variant="light">
|
{
|
||||||
<b className="text-md"> {t("Sign In")}</b>
|
!userToken && (
|
||||||
</Button>
|
<>
|
||||||
|
<Button onPress={handleLogin} variant="light">
|
||||||
|
<b className="text-md"> {t("Sign In")}</b>
|
||||||
|
</Button>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
<Button
|
<Button
|
||||||
className="bg-orange-500 hover:bg-orange-600 text-white font-semibold px-6 h-[40px] transition-all duration-200"
|
className="bg-orange-500 hover:bg-orange-600 text-white font-semibold px-6 h-[40px] transition-all duration-200"
|
||||||
radius="md"
|
radius="md"
|
||||||
onPress={handleLogin}
|
onPress={handleLogin}
|
||||||
>
|
>
|
||||||
{t("Get Started")}
|
{userToken ? t("Dashboard") : t("Get Started")}
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
<div className="sm:hidden">
|
<div className="sm:hidden">
|
||||||
@@ -81,7 +95,7 @@ export const Navigation: React.FC<NavigationProps> = ({ items }) => {
|
|||||||
onPress={handleLogin}
|
onPress={handleLogin}
|
||||||
size="sm"
|
size="sm"
|
||||||
>
|
>
|
||||||
{t("Sign In")}
|
{userToken ? t("Dashboard") : t("Sign In")}
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</NavbarContent>
|
</NavbarContent>
|
||||||
@@ -100,7 +114,7 @@ export const Navigation: React.FC<NavigationProps> = ({ items }) => {
|
|||||||
radius="md"
|
radius="md"
|
||||||
onPress={handleLogin}
|
onPress={handleLogin}
|
||||||
>
|
>
|
||||||
{t("Sign In")}
|
{userToken ? t("Dashboard") : t("Sign In")}
|
||||||
</Button>
|
</Button>
|
||||||
</NavbarMenuItem>
|
</NavbarMenuItem>
|
||||||
</NavbarMenu>
|
</NavbarMenu>
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ export const AdminRechargeModal: React.FC<AdminRechargeModalProps> = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (numAmount < 1) {
|
if (numAmount < 1) {
|
||||||
setError(t("Minimum recharge amount is $1"));
|
setError(t("Minimum recharge amount is ¥1"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,7 +102,7 @@ export const AdminRechargeModal: React.FC<AdminRechargeModalProps> = ({
|
|||||||
onChange={handleAmountChange}
|
onChange={handleAmountChange}
|
||||||
startContent={
|
startContent={
|
||||||
<div className="pointer-events-none flex items-center">
|
<div className="pointer-events-none flex items-center">
|
||||||
<span className="text-default-400 text-small">$</span>
|
<span className="text-default-400 text-small">¥</span>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
isInvalid={!!error}
|
isInvalid={!!error}
|
||||||
|
|||||||
@@ -0,0 +1,48 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import React from "react";
|
||||||
|
import { Button} from "@nextui-org/react";
|
||||||
|
import { ChevronLeftIcon } from "lucide-react";
|
||||||
|
import { useTranslation } from "@/shared/lib/useTranslation";
|
||||||
|
import { withComponentInjection } from "@/shared/hooks/useComponentInjection";
|
||||||
|
import AccountBalanceTable from "../dashboard/AccountBalanceTable";
|
||||||
|
|
||||||
|
interface UserBalanceDetailProps {
|
||||||
|
userId: string;
|
||||||
|
userEmail: string;
|
||||||
|
onCancel: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
const BaseUserBalanceDetail: React.FC<UserBalanceDetailProps> = ({
|
||||||
|
userId,
|
||||||
|
userEmail,
|
||||||
|
onCancel,
|
||||||
|
}) => {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="w-full py-8 h-full flex flex-col">
|
||||||
|
{/* page title */}
|
||||||
|
<div className="flex items-center justify-between mb-6 px-8">
|
||||||
|
<div className="flex items-center gap-3">
|
||||||
|
<Button isIconOnly onPress={onCancel} variant="flat" size="sm">
|
||||||
|
<ChevronLeftIcon className="w-5 h-5" />
|
||||||
|
</Button>
|
||||||
|
<h1 className="text-2xl font-bold">
|
||||||
|
{t("Account Balance")}
|
||||||
|
</h1>
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<span>{t("Email")}: </span>{userEmail || '-'}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="px-8">
|
||||||
|
<AccountBalanceTable userId={userId} source="admin" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
export const UserBalanceDetail = withComponentInjection(
|
||||||
|
"components/user-management/UserBalanceDetail",
|
||||||
|
BaseUserBalanceDetail
|
||||||
|
);
|
||||||
@@ -1,12 +1,17 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import React, { useState, useCallback } from "react";
|
import React, { useState, useCallback, useRef, useEffect } from "react";
|
||||||
import { useTranslation } from "@/shared/lib/useTranslation";
|
import { useTranslation } from "@/shared/lib/useTranslation";
|
||||||
import { User } from "@/types/user";
|
import { User } from "@/types/user";
|
||||||
import { UserTable } from "./UserTable";
|
import { UserTable } from "./UserTable";
|
||||||
import { DeleteConfirmModal } from "@/shared/components/modal/DeleteConfirmModal";
|
import { DeleteConfirmModal } from "@/shared/components/modal/DeleteConfirmModal";
|
||||||
import DashboardDemoContent from "@/shared/components/DashboardDemoContent";
|
import DashboardDemoContent from "@/shared/components/DashboardDemoContent";
|
||||||
import { useUserManagement } from "@/hooks/useUserManagement";
|
import { useUserManagement } from "@/hooks/useUserManagement";
|
||||||
|
import { UserBalanceDetail } from "./UserBalanceDetail";
|
||||||
|
import { Input } from "@nextui-org/react";
|
||||||
|
import { Search } from "lucide-react";
|
||||||
|
|
||||||
|
type ViewMode = "list" | "detail";
|
||||||
|
|
||||||
const UserManagement: React.FC = () => {
|
const UserManagement: React.FC = () => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
@@ -14,11 +19,13 @@ const UserManagement: React.FC = () => {
|
|||||||
// use custom hook to manage user data
|
// use custom hook to manage user data
|
||||||
const {
|
const {
|
||||||
users,
|
users,
|
||||||
|
fetchUsers,
|
||||||
loading,
|
loading,
|
||||||
pagination,
|
pagination,
|
||||||
handleDeleteUser,
|
handleDeleteUser,
|
||||||
setPage,
|
setPage,
|
||||||
handleRechargeUser,
|
handleRechargeUser,
|
||||||
|
setSearch,
|
||||||
} = useUserManagement();
|
} = useUserManagement();
|
||||||
|
|
||||||
// Modal states
|
// Modal states
|
||||||
@@ -27,6 +34,24 @@ const UserManagement: React.FC = () => {
|
|||||||
user: null as User | null,
|
user: null as User | null,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const [viewMode, setViewMode] = useState<ViewMode>('list');
|
||||||
|
const [selectedUserId, setSelectedUserId] = useState<string | null>(null);
|
||||||
|
const [selectedUserEmail, setSelectedUserEmail] = useState<string | null>(null);
|
||||||
|
|
||||||
|
// 搜索相关状态
|
||||||
|
const [searchValue, setSearchValue] = useState('');
|
||||||
|
const searchTimerRef = useRef<NodeJS.Timeout | null>(null);
|
||||||
|
|
||||||
|
// 清理定时器
|
||||||
|
useEffect(() => {
|
||||||
|
return () => {
|
||||||
|
if (searchTimerRef.current) {
|
||||||
|
clearTimeout(searchTimerRef.current);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
|
||||||
const handleDeleteUserClick = useCallback((user: User) => {
|
const handleDeleteUserClick = useCallback((user: User) => {
|
||||||
setDeleteModal({
|
setDeleteModal({
|
||||||
isOpen: true,
|
isOpen: true,
|
||||||
@@ -34,6 +59,18 @@ const UserManagement: React.FC = () => {
|
|||||||
});
|
});
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
const handleViewUserBalanceDetail = useCallback((user: User) => {
|
||||||
|
setSelectedUserId(user.id);
|
||||||
|
setSelectedUserEmail(user.email);
|
||||||
|
setViewMode('detail');
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const handleCloseUserBalanceDetail = useCallback(() => {
|
||||||
|
setSelectedUserId(null);
|
||||||
|
setSelectedUserEmail(null);
|
||||||
|
setViewMode('list');
|
||||||
|
}, []);
|
||||||
|
|
||||||
const handleConfirmDelete = useCallback(async () => {
|
const handleConfirmDelete = useCallback(async () => {
|
||||||
if (deleteModal.user) {
|
if (deleteModal.user) {
|
||||||
try {
|
try {
|
||||||
@@ -60,6 +97,31 @@ const UserManagement: React.FC = () => {
|
|||||||
[handleRechargeUser]
|
[handleRechargeUser]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// 处理搜索 - 使用防抖
|
||||||
|
const handleSearchChange = useCallback((value: string) => {
|
||||||
|
setSearchValue(value);
|
||||||
|
|
||||||
|
// 清除之前的定时器
|
||||||
|
if (searchTimerRef.current) {
|
||||||
|
clearTimeout(searchTimerRef.current);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 设置新的定时器,500ms 后触发搜索
|
||||||
|
searchTimerRef.current = setTimeout(() => {
|
||||||
|
setSearch(value);
|
||||||
|
}, 500);
|
||||||
|
}, [setSearch]);
|
||||||
|
|
||||||
|
if (viewMode === "detail" ) {
|
||||||
|
return (
|
||||||
|
<UserBalanceDetail
|
||||||
|
userId={selectedUserId || ''}
|
||||||
|
userEmail={selectedUserEmail || ''}
|
||||||
|
onCancel={handleCloseUserBalanceDetail}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DashboardDemoContent
|
<DashboardDemoContent
|
||||||
title={t("User")}
|
title={t("User")}
|
||||||
@@ -68,10 +130,31 @@ const UserManagement: React.FC = () => {
|
|||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<div className="space-y-6 w-full">
|
<div className="space-y-6 w-full">
|
||||||
|
{/* 搜索框 - 右上角 */}
|
||||||
|
<div className="flex justify-end items-center gap-4">
|
||||||
|
<Input
|
||||||
|
isClearable
|
||||||
|
className="w-full sm:max-w-[400px]"
|
||||||
|
placeholder={t('Search by email')}
|
||||||
|
startContent={<Search className="w-4 h-4" />}
|
||||||
|
value={searchValue}
|
||||||
|
onClear={() => {
|
||||||
|
setSearchValue('');
|
||||||
|
if (searchTimerRef.current) {
|
||||||
|
clearTimeout(searchTimerRef.current);
|
||||||
|
}
|
||||||
|
setSearch('');
|
||||||
|
}}
|
||||||
|
onValueChange={handleSearchChange}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
<UserTable
|
<UserTable
|
||||||
users={users}
|
users={users}
|
||||||
|
fetchUsers={fetchUsers}
|
||||||
loading={loading}
|
loading={loading}
|
||||||
onDelete={handleDeleteUserClick}
|
onDelete={handleDeleteUserClick}
|
||||||
|
viewUserBalanceDetail={handleViewUserBalanceDetail}
|
||||||
onRecharge={handleRecharge}
|
onRecharge={handleRecharge}
|
||||||
pagination={pagination}
|
pagination={pagination}
|
||||||
onPageChange={setPage}
|
onPageChange={setPage}
|
||||||
@@ -79,6 +162,7 @@ const UserManagement: React.FC = () => {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<DeleteConfirmModal
|
<DeleteConfirmModal
|
||||||
|
user={deleteModal.user}
|
||||||
isOpen={deleteModal.isOpen}
|
isOpen={deleteModal.isOpen}
|
||||||
onClose={handleCloseDeleteModal}
|
onClose={handleCloseDeleteModal}
|
||||||
onConfirm={handleConfirmDelete}
|
onConfirm={handleConfirmDelete}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import React from "react";
|
import React, { useCallback, useEffect, useState } from "react";
|
||||||
import {
|
import {
|
||||||
Table,
|
Table,
|
||||||
TableHeader,
|
TableHeader,
|
||||||
@@ -12,16 +12,24 @@ import {
|
|||||||
Pagination,
|
Pagination,
|
||||||
Tooltip,
|
Tooltip,
|
||||||
Spinner,
|
Spinner,
|
||||||
|
Select,
|
||||||
|
SelectItem,
|
||||||
|
Link
|
||||||
} from "@nextui-org/react";
|
} from "@nextui-org/react";
|
||||||
import { useTranslation } from "@/shared/lib/useTranslation";
|
import { useTranslation } from "@/shared/lib/useTranslation";
|
||||||
import { User } from "@/types/user";
|
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 { AdminRechargeModal } from "@/components/user-management/AdminRechargeModal";
|
||||||
|
import { fetchSimpleResourceGroups, updateUserResourceGroup } from "@/api/resourceGroup.api";
|
||||||
|
import toast from "react-hot-toast";
|
||||||
|
|
||||||
interface UserTableProps {
|
interface UserTableProps {
|
||||||
users: User[];
|
users: User[];
|
||||||
|
fetchUsers: () => void;
|
||||||
loading?: boolean;
|
loading?: boolean;
|
||||||
onDelete: (user: User) => void;
|
onDelete: (user: User) => void;
|
||||||
|
viewUserBalanceDetail: (userId: User) => void;
|
||||||
onRecharge: (id: string, amount: number) => Promise<boolean>;
|
onRecharge: (id: string, amount: number) => Promise<boolean>;
|
||||||
pagination: {
|
pagination: {
|
||||||
page: number;
|
page: number;
|
||||||
@@ -33,7 +41,9 @@ interface UserTableProps {
|
|||||||
|
|
||||||
export const UserTable: React.FC<UserTableProps> = ({
|
export const UserTable: React.FC<UserTableProps> = ({
|
||||||
users,
|
users,
|
||||||
|
fetchUsers,
|
||||||
loading = false,
|
loading = false,
|
||||||
|
viewUserBalanceDetail,
|
||||||
onDelete,
|
onDelete,
|
||||||
onRecharge,
|
onRecharge,
|
||||||
pagination,
|
pagination,
|
||||||
@@ -51,6 +61,9 @@ export const UserTable: React.FC<UserTableProps> = ({
|
|||||||
const [isRechargeModalOpen, setIsRechargeModalOpen] = React.useState(false);
|
const [isRechargeModalOpen, setIsRechargeModalOpen] = React.useState(false);
|
||||||
const [selectedUser, setSelectedUser] = React.useState<User | null>(null);
|
const [selectedUser, setSelectedUser] = React.useState<User | null>(null);
|
||||||
|
|
||||||
|
const [simpleResourceGroups, setSimpleResourceGroups] = useState<{ id: string, name: string }[]>([]);
|
||||||
|
const [groupsLoading, setGroupsLoading] = useState(true);
|
||||||
|
|
||||||
const handleDelete = React.useCallback(
|
const handleDelete = React.useCallback(
|
||||||
(user: User) => {
|
(user: User) => {
|
||||||
onDelete(user);
|
onDelete(user);
|
||||||
@@ -68,7 +81,45 @@ export const UserTable: React.FC<UserTableProps> = ({
|
|||||||
setSelectedUser(null);
|
setSelectedUser(null);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
if (loading && users.length === 0) {
|
// 加载简易资源组列表
|
||||||
|
const loadSimpleResourceGroups = useCallback(async () => {
|
||||||
|
setGroupsLoading(true);
|
||||||
|
try {
|
||||||
|
const data = await fetchSimpleResourceGroups();
|
||||||
|
setSimpleResourceGroups(data);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Failed to load simple resource groups:", error);
|
||||||
|
} finally {
|
||||||
|
setGroupsLoading(false);
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const changeResourceGroup = async (user: User, resourceGroupId: string) => {
|
||||||
|
const success = await updateUserResourceGroup(user.id, resourceGroupId);
|
||||||
|
if (success) {
|
||||||
|
toast.success(t("Resource group updated successfully"));
|
||||||
|
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 (
|
return (
|
||||||
<div className="flex justify-center items-center h-64">
|
<div className="flex justify-center items-center h-64">
|
||||||
<Spinner size="lg" />
|
<Spinner size="lg" />
|
||||||
@@ -87,9 +138,22 @@ export const UserTable: React.FC<UserTableProps> = ({
|
|||||||
>
|
>
|
||||||
<TableHeader>
|
<TableHeader>
|
||||||
<TableColumn>{t("Email")}</TableColumn>
|
<TableColumn>{t("Email")}</TableColumn>
|
||||||
<TableColumn>{t("Register Date")}</TableColumn>
|
<TableColumn width={250}>{t("Resource Group")}</TableColumn>
|
||||||
<TableColumn>{t("Balance")}</TableColumn>
|
<TableColumn width={200}>
|
||||||
<TableColumn>{t("Actions")}</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 width={120}>{t("Balance")}</TableColumn>
|
||||||
|
<TableColumn width={100}>{t("Actions")}</TableColumn>
|
||||||
</TableHeader>
|
</TableHeader>
|
||||||
<TableBody
|
<TableBody
|
||||||
items={items}
|
items={items}
|
||||||
@@ -102,8 +166,38 @@ export const UserTable: React.FC<UserTableProps> = ({
|
|||||||
<TableCell>
|
<TableCell>
|
||||||
<span className="text-sm">{user.email}</span>
|
<span className="text-sm">{user.email}</span>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell>{user.created_at || "-"}</TableCell>
|
<TableCell>
|
||||||
<TableCell>{user.balance.toFixed(2) || "-"}</TableCell>
|
<Select
|
||||||
|
items={simpleResourceGroups}
|
||||||
|
placeholder={t("Select resource group")}
|
||||||
|
selectedKeys={user.group_id ? [user.group_id] : []}
|
||||||
|
onSelectionChange={(keys) => {
|
||||||
|
const selectedKey = Array.from(keys)[0] as string;
|
||||||
|
if (selectedKey) {
|
||||||
|
changeResourceGroup(user, selectedKey);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
size="sm"
|
||||||
|
className="max-w-[250px]"
|
||||||
|
aria-label={t("Select resource group")}
|
||||||
|
>
|
||||||
|
{(group) => (
|
||||||
|
<SelectItem key={group.id} value={group.id}>
|
||||||
|
{group.name}
|
||||||
|
</SelectItem>
|
||||||
|
)}
|
||||||
|
</Select>
|
||||||
|
</TableCell>
|
||||||
|
<TableCell>{formatDate(user.created_at)}</TableCell>
|
||||||
|
<TableCell>
|
||||||
|
<Link
|
||||||
|
href="#"
|
||||||
|
className="text-xs cursor-pointer"
|
||||||
|
onPress={() => viewUserBalanceDetail(user)}
|
||||||
|
>
|
||||||
|
{user.balance.toFixed(2) || "-"}
|
||||||
|
</Link>
|
||||||
|
</TableCell>
|
||||||
|
|
||||||
<TableCell>
|
<TableCell>
|
||||||
<div className="relative flex items-center gap-2">
|
<div className="relative flex items-center gap-2">
|
||||||
|
|||||||
@@ -3,8 +3,13 @@
|
|||||||
import { useState, useCallback } from "react";
|
import { useState, useCallback } from "react";
|
||||||
import { MCPService } from "@/shared/types/mcp-service";
|
import { MCPService } from "@/shared/types/mcp-service";
|
||||||
import {
|
import {
|
||||||
|
GetMCPResourceGroupsParams,
|
||||||
getMCPServiceDetail,
|
getMCPServiceDetail,
|
||||||
parseOpenAPIDocumentForUpdate as parseOpenAPIDocumentForUpdateAPI,
|
parseOpenAPIDocumentForUpdate as parseOpenAPIDocumentForUpdateAPI,
|
||||||
|
fetchMCPResourceGroups as fetchMCPResourceGroupsAPI,
|
||||||
|
deleteResourceGroup as deleteResourceGroupAPI,
|
||||||
|
addServiceToGroup as addServiceToGroupAPI,
|
||||||
|
fetchUnboundResourceGroups as fetchUnboundResourceGroupsAPI,
|
||||||
} from "@/services/mcpService";
|
} from "@/services/mcpService";
|
||||||
|
|
||||||
export const useMCPServiceDetail = () => {
|
export const useMCPServiceDetail = () => {
|
||||||
@@ -81,7 +86,7 @@ export const useMCPServiceDetail = () => {
|
|||||||
} else {
|
} else {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
response.error_message ||
|
response.error_message ||
|
||||||
"Failed to parse OpenAPI document for update"
|
"Failed to parse OpenAPI document for update"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -98,6 +103,40 @@ export const useMCPServiceDetail = () => {
|
|||||||
[]
|
[]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取资源组列表
|
||||||
|
* @param page 页码
|
||||||
|
* @param page_size 每页条数
|
||||||
|
* @param keyword 关键词
|
||||||
|
* @returns 资源组列表
|
||||||
|
*/
|
||||||
|
const fetchMCPResourceGroups = useCallback(async (id: string, page: number, page_size: number, keyword: string): Promise<GetMCPResourceGroupsParams> => {
|
||||||
|
const response = await fetchMCPResourceGroupsAPI(id, page, page_size, keyword);
|
||||||
|
return response;
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除资源组
|
||||||
|
* @param serviceById 服务ID
|
||||||
|
* @param resourceGroupId 资源组ID
|
||||||
|
* @returns 是否删除成功
|
||||||
|
*/
|
||||||
|
const deleteResourceGroup = useCallback(async (serviceById: string, resourceGroupId: string[]): Promise<boolean> => {
|
||||||
|
const response = await deleteResourceGroupAPI(serviceById, resourceGroupId);
|
||||||
|
return response;
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加服务到资源组
|
||||||
|
* @param groupId 资源组ID
|
||||||
|
* @param serverIds 服务ID列表
|
||||||
|
* @returns 是否添加成功
|
||||||
|
*/
|
||||||
|
const addServiceToGroup = useCallback(async (groupId: string, serverIds: string[]): Promise<boolean> => {
|
||||||
|
const response = await addServiceToGroupAPI(groupId, serverIds);
|
||||||
|
return response;
|
||||||
|
}, []);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
serviceDetail,
|
serviceDetail,
|
||||||
detailLoading,
|
detailLoading,
|
||||||
@@ -107,5 +146,8 @@ export const useMCPServiceDetail = () => {
|
|||||||
getServiceDetail,
|
getServiceDetail,
|
||||||
clearServiceDetail,
|
clearServiceDetail,
|
||||||
parseOpenAPIDocumentForUpdate,
|
parseOpenAPIDocumentForUpdate,
|
||||||
|
fetchMCPResourceGroups,
|
||||||
|
deleteResourceGroup,
|
||||||
|
addServiceToGroup
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@@ -78,15 +78,15 @@ export const useMCPServicesList = () => {
|
|||||||
|
|
||||||
// load servers list when component mount
|
// load servers list when component mount
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
loadServices(1);
|
loadServices(1, searchTerm, statusFilter);
|
||||||
}, []); // only execute once when component mount
|
}, []); // only execute once when component mount
|
||||||
|
|
||||||
// pagination
|
// pagination
|
||||||
const handlePageChange = useCallback(
|
const handlePageChange = useCallback(
|
||||||
(page: number) => {
|
(page: number) => {
|
||||||
loadServices(page);
|
loadServices(page, searchTerm, statusFilter);
|
||||||
},
|
},
|
||||||
[loadServices]
|
[loadServices, searchTerm, statusFilter]
|
||||||
);
|
);
|
||||||
|
|
||||||
// search
|
// search
|
||||||
@@ -156,7 +156,7 @@ export const useMCPServicesList = () => {
|
|||||||
try {
|
try {
|
||||||
const result = await saveMCPService(data);
|
const result = await saveMCPService(data);
|
||||||
|
|
||||||
if (result) await loadServices(1);
|
if (result) await loadServices(1, searchTerm, statusFilter);
|
||||||
return result;
|
return result;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const errorMessage =
|
const errorMessage =
|
||||||
@@ -167,7 +167,7 @@ export const useMCPServicesList = () => {
|
|||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[loadServices]
|
[loadServices, searchTerm, statusFilter]
|
||||||
);
|
);
|
||||||
|
|
||||||
// update server
|
// update server
|
||||||
@@ -180,7 +180,7 @@ export const useMCPServicesList = () => {
|
|||||||
const formDataWithId = { ...data, id: serviceId };
|
const formDataWithId = { ...data, id: serviceId };
|
||||||
const result = await saveMCPService(formDataWithId);
|
const result = await saveMCPService(formDataWithId);
|
||||||
|
|
||||||
if (result) await loadServices(pagination.page);
|
if (result) await loadServices(pagination.page, searchTerm, statusFilter);
|
||||||
return result;
|
return result;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const errorMessage =
|
const errorMessage =
|
||||||
@@ -191,7 +191,7 @@ export const useMCPServicesList = () => {
|
|||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[loadServices, pagination.page]
|
[loadServices, pagination.page, searchTerm, statusFilter]
|
||||||
);
|
);
|
||||||
|
|
||||||
// delete server
|
// delete server
|
||||||
@@ -205,7 +205,7 @@ export const useMCPServicesList = () => {
|
|||||||
|
|
||||||
if (result) {
|
if (result) {
|
||||||
// reload servers list
|
// reload servers list
|
||||||
await loadServices();
|
await loadServices(pagination.page, searchTerm, statusFilter);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const errorMessage =
|
const errorMessage =
|
||||||
@@ -216,7 +216,7 @@ export const useMCPServicesList = () => {
|
|||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[loadServices]
|
[loadServices, pagination.page, searchTerm, statusFilter]
|
||||||
);
|
);
|
||||||
|
|
||||||
// toggle server status
|
// toggle server status
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import {
|
|||||||
StripeConfig,
|
StripeConfig,
|
||||||
AlipayConfig,
|
AlipayConfig,
|
||||||
WechatConfig,
|
WechatConfig,
|
||||||
|
EpayChannelConfig,
|
||||||
PaymentChannelTestResult,
|
PaymentChannelTestResult,
|
||||||
} from "@/types/payment";
|
} from "@/types/payment";
|
||||||
import { paymentChannelService } from "@/services/paymentChannelService";
|
import { paymentChannelService } from "@/services/paymentChannelService";
|
||||||
@@ -29,6 +30,14 @@ export const usePaymentChannelManagement = () => {
|
|||||||
mch_id: "",
|
mch_id: "",
|
||||||
is_enabled: false,
|
is_enabled: false,
|
||||||
});
|
});
|
||||||
|
const [epayConfig, setEpayConfig] = useState<EpayChannelConfig>({
|
||||||
|
gateway: "",
|
||||||
|
pid: "",
|
||||||
|
key: "",
|
||||||
|
pay_type: "",
|
||||||
|
exchange_rate: 1,
|
||||||
|
is_enabled: false,
|
||||||
|
});
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
const [testResult, setTestResult] = useState<PaymentChannelTestResult | null>(
|
const [testResult, setTestResult] = useState<PaymentChannelTestResult | null>(
|
||||||
@@ -37,6 +46,7 @@ export const usePaymentChannelManagement = () => {
|
|||||||
const [isWechatSaving, setIsWechatSaving] = useState(false);
|
const [isWechatSaving, setIsWechatSaving] = useState(false);
|
||||||
const [isStripeSaving, setIsStripeSaving] = useState(false);
|
const [isStripeSaving, setIsStripeSaving] = useState(false);
|
||||||
const [isAlipaySaving, setIsAlipaySaving] = useState(false);
|
const [isAlipaySaving, setIsAlipaySaving] = useState(false);
|
||||||
|
const [isEpaySaving, setIsEpaySaving] = useState(false);
|
||||||
|
|
||||||
// get payment channel list
|
// get payment channel list
|
||||||
const fetchChannels = useCallback(async () => {
|
const fetchChannels = useCallback(async () => {
|
||||||
@@ -69,6 +79,16 @@ export const usePaymentChannelManagement = () => {
|
|||||||
} as AlipayConfig);
|
} as AlipayConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const epayChannel = response.data.find(
|
||||||
|
(channel) => channel.id === "epay"
|
||||||
|
);
|
||||||
|
if (epayChannel) {
|
||||||
|
setEpayConfig({
|
||||||
|
...epayChannel.config,
|
||||||
|
is_enabled: epayChannel.is_enabled,
|
||||||
|
} as EpayChannelConfig);
|
||||||
|
}
|
||||||
|
|
||||||
const wechatChannel = response.data.find(
|
const wechatChannel = response.data.find(
|
||||||
(channel) => channel.id === "wechat"
|
(channel) => channel.id === "wechat"
|
||||||
);
|
);
|
||||||
@@ -184,6 +204,28 @@ export const usePaymentChannelManagement = () => {
|
|||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
// save epay config
|
||||||
|
const saveEpayConfig = useCallback(async (config: EpayChannelConfig) => {
|
||||||
|
setIsEpaySaving(true);
|
||||||
|
setError(null);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const result = await paymentChannelService.saveEpayConfig(config);
|
||||||
|
if (result) {
|
||||||
|
setEpayConfig(config);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
} catch (err) {
|
||||||
|
const errorMessage =
|
||||||
|
err instanceof Error ? err.message : "Failed to save epay config";
|
||||||
|
setError(errorMessage);
|
||||||
|
return false;
|
||||||
|
} finally {
|
||||||
|
setIsEpaySaving(false);
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
// save stripe config
|
// save stripe config
|
||||||
const saveStripeConfig = useCallback(async (config: StripeConfig) => {
|
const saveStripeConfig = useCallback(async (config: StripeConfig) => {
|
||||||
setIsStripeSaving(true);
|
setIsStripeSaving(true);
|
||||||
@@ -316,6 +358,8 @@ export const usePaymentChannelManagement = () => {
|
|||||||
stripeConfig,
|
stripeConfig,
|
||||||
alipayConfig,
|
alipayConfig,
|
||||||
wechatConfig,
|
wechatConfig,
|
||||||
|
epayConfig,
|
||||||
|
isEpaySaving,
|
||||||
isWechatSaving,
|
isWechatSaving,
|
||||||
isStripeSaving,
|
isStripeSaving,
|
||||||
isAlipaySaving,
|
isAlipaySaving,
|
||||||
@@ -326,6 +370,7 @@ export const usePaymentChannelManagement = () => {
|
|||||||
saveStripeConfig,
|
saveStripeConfig,
|
||||||
saveAlipayConfig,
|
saveAlipayConfig,
|
||||||
saveWechatConfig,
|
saveWechatConfig,
|
||||||
|
saveEpayConfig,
|
||||||
testStripeConnection,
|
testStripeConnection,
|
||||||
testAlipayConnection,
|
testAlipayConnection,
|
||||||
testWechatConnection,
|
testWechatConnection,
|
||||||
|
|||||||
@@ -0,0 +1,269 @@
|
|||||||
|
import { useState, useEffect, useCallback, useRef } from "react";
|
||||||
|
import { ResourceGroup } from "@/components/resource-group/GroupList";
|
||||||
|
import { GroupService } from "@/components/resource-group/GroupServiceTable";
|
||||||
|
import {
|
||||||
|
fetchResourceGroups,
|
||||||
|
fetchGroupServices,
|
||||||
|
createResourceGroup,
|
||||||
|
updateResourceGroup,
|
||||||
|
deleteResourceGroup,
|
||||||
|
removeServiceFromGroup,
|
||||||
|
fetchSimpleResourceGroups,
|
||||||
|
addServiceToGroup,
|
||||||
|
} from "@/api/resourceGroup.api";
|
||||||
|
import { toast } from "react-hot-toast";
|
||||||
|
import { useTranslation } from "@/shared/lib/useTranslation";
|
||||||
|
|
||||||
|
|
||||||
|
export const useResourceGroups = () => {
|
||||||
|
const [groups, setGroups] = useState<ResourceGroup[]>([]);
|
||||||
|
const [groupServices, setGroupServices] = useState<GroupService[]>([]);
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
const [servicesLoading, setServicesLoading] = useState(false);
|
||||||
|
const [hasMore, setHasMore] = useState(true);
|
||||||
|
const [shouldScrollToTop, setShouldScrollToTop] = useState(false);
|
||||||
|
const { t } = useTranslation();
|
||||||
|
|
||||||
|
const [simpleResourceGroups, setSimpleResourceGroups] = useState<{ id: string, name: string }[]>([]);
|
||||||
|
|
||||||
|
// 菜单列表(GroupList)的分页和搜索状态
|
||||||
|
const groupListParams = useRef({
|
||||||
|
page: 1,
|
||||||
|
pageSize: 10,
|
||||||
|
keyword: ""
|
||||||
|
});
|
||||||
|
|
||||||
|
// 服务列表(GroupServiceTable)的分页状态
|
||||||
|
const [serviceTablePagination, setServiceTablePagination] = useState({
|
||||||
|
page: 1,
|
||||||
|
pageSize: 10,
|
||||||
|
total: 0,
|
||||||
|
});
|
||||||
|
const serviceTableParams = useRef({
|
||||||
|
pageSize: 10,
|
||||||
|
keyword: ""
|
||||||
|
});
|
||||||
|
|
||||||
|
// 加载资源组列表(支持初始加载和追加加载)
|
||||||
|
const loadGroups = useCallback(async (page: number, page_size: number, search_keyword: string, append: boolean = false) => {
|
||||||
|
setLoading(true);
|
||||||
|
try {
|
||||||
|
groupListParams.current = {
|
||||||
|
page,
|
||||||
|
pageSize: page_size,
|
||||||
|
keyword: search_keyword
|
||||||
|
};
|
||||||
|
|
||||||
|
const response = await fetchResourceGroups(page, page_size, search_keyword);
|
||||||
|
const mappedData = response.data.map((item) => ({
|
||||||
|
id: item.id,
|
||||||
|
name: item.name,
|
||||||
|
description: item.description,
|
||||||
|
isDefault: item.is_default,
|
||||||
|
serviceCount: item.service_count,
|
||||||
|
createdAt: item.create_at,
|
||||||
|
}));
|
||||||
|
|
||||||
|
if (append) {
|
||||||
|
// 追加模式:将新数据追加到现有数据后面
|
||||||
|
setGroups((prev) => {
|
||||||
|
const newGroups = [...prev, ...mappedData];
|
||||||
|
setHasMore(newGroups.length < response.total);
|
||||||
|
return newGroups;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// 重置模式:替换所有数据
|
||||||
|
setGroups(mappedData);
|
||||||
|
setHasMore(mappedData.length < response.total);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
// 加载更多资源组(追加数据)
|
||||||
|
const loadMoreGroups = useCallback(async () => {
|
||||||
|
if (loading || !hasMore) return;
|
||||||
|
|
||||||
|
const { page, pageSize, keyword } = groupListParams.current;
|
||||||
|
await loadGroups(page + 1, pageSize, keyword, true);
|
||||||
|
}, [loading, hasMore, loadGroups]);
|
||||||
|
|
||||||
|
// 加载指定组的服务列表(支持分页)
|
||||||
|
const loadGroupServices = useCallback(async (
|
||||||
|
groupId: string,
|
||||||
|
page: number = 1,
|
||||||
|
pageSize: number = 10,
|
||||||
|
keyword: string = ""
|
||||||
|
) => {
|
||||||
|
setServicesLoading(true);
|
||||||
|
try {
|
||||||
|
const response = await fetchGroupServices(groupId, page, pageSize, keyword);
|
||||||
|
setGroupServices(response.data);
|
||||||
|
setServiceTablePagination({
|
||||||
|
page: response.page,
|
||||||
|
pageSize: response.page_size,
|
||||||
|
total: response.total,
|
||||||
|
});
|
||||||
|
// 保存当前的 pageSize 和 keyword 到 ref
|
||||||
|
serviceTableParams.current = {
|
||||||
|
pageSize: response.page_size,
|
||||||
|
keyword
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
console.error(t("Failed to load group services"), error);
|
||||||
|
} finally {
|
||||||
|
setServicesLoading(false);
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
// 创建资源组
|
||||||
|
const handleCreateGroup = useCallback(
|
||||||
|
async (name: string, isDefault: boolean): Promise<string> => {
|
||||||
|
try {
|
||||||
|
const result = await createResourceGroup(name, isDefault);
|
||||||
|
if (!result.success) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
// 创建成功后重新加载列表(重置到第1页)
|
||||||
|
toast.success(t("Resource group created successfully"));
|
||||||
|
const { pageSize, keyword } = groupListParams.current;
|
||||||
|
await loadGroups(1, pageSize, keyword, false);
|
||||||
|
// 触发滚动到顶部
|
||||||
|
setShouldScrollToTop(true);
|
||||||
|
return result.id;
|
||||||
|
} catch {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[loadGroups]
|
||||||
|
);
|
||||||
|
|
||||||
|
// 更新资源组
|
||||||
|
const handleUpdateGroup = useCallback(
|
||||||
|
async (groupId: string, name: string, isDefault: boolean): Promise<boolean> => {
|
||||||
|
try {
|
||||||
|
const result = await updateResourceGroup(groupId, name, isDefault);
|
||||||
|
if (!result) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// 更新成功后重新加载列表(重置到第1页)
|
||||||
|
const { pageSize, keyword } = groupListParams.current;
|
||||||
|
await loadGroups(1, pageSize, keyword, false);
|
||||||
|
toast.success(t("Resource group updated successfully"));
|
||||||
|
return true;
|
||||||
|
} catch {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[loadGroups]
|
||||||
|
);
|
||||||
|
|
||||||
|
// 删除资源组
|
||||||
|
const handleDeleteGroup = useCallback(
|
||||||
|
async (groupId: string, transferToGroupId: string): Promise<boolean> => {
|
||||||
|
try {
|
||||||
|
const result = await deleteResourceGroup(groupId, transferToGroupId);
|
||||||
|
if (!result) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// 删除成功后重新加载列表(重置到第1页)
|
||||||
|
const { pageSize, keyword } = groupListParams.current;
|
||||||
|
await loadGroups(1, pageSize, keyword, false);
|
||||||
|
toast.success(t("Resource group deleted successfully"));
|
||||||
|
return true;
|
||||||
|
} catch {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[loadGroups]
|
||||||
|
);
|
||||||
|
|
||||||
|
// 服务列表翻页
|
||||||
|
const handleServicePageChange = useCallback(
|
||||||
|
async (groupId: string, page: number) => {
|
||||||
|
await loadGroupServices(
|
||||||
|
groupId,
|
||||||
|
page,
|
||||||
|
serviceTableParams.current.pageSize,
|
||||||
|
serviceTableParams.current.keyword
|
||||||
|
);
|
||||||
|
},
|
||||||
|
[loadGroupServices]
|
||||||
|
);
|
||||||
|
|
||||||
|
// 添加服务到组
|
||||||
|
const handleAddServiceToGroup = useCallback(
|
||||||
|
async (groupId: string, serviceIds: string[]): Promise<boolean> => {
|
||||||
|
try {
|
||||||
|
const success = await addServiceToGroup(groupId, serviceIds);
|
||||||
|
if (!success) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
toast.success(t("Services added successfully"));
|
||||||
|
return true;
|
||||||
|
} catch {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[loadGroupServices, serviceTablePagination.page]
|
||||||
|
);
|
||||||
|
|
||||||
|
// 从组中移除服务
|
||||||
|
const handleRemoveService = useCallback(
|
||||||
|
async (groupId: string, serviceId: string): Promise<boolean> => {
|
||||||
|
try {
|
||||||
|
const success = await removeServiceFromGroup(groupId, [serviceId]);
|
||||||
|
if (!success) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
toast.success(t("Service removed successfully"));
|
||||||
|
return true;
|
||||||
|
} catch {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[loadGroupServices, serviceTablePagination.page]
|
||||||
|
);
|
||||||
|
|
||||||
|
// 加载简单资源组列表(用于下拉选择)
|
||||||
|
const loadSimpleResourceGroups = useCallback(async () => {
|
||||||
|
try {
|
||||||
|
const data = await fetchSimpleResourceGroups();
|
||||||
|
setSimpleResourceGroups(data);
|
||||||
|
return data
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Failed to load simple resource groups:", error);
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
// 初始加载
|
||||||
|
useEffect(() => {
|
||||||
|
loadGroups(1, 10, "");
|
||||||
|
}, [loadGroups]);
|
||||||
|
|
||||||
|
return {
|
||||||
|
groups,
|
||||||
|
simpleResourceGroups,
|
||||||
|
groupServices,
|
||||||
|
serviceTablePagination,
|
||||||
|
serviceTableParams,
|
||||||
|
loading,
|
||||||
|
servicesLoading,
|
||||||
|
hasMore,
|
||||||
|
shouldScrollToTop,
|
||||||
|
setShouldScrollToTop,
|
||||||
|
loadGroups,
|
||||||
|
loadMoreGroups,
|
||||||
|
loadGroupServices,
|
||||||
|
loadSimpleResourceGroups,
|
||||||
|
handleServicePageChange,
|
||||||
|
handleAddServiceToGroup,
|
||||||
|
handleCreateGroup,
|
||||||
|
handleUpdateGroup,
|
||||||
|
handleDeleteGroup,
|
||||||
|
handleRemoveService,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
@@ -14,6 +14,9 @@ export const useRevenueManagement = () => {
|
|||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
const [searchQuery, setSearchQuery] = useState("");
|
const [searchQuery, setSearchQuery] = useState("");
|
||||||
const [statusFilter, setStatusFilter] = useState("all");
|
const [statusFilter, setStatusFilter] = useState("all");
|
||||||
|
const [paymentTypeFilter, setPaymentTypeFilter] = useState("all"); // 付款方式筛选
|
||||||
|
const [sortBy, setSortBy] = useState<string | undefined>(undefined); // 排序字段
|
||||||
|
const [sortOrder, setSortOrder] = useState<'asc' | 'desc' | undefined>(undefined); // 排序顺序
|
||||||
const [pagination, setPagination] = useState<PaginationInfo>({
|
const [pagination, setPagination] = useState<PaginationInfo>({
|
||||||
page: 1,
|
page: 1,
|
||||||
pageSize: 10,
|
pageSize: 10,
|
||||||
@@ -30,6 +33,9 @@ export const useRevenueManagement = () => {
|
|||||||
page_size: pagination.pageSize,
|
page_size: pagination.pageSize,
|
||||||
search: searchQuery,
|
search: searchQuery,
|
||||||
status: statusFilter === "all" ? undefined : statusFilter,
|
status: statusFilter === "all" ? undefined : statusFilter,
|
||||||
|
payment_type: paymentTypeFilter === "all" ? undefined : paymentTypeFilter,
|
||||||
|
sort_by: sortBy,
|
||||||
|
sort_order: sortOrder,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (response.success && response.data) {
|
if (response.success && response.data) {
|
||||||
@@ -52,7 +58,7 @@ export const useRevenueManagement = () => {
|
|||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
}, [pagination.page, pagination.pageSize, searchQuery, statusFilter]);
|
}, [pagination.page, pagination.pageSize, searchQuery, statusFilter, paymentTypeFilter, sortBy, sortOrder]);
|
||||||
|
|
||||||
const setSearch = useCallback((search: string) => {
|
const setSearch = useCallback((search: string) => {
|
||||||
setSearchQuery(search);
|
setSearchQuery(search);
|
||||||
@@ -72,6 +78,17 @@ export const useRevenueManagement = () => {
|
|||||||
setPagination((prev) => ({ ...prev, pageSize, page: 1 }));
|
setPagination((prev) => ({ ...prev, pageSize, page: 1 }));
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
const setPaymentType = useCallback((paymentType: string) => {
|
||||||
|
setPaymentTypeFilter(paymentType);
|
||||||
|
setPagination((prev) => ({ ...prev, page: 1 })); // reset to first page
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const setSort = useCallback((field: string | undefined, order: 'asc' | 'desc' | undefined) => {
|
||||||
|
setSortBy(field);
|
||||||
|
setSortOrder(order);
|
||||||
|
setPagination((prev) => ({ ...prev, page: 1 })); // reset to first page
|
||||||
|
}, []);
|
||||||
|
|
||||||
// initial load and pagination change
|
// initial load and pagination change
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetchRevenues();
|
fetchRevenues();
|
||||||
@@ -83,10 +100,15 @@ export const useRevenueManagement = () => {
|
|||||||
error,
|
error,
|
||||||
searchQuery,
|
searchQuery,
|
||||||
statusFilter,
|
statusFilter,
|
||||||
|
paymentTypeFilter,
|
||||||
|
sortBy,
|
||||||
|
sortOrder,
|
||||||
pagination,
|
pagination,
|
||||||
fetchRevenues,
|
fetchRevenues,
|
||||||
setSearch,
|
setSearch,
|
||||||
setStatus,
|
setStatus,
|
||||||
|
setPaymentType,
|
||||||
|
setSort,
|
||||||
setPage,
|
setPage,
|
||||||
setPageSize,
|
setPageSize,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ export const useSystemConfigManagement = () => {
|
|||||||
const [platformConfig, setPlatformConfig] = useState<PlatformConfig>({
|
const [platformConfig, setPlatformConfig] = useState<PlatformConfig>({
|
||||||
name: "",
|
name: "",
|
||||||
logo: "",
|
logo: "",
|
||||||
currency: "USD",
|
currency: "CNY",
|
||||||
});
|
});
|
||||||
const [platformLoading, setPlatformLoading] = useState(false);
|
const [platformLoading, setPlatformLoading] = useState(false);
|
||||||
const [platformError, setPlatformError] = useState<string | null>(null);
|
const [platformError, setPlatformError] = useState<string | null>(null);
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ interface FetchServicesParams {
|
|||||||
page?: number;
|
page?: number;
|
||||||
page_size?: number;
|
page_size?: number;
|
||||||
keyword?: string;
|
keyword?: string;
|
||||||
|
tag?: string;
|
||||||
}
|
}
|
||||||
interface ServicesResponseData {
|
interface ServicesResponseData {
|
||||||
services: ServiceData[];
|
services: ServiceData[];
|
||||||
@@ -42,6 +43,7 @@ export async function fetchServices(
|
|||||||
page_size: _BasePageDetail.page_size,
|
page_size: _BasePageDetail.page_size,
|
||||||
page: _BasePageDetail.page,
|
page: _BasePageDetail.page,
|
||||||
keyword: "",
|
keyword: "",
|
||||||
|
tag: "",
|
||||||
}
|
}
|
||||||
): Promise<ServicesResponse> {
|
): Promise<ServicesResponse> {
|
||||||
// Build query parameters
|
// Build query parameters
|
||||||
@@ -50,7 +52,7 @@ export async function fetchServices(
|
|||||||
if (params.page_size)
|
if (params.page_size)
|
||||||
queryParams.append("page_size", params.page_size.toString());
|
queryParams.append("page_size", params.page_size.toString());
|
||||||
if (params.keyword) queryParams.append("keyword", params.keyword);
|
if (params.keyword) queryParams.append("keyword", params.keyword);
|
||||||
|
if (params.tag) queryParams.append("tag", params.tag);
|
||||||
const response = await fetchAPI<BaseMCPService[]>(
|
const response = await fetchAPI<BaseMCPService[]>(
|
||||||
`/api/web/mcp_services${queryParams.toString() ? "?" + queryParams.toString() : ""}`
|
`/api/web/mcp_services${queryParams.toString() ? "?" + queryParams.toString() : ""}`
|
||||||
);
|
);
|
||||||
@@ -99,3 +101,26 @@ export async function fetchServiceById(
|
|||||||
|
|
||||||
return convertMcpService([response.data])[0];
|
return convertMcpService([response.data])[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetch tags list
|
||||||
|
*/
|
||||||
|
export async function fetchTagsList(
|
||||||
|
): Promise<string[] | []> {
|
||||||
|
const response = await fetchAPI<string[]>(
|
||||||
|
`/api/web/mcp_tags`,
|
||||||
|
{
|
||||||
|
method: "GET",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!response.success) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
return response.data || []
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
import { ApiArrayResponse, ApiObjectResponse } from "@/shared/types";
|
import { ApiArrayResponse, ApiObjectResponse } from "@/shared/types";
|
||||||
import { fetchAdminAPI } from "@/rpc/admin-api";
|
import { fetchAdminAPI } from "@/rpc/admin-api";
|
||||||
import {
|
import {
|
||||||
|
MCPResourceGroupResponse,
|
||||||
MCPService,
|
MCPService,
|
||||||
MCPServiceFormData,
|
MCPServiceFormData,
|
||||||
OpenAPIParseResponse,
|
OpenAPIParseResponse,
|
||||||
@@ -10,15 +11,15 @@ import i18n from "@/shared/lib/i18n";
|
|||||||
|
|
||||||
// MCP server list API response interface
|
// MCP server list API response interface
|
||||||
export interface MCPServiceListApiResponse
|
export interface MCPServiceListApiResponse
|
||||||
extends ApiArrayResponse<MCPService> {}
|
extends ApiArrayResponse<MCPService> { }
|
||||||
|
|
||||||
// MCP server detail API response interface
|
// MCP server detail API response interface
|
||||||
export interface MCPServiceDetailApiResponse
|
export interface MCPServiceDetailApiResponse
|
||||||
extends ApiObjectResponse<MCPService> {}
|
extends ApiObjectResponse<MCPService> { }
|
||||||
|
|
||||||
// OpenAPI parse API response interface
|
// OpenAPI parse API response interface
|
||||||
export interface OpenAPIParseApiResponse
|
export interface OpenAPIParseApiResponse
|
||||||
extends ApiObjectResponse<OpenAPIParseResponse> {}
|
extends ApiObjectResponse<OpenAPIParseResponse> { }
|
||||||
|
|
||||||
// get MCP server list params interface
|
// get MCP server list params interface
|
||||||
export interface GetMCPServiceListParams {
|
export interface GetMCPServiceListParams {
|
||||||
@@ -28,6 +29,13 @@ export interface GetMCPServiceListParams {
|
|||||||
status?: string;
|
status?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface GetMCPResourceGroupsParams {
|
||||||
|
data: MCPResourceGroupResponse[];
|
||||||
|
total: number;
|
||||||
|
page: number;
|
||||||
|
page_size: number;
|
||||||
|
}
|
||||||
|
|
||||||
// get MCP server detail params interface
|
// get MCP server detail params interface
|
||||||
export interface GetMCPServiceDetailParams {
|
export interface GetMCPServiceDetailParams {
|
||||||
id: string;
|
id: string;
|
||||||
@@ -55,8 +63,8 @@ export const getMCPServiceList = async (
|
|||||||
const queryParams = new URLSearchParams({
|
const queryParams = new URLSearchParams({
|
||||||
page: params.page.toString(),
|
page: params.page.toString(),
|
||||||
page_size: params.page_size.toString(),
|
page_size: params.page_size.toString(),
|
||||||
...(params.search && { search: params.search }),
|
...(params.search && { keyword: params.search }),
|
||||||
...(params.status && { status: params.status }),
|
...(params.status && { filter_status: params.status }),
|
||||||
});
|
});
|
||||||
|
|
||||||
const response = await fetchAdminAPI<MCPService[]>(
|
const response = await fetchAdminAPI<MCPService[]>(
|
||||||
@@ -217,3 +225,97 @@ export const parseOpenAPIDocumentForUpdate = async (
|
|||||||
|
|
||||||
return response as ApiObjectResponse<MCPService>;
|
return response as ApiObjectResponse<MCPService>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取资源组列表
|
||||||
|
*/
|
||||||
|
export const fetchMCPResourceGroups = async (id: string, page: number, page_size: number, keyword: string): Promise<GetMCPResourceGroupsParams> => {
|
||||||
|
try {
|
||||||
|
const response = await fetchAdminAPI<MCPResourceGroupResponse[]>(`/api/mcp/service/resource_group/list?id=${id}&page=${page}&page_size=${page_size}&keyword=${keyword}`);
|
||||||
|
if (!response.success) {
|
||||||
|
toast.error(response.error_message || i18n.t("Failed to load resource groups"));
|
||||||
|
return {
|
||||||
|
data: [],
|
||||||
|
total: 0,
|
||||||
|
page,
|
||||||
|
page_size,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
data: response.data || [],
|
||||||
|
total: response.page?.total || 0,
|
||||||
|
page: response.page?.page || page,
|
||||||
|
page_size: response.page?.page_size || page_size,
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error fetching auth keys:", error);
|
||||||
|
return {
|
||||||
|
data: [],
|
||||||
|
total: 0,
|
||||||
|
page,
|
||||||
|
page_size,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取未加入的资源组
|
||||||
|
*/
|
||||||
|
export const fetchUnboundResourceGroups = async (id: string): Promise<{ id: string, name: string }[]> => {
|
||||||
|
try {
|
||||||
|
const response = await fetchAdminAPI<{ id: string, name: string }[]>(`/api/mcp/service/resource_group/list/unbind?id=${id}`);
|
||||||
|
if (!response.success) {
|
||||||
|
toast.error(response.error_message || i18n.t("Failed to load resource groups"));
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
return response.data || []
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error fetching auth keys:", error);
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除资源组
|
||||||
|
*/
|
||||||
|
export const deleteResourceGroup = async (serviceById: string, resourceGroupId: string[]): Promise<boolean> => {
|
||||||
|
try {
|
||||||
|
const response = await fetchAdminAPI<boolean>(`/api/mcp/service/resource_group?id=${serviceById}`, {
|
||||||
|
method: "DELETE",
|
||||||
|
body: { resource_groups: resourceGroupId } as unknown as BodyInit,
|
||||||
|
});
|
||||||
|
if (!response.success) {
|
||||||
|
toast.error(response?.error_message || i18n.t("Failed to delete resource group"));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error fetching auth keys:", error);
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加服务到资源组
|
||||||
|
*/
|
||||||
|
export const addServiceToGroup = async (
|
||||||
|
groupId: string,
|
||||||
|
services: string[]
|
||||||
|
): Promise<boolean> => {
|
||||||
|
try {
|
||||||
|
const response = await fetchAdminAPI<boolean>(`/api/mcp/service/resource_group?id=${groupId}`, {
|
||||||
|
method: "PUT",
|
||||||
|
body: { resource_groups: services } as unknown as BodyInit,
|
||||||
|
});
|
||||||
|
if (!response.success) {
|
||||||
|
toast.error(response?.error_message || i18n.t("Failed to add service to group"));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error fetching auth keys:", error);
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
@@ -2,6 +2,7 @@ import {
|
|||||||
StripeConfig,
|
StripeConfig,
|
||||||
AlipayConfig,
|
AlipayConfig,
|
||||||
WechatConfig,
|
WechatConfig,
|
||||||
|
EpayChannelConfig,
|
||||||
PaymentChannelApiItem,
|
PaymentChannelApiItem,
|
||||||
PaymentChannelListResponse,
|
PaymentChannelListResponse,
|
||||||
PaymentChannelTestResult,
|
PaymentChannelTestResult,
|
||||||
@@ -187,6 +188,11 @@ export class PaymentChannelService {
|
|||||||
return this.savePaymentChannelConfig("wechat", config, "WeChat");
|
return this.savePaymentChannelConfig("wechat", config, "WeChat");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Save Epay (易支付) configuration
|
||||||
|
async saveEpayConfig(config: EpayChannelConfig): Promise<boolean> {
|
||||||
|
return this.savePaymentChannelConfig("epay", config, "Epay");
|
||||||
|
}
|
||||||
|
|
||||||
// Test Alipay connection
|
// Test Alipay connection
|
||||||
async testAlipayConnection(
|
async testAlipayConnection(
|
||||||
config: AlipayConfig
|
config: AlipayConfig
|
||||||
|
|||||||
@@ -15,6 +15,9 @@ export interface GetRevenueListParams {
|
|||||||
user_id?: string;
|
user_id?: string;
|
||||||
search?: string;
|
search?: string;
|
||||||
status?: string;
|
status?: string;
|
||||||
|
payment_type?: string; // 付款方式筛选
|
||||||
|
sort_by?: string; // 排序字段
|
||||||
|
sort_order?: 'asc' | 'desc'; // 排序顺序
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -29,8 +32,10 @@ export const getRevenueList = async (
|
|||||||
...(params.start_date && { start_date: params.start_date }),
|
...(params.start_date && { start_date: params.start_date }),
|
||||||
...(params.end_date && { end_date: params.end_date }),
|
...(params.end_date && { end_date: params.end_date }),
|
||||||
...(params.user_id && { user_id: params.user_id }),
|
...(params.user_id && { user_id: params.user_id }),
|
||||||
...(params.search && { search: params.search }),
|
...(params.search && { keyword: params.search }),
|
||||||
...(params.status && { status: params.status }),
|
...(params.status && { status: params.status }),
|
||||||
|
...(params.payment_type && { filter_payment_type: params.payment_type }),
|
||||||
|
...(params.sort_by === 'amount' && params.sort_order && { sort_amount: params.sort_order }),
|
||||||
});
|
});
|
||||||
|
|
||||||
const response = await fetchAdminAPI<RevenueRecord[]>(
|
const response = await fetchAdminAPI<RevenueRecord[]>(
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ export const getUserList = async (
|
|||||||
const queryParams = new URLSearchParams({
|
const queryParams = new URLSearchParams({
|
||||||
page: params.page.toString(),
|
page: params.page.toString(),
|
||||||
page_size: params.page_size.toString(),
|
page_size: params.page_size.toString(),
|
||||||
...(params.search && { search: params.search }),
|
...(params.search && { keyword: params.search }),
|
||||||
...(params.status && { status: params.status }),
|
...(params.status && { status: params.status }),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import React, { useState } from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
import {
|
import {
|
||||||
Navbar,
|
Navbar,
|
||||||
NavbarContent,
|
NavbarContent,
|
||||||
@@ -15,6 +15,7 @@ import { useAuth } from "@/shared/lib/useAuth";
|
|||||||
import { ArrowRightIcon } from "lucide-react";
|
import { ArrowRightIcon } from "lucide-react";
|
||||||
import { DynamicLogo } from "@/shared/components/DynamicLogo";
|
import { DynamicLogo } from "@/shared/components/DynamicLogo";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
|
import { useSharedStore } from "../store/share";
|
||||||
export type NavigationItem = {
|
export type NavigationItem = {
|
||||||
label: string;
|
label: string;
|
||||||
href: string;
|
href: string;
|
||||||
@@ -45,6 +46,13 @@ function NavigationClient({
|
|||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { handleLogin } = useAuth();
|
const { handleLogin } = useAuth();
|
||||||
|
|
||||||
|
const [userToken, setUserToken] = useState<string | null>(null);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const userToken = useSharedStore?.getState?.().user_token
|
||||||
|
setUserToken(userToken);
|
||||||
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{/* Main Navigation */}
|
{/* Main Navigation */}
|
||||||
@@ -97,9 +105,17 @@ function NavigationClient({
|
|||||||
{langNode ? (
|
{langNode ? (
|
||||||
langNode
|
langNode
|
||||||
) : (
|
) : (
|
||||||
<Button onPress={handleLogin} variant="light">
|
<>
|
||||||
<b className="text-md"> {t("Sign In")}</b>
|
{
|
||||||
</Button>
|
!userToken && (
|
||||||
|
<>
|
||||||
|
<Button onPress={handleLogin} variant="light">
|
||||||
|
<b className="text-md"> {t("Sign In")}</b>
|
||||||
|
</Button>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
</>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* Desktop Auth Button */}
|
{/* Desktop Auth Button */}
|
||||||
@@ -110,7 +126,7 @@ function NavigationClient({
|
|||||||
radius="full"
|
radius="full"
|
||||||
onPress={onLogin || handleLogin}
|
onPress={onLogin || handleLogin}
|
||||||
>
|
>
|
||||||
<b className="text-md"> {t(signinText)}</b>
|
<b className="text-md"> {userToken ? t("Dashboard") : t(signinText) }</b>
|
||||||
<div className="w-8 h-8 bg-gradient-to-r from-primary to-[#9ab0f2] flex items-center justify-center rounded-full">
|
<div className="w-8 h-8 bg-gradient-to-r from-primary to-[#9ab0f2] flex items-center justify-center rounded-full">
|
||||||
<ArrowRightIcon
|
<ArrowRightIcon
|
||||||
size={16}
|
size={16}
|
||||||
@@ -128,7 +144,7 @@ function NavigationClient({
|
|||||||
onPress={onLogin || handleLogin}
|
onPress={onLogin || handleLogin}
|
||||||
size="sm"
|
size="sm"
|
||||||
>
|
>
|
||||||
<b className="text-md"> {t(signinText)}</b>
|
<b className="text-md"> {userToken ? t("Dashboard") : t(signinText) }</b>
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
@@ -156,7 +172,7 @@ function NavigationClient({
|
|||||||
radius="full"
|
radius="full"
|
||||||
onPress={onLogin || handleLogin}
|
onPress={onLogin || handleLogin}
|
||||||
>
|
>
|
||||||
<b className="text-md"> {t(signinText)}</b>
|
<b className="text-md"> {userToken ? t("Dashboard") : t(signinText) }</b>
|
||||||
<div className="w-8 h-8 bg-gradient-to-r from-primary to-[#9ab0f2] flex items-center justify-center rounded-full">
|
<div className="w-8 h-8 bg-gradient-to-r from-primary to-[#9ab0f2] flex items-center justify-center rounded-full">
|
||||||
<ArrowRightIcon
|
<ArrowRightIcon
|
||||||
size={16}
|
size={16}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import {
|
|||||||
|
|
||||||
interface HeroSectionProps {
|
interface HeroSectionProps {
|
||||||
searchQuery: string;
|
searchQuery: string;
|
||||||
|
isTagBarDisplay: boolean;
|
||||||
onSearchChange: (value: string) => void;
|
onSearchChange: (value: string) => void;
|
||||||
onSearch?: () => void;
|
onSearch?: () => void;
|
||||||
searchSuggestions?: string[];
|
searchSuggestions?: string[];
|
||||||
@@ -16,6 +17,7 @@ interface HeroSectionProps {
|
|||||||
|
|
||||||
export const HeroSection: React.FC<HeroSectionProps> = ({
|
export const HeroSection: React.FC<HeroSectionProps> = ({
|
||||||
searchQuery,
|
searchQuery,
|
||||||
|
isTagBarDisplay,
|
||||||
onSearchChange,
|
onSearchChange,
|
||||||
onSearch,
|
onSearch,
|
||||||
searchSuggestions = [],
|
searchSuggestions = [],
|
||||||
@@ -77,7 +79,7 @@ export const HeroSection: React.FC<HeroSectionProps> = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="relative overflow-hidden mx-auto p-6 py-24 max-w-7xl">
|
<div className={`relative overflow-hidden mx-auto p-6 ${isTagBarDisplay ? 'py-12' : 'py-24'} max-w-7xl`}>
|
||||||
<div className="text-center mb-12">
|
<div className="text-center mb-12">
|
||||||
<h1 className="text-5xl lg:text-6xl font-bold mb-6 leading-tight">
|
<h1 className="text-5xl lg:text-6xl font-bold mb-6 leading-tight">
|
||||||
{t(
|
{t(
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ export const Price: React.FC<PriceProps> = ({
|
|||||||
return (
|
return (
|
||||||
<div className="flex items-center gap-1">
|
<div className="flex items-center gap-1">
|
||||||
<span className="text-sm font-medium text-green-600">
|
<span className="text-sm font-medium text-green-600">
|
||||||
${priceText.toFixed(2)}
|
¥{priceText.toFixed(2)}
|
||||||
</span>
|
</span>
|
||||||
<span className="text-xs text-gray-500">/{t("Per Call")}</span>
|
<span className="text-xs text-gray-500">/{t("Per Call")}</span>
|
||||||
</div>
|
</div>
|
||||||
@@ -51,14 +51,14 @@ export const Price: React.FC<PriceProps> = ({
|
|||||||
<div className="flex items-center gap-1">
|
<div className="flex items-center gap-1">
|
||||||
<span className="text-gray-600">{t("Input")}:</span>
|
<span className="text-gray-600">{t("Input")}:</span>
|
||||||
<span className="font-medium text-green-600">
|
<span className="font-medium text-green-600">
|
||||||
${inputPrice.toFixed(2)}
|
¥{inputPrice.toFixed(2)}
|
||||||
</span>
|
</span>
|
||||||
<span className="text-xs text-gray-500">/{t("1M tokens")}</span>
|
<span className="text-xs text-gray-500">/{t("1M tokens")}</span>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex items-center gap-1">
|
<div className="flex items-center gap-1">
|
||||||
<span className="text-gray-600">{t("Output")}:</span>
|
<span className="text-gray-600">{t("Output")}:</span>
|
||||||
<span className="font-medium text-blue-600">
|
<span className="font-medium text-blue-600">
|
||||||
${outputPrice.toFixed(2)}
|
¥{outputPrice.toFixed(2)}
|
||||||
</span>
|
</span>
|
||||||
<span className="text-xs text-gray-500">/{t("1M tokens")}</span>
|
<span className="text-xs text-gray-500">/{t("1M tokens")}</span>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import React, { useState } from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
import { useTranslation } from "@/shared/lib/useTranslation";
|
import { useTranslation } from "@/shared/lib/useTranslation";
|
||||||
import { Tabs, Tab, Chip } from "@nextui-org/react";
|
import { Tabs, Tab, Chip } from "@nextui-org/react";
|
||||||
import { ProductHeader } from "./ProductHeader";
|
import { ProductHeader } from "./ProductHeader";
|
||||||
@@ -9,27 +9,40 @@ import { ProductTools } from "./ProductTools";
|
|||||||
import { ProductNotFound } from "./ProductNotFound";
|
import { ProductNotFound } from "./ProductNotFound";
|
||||||
import { ServerConfig } from "./ServerConfig";
|
import { ServerConfig } from "./ServerConfig";
|
||||||
import { ServiceData } from "@/shared/types/marketplace";
|
import { ServiceData } from "@/shared/types/marketplace";
|
||||||
|
import { useGlobalStore } from "@/shared/store/global";
|
||||||
|
import { useSharedStore } from "@/shared/store/share";
|
||||||
|
|
||||||
interface ProductDetailClientProps {
|
interface ProductDetailClientProps {
|
||||||
product: ServiceData;
|
product: ServiceData;
|
||||||
|
visitor?: boolean;
|
||||||
breadcrumbs?: {
|
breadcrumbs?: {
|
||||||
link: string;
|
link: string;
|
||||||
name: string;
|
name: string;
|
||||||
}[];
|
}[];
|
||||||
mcpName?: string;
|
mcpName?: string;
|
||||||
url?: string;
|
url?: string;
|
||||||
|
can_invoke?: boolean;
|
||||||
innerHeaderNode?: React.ReactNode;
|
innerHeaderNode?: React.ReactNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const ProductDetailClient: React.FC<ProductDetailClientProps> = ({
|
export const ProductDetailClient: React.FC<ProductDetailClientProps> = ({
|
||||||
product,
|
product,
|
||||||
|
visitor,
|
||||||
breadcrumbs,
|
breadcrumbs,
|
||||||
mcpName,
|
mcpName,
|
||||||
url,
|
url,
|
||||||
|
can_invoke,
|
||||||
innerHeaderNode,
|
innerHeaderNode,
|
||||||
}) => {
|
}) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
const [getUser] = useGlobalStore((state) => [state.getUser]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const userToken = useSharedStore?.getState?.().user_token
|
||||||
|
if (userToken) {
|
||||||
|
getUser();
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
const [activeTab, setActiveTab] = useState("overview");
|
const [activeTab, setActiveTab] = useState("overview");
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -69,7 +82,7 @@ export const ProductDetailClient: React.FC<ProductDetailClientProps> = ({
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Right side - Server Config */}
|
{/* Right side - Server Config */}
|
||||||
<ServerConfig mcpName={mcpName} url={url} />
|
<ServerConfig mcpName={mcpName} url={url} can_invoke={can_invoke} visitor={visitor} />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* SEO-friendly: Simple text content for search engines */}
|
{/* SEO-friendly: Simple text content for search engines */}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import React, { useState } from "react";
|
import React, { useCallback, useEffect, useState } from "react";
|
||||||
import { Card, Chip, Button, Select, SelectItem } from "@nextui-org/react";
|
import { Card, Chip, Button, Select, SelectItem } from "@nextui-org/react";
|
||||||
import { FlipButton } from "@/shared/components/FlipButton";
|
import { FlipButton } from "@/shared/components/FlipButton";
|
||||||
import { useAuth } from "@/shared/lib/useAuth";
|
import { useAuth } from "@/shared/lib/useAuth";
|
||||||
@@ -9,24 +9,92 @@ import { usePlatformConfig } from "@/shared/contexts/PlatformConfigContext";
|
|||||||
import { Copy } from "lucide-react";
|
import { Copy } from "lucide-react";
|
||||||
import { copyToClipboard } from "@/shared/utils/clipboard";
|
import { copyToClipboard } from "@/shared/utils/clipboard";
|
||||||
import toast from "react-hot-toast";
|
import toast from "react-hot-toast";
|
||||||
|
import { useSharedStore } from "@/shared/store/share";
|
||||||
|
import { fetchAPI } from "@/shared/rpc/common-function";
|
||||||
|
import i18n from "@/shared/lib/i18n";
|
||||||
|
|
||||||
|
type apiKeyList = {
|
||||||
|
name: string;
|
||||||
|
apikey: string;
|
||||||
|
create_time: string;
|
||||||
|
apikey_id: number;
|
||||||
|
}
|
||||||
interface ServerConfigProps {
|
interface ServerConfigProps {
|
||||||
mcpName?: string;
|
mcpName?: string;
|
||||||
url?: string;
|
url?: string;
|
||||||
className?: string;
|
className?: string;
|
||||||
|
can_invoke?: boolean;
|
||||||
|
visitor?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
type McpType = "sse" | "streamable-http";
|
type McpType = "sse" | "streamable-http";
|
||||||
|
|
||||||
|
// 辅助函数:将 API Key 掩码显示,只保留前2位和后4位
|
||||||
|
const maskApiKey = (apiKey: string): string => {
|
||||||
|
if (!apiKey || apiKey.length <= 6) {
|
||||||
|
return apiKey; // 如果太短就直接返回
|
||||||
|
}
|
||||||
|
const prefix = apiKey.slice(0, 2);
|
||||||
|
const suffix = apiKey.slice(-4);
|
||||||
|
const maskedLength = apiKey.length - 6;
|
||||||
|
const masked = '*'.repeat(maskedLength);
|
||||||
|
return `${prefix}${masked}${suffix}`;
|
||||||
|
};
|
||||||
|
|
||||||
export const ServerConfig: React.FC<ServerConfigProps> = ({
|
export const ServerConfig: React.FC<ServerConfigProps> = ({
|
||||||
mcpName,
|
mcpName,
|
||||||
url = process.env.NEXT_PUBLIC_MCP_URL,
|
url = process.env.NEXT_PUBLIC_MCP_URL,
|
||||||
className = "md:min-w-[40%] w-[40%] max-w-100 mt-12",
|
className = "md:min-w-[40%] w-[40%] max-w-100 mt-12",
|
||||||
|
can_invoke,
|
||||||
|
visitor,
|
||||||
}) => {
|
}) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { handleLogin } = useAuth();
|
const { handleLogin } = useAuth();
|
||||||
const { platformConfig } = usePlatformConfig();
|
const { platformConfig } = usePlatformConfig();
|
||||||
const [mcpType, setMcpType] = useState<McpType>("sse");
|
const [mcpType, setMcpType] = useState<McpType>("sse");
|
||||||
|
// API Key List
|
||||||
|
const [apiKeys, setApiKeys] = useState<{ key: string, label: string }[]>([]);
|
||||||
|
// Selected API Key
|
||||||
|
const [selectedApiKey, setSelectedApiKey] = useState<string | null>(null);
|
||||||
|
// User Token
|
||||||
|
const [userToken, setUserToken] = useState<string | null>(null);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const fetchData = async () => {
|
||||||
|
const userToken = useSharedStore?.getState?.().user_token
|
||||||
|
setUserToken(userToken);
|
||||||
|
if (userToken) {
|
||||||
|
const data = await fetchApiKeys()
|
||||||
|
if (data.length > 0) {
|
||||||
|
setApiKeys(data.map((item) => ({
|
||||||
|
key: item.apikey,
|
||||||
|
label: item.name,
|
||||||
|
})));
|
||||||
|
setSelectedApiKey(data[0].apikey)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fetchData();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const fetchApiKeys = useCallback(
|
||||||
|
async (
|
||||||
|
): Promise<apiKeyList[]> => {
|
||||||
|
try {
|
||||||
|
|
||||||
|
const response = await fetchAPI<apiKeyList[]>('/api/apikey/list');
|
||||||
|
if (!response.success) {
|
||||||
|
toast.error(response.error_message || i18n.t("Failed to load api keys"));
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
return response.data || []
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error fetching api keys:", error);
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[]
|
||||||
|
);
|
||||||
|
|
||||||
const mcpTypeOptions = [
|
const mcpTypeOptions = [
|
||||||
{ key: "sse", label: "SSE (Server-Sent Events)" },
|
{ key: "sse", label: "SSE (Server-Sent Events)" },
|
||||||
@@ -36,8 +104,8 @@ export const ServerConfig: React.FC<ServerConfigProps> = ({
|
|||||||
const getCodeContent = () => {
|
const getCodeContent = () => {
|
||||||
const serverUrl =
|
const serverUrl =
|
||||||
mcpType === "streamable-http"
|
mcpType === "streamable-http"
|
||||||
? `${url}/streamable-http?authkey={Your-${platformConfig?.name}-Auth-Key}`
|
? `${url}/streamable-http?authkey=${selectedApiKey ? selectedApiKey : `{Your-${platformConfig?.name}-Auth-Key}`}`
|
||||||
: `${url}?authkey={Your-${platformConfig?.name}-Auth-Key}`;
|
: `${url}?authkey=${selectedApiKey ? selectedApiKey : `{Your-${platformConfig?.name}-Auth-Key}`}`;
|
||||||
|
|
||||||
return `{
|
return `{
|
||||||
"mcpServers": {
|
"mcpServers": {
|
||||||
@@ -59,14 +127,71 @@ export const ServerConfig: React.FC<ServerConfigProps> = ({
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleCreateNewAuthorization = () => {
|
||||||
|
sessionStorage.setItem('create_new_authorization', 'true');
|
||||||
|
handleLogin()
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={`min-w-full ${className} flex-shrink-0`}>
|
<div className={`min-w-full ${className} flex-shrink-0`}>
|
||||||
<div className="mb-2 mt-1">
|
<div className="mb-2 mt-1">
|
||||||
<FlipButton
|
{
|
||||||
className="w-full rounded-md"
|
visitor || can_invoke ? <>
|
||||||
text={t("Sign up to get the auth key")}
|
{
|
||||||
onPress={handleLogin}
|
!userToken ? <>
|
||||||
/>
|
<FlipButton
|
||||||
|
className="w-full rounded-md"
|
||||||
|
text={t("Sign up to get the auth key")}
|
||||||
|
onPress={handleLogin}
|
||||||
|
/>
|
||||||
|
</> : <>
|
||||||
|
{
|
||||||
|
apiKeys.length ?
|
||||||
|
<>
|
||||||
|
<Select
|
||||||
|
label={t("Auth Key")}
|
||||||
|
placeholder={t("Auth Key Name")}
|
||||||
|
selectedKeys={selectedApiKey ? [selectedApiKey] : []}
|
||||||
|
onSelectionChange={(keys) => {
|
||||||
|
const selectedKey = Array.from(keys)[0] as string;
|
||||||
|
setSelectedApiKey(selectedKey);
|
||||||
|
}}
|
||||||
|
className="w-full"
|
||||||
|
size="sm"
|
||||||
|
classNames={{
|
||||||
|
trigger: " bg-black text-white data-[hover=true]:bg-dark-200",
|
||||||
|
label: "!text-default-200",
|
||||||
|
value: "!text-white",
|
||||||
|
popoverContent: "bg-black text-white",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{apiKeys.map((option) => (
|
||||||
|
<SelectItem key={option.key} value={option.key}>
|
||||||
|
{option.label}
|
||||||
|
</SelectItem>
|
||||||
|
))}
|
||||||
|
</Select>
|
||||||
|
</>
|
||||||
|
:
|
||||||
|
<>
|
||||||
|
<FlipButton
|
||||||
|
className="w-full rounded-md"
|
||||||
|
text={t("Create New Authorization")}
|
||||||
|
onPress={handleCreateNewAuthorization}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
}
|
||||||
|
</>
|
||||||
|
}
|
||||||
|
</> : <>
|
||||||
|
<div className="w-full rounded-lg bg-[#F3126033] md:pr-2 h-[40px] md:h-[50px] shadow-lg flex items-center justify-center">
|
||||||
|
<p className="text-[#C20E4D] text-center font-bold text-lg leading-none">
|
||||||
|
{t("You don't have permission to access this MCP server.")}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
}
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* MCP Type Selection */}
|
{/* MCP Type Selection */}
|
||||||
@@ -125,7 +250,7 @@ export const ServerConfig: React.FC<ServerConfigProps> = ({
|
|||||||
{mcpType === "streamable-http"
|
{mcpType === "streamable-http"
|
||||||
? `${url}/streamable-http?authkey=`
|
? `${url}/streamable-http?authkey=`
|
||||||
: `${url}?authkey=`}
|
: `${url}?authkey=`}
|
||||||
<span className="text-success">{`{Your-${platformConfig?.name}-Auth-Key}`}</span>
|
<span className="text-success">{selectedApiKey ? maskApiKey(selectedApiKey) : `{Your-${platformConfig?.name}-Auth-Key}`}</span>
|
||||||
{`"
|
{`"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,309 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import React, { useState, useEffect, useRef } from "react";
|
||||||
|
import {
|
||||||
|
Modal,
|
||||||
|
ModalContent,
|
||||||
|
ModalHeader,
|
||||||
|
ModalBody,
|
||||||
|
ModalFooter,
|
||||||
|
Button,
|
||||||
|
} from "@nextui-org/react";
|
||||||
|
import { Theme, ThemeType } from "@/shared/types/system";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
|
||||||
|
interface TagFilterProps {
|
||||||
|
tags: string[];
|
||||||
|
theme: ThemeType;
|
||||||
|
selectedTag: string;
|
||||||
|
onTagChange: (tag: string) => void;
|
||||||
|
maxWidthPercent?: number; // 最大宽度百分比,默认80%
|
||||||
|
}
|
||||||
|
|
||||||
|
export const TagFilter: React.FC<TagFilterProps> = ({
|
||||||
|
tags,
|
||||||
|
theme,
|
||||||
|
selectedTag,
|
||||||
|
onTagChange,
|
||||||
|
maxWidthPercent = 80,
|
||||||
|
}) => {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
// 是否打开标签筛选弹窗
|
||||||
|
const [isModalOpen, setIsModalOpen] = useState(false);
|
||||||
|
// 临时选中的标签
|
||||||
|
const [tempSelectedTag, setTempSelectedTag] = useState<string | null>(null);
|
||||||
|
// 可见的标签
|
||||||
|
const [visibleTags, setVisibleTags] = useState<string[]>(["ALL", ...tags]);
|
||||||
|
// 是否显示更多按钮
|
||||||
|
const [showMore, setShowMore] = useState(false);
|
||||||
|
// 从弹窗选择的额外标签
|
||||||
|
const [extraTag, setExtraTag] = useState<string | null>(null);
|
||||||
|
// 容器引用
|
||||||
|
const containerRef = useRef<HTMLDivElement>(null);
|
||||||
|
// 标签容器引用
|
||||||
|
const tagsContainerRef = useRef<HTMLDivElement>(null);
|
||||||
|
|
||||||
|
|
||||||
|
// 根据主题获取颜色配置
|
||||||
|
const getThemeColors = () => {
|
||||||
|
switch (theme) {
|
||||||
|
case Theme.DEFAULT:
|
||||||
|
case Theme.MODERN:
|
||||||
|
return {
|
||||||
|
selected: "bg-[#C8DCFF] text-[#1E40AF]",
|
||||||
|
unselected: "text-gray-700 hover:bg-gray-200",
|
||||||
|
shadow: "shadow-lg shadow-[#C8DCFF]/50",
|
||||||
|
};
|
||||||
|
case Theme.CLASSIC:
|
||||||
|
return {
|
||||||
|
selected: "bg-[#475569] text-white",
|
||||||
|
unselected: "text-gray-700 hover:bg-gray-200",
|
||||||
|
shadow: "shadow-lg shadow-[#475569]/50",
|
||||||
|
};
|
||||||
|
case Theme.TEMU:
|
||||||
|
return {
|
||||||
|
selected: "bg-[#F97316] text-white",
|
||||||
|
unselected: "text-gray-700 hover:bg-gray-200",
|
||||||
|
shadow: "shadow-lg shadow-[#F97316]/50",
|
||||||
|
};
|
||||||
|
case Theme.CREATIVE:
|
||||||
|
return {
|
||||||
|
selected: "to-orange-500 via-red-500 from-pink-500 bg-gradient-to-r text-white",
|
||||||
|
unselected: "text-gray-700 hover:bg-gray-200",
|
||||||
|
shadow: "shadow-lg shadow-[#EF5082]/50",
|
||||||
|
};
|
||||||
|
default:
|
||||||
|
return {
|
||||||
|
selected: "bg-[#C8DCFF] text-[#1E40AF]",
|
||||||
|
unselected: "text-gray-700 hover:bg-gray-200",
|
||||||
|
shadow: "shadow-lg shadow-[#C8DCFF]/50",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const themeColors = getThemeColors();
|
||||||
|
|
||||||
|
// 计算哪些标签可以显示
|
||||||
|
useEffect(() => {
|
||||||
|
const calculateVisibleTags = () => {
|
||||||
|
if (!containerRef.current) return;
|
||||||
|
|
||||||
|
const containerWidth = containerRef.current.offsetWidth;
|
||||||
|
const maxWidth = (containerWidth * maxWidthPercent) / 100;
|
||||||
|
|
||||||
|
// More按钮的宽度(估算)
|
||||||
|
const moreButtonWidth = 80;
|
||||||
|
|
||||||
|
// 创建临时元素来测量标签宽度
|
||||||
|
const tempDiv = document.createElement("div");
|
||||||
|
tempDiv.style.position = "absolute";
|
||||||
|
tempDiv.style.visibility = "hidden";
|
||||||
|
tempDiv.style.whiteSpace = "nowrap";
|
||||||
|
tempDiv.className = "px-6 py-2 rounded-full text-sm font-medium";
|
||||||
|
document.body.appendChild(tempDiv);
|
||||||
|
|
||||||
|
let currentWidth = 0;
|
||||||
|
const visible: string[] = ["ALL"];
|
||||||
|
let needsMore = false;
|
||||||
|
|
||||||
|
// 先计算常规标签
|
||||||
|
for (const tag of tags) {
|
||||||
|
if (tag === extraTag) continue; // 跳过额外标签,稍后处理
|
||||||
|
|
||||||
|
tempDiv.textContent = tag;
|
||||||
|
const tagWidth = tempDiv.offsetWidth; // 不加间距
|
||||||
|
|
||||||
|
if (currentWidth + tagWidth + moreButtonWidth > maxWidth) {
|
||||||
|
needsMore = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
currentWidth += tagWidth;
|
||||||
|
visible.push(tag);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理额外标签或当前选中的标签
|
||||||
|
// 如果当前选中的标签不在可见列表中(除了ALL),需要作为额外标签显示
|
||||||
|
const tagToShow = extraTag || (selectedTag !== "ALL" && !visible.includes(selectedTag) ? selectedTag : null);
|
||||||
|
|
||||||
|
if (tagToShow && tagToShow !== "ALL" && !visible.includes(tagToShow)) {
|
||||||
|
tempDiv.textContent = tagToShow;
|
||||||
|
const tagWidth = tempDiv.offsetWidth; // 不加间距
|
||||||
|
|
||||||
|
// 检查是否还有空间显示额外标签
|
||||||
|
if (currentWidth + tagWidth + moreButtonWidth <= maxWidth) {
|
||||||
|
// 空间足够,直接添加
|
||||||
|
currentWidth += tagWidth;
|
||||||
|
visible.push(tagToShow);
|
||||||
|
} else {
|
||||||
|
// 空间不够,替换掉最后一个常规标签(保留 ALL)
|
||||||
|
if (visible.length > 1) {
|
||||||
|
visible.pop(); // 移除最后一个标签
|
||||||
|
visible.push(tagToShow); // 添加额外标签
|
||||||
|
needsMore = true; // 确保显示 More 按钮
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
document.body.removeChild(tempDiv);
|
||||||
|
|
||||||
|
setVisibleTags(visible);
|
||||||
|
setShowMore(needsMore);
|
||||||
|
};
|
||||||
|
|
||||||
|
// 延迟执行以确保DOM已渲染
|
||||||
|
setTimeout(calculateVisibleTags, 0);
|
||||||
|
|
||||||
|
// 监听窗口大小变化
|
||||||
|
window.addEventListener("resize", calculateVisibleTags);
|
||||||
|
return () => window.removeEventListener("resize", calculateVisibleTags);
|
||||||
|
}, [tags, extraTag, selectedTag, maxWidthPercent]);
|
||||||
|
|
||||||
|
const handleTagClick = (tag: string) => {
|
||||||
|
// 如果点击的是额外标签以外的标签,清除额外标签
|
||||||
|
if (extraTag && tag !== extraTag) {
|
||||||
|
setExtraTag(null);
|
||||||
|
}
|
||||||
|
onTagChange(tag);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleModalOpen = () => {
|
||||||
|
// 打开弹窗时,初始化临时选中的标签为当前选中的标签
|
||||||
|
setTempSelectedTag(selectedTag);
|
||||||
|
setIsModalOpen(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleModalConfirm = () => {
|
||||||
|
if (tempSelectedTag) {
|
||||||
|
// 如果选择的是 ALL 或者已经在可见标签中的标签,不设置为额外标签
|
||||||
|
if (tempSelectedTag === "ALL" || visibleTags.includes(tempSelectedTag)) {
|
||||||
|
setExtraTag(null);
|
||||||
|
} else {
|
||||||
|
// 否则设置为额外标签
|
||||||
|
setExtraTag(tempSelectedTag);
|
||||||
|
}
|
||||||
|
onTagChange(tempSelectedTag);
|
||||||
|
}
|
||||||
|
setIsModalOpen(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleModalCancel = () => {
|
||||||
|
setTempSelectedTag(null);
|
||||||
|
setIsModalOpen(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleModalTagClick = (tag: string) => {
|
||||||
|
setTempSelectedTag(tag);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div ref={containerRef} className="w-full px-6 py-6">
|
||||||
|
<div className="mx-auto max-w-7xl text-center">
|
||||||
|
<div
|
||||||
|
ref={tagsContainerRef}
|
||||||
|
className="inline-flex items-center border-1 bg-[#fff] rounded-full transition-all duration-300"
|
||||||
|
>
|
||||||
|
{visibleTags.map((tag) => {
|
||||||
|
const isSelected = selectedTag === tag;
|
||||||
|
return (
|
||||||
|
<button
|
||||||
|
key={tag}
|
||||||
|
onClick={() => handleTagClick(tag)}
|
||||||
|
className={`
|
||||||
|
px-6 py-2 rounded-full text-sm font-medium transition-all duration-200
|
||||||
|
whitespace-nowrap
|
||||||
|
${
|
||||||
|
isSelected
|
||||||
|
? `${themeColors.selected} ${themeColors.shadow}`
|
||||||
|
: themeColors.unselected
|
||||||
|
}
|
||||||
|
`}
|
||||||
|
>
|
||||||
|
{tag}
|
||||||
|
</button>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
|
||||||
|
{showMore && (
|
||||||
|
<button
|
||||||
|
onClick={handleModalOpen}
|
||||||
|
className="px-4 py-2 text-sm font-medium text-blue-500 hover:text-blue-600 transition-colors whitespace-nowrap"
|
||||||
|
>
|
||||||
|
More
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* More Modal */}
|
||||||
|
<Modal
|
||||||
|
isOpen={isModalOpen}
|
||||||
|
onClose={handleModalCancel}
|
||||||
|
size="2xl"
|
||||||
|
scrollBehavior="inside"
|
||||||
|
>
|
||||||
|
<ModalContent>
|
||||||
|
<ModalHeader className="flex flex-col gap-1">
|
||||||
|
Tag Filter
|
||||||
|
</ModalHeader>
|
||||||
|
<ModalBody>
|
||||||
|
<div className="flex flex-wrap gap-3 py-4">
|
||||||
|
<button
|
||||||
|
onClick={() => handleModalTagClick("ALL")}
|
||||||
|
className={`
|
||||||
|
px-6 py-2 rounded-full text-sm font-medium transition-all duration-200
|
||||||
|
${
|
||||||
|
tempSelectedTag === "ALL"
|
||||||
|
? "bg-blue-500 text-white shadow-lg shadow-blue-500/50"
|
||||||
|
: "bg-gray-100 text-gray-700 hover:bg-gray-200"
|
||||||
|
}
|
||||||
|
`}
|
||||||
|
>
|
||||||
|
ALL
|
||||||
|
</button>
|
||||||
|
|
||||||
|
{tags.map((tag) => {
|
||||||
|
const isSelected = tempSelectedTag === tag;
|
||||||
|
return (
|
||||||
|
<button
|
||||||
|
key={tag}
|
||||||
|
onClick={() => handleModalTagClick(tag)}
|
||||||
|
className={`
|
||||||
|
px-6 py-2 rounded-full text-sm font-medium transition-all duration-200
|
||||||
|
${
|
||||||
|
isSelected
|
||||||
|
? "bg-blue-500 text-white shadow-lg shadow-blue-500/50"
|
||||||
|
: "bg-gray-100 text-gray-700 hover:bg-gray-200"
|
||||||
|
}
|
||||||
|
`}
|
||||||
|
>
|
||||||
|
{tag}
|
||||||
|
</button>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
</ModalBody>
|
||||||
|
<ModalFooter>
|
||||||
|
<Button
|
||||||
|
color="default"
|
||||||
|
variant="light"
|
||||||
|
onPress={handleModalCancel}
|
||||||
|
>
|
||||||
|
{t("Cancel")}
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
color="primary"
|
||||||
|
onPress={handleModalConfirm}
|
||||||
|
isDisabled={!tempSelectedTag}
|
||||||
|
>
|
||||||
|
{t("Confirm")}
|
||||||
|
</Button>
|
||||||
|
</ModalFooter>
|
||||||
|
</ModalContent>
|
||||||
|
</Modal>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
@@ -13,6 +13,7 @@ interface BasicInfoTabProps {
|
|||||||
onInputChange: (field: keyof MCPServiceFormData, value: any) => void;
|
onInputChange: (field: keyof MCPServiceFormData, value: any) => void;
|
||||||
onAddTag: () => void;
|
onAddTag: () => void;
|
||||||
onRemoveTag: (tag: string) => void;
|
onRemoveTag: (tag: string) => void;
|
||||||
|
errors?: Record<string, string>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const BasicInfoTab: React.FC<BasicInfoTabProps> = ({
|
export const BasicInfoTab: React.FC<BasicInfoTabProps> = ({
|
||||||
@@ -22,6 +23,7 @@ export const BasicInfoTab: React.FC<BasicInfoTabProps> = ({
|
|||||||
onInputChange,
|
onInputChange,
|
||||||
onAddTag,
|
onAddTag,
|
||||||
onRemoveTag,
|
onRemoveTag,
|
||||||
|
errors,
|
||||||
}) => {
|
}) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
@@ -41,7 +43,9 @@ export const BasicInfoTab: React.FC<BasicInfoTabProps> = ({
|
|||||||
)}
|
)}
|
||||||
labelPlacement="outside"
|
labelPlacement="outside"
|
||||||
isRequired
|
isRequired
|
||||||
errorMessage={t("Server ID is required")}
|
maxLength={255}
|
||||||
|
isInvalid={!!errors?.slug_name}
|
||||||
|
errorMessage={errors?.slug_name || t("Server ID is required")}
|
||||||
/>
|
/>
|
||||||
<Input
|
<Input
|
||||||
label={t("Server Name")}
|
label={t("Server Name")}
|
||||||
@@ -50,7 +54,9 @@ export const BasicInfoTab: React.FC<BasicInfoTabProps> = ({
|
|||||||
onChange={(e) => onInputChange("name", e.target.value)}
|
onChange={(e) => onInputChange("name", e.target.value)}
|
||||||
isRequired
|
isRequired
|
||||||
labelPlacement="outside"
|
labelPlacement="outside"
|
||||||
errorMessage={t("Server name is required")}
|
maxLength={255}
|
||||||
|
isInvalid={!!errors?.name}
|
||||||
|
errorMessage={errors?.name || t("Server name is required")}
|
||||||
/>
|
/>
|
||||||
<Input
|
<Input
|
||||||
label={t("Short Description")}
|
label={t("Short Description")}
|
||||||
@@ -59,7 +65,10 @@ export const BasicInfoTab: React.FC<BasicInfoTabProps> = ({
|
|||||||
onChange={(e) => onInputChange("short_description", e.target.value)}
|
onChange={(e) => onInputChange("short_description", e.target.value)}
|
||||||
isRequired
|
isRequired
|
||||||
labelPlacement="outside"
|
labelPlacement="outside"
|
||||||
errorMessage={t("Short description is required")}
|
isInvalid={!!errors?.short_description}
|
||||||
|
errorMessage={
|
||||||
|
errors?.short_description || t("Short description is required")
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Input
|
<Input
|
||||||
@@ -69,7 +78,8 @@ export const BasicInfoTab: React.FC<BasicInfoTabProps> = ({
|
|||||||
onChange={(e) => onInputChange("base_url", e.target.value)}
|
onChange={(e) => onInputChange("base_url", e.target.value)}
|
||||||
isRequired
|
isRequired
|
||||||
labelPlacement="outside"
|
labelPlacement="outside"
|
||||||
errorMessage={t("API Endpoint is required")}
|
isInvalid={!!errors?.base_url}
|
||||||
|
errorMessage={errors?.base_url || t("API Endpoint is required")}
|
||||||
/>
|
/>
|
||||||
{/* headers input fields */}
|
{/* headers input fields */}
|
||||||
<HeadersManagementSettings
|
<HeadersManagementSettings
|
||||||
|
|||||||
@@ -65,6 +65,27 @@ export const PricingTab: React.FC<PricingTabProps> = ({
|
|||||||
</SelectItem>
|
</SelectItem>
|
||||||
</Select>
|
</Select>
|
||||||
|
|
||||||
|
{formData.charge_type === ChargeType.Free && (
|
||||||
|
<Input
|
||||||
|
type="number"
|
||||||
|
min="0"
|
||||||
|
step="1"
|
||||||
|
value={
|
||||||
|
formData.free_daily_limit === null ||
|
||||||
|
formData.free_daily_limit === undefined
|
||||||
|
? ""
|
||||||
|
: String(formData.free_daily_limit)
|
||||||
|
}
|
||||||
|
onChange={(e) => onInputChange("free_daily_limit", e.target.value)}
|
||||||
|
description={t(
|
||||||
|
"Max calls per user per day (Beijing time). Leave blank or 0 for unlimited"
|
||||||
|
)}
|
||||||
|
placeholder={t("e.g. 50")}
|
||||||
|
label={t("Daily call limit per user")}
|
||||||
|
labelPlacement="outside"
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
{formData.charge_type !== ChargeType.Free && (
|
{formData.charge_type !== ChargeType.Free && (
|
||||||
<>
|
<>
|
||||||
{formData.charge_type === ChargeType.PerToken ? (
|
{formData.charge_type === ChargeType.PerToken ? (
|
||||||
@@ -85,6 +106,7 @@ export const PricingTab: React.FC<PricingTabProps> = ({
|
|||||||
</span>
|
</span>
|
||||||
}
|
}
|
||||||
labelPlacement="outside"
|
labelPlacement="outside"
|
||||||
|
required
|
||||||
/>
|
/>
|
||||||
<Input
|
<Input
|
||||||
type="number"
|
type="number"
|
||||||
@@ -102,6 +124,7 @@ export const PricingTab: React.FC<PricingTabProps> = ({
|
|||||||
</span>
|
</span>
|
||||||
}
|
}
|
||||||
labelPlacement="outside"
|
labelPlacement="outside"
|
||||||
|
required
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
@@ -118,6 +141,7 @@ export const PricingTab: React.FC<PricingTabProps> = ({
|
|||||||
</span>
|
</span>
|
||||||
}
|
}
|
||||||
labelPlacement="outside"
|
labelPlacement="outside"
|
||||||
|
required
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
|
|||||||
@@ -0,0 +1,316 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import React, { useCallback, useEffect, useRef, useState } from "react";
|
||||||
|
import {
|
||||||
|
Button,
|
||||||
|
Table,
|
||||||
|
TableHeader,
|
||||||
|
TableColumn,
|
||||||
|
TableBody,
|
||||||
|
TableRow,
|
||||||
|
TableCell,
|
||||||
|
Tooltip,
|
||||||
|
Spinner,
|
||||||
|
Pagination,
|
||||||
|
} from "@nextui-org/react";
|
||||||
|
import { useTranslation } from "@/shared/lib/useTranslation";
|
||||||
|
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";
|
||||||
|
import ResourceGroupDetailModal from "../modal/ResourceGroupDetailModal";
|
||||||
|
|
||||||
|
// 组内服务类型定义
|
||||||
|
export interface ResourceGroup {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
join_at: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ResourceGroupProps {
|
||||||
|
deleteResourceGroup: (serviceById: string, resourceGroupId: string[]) => Promise<boolean>;
|
||||||
|
fetchMCPResourceGroups: (id: string, page: number, page_size: number, keyword: string) => Promise<GetMCPResourceGroupsParams>;
|
||||||
|
addServiceToGroup: (groupId: string, serverIds: string[]) => Promise<boolean>;
|
||||||
|
formData: MCPServiceFormData;
|
||||||
|
}
|
||||||
|
|
||||||
|
const ResourceGroup: React.FC<ResourceGroupProps> = ({
|
||||||
|
deleteResourceGroup,
|
||||||
|
fetchMCPResourceGroups,
|
||||||
|
addServiceToGroup,
|
||||||
|
formData
|
||||||
|
}) => {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const [resourceGroups, setResourceGroups] = useState<ResourceGroup[]>([]);
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
const [pagination, setPagination] = useState({
|
||||||
|
page: 1,
|
||||||
|
pageSize: 10,
|
||||||
|
total: 0,
|
||||||
|
});
|
||||||
|
const resourceGroupsParams = useRef({
|
||||||
|
page: 1,
|
||||||
|
pageSize: 10,
|
||||||
|
keyword: "",
|
||||||
|
});
|
||||||
|
const [isDeleteResourceGroupModalOpen, setIsDeleteResourceGroupModalOpen] = useState(false);
|
||||||
|
const [resourceGroupToDelete, setResourceGroupToDelete] = useState<ResourceGroup | null>(null);
|
||||||
|
|
||||||
|
// 资源组详情模态框
|
||||||
|
const [isResourceGroupDetailModalOpen, setIsResourceGroupDetailModalOpen] = useState(false);
|
||||||
|
const [resourceGroupDetailId, setResourceGroupDetailId] = useState<string | null>(null);
|
||||||
|
// 添加 MCP 服务模态框
|
||||||
|
const [isAddMcpGroupModalOpen, setIsAddMcpGroupModalOpen] = useState(false);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加载资源组列表
|
||||||
|
*/
|
||||||
|
const loadResourceGroups = useCallback(async (
|
||||||
|
page: number = 1,
|
||||||
|
pageSize: number = 10,
|
||||||
|
keyword: string = ""
|
||||||
|
) => {
|
||||||
|
setLoading(true);
|
||||||
|
try {
|
||||||
|
const response = await fetchMCPResourceGroups(formData?.id || "", page, pageSize, keyword);
|
||||||
|
setResourceGroups(response.data);
|
||||||
|
setPagination({
|
||||||
|
page: response.page,
|
||||||
|
pageSize: response.page_size,
|
||||||
|
total: response.total,
|
||||||
|
});
|
||||||
|
// 保存当前的 pageSize 和 keyword 到 ref
|
||||||
|
resourceGroupsParams.current = {
|
||||||
|
page: response.page,
|
||||||
|
pageSize: response.page_size,
|
||||||
|
keyword
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
console.error(t("Failed to load group services"), error);
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
const success = await addServiceToGroup(formData?.id, serverIds);
|
||||||
|
if (success) {
|
||||||
|
setIsAddMcpGroupModalOpen(false);
|
||||||
|
await loadResourceGroups(1, resourceGroupsParams.current.pageSize, resourceGroupsParams.current.keyword);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* 确认删除资源组
|
||||||
|
*/
|
||||||
|
const handleConfirmDeleteResourceGroup = async () => {
|
||||||
|
const result = await deleteResourceGroup(formData?.id || "", [resourceGroupToDelete?.id || ""]);
|
||||||
|
if (result) {
|
||||||
|
loadResourceGroups(1, 10, "");
|
||||||
|
setIsDeleteResourceGroupModalOpen(false);
|
||||||
|
setResourceGroupToDelete(null);
|
||||||
|
toast.success(t("Resource group deleted successfully"));
|
||||||
|
} else {
|
||||||
|
setIsDeleteResourceGroupModalOpen(false);
|
||||||
|
setResourceGroupToDelete(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除资源组
|
||||||
|
* @param groupId 删除资源组
|
||||||
|
*/
|
||||||
|
const onRemoveResourceGroup = async (groupId: string) => {
|
||||||
|
const group = resourceGroups.find((group) => group.id === groupId);
|
||||||
|
if (group) {
|
||||||
|
setResourceGroupToDelete(group);
|
||||||
|
setIsDeleteResourceGroupModalOpen(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const onPageChange = (page: number) => {
|
||||||
|
const { pageSize, keyword } = resourceGroupsParams.current;
|
||||||
|
loadResourceGroups(page, pageSize, keyword);
|
||||||
|
}
|
||||||
|
|
||||||
|
const openResourceGroupPage = (group: ResourceGroup) => {
|
||||||
|
setResourceGroupDetailId(group.id);
|
||||||
|
setIsResourceGroupDetailModalOpen(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
loadResourceGroups(1, 10, "");
|
||||||
|
}, [loadResourceGroups]);
|
||||||
|
|
||||||
|
const pages = Math.ceil(pagination.total / pagination.pageSize);
|
||||||
|
const currentPage = Number(pagination.page);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div className="space-y-4">
|
||||||
|
<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 to Groups")}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex gap-2"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Table
|
||||||
|
aria-label="Group services table"
|
||||||
|
removeWrapper
|
||||||
|
classNames={{
|
||||||
|
wrapper: "min-h-[400px]",
|
||||||
|
}}
|
||||||
|
bottomContent={
|
||||||
|
pages > 1 ? (
|
||||||
|
<div className="flex w-full justify-center">
|
||||||
|
<Pagination
|
||||||
|
showControls
|
||||||
|
variant="light"
|
||||||
|
color="primary"
|
||||||
|
page={currentPage}
|
||||||
|
total={pages}
|
||||||
|
onChange={onPageChange}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
) : null
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<TableHeader>
|
||||||
|
<TableColumn>{t("Group Name")}</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
|
||||||
|
items={resourceGroups}
|
||||||
|
isLoading={loading}
|
||||||
|
loadingContent={<Spinner />}
|
||||||
|
emptyContent={t("No services in this group")}
|
||||||
|
>
|
||||||
|
{(group) => (
|
||||||
|
<TableRow key={group.id}>
|
||||||
|
<TableCell>
|
||||||
|
<span className="text-sm">{group.name}</span>
|
||||||
|
</TableCell>
|
||||||
|
<TableCell>
|
||||||
|
{formatDate(group.join_at)}
|
||||||
|
</TableCell>
|
||||||
|
<TableCell>
|
||||||
|
<div className="relative flex items-center gap-2">
|
||||||
|
<Tooltip
|
||||||
|
content={t("View Resource Group Detail")}
|
||||||
|
color="primary"
|
||||||
|
closeDelay={0}
|
||||||
|
disableAnimation
|
||||||
|
>
|
||||||
|
<Button
|
||||||
|
isIconOnly
|
||||||
|
size="sm"
|
||||||
|
variant="light"
|
||||||
|
color="primary"
|
||||||
|
onPress={() => openResourceGroupPage(group)}
|
||||||
|
>
|
||||||
|
<Eye className="w-4 h-4" />
|
||||||
|
</Button>
|
||||||
|
</Tooltip>
|
||||||
|
<Tooltip
|
||||||
|
content={t("Remove")}
|
||||||
|
color="danger"
|
||||||
|
closeDelay={0}
|
||||||
|
disableAnimation
|
||||||
|
>
|
||||||
|
<Button
|
||||||
|
isIconOnly
|
||||||
|
size="sm"
|
||||||
|
variant="light"
|
||||||
|
color="danger"
|
||||||
|
onPress={() => onRemoveResourceGroup(group.id)}
|
||||||
|
>
|
||||||
|
<Trash2 className="w-4 h-4" />
|
||||||
|
</Button>
|
||||||
|
</Tooltip>
|
||||||
|
</div>
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
)}
|
||||||
|
</TableBody>
|
||||||
|
</Table>
|
||||||
|
</div>
|
||||||
|
{/* 删除服务模态框 */}
|
||||||
|
<DeleteServerModal
|
||||||
|
isOpen={isDeleteResourceGroupModalOpen}
|
||||||
|
onClose={() => {
|
||||||
|
setIsDeleteResourceGroupModalOpen(false);
|
||||||
|
setResourceGroupToDelete(null);
|
||||||
|
}}
|
||||||
|
onConfirm={handleConfirmDeleteResourceGroup}
|
||||||
|
title={t("Confirm Remove")}
|
||||||
|
description={t(
|
||||||
|
'Are you sure you want to remove this "{{name}}" mcp server from "{{groupName}}" resource group?',
|
||||||
|
{
|
||||||
|
name: resourceGroupToDelete?.name || "",
|
||||||
|
groupName: formData?.name || "",
|
||||||
|
}
|
||||||
|
)}
|
||||||
|
alertDescription={t("Users associated with this resource group will not be able to call the removed MCP server")}
|
||||||
|
/>
|
||||||
|
<McpAddGroupModal
|
||||||
|
id={formData.id || ""}
|
||||||
|
isOpen={isAddMcpGroupModalOpen}
|
||||||
|
onClose={() => {
|
||||||
|
setIsAddMcpGroupModalOpen(false);
|
||||||
|
}}
|
||||||
|
onSaveMcpServer={handleSaveMcpServer}
|
||||||
|
/>
|
||||||
|
<ResourceGroupDetailModal
|
||||||
|
groupId={resourceGroupDetailId || ""}
|
||||||
|
isOpen={isResourceGroupDetailModalOpen}
|
||||||
|
onClose={() => {
|
||||||
|
setIsResourceGroupDetailModalOpen(false);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ResourceGroup
|
||||||
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import React from "react";
|
import React, { useState } from "react";
|
||||||
import {
|
import {
|
||||||
Table,
|
Table,
|
||||||
TableHeader,
|
TableHeader,
|
||||||
@@ -13,10 +13,14 @@ import {
|
|||||||
Tooltip,
|
Tooltip,
|
||||||
Pagination,
|
Pagination,
|
||||||
Spinner,
|
Spinner,
|
||||||
|
Dropdown,
|
||||||
|
DropdownTrigger,
|
||||||
|
DropdownMenu,
|
||||||
|
DropdownItem,
|
||||||
} from "@nextui-org/react";
|
} from "@nextui-org/react";
|
||||||
import { useTranslation } from "@/shared/lib/useTranslation";
|
import { useTranslation } from "@/shared/lib/useTranslation";
|
||||||
import { EnabledEnum, MCPService } from "@/shared/types/mcp-service";
|
import { EnabledEnum, MCPService } from "@/shared/types/mcp-service";
|
||||||
import { Trash2, PencilIcon } from "lucide-react";
|
import { Trash2, PencilIcon, Calendar, Filter } from "lucide-react";
|
||||||
import { Price } from "@/shared/components/marketplace/Price";
|
import { Price } from "@/shared/components/marketplace/Price";
|
||||||
import { MdOutlineUnpublished, MdOutlineCheckCircle } from "react-icons/md";
|
import { MdOutlineUnpublished, MdOutlineCheckCircle } from "react-icons/md";
|
||||||
import { withComponentInjection } from "@/shared/hooks/useComponentInjection";
|
import { withComponentInjection } from "@/shared/hooks/useComponentInjection";
|
||||||
@@ -33,6 +37,7 @@ interface ServiceTableProps {
|
|||||||
onDelete: (service: MCPService) => void;
|
onDelete: (service: MCPService) => void;
|
||||||
onToggleStatus: (serviceId: string) => void;
|
onToggleStatus: (serviceId: string) => void;
|
||||||
onPageChange: (page: number) => void;
|
onPageChange: (page: number) => void;
|
||||||
|
onStatusFilterChange?: (status: string) => void;
|
||||||
columns?: string[];
|
columns?: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,9 +49,11 @@ const BaseServiceTable: React.FC<ServiceTableProps> = ({
|
|||||||
onDelete,
|
onDelete,
|
||||||
onToggleStatus,
|
onToggleStatus,
|
||||||
onPageChange,
|
onPageChange,
|
||||||
|
onStatusFilterChange,
|
||||||
columns = ["name", "endpoints", "status", "pricing", "actions"],
|
columns = ["name", "endpoints", "status", "pricing", "actions"],
|
||||||
}) => {
|
}) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
const [selectedStatusFilter, setSelectedStatusFilter] = useState('all');
|
||||||
|
|
||||||
const pages = Math.ceil(pagination.total / pagination.pageSize);
|
const pages = Math.ceil(pagination.total / pagination.pageSize);
|
||||||
const currentPage = pagination.page;
|
const currentPage = pagination.page;
|
||||||
@@ -79,6 +86,22 @@ const BaseServiceTable: React.FC<ServiceTableProps> = ({
|
|||||||
[onToggleStatus]
|
[onToggleStatus]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// 处理状态筛选
|
||||||
|
const handleStatusFilterChange = React.useCallback((status: string) => {
|
||||||
|
setSelectedStatusFilter(status);
|
||||||
|
onStatusFilterChange?.(status);
|
||||||
|
}, [onStatusFilterChange]);
|
||||||
|
|
||||||
|
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) {
|
if (loading && services.length === 0) {
|
||||||
return (
|
return (
|
||||||
<div className="flex justify-center items-center h-64">
|
<div className="flex justify-center items-center h-64">
|
||||||
@@ -113,10 +136,45 @@ const BaseServiceTable: React.FC<ServiceTableProps> = ({
|
|||||||
<TableHeader>
|
<TableHeader>
|
||||||
<TableColumn>{t("Service Name")}</TableColumn>
|
<TableColumn>{t("Service Name")}</TableColumn>
|
||||||
<TableColumn>{t("API Endpoint")}</TableColumn>
|
<TableColumn>{t("API Endpoint")}</TableColumn>
|
||||||
<TableColumn>{t("Status")}</TableColumn>
|
<TableColumn>
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<span>{t("Status")}</span>
|
||||||
|
<Dropdown>
|
||||||
|
<DropdownTrigger>
|
||||||
|
<Button
|
||||||
|
isIconOnly
|
||||||
|
size="sm"
|
||||||
|
variant="light"
|
||||||
|
aria-label="Filter by status"
|
||||||
|
className="min-w-unit-6 w-6 h-6"
|
||||||
|
>
|
||||||
|
<Filter
|
||||||
|
className={`w-4 h-4 ${
|
||||||
|
selectedStatusFilter !== 'all' ? 'text-primary' : ''
|
||||||
|
}`}
|
||||||
|
/>
|
||||||
|
</Button>
|
||||||
|
</DropdownTrigger>
|
||||||
|
<DropdownMenu
|
||||||
|
aria-label="Status filter"
|
||||||
|
selectionMode="single"
|
||||||
|
selectedKeys={[selectedStatusFilter]}
|
||||||
|
onSelectionChange={(keys) => {
|
||||||
|
const selected = Array.from(keys)[0] as string;
|
||||||
|
handleStatusFilterChange(selected);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<DropdownItem key="all">{t('All')}</DropdownItem>
|
||||||
|
<DropdownItem key="1">{t('Published')}</DropdownItem>
|
||||||
|
<DropdownItem key="0">{t('Unpublished')}</DropdownItem>
|
||||||
|
</DropdownMenu>
|
||||||
|
</Dropdown>
|
||||||
|
</div>
|
||||||
|
</TableColumn>
|
||||||
<TableColumn hidden={!columns.includes("pricing")}>
|
<TableColumn hidden={!columns.includes("pricing")}>
|
||||||
{t("Pricing")}
|
{t("Pricing")}
|
||||||
</TableColumn>
|
</TableColumn>
|
||||||
|
<TableColumn>{t("Created_at")}</TableColumn>
|
||||||
<TableColumn className="w-20">{t("Actions")}</TableColumn>
|
<TableColumn className="w-20">{t("Actions")}</TableColumn>
|
||||||
</TableHeader>
|
</TableHeader>
|
||||||
<TableBody
|
<TableBody
|
||||||
@@ -153,6 +211,7 @@ const BaseServiceTable: React.FC<ServiceTableProps> = ({
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
|
<TableCell>{formatDate(service.created_at)}</TableCell>
|
||||||
<TableCell>
|
<TableCell>
|
||||||
<div className="relative flex items-center gap-2">
|
<div className="relative flex items-center gap-2">
|
||||||
<Tooltip content={t("Edit")} closeDelay={0} disableAnimation>
|
<Tooltip content={t("Edit")} closeDelay={0} disableAnimation>
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import {
|
|||||||
Alert,
|
Alert,
|
||||||
} from "@nextui-org/react";
|
} from "@nextui-org/react";
|
||||||
import { useTranslation } from "@/shared/lib/useTranslation";
|
import { useTranslation } from "@/shared/lib/useTranslation";
|
||||||
|
import { User } from "@/types/user";
|
||||||
|
|
||||||
interface DeleteConfirmModalProps {
|
interface DeleteConfirmModalProps {
|
||||||
isOpen: boolean;
|
isOpen: boolean;
|
||||||
@@ -23,6 +24,7 @@ interface DeleteConfirmModalProps {
|
|||||||
requireNameConfirmation?: boolean;
|
requireNameConfirmation?: boolean;
|
||||||
confirmationName?: string;
|
confirmationName?: string;
|
||||||
confirmationPlaceholder?: string;
|
confirmationPlaceholder?: string;
|
||||||
|
user?: User | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const DeleteConfirmModal: React.FC<DeleteConfirmModalProps> = ({
|
export const DeleteConfirmModal: React.FC<DeleteConfirmModalProps> = ({
|
||||||
@@ -35,6 +37,7 @@ export const DeleteConfirmModal: React.FC<DeleteConfirmModalProps> = ({
|
|||||||
requireNameConfirmation = false,
|
requireNameConfirmation = false,
|
||||||
confirmationName = "",
|
confirmationName = "",
|
||||||
confirmationPlaceholder,
|
confirmationPlaceholder,
|
||||||
|
user,
|
||||||
}) => {
|
}) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const [inputValue, setInputValue] = useState("");
|
const [inputValue, setInputValue] = useState("");
|
||||||
@@ -83,7 +86,16 @@ export const DeleteConfirmModal: React.FC<DeleteConfirmModalProps> = ({
|
|||||||
<div className="text-default-600">
|
<div className="text-default-600">
|
||||||
{description || defaultDescription}
|
{description || defaultDescription}
|
||||||
</div>
|
</div>
|
||||||
|
{user && (
|
||||||
|
<div className="mb-4 p-3 bg-gray-50 rounded-lg">
|
||||||
|
<p className="text-sm text-gray-600">
|
||||||
|
{t("User")}: {user.email}
|
||||||
|
</p>
|
||||||
|
<p className="text-sm text-gray-600">
|
||||||
|
{t("Current Balance")}: ${user.balance.toFixed(2)}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
{/* Warning message */}
|
{/* Warning message */}
|
||||||
<Alert title={t("This action cannot be undone.")} color="danger" />
|
<Alert title={t("This action cannot be undone.")} color="danger" />
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,143 @@
|
|||||||
|
import {
|
||||||
|
Button,
|
||||||
|
Modal,
|
||||||
|
ModalBody,
|
||||||
|
ModalContent,
|
||||||
|
ModalFooter,
|
||||||
|
ModalHeader,
|
||||||
|
Table,
|
||||||
|
TableHeader,
|
||||||
|
TableColumn,
|
||||||
|
TableBody,
|
||||||
|
TableRow,
|
||||||
|
TableCell,
|
||||||
|
Spinner,
|
||||||
|
} from "@nextui-org/react";
|
||||||
|
import { useState, useEffect, useCallback } from "react";
|
||||||
|
import { useTranslation } from "@/shared/lib/useTranslation";
|
||||||
|
import { fetchUnboundResourceGroups } from "@/services/mcpService";
|
||||||
|
|
||||||
|
interface McpAddGroupModalProps {
|
||||||
|
isOpen: boolean;
|
||||||
|
onClose: () => void;
|
||||||
|
id: string;
|
||||||
|
onSaveMcpServer: (serverIds: string[]) => Promise<void>;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ResourceGroup {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const McpAddGroupModal: React.FC<McpAddGroupModalProps> = ({
|
||||||
|
isOpen,
|
||||||
|
onClose,
|
||||||
|
id,
|
||||||
|
onSaveMcpServer,
|
||||||
|
}) => {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
const [resourceGroups, setResourceGroups] = useState<ResourceGroup[]>([]);
|
||||||
|
const [selectedKeys, setSelectedKeys] = useState<Set<string>>(new Set());
|
||||||
|
|
||||||
|
// 加载服务列表
|
||||||
|
const loadServices = useCallback(async () => {
|
||||||
|
setLoading(true);
|
||||||
|
try {
|
||||||
|
const response = await fetchUnboundResourceGroups(id);
|
||||||
|
setResourceGroups(response);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Failed to load resource groups:", error);
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
// 当模态框打开时加载数据
|
||||||
|
useEffect(() => {
|
||||||
|
if (isOpen) {
|
||||||
|
setSelectedKeys(new Set());
|
||||||
|
loadServices();
|
||||||
|
}
|
||||||
|
}, [isOpen, loadServices]);
|
||||||
|
|
||||||
|
// 处理保存
|
||||||
|
const handleSave = async () => {
|
||||||
|
const serverIds = typeof selectedKeys === 'string' && selectedKeys === 'all' ? resourceGroups.map((group) => group.id) : Array.from(selectedKeys);
|
||||||
|
if (serverIds.length === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setIsLoading(true);
|
||||||
|
try {
|
||||||
|
await onSaveMcpServer(serverIds);
|
||||||
|
onClose();
|
||||||
|
} finally {
|
||||||
|
setIsLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Modal isOpen={isOpen} onClose={onClose} size="5xl" scrollBehavior="inside">
|
||||||
|
<ModalContent>
|
||||||
|
{() => (
|
||||||
|
<>
|
||||||
|
<ModalHeader className="flex flex-col gap-1">
|
||||||
|
{t("Add to Groups")}
|
||||||
|
</ModalHeader>
|
||||||
|
<ModalBody>
|
||||||
|
<Table
|
||||||
|
aria-label="Resource groups selection table"
|
||||||
|
selectionMode="multiple"
|
||||||
|
selectedKeys={selectedKeys}
|
||||||
|
onSelectionChange={(keys) => setSelectedKeys(keys as Set<string>)}
|
||||||
|
removeWrapper
|
||||||
|
classNames={{
|
||||||
|
wrapper: "min-h-[400px]",
|
||||||
|
}}
|
||||||
|
className="[&_td:first-child]:w-[30px] [&_th:first-child]:w-[30px]"
|
||||||
|
>
|
||||||
|
<TableHeader>
|
||||||
|
<TableColumn>{t("Group Name")}</TableColumn>
|
||||||
|
</TableHeader>
|
||||||
|
<TableBody
|
||||||
|
items={resourceGroups}
|
||||||
|
isLoading={loading}
|
||||||
|
loadingContent={<Spinner />}
|
||||||
|
emptyContent={t("No resource groups available")}
|
||||||
|
>
|
||||||
|
{(resourceGroup) => (
|
||||||
|
<TableRow key={resourceGroup.id}>
|
||||||
|
<TableCell>
|
||||||
|
<span className="text-sm">{resourceGroup.name}</span>
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
)}
|
||||||
|
</TableBody>
|
||||||
|
</Table>
|
||||||
|
</ModalBody>
|
||||||
|
<ModalFooter>
|
||||||
|
<Button
|
||||||
|
color="danger"
|
||||||
|
variant="light"
|
||||||
|
onPress={onClose}
|
||||||
|
isDisabled={isLoading}
|
||||||
|
>
|
||||||
|
{t("Close")}
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
color="primary"
|
||||||
|
onPress={handleSave}
|
||||||
|
isLoading={isLoading}
|
||||||
|
isDisabled={selectedKeys.size === 0}
|
||||||
|
>
|
||||||
|
{t("Add")}
|
||||||
|
</Button>
|
||||||
|
</ModalFooter>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</ModalContent>
|
||||||
|
</Modal>
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -33,6 +33,17 @@ export const RechargeModal: React.FC<RechargeModalProps> = ({
|
|||||||
paymentChannels[0]?.id || ""
|
paymentChannels[0]?.id || ""
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// payment channels arrive asynchronously -- fall back to the first one so the
|
||||||
|
// confirm button is not stuck disabled on a modal opened before they load.
|
||||||
|
const effectiveChannel = selectedPaymentChannel || paymentChannels[0]?.id || "";
|
||||||
|
const currencySymbol = effectiveChannel === "epay" ? "¥" : "¥";
|
||||||
|
|
||||||
|
const channelLabel = (id: string, name: string) => {
|
||||||
|
if (id === "epay") return t("Epay (Alipay / WeChat)");
|
||||||
|
if (id === "stripe") return name || t("Credit Card");
|
||||||
|
return name || id;
|
||||||
|
};
|
||||||
|
|
||||||
const [paymentId, setPaymentId] = useState("");
|
const [paymentId, setPaymentId] = useState("");
|
||||||
const [isConfirmOpen, setIsConfirmOpen] = useState(false);
|
const [isConfirmOpen, setIsConfirmOpen] = useState(false);
|
||||||
|
|
||||||
@@ -44,11 +55,11 @@ export const RechargeModal: React.FC<RechargeModalProps> = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (numAmount < 1) {
|
if (numAmount < 1) {
|
||||||
setError(t("Minimum recharge amount is $1"));
|
setError(t("Minimum recharge amount is ¥1"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!selectedPaymentChannel) {
|
if (!effectiveChannel) {
|
||||||
setError(t("Please select a payment method"));
|
setError(t("Please select a payment method"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -57,7 +68,9 @@ export const RechargeModal: React.FC<RechargeModalProps> = ({
|
|||||||
method: "POST",
|
method: "POST",
|
||||||
body: {
|
body: {
|
||||||
amount: numAmount,
|
amount: numAmount,
|
||||||
payment_channel: selectedPaymentChannel,
|
currency: effectiveChannel === "epay" ? "cny" : "usd",
|
||||||
|
// channel id doubles as the payment method the backend switches on
|
||||||
|
payment_method: effectiveChannel,
|
||||||
success_url: window.location.origin + "/pay_success",
|
success_url: window.location.origin + "/pay_success",
|
||||||
} as unknown as BodyInit,
|
} as unknown as BodyInit,
|
||||||
});
|
});
|
||||||
@@ -128,7 +141,9 @@ export const RechargeModal: React.FC<RechargeModalProps> = ({
|
|||||||
onChange={handleAmountChange}
|
onChange={handleAmountChange}
|
||||||
startContent={
|
startContent={
|
||||||
<div className="pointer-events-none flex items-center">
|
<div className="pointer-events-none flex items-center">
|
||||||
<span className="text-default-400 text-small">$</span>
|
<span className="text-default-400 text-small">
|
||||||
|
{currencySymbol}
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
type="text"
|
type="text"
|
||||||
@@ -144,15 +159,13 @@ export const RechargeModal: React.FC<RechargeModalProps> = ({
|
|||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
{/**coming soon : select payment channel*/}
|
{paymentChannels.length > 1 && (
|
||||||
|
|
||||||
{/* {paymentChannels.length > 0 && (
|
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<label className="text-sm font-medium text-default-700">
|
<label className="text-sm font-medium text-default-700">
|
||||||
{t("Payment Method")}
|
{t("Payment Method")}
|
||||||
</label>
|
</label>
|
||||||
<RadioGroup
|
<RadioGroup
|
||||||
value={selectedPaymentChannel}
|
value={effectiveChannel}
|
||||||
onValueChange={setSelectedPaymentChannel}
|
onValueChange={setSelectedPaymentChannel}
|
||||||
isInvalid={!!error && error.includes("payment method")}
|
isInvalid={!!error && error.includes("payment method")}
|
||||||
errorMessage={
|
errorMessage={
|
||||||
@@ -165,12 +178,20 @@ export const RechargeModal: React.FC<RechargeModalProps> = ({
|
|||||||
>
|
>
|
||||||
{paymentChannels.map((channel) => (
|
{paymentChannels.map((channel) => (
|
||||||
<Radio key={channel.id} value={channel.id}>
|
<Radio key={channel.id} value={channel.id}>
|
||||||
{channel.name}
|
{channelLabel(channel.id, channel.name)}
|
||||||
</Radio>
|
</Radio>
|
||||||
))}
|
))}
|
||||||
</RadioGroup>
|
</RadioGroup>
|
||||||
</div>
|
</div>
|
||||||
)} */}
|
)}
|
||||||
|
|
||||||
|
{effectiveChannel === "epay" && (
|
||||||
|
<p className="text-xs text-default-500">
|
||||||
|
{t(
|
||||||
|
"Billed in CNY via your epay gateway (Alipay / WeChat Pay), credited to your balance 1:1"
|
||||||
|
)}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
</ModalBody>
|
</ModalBody>
|
||||||
<ModalFooter>
|
<ModalFooter>
|
||||||
<Button variant="light" onPress={handleClose}>
|
<Button variant="light" onPress={handleClose}>
|
||||||
@@ -179,7 +200,7 @@ export const RechargeModal: React.FC<RechargeModalProps> = ({
|
|||||||
<Button
|
<Button
|
||||||
color="primary"
|
color="primary"
|
||||||
onPress={handlePurchase}
|
onPress={handlePurchase}
|
||||||
isDisabled={!selectedPaymentChannel || !amount}
|
isDisabled={!effectiveChannel || !amount}
|
||||||
>
|
>
|
||||||
{t("Confirm")}
|
{t("Confirm")}
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@@ -0,0 +1,205 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import React, { useCallback, useEffect, useRef, useState } from "react";
|
||||||
|
import {
|
||||||
|
Button,
|
||||||
|
Card,
|
||||||
|
Chip,
|
||||||
|
Table,
|
||||||
|
TableHeader,
|
||||||
|
TableColumn,
|
||||||
|
TableBody,
|
||||||
|
TableRow,
|
||||||
|
TableCell,
|
||||||
|
Tooltip,
|
||||||
|
Spinner,
|
||||||
|
Divider,
|
||||||
|
CardHeader,
|
||||||
|
CardBody,
|
||||||
|
Pagination,
|
||||||
|
ModalContent,
|
||||||
|
Modal,
|
||||||
|
ModalHeader,
|
||||||
|
ModalBody,
|
||||||
|
} from "@nextui-org/react";
|
||||||
|
import { useTranslation } from "@/shared/lib/useTranslation";
|
||||||
|
import { Plus, Trash2, Edit2 } from "lucide-react";
|
||||||
|
import { Price } from "@/shared/components/marketplace/Price";
|
||||||
|
import { ChargeType } from "@/shared/types/marketplace";
|
||||||
|
import { fetchGroupServices, fetchResourceGroupDetail, ResourceGroupDetailResponse } from "@/api/resourceGroup.api";
|
||||||
|
import { useSearchParams } from "next/navigation";
|
||||||
|
|
||||||
|
// 组内服务类型定义
|
||||||
|
export interface GroupService {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
base_url: string;
|
||||||
|
charge_type: ChargeType;
|
||||||
|
price: string;
|
||||||
|
enabled: boolean;
|
||||||
|
slug_name?: string;
|
||||||
|
input_token_price?: string;
|
||||||
|
output_token_price?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ResourceGroupDetailModalProps {
|
||||||
|
groupId?: string; // 可选,因为可能从 URL 获取
|
||||||
|
isOpen: boolean;
|
||||||
|
onClose: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
const ResourceGroupDetailModal: React.FC<ResourceGroupDetailModalProps> = ({
|
||||||
|
groupId,
|
||||||
|
isOpen,
|
||||||
|
onClose,
|
||||||
|
}) => {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
|
||||||
|
const [services, setServices] = useState<GroupService[]>([]);
|
||||||
|
const [serviceTablePagination, setServiceTablePagination] = useState({
|
||||||
|
page: 1,
|
||||||
|
pageSize: 10,
|
||||||
|
total: 0,
|
||||||
|
});
|
||||||
|
const serviceTableParams = useRef({
|
||||||
|
pageSize: 10,
|
||||||
|
keyword: ""
|
||||||
|
});
|
||||||
|
const [pages, setPages] = useState(0);
|
||||||
|
const [servicesLoading, setServicesLoading] = useState(false);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setPages(Math.ceil(serviceTablePagination.total / serviceTablePagination.pageSize));
|
||||||
|
}, [serviceTablePagination.total, serviceTablePagination.pageSize]);
|
||||||
|
|
||||||
|
// 加载指定组的服务列表(支持分页)
|
||||||
|
const loadGroupServices = useCallback(async (
|
||||||
|
groupId: string,
|
||||||
|
page: number = 1,
|
||||||
|
pageSize: number = 10,
|
||||||
|
keyword: string = ""
|
||||||
|
) => {
|
||||||
|
setServicesLoading(true);
|
||||||
|
try {
|
||||||
|
const response = await fetchGroupServices(groupId, page, pageSize, keyword);
|
||||||
|
setServices(response.data);
|
||||||
|
setServiceTablePagination({
|
||||||
|
page: response.page,
|
||||||
|
pageSize: response.page_size,
|
||||||
|
total: response.total,
|
||||||
|
});
|
||||||
|
// 保存当前的 pageSize 和 keyword 到 ref
|
||||||
|
serviceTableParams.current = {
|
||||||
|
pageSize: response.page_size,
|
||||||
|
keyword
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
console.error(t("Failed to load group services"), error);
|
||||||
|
} finally {
|
||||||
|
setServicesLoading(false);
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
// 服务列表翻页
|
||||||
|
const handleServicePageChange = async (page: number) => {
|
||||||
|
await loadGroupServices(
|
||||||
|
groupId || "",
|
||||||
|
page,
|
||||||
|
serviceTableParams.current.pageSize,
|
||||||
|
serviceTableParams.current.keyword
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (isOpen && groupId) {
|
||||||
|
loadGroupServices(groupId, 1, 10, "");
|
||||||
|
}
|
||||||
|
}, [isOpen, groupId, loadGroupServices]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Modal isOpen={isOpen} onClose={onClose} size="4xl">
|
||||||
|
<ModalContent>
|
||||||
|
{() => (
|
||||||
|
<>
|
||||||
|
<ModalHeader className="flex flex-col gap-1">
|
||||||
|
{t("Resource Group Detail")}
|
||||||
|
</ModalHeader>
|
||||||
|
<ModalBody>
|
||||||
|
<div className="space-y-4">
|
||||||
|
<Table
|
||||||
|
aria-label="Group services table"
|
||||||
|
removeWrapper
|
||||||
|
classNames={{
|
||||||
|
wrapper: "min-h-[400px]",
|
||||||
|
}}
|
||||||
|
bottomContent={
|
||||||
|
pages > 1 ? (
|
||||||
|
<div className="flex w-full justify-center">
|
||||||
|
<Pagination
|
||||||
|
showControls
|
||||||
|
variant="light"
|
||||||
|
color="primary"
|
||||||
|
page={serviceTablePagination.page}
|
||||||
|
total={pages}
|
||||||
|
onChange={(page) => handleServicePageChange(page)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
) : null
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<TableHeader>
|
||||||
|
<TableColumn>{t("Service Name")}</TableColumn>
|
||||||
|
<TableColumn>{t("API Endpoint")}</TableColumn>
|
||||||
|
<TableColumn>{t("Status")}</TableColumn>
|
||||||
|
<TableColumn>{t("Pricing")}</TableColumn>
|
||||||
|
</TableHeader>
|
||||||
|
<TableBody
|
||||||
|
items={services}
|
||||||
|
isLoading={servicesLoading}
|
||||||
|
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>
|
||||||
|
</TableRow>
|
||||||
|
)}
|
||||||
|
</TableBody>
|
||||||
|
</Table>
|
||||||
|
</div>
|
||||||
|
</ModalBody>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</ModalContent>
|
||||||
|
</Modal >
|
||||||
|
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ResourceGroupDetailModal;
|
||||||
|
|
||||||
@@ -14,7 +14,7 @@ import {
|
|||||||
export const _DefaultPlatformConfig: PlatformConfig = {
|
export const _DefaultPlatformConfig: PlatformConfig = {
|
||||||
name: "XPack",
|
name: "XPack",
|
||||||
logo: "/static/logo/logo.png",
|
logo: "/static/logo/logo.png",
|
||||||
currency: "USD",
|
currency: "CNY",
|
||||||
language: "en",
|
language: "en",
|
||||||
website_title: "Connect Your AI Agent to the Real World - XPack",
|
website_title: "Connect Your AI Agent to the Real World - XPack",
|
||||||
headline: "Connect Your AI Agent to the Real World",
|
headline: "Connect Your AI Agent to the Real World",
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ export interface User {
|
|||||||
user_email: string;
|
user_email: string;
|
||||||
user_name: string;
|
user_name: string;
|
||||||
avatar?: string;
|
avatar?: string;
|
||||||
|
allow_all?: boolean;
|
||||||
|
service_ids?: string[];
|
||||||
nick_name?: string;
|
nick_name?: string;
|
||||||
language: NavigatorLanguage | "en" | "zh-CN";
|
language: NavigatorLanguage | "en" | "zh-CN";
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -2,13 +2,16 @@ export enum TabKey {
|
|||||||
CONSOLE = "console",
|
CONSOLE = "console",
|
||||||
MCP_SERVICES = "mcp-services",
|
MCP_SERVICES = "mcp-services",
|
||||||
USER_MANAGEMENT = "user-management",
|
USER_MANAGEMENT = "user-management",
|
||||||
|
RESOURCE_GROUP = "resource-group",
|
||||||
REVENUE_MANAGEMENT = "revenue-management",
|
REVENUE_MANAGEMENT = "revenue-management",
|
||||||
|
SUBMISSIONS = "submissions",
|
||||||
PAYMENT_CHANNELS = "payment-channels",
|
PAYMENT_CHANNELS = "payment-channels",
|
||||||
LOGIN_SETTINGS = "login-settings",
|
LOGIN_SETTINGS = "login-settings",
|
||||||
SYSTEM_SETTINGS = "system-settings",
|
SYSTEM_SETTINGS = "system-settings",
|
||||||
OVERVIEW = "overview",
|
OVERVIEW = "overview",
|
||||||
WALLET = "wallet",
|
WALLET = "wallet",
|
||||||
ACCOUNT = "account",
|
ACCOUNT = "account",
|
||||||
|
USER_ACCOUNT = "user-account",
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface SidebarSubItem {
|
export interface SidebarSubItem {
|
||||||
|
|||||||
Loaded 100 of 200 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user