feat(console): 用户中心新增发布 MCP 服务入口与我的提交记录
- 侧边栏新增「发布 MCP 服务」入口(Rocket 图标)跳转 /submit,补 zh-CN 翻译键 - /submit 新增「我的提交记录」:登录后展示自己的提交列表(类型/时间/状态徽章/审核备注),提交成功自动刷新 - 修复登录判断:改读 zustand store 的 user_token(原读 localStorage['user_token'], 网页登录只写 zustand 不写该键,导致所有网页用户提交时误报「请先登录后再提交」) - 列表加载改为按接口返回判定登录态(token 失效自动清空记录)
This commit is contained in:
1 parent
b7a10ca678
commit
851d45a573
3 files changed
+121
-4
No files matched your search
@@ -968,5 +968,12 @@
|
||||
"Example 100": "如 100",
|
||||
"Enter a non-negative integer": "请输入非负整数",
|
||||
"Free call limit saved": "免费调用上限已保存",
|
||||
"Failed to save free call limit": "保存免费调用上限失败"
|
||||
"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": "已拒绝"
|
||||
}
|
||||
@@ -1,10 +1,35 @@
|
||||
"use client";
|
||||
import React, { useState } from "react";
|
||||
import React, { useEffect, useState } from "react";
|
||||
import { fetchAPI } from "@/shared/rpc/common-function";
|
||||
import { useSharedStore } from "@/shared/store/share";
|
||||
|
||||
type SubType = "mcp" | "skill" | "plugin";
|
||||
|
||||
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 服务",
|
||||
skill: "AI 技能",
|
||||
plugin: "AI 插件",
|
||||
};
|
||||
|
||||
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, setType] = useState<SubType>("mcp");
|
||||
const [name, setName] = useState("");
|
||||
const [desc, setDesc] = useState("");
|
||||
@@ -17,12 +42,38 @@ export default function SubmitPage() {
|
||||
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" && !localStorage.getItem("user_token")) {
|
||||
if (typeof window !== "undefined" && !user_token) {
|
||||
setMsg({ ok: false, text: "请先登录后再提交(右上角登录)" });
|
||||
return;
|
||||
}
|
||||
@@ -54,6 +105,7 @@ export default function SubmitPage() {
|
||||
if (data?.success) {
|
||||
setMsg({ ok: true, text: "提交成功,等待管理员审核。审核通过后将自动上架到市场。" });
|
||||
setName(""); setDesc(""); setFile(null); setBaseUrl(""); setTags("");
|
||||
loadSubs();
|
||||
} else {
|
||||
setMsg({ ok: false, text: data?.error_message || "提交失败,请稍后重试" });
|
||||
}
|
||||
@@ -168,6 +220,53 @@ export default function SubmitPage() {
|
||||
{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>
|
||||
);
|
||||
}
|
||||
@@ -12,7 +12,7 @@ import { formatCurrency } from "@/shared/utils/currency";
|
||||
import DashboardOverview from "@/components/dashboard/DashboardOverview";
|
||||
import WalletManagement from "@/components/wallet/WalletManagement";
|
||||
import UserAccountBalance from "@/components/dashboard/UserAccountBalance";
|
||||
import { Home, Key, Wallet } from "lucide-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 { useTranslation } from "@/shared/lib/useTranslation";
|
||||
@@ -92,9 +92,20 @@ const DashboardContent: React.FC = () => {
|
||||
label: "Dashboard",
|
||||
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) => {
|
||||
// 发布 MCP 服务:跳转到独立提交页
|
||||
if (tab === "publish-service") {
|
||||
router.push("/submit");
|
||||
return;
|
||||
}
|
||||
setActiveTab(tab as TabKey);
|
||||
// update url params
|
||||
if (tab === TabKey.OVERVIEW) {
|
||||
|
||||
Reference in new issue
Block a user