From ca2b73295258440a6631fa91e0da20fb19213fcc Mon Sep 17 00:00:00 2001 From: lethe Date: Thu, 24 Jul 2025 10:28:14 +0800 Subject: [PATCH] feat/0.2:add theme setting and about page setting and support use email and password login --- frontend/README.md | 2 +- frontend/README_zh.md | 2 +- frontend/docs/development.md | 2 +- frontend/next.config.js | 6 +- frontend/public/locales/en/config.json | 14 +- frontend/public/locales/en/translation.json | 57 ++- frontend/public/locales/zh-CN/config.json | 14 +- .../public/locales/zh-CN/translation.json | 57 ++- frontend/src/app/about/page.tsx | 13 + .../components/AdminLoginForm.tsx | 0 .../components/AdminSignIn.tsx | 0 .../src/app/{admin-signin => admin}/page.tsx | 36 +- frontend/src/app/globals.css | 3 + frontend/src/app/marketplace/[id]/page.tsx | 35 +- frontend/src/app/page.tsx | 27 +- .../app/signin/components/LoginEmailFrom.tsx | 40 +- .../components/LoginEmailPasswordForm.tsx | 114 +++++ frontend/src/app/signin/components/SignIn.tsx | 33 +- .../src/components/about/AboutContent.tsx | 42 ++ .../components/common/ChangePasswordModal.tsx | 159 +++++++ .../console/LoginSettingsContent.tsx | 106 +++++ frontend/src/components/console/Main.tsx | 356 ++++++++------- .../console/SystemSettingsContent.tsx | 74 ++-- frontend/src/components/dashboard/Main.tsx | 72 ++-- .../login-setting/EmailConfigForm.tsx | 210 +++++++++ .../login-setting/GoogleAuthConfigForm.tsx | 161 +++++++ .../system-setting/GoogleAuthConfigForm.tsx | 136 ------ .../system-setting/PlatformConfigForm.tsx | 407 +++++++++++++----- .../system-setting/ThemeCardPanel.css | 5 + .../system-setting/ThemeSelector.tsx | 111 +++++ .../components/theme/AboutThemeSelector.tsx | 43 ++ .../theme/ProductDetailThemeSelector.tsx | 87 ++++ frontend/src/components/theme/Theme.const.ts | 12 + .../src/components/theme/ThemeSelector.tsx | 200 +++++++++ .../src/components/theme/classic/About.tsx | 34 ++ .../src/components/theme/classic/Demo.tsx | 92 ++++ .../src/components/theme/classic/Detail.tsx | 259 +++++++++++ .../src/components/theme/classic/Footer.tsx | 32 ++ .../src/components/theme/classic/Home.tsx | 254 +++++++++++ .../components/theme/classic/Navigation.tsx | 55 +++ .../src/components/theme/creative/About.tsx | 41 ++ .../src/components/theme/creative/Demo.tsx | 69 +++ .../src/components/theme/creative/Detail.tsx | 191 ++++++++ .../src/components/theme/creative/Footer.tsx | 23 + .../src/components/theme/creative/Home.tsx | 323 ++++++++++++++ .../components/theme/creative/Navigation.tsx | 119 +++++ .../src/components/theme/default/Demo.tsx | 118 +++++ .../src/components/theme/modern/About.tsx | 43 ++ frontend/src/components/theme/modern/Demo.tsx | 59 +++ .../src/components/theme/modern/Detail.tsx | 188 ++++++++ .../src/components/theme/modern/Footer.tsx | 36 ++ frontend/src/components/theme/modern/Home.tsx | 239 ++++++++++ .../components/theme/modern/Navigation.tsx | 105 +++++ frontend/src/components/theme/temu/About.tsx | 27 ++ frontend/src/components/theme/temu/Demo.tsx | 103 +++++ frontend/src/components/theme/temu/Detail.tsx | 195 +++++++++ frontend/src/components/theme/temu/Footer.tsx | 68 +++ frontend/src/components/theme/temu/Home.tsx | 220 ++++++++++ .../src/components/theme/temu/Navigation.tsx | 113 +++++ .../user-management/UserManagement.tsx | 25 +- frontend/src/hooks/useAdminLogin.tsx | 4 +- frontend/src/hooks/useLogin.tsx | 64 ++- .../src/hooks/useSystemConfigManagement.ts | 124 ++++-- frontend/src/services/systemConfigService.ts | 57 ++- .../shared/components/ClientI18nProvider.tsx | 27 +- .../shared/components/ClientRootProviders.tsx | 5 +- .../shared/components/DashboardSidebar.tsx | 44 +- frontend/src/shared/components/Footer.tsx | 10 +- frontend/src/shared/components/Navigation.tsx | 26 +- .../components/marketplace/HeroSection.tsx | 44 +- .../shared/components/marketplace/Price.tsx | 70 +-- .../components/marketplace/ProductHeader.tsx | 26 +- .../marketplace/ProductOverview.tsx | 4 +- .../components/marketplace/ServiceCard.tsx | 4 +- .../shared/contexts/PlatformConfigContext.tsx | 44 +- frontend/src/shared/lib/i18n.ts | 33 +- frontend/src/shared/rpc/adapter.ts | 2 +- frontend/src/shared/store/global.ts | 9 + frontend/src/shared/types/dashboard.ts | 23 +- frontend/src/shared/types/system.ts | 36 +- frontend/src/shared/utils/crypto.ts | 35 ++ frontend/src/store/admin.ts | 9 + frontend/src/styles/themes.css | 235 ++++++++++ frontend/src/types/global.d.ts | 1 + frontend/src/types/system.ts | 10 +- 85 files changed, 5797 insertions(+), 816 deletions(-) create mode 100644 frontend/src/app/about/page.tsx rename frontend/src/app/{admin-signin => admin}/components/AdminLoginForm.tsx (100%) rename frontend/src/app/{admin-signin => admin}/components/AdminSignIn.tsx (100%) rename frontend/src/app/{admin-signin => admin}/page.tsx (52%) create mode 100644 frontend/src/app/signin/components/LoginEmailPasswordForm.tsx create mode 100644 frontend/src/components/about/AboutContent.tsx create mode 100644 frontend/src/components/common/ChangePasswordModal.tsx create mode 100644 frontend/src/components/console/LoginSettingsContent.tsx create mode 100644 frontend/src/components/login-setting/EmailConfigForm.tsx create mode 100644 frontend/src/components/login-setting/GoogleAuthConfigForm.tsx delete mode 100644 frontend/src/components/system-setting/GoogleAuthConfigForm.tsx create mode 100644 frontend/src/components/system-setting/ThemeCardPanel.css create mode 100644 frontend/src/components/system-setting/ThemeSelector.tsx create mode 100644 frontend/src/components/theme/AboutThemeSelector.tsx create mode 100644 frontend/src/components/theme/ProductDetailThemeSelector.tsx create mode 100644 frontend/src/components/theme/Theme.const.ts create mode 100644 frontend/src/components/theme/ThemeSelector.tsx create mode 100644 frontend/src/components/theme/classic/About.tsx create mode 100644 frontend/src/components/theme/classic/Demo.tsx create mode 100644 frontend/src/components/theme/classic/Detail.tsx create mode 100644 frontend/src/components/theme/classic/Footer.tsx create mode 100644 frontend/src/components/theme/classic/Home.tsx create mode 100644 frontend/src/components/theme/classic/Navigation.tsx create mode 100644 frontend/src/components/theme/creative/About.tsx create mode 100644 frontend/src/components/theme/creative/Demo.tsx create mode 100644 frontend/src/components/theme/creative/Detail.tsx create mode 100644 frontend/src/components/theme/creative/Footer.tsx create mode 100644 frontend/src/components/theme/creative/Home.tsx create mode 100644 frontend/src/components/theme/creative/Navigation.tsx create mode 100644 frontend/src/components/theme/default/Demo.tsx create mode 100644 frontend/src/components/theme/modern/About.tsx create mode 100644 frontend/src/components/theme/modern/Demo.tsx create mode 100644 frontend/src/components/theme/modern/Detail.tsx create mode 100644 frontend/src/components/theme/modern/Footer.tsx create mode 100644 frontend/src/components/theme/modern/Home.tsx create mode 100644 frontend/src/components/theme/modern/Navigation.tsx create mode 100644 frontend/src/components/theme/temu/About.tsx create mode 100644 frontend/src/components/theme/temu/Demo.tsx create mode 100644 frontend/src/components/theme/temu/Detail.tsx create mode 100644 frontend/src/components/theme/temu/Footer.tsx create mode 100644 frontend/src/components/theme/temu/Home.tsx create mode 100644 frontend/src/components/theme/temu/Navigation.tsx create mode 100644 frontend/src/styles/themes.css diff --git a/frontend/README.md b/frontend/README.md index 10f6a91..ab40a66 100644 --- a/frontend/README.md +++ b/frontend/README.md @@ -57,7 +57,7 @@ Create `.env.local` file in the project root and configure your backend service ```bash # Backend Service API URL Prefix -NEXT_PUBLIC_API_URL=http://127.0.0.1:8100 +NEXT_PUBLIC_API_URL=http://127.0.0.1:8001 ``` diff --git a/frontend/README_zh.md b/frontend/README_zh.md index a5c41eb..7736e24 100644 --- a/frontend/README_zh.md +++ b/frontend/README_zh.md @@ -59,7 +59,7 @@ pnpm dev ```bash # 后端服务 API URL 前缀 -NEXT_PUBLIC_API_URL=http://127.0.0.1:8100 +NEXT_PUBLIC_API_URL=http://127.0.0.1:8001 ``` diff --git a/frontend/docs/development.md b/frontend/docs/development.md index 65894bd..dafb550 100644 --- a/frontend/docs/development.md +++ b/frontend/docs/development.md @@ -30,7 +30,7 @@ ```env # Backend Service API URL Prefix - NEXT_PUBLIC_API_URL=http://127.0.0.1:8100 + NEXT_PUBLIC_API_URL=http://127.0.0.1:8001 ``` 3. **Start Development Server** diff --git a/frontend/next.config.js b/frontend/next.config.js index ad67eba..cda7e23 100644 --- a/frontend/next.config.js +++ b/frontend/next.config.js @@ -23,7 +23,11 @@ const nextConfig = { return [ { source: "/api/:path*", - destination: `${process.env.NEXT_PUBLIC_API_URL || "http://127.0.0.1:8100"}/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*`, }, ]; }, diff --git a/frontend/public/locales/en/config.json b/frontend/public/locales/en/config.json index 0967ef4..e400cb4 100644 --- a/frontend/public/locales/en/config.json +++ b/frontend/public/locales/en/config.json @@ -1 +1,13 @@ -{} +{ + "**XPack** is a lightweight, open-source marketplace framework for MCP (Model Context Protocol) services.": "**XPack** is a lightweight, open-source marketplace framework for MCP (Model Context Protocol) services.", + "It allows you to transform any OpenAPI into a monetizable MCP service and build your own API store in just minutes.": "It allows you to transform any OpenAPI into a monetizable MCP service and build your own API store in just minutes.", + "✨ With XPack, you can:": "✨ With XPack, you can:", + "- ✅ **One-click OpenAPI → MCP service config**": "- ✅ **One-click OpenAPI → MCP service config**", + "- 🧾 **SEO-friendly homepage + mcp service page**": "- 🧾 **SEO-friendly homepage + mcp service page**", + "- 💳 **Built-in billing (per-call)**": "- 💳 **Built-in billing (per-call)**", + "- 👥 **User account management**": "- 👥 **User account management**", + "- 🛠 **Support Stripe Payment**": "- 🛠 **Support Stripe Payment**", + "- 🔐 **Support Email & Google OAuth Sign in**": "- 🔐 **Support Email & Google OAuth Sign in**", + "Everything is open-source and licensed under **Apache 2.0** — ready for commercial use.": "Everything is open-source and licensed under **Apache 2.0** — ready for commercial use.", + "About Us": "About Us" +} \ No newline at end of file diff --git a/frontend/public/locales/en/translation.json b/frontend/public/locales/en/translation.json index 7dd6b31..27d58ea 100644 --- a/frontend/public/locales/en/translation.json +++ b/frontend/public/locales/en/translation.json @@ -139,10 +139,6 @@ "Number of MCP Tools": "Number of MCP Tools", "Time for integration": "Time for integration", "Daily MCP request count": "Daily MCP request count", - "10 Second": "10 Second", - "15 Categories": "15 Categories", - "1000+ Tools": "1000+ Tools", - "1 Million+": "1 Million+", "API Name": "API Name", "Description": "Description", "Integrate once,\nnot a thousand times.": "Integrate once,\nnot a thousand times.", @@ -680,5 +676,56 @@ "Secondary headline displayed below the main headline": "Secondary headline displayed below the main headline", "Platform Language": "Platform Language", "Select platform language": "Select platform language", - "Configure platform logo, name, titles, language": "Configure platform logo, name, titles, language" + "Platform Theme": "Platform Theme", + "Select platform theme": "Select platform theme", + "Choose the visual theme for homepage and marketplace templates": "Choose the visual theme for homepage and marketplace templates", + "Modern": "Modern", + "Classic": "Classic", + "Creative": "Creative", + "Clean and minimalist design with modern UI elements": "Clean and minimalist design with modern UI elements", + "Traditional layout with professional appearance": "Traditional layout with professional appearance", + "Bold and artistic design with vibrant colors": "Bold and artistic design with vibrant colors", + "Configure platform logo, name, titles, language": "Configure platform logo, name, titles, language", + "At least one login method must be enabled": "At least one login method must be enabled", + "About Page Content": "About Page Content", + "Configure about page content": "Configure about page content", + "Enter about page content (supports Markdown)": "Enter about page content (supports Markdown)", + "Theme": "Theme", + "Choose your preferred theme style": "Choose your preferred theme style", + "Default": "Default", + "Standard layout with clean and simple design": "Standard layout with clean and simple design", + "Temu": "Temu", + "E-commerce style with vibrant orange gradient background": "E-commerce style with vibrant orange gradient background", + "Login Settings": "Login Settings", + "Configure authentication methods": "Configure authentication methods", + "Email Login": "Email Login", + "Configure email-based authentication": "Configure email-based authentication", + "Enable Email Login": "Enable Email Login", + "Allow users to sign in with email": "Allow users to sign in with email", + "Authentication Mode": "Authentication Mode", + "Choose how users authenticate with email": "Choose how users authenticate with email", + "Email/Password": "Email/Password", + "Traditional email and password authentication": "Traditional email and password authentication", + "Email/Verification Code": "Email/Verification Code", + "Passwordless login with email verification code": "Passwordless login with email verification code", + "Email service is not configured. Please configure email settings first.": "Email service is not configured. Please configure email settings first.", + "Go to Settings": "Go to Settings", + "AI Tools Marketplace": "AI Tools Marketplace", + "A marketplace for AI tools and services. Discover and integrate powerful AI solutions for your projects.": "A marketplace for AI tools and services. Discover and integrate powerful AI solutions for your projects.", + "Configuration": "Configuration", + "Featured Products": "Featured Products", + "Search": "Search", + "Change Password": "Change Password", + "Enter new password": "Enter new password", + "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": "New password must be at least 8 characters long", + "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", + "Theme changed successfully": "Theme changed successfully", + "Failed to change theme": "Failed to change theme", + "About page saved successfully": "About page saved successfully", + "Failed to save about page": "Failed to save about page" } diff --git a/frontend/public/locales/zh-CN/config.json b/frontend/public/locales/zh-CN/config.json index 0967ef4..fafd6d8 100644 --- a/frontend/public/locales/zh-CN/config.json +++ b/frontend/public/locales/zh-CN/config.json @@ -1 +1,13 @@ -{} +{ + "**XPack** is a lightweight, open-source marketplace framework for MCP (Model Context Protocol) services.": "**XPack** 是一个轻量级的开源 MCP(模型上下文协议)服务市场框架。", + "It allows you to transform any OpenAPI into a monetizable MCP service and build your own API store in just minutes.": "它允许您将任何 OpenAPI 转换为可盈利的 MCP 服务,并在几分钟内构建您自己的 API 商店。", + "✨ With XPack, you can:": "✨ 使用 XPack,您可以:", + "- ✅ **One-click OpenAPI → MCP service config**": "- ✅ **一键 OpenAPI → MCP 服务配置**", + "- 🧾 **SEO-friendly homepage + mcp service page**": "- 🧾 **SEO 友好的主页 + MCP 服务页面**", + "- 💳 **Built-in billing (per-call)**": "- 💳 **内置计费(按调用计费)**", + "- 👥 **User account management**": "- 👥 **用户账户管理**", + "- 🛠 **Support Stripe Payment**": "- 🛠 **支持 Stripe 支付**", + "- 🔐 **Support Email & Google OAuth Sign in**": "- 🔐 **支持邮箱和 Google OAuth 登录**", + "Everything is open-source and licensed under **Apache 2.0** — ready for commercial use.": "一切都是开源的,采用 **Apache 2.0** 许可证 — 可用于商业用途。", + "About Us": "关于我们" +} \ No newline at end of file diff --git a/frontend/public/locales/zh-CN/translation.json b/frontend/public/locales/zh-CN/translation.json index 3469e3f..8cf41e9 100644 --- a/frontend/public/locales/zh-CN/translation.json +++ b/frontend/public/locales/zh-CN/translation.json @@ -139,10 +139,6 @@ "Number of MCP Tools": "MCP 工具数量", "Time for integration": "集成时间", "Daily MCP request count": "每日 MCP 请求数量", - "10 Second": "10 秒", - "15 Categories": "15 个分类", - "1000+ Tools": "1000+ 工具", - "1 Million+": "100 万+", "API Name": "API 名称", "Description": "描述", "Integrate once,\nnot a thousand times.": "集成一次,\n而不是千次。", @@ -682,5 +678,56 @@ "Secondary headline displayed below the main headline": "副标题显示在主标题下方", "Platform Language": "平台语言", "Select platform language": "选择平台语言", - "Configure platform logo, name, titles, language": "配置平台logo、名称、标题、语言" + "Platform Theme": "平台主题", + "Select platform theme": "选择平台主题", + "Choose the visual theme for homepage and marketplace templates": "选择首页和市场模板的视觉主题", + "Modern": "现代风格", + "Classic": "经典风格", + "Creative": "创意风格", + "Clean and minimalist design with modern UI elements": "简洁的极简设计,配有现代UI元素", + "Traditional layout with professional appearance": "传统布局,专业外观", + "Bold and artistic design with vibrant colors": "大胆的艺术设计,色彩鲜艳", + "Configure platform logo, name, titles, language": "配置平台logo、名称、标题、语言", + "At least one login method must be enabled": "至少需要启用一种登录方式", + "About Page Content": "关于页面内容", + "Configure about page content": "配置关于页面内容", + "Enter about page content (supports Markdown)": "输入关于页面内容(支持Markdown)", + "Theme": "主题", + "Choose your preferred theme style": "选择您喜欢的主题风格", + "Default": "默认", + "Standard layout with clean and simple design": "标准布局,简洁明了", + "Temu": "Temu", + "E-commerce style with vibrant orange gradient background": "电商风格,橙色渐变背景", + "Login Settings": "登录设置", + "Configure authentication methods": "配置认证方法", + "Email Login": "邮箱登录", + "Configure email-based authentication": "配置邮箱登录", + "Enable Email Login": "启用邮箱登录", + "Allow users to sign in with email": "允许用户使用邮箱登录", + "Authentication Mode": "认证模式", + "Choose how users authenticate with email": "选择用户认证方式", + "Email/Password": "邮箱/密码", + "Traditional email and password authentication": "传统邮箱和密码认证", + "Email/Verification Code": "邮箱/验证码", + "Passwordless login with email verification code": "邮箱验证码登录", + "Email service is not configured. Please configure email settings first.": "邮箱服务未配置。请先配置邮箱设置。", + "Go to Settings": "前往设置", + "AI Tools Marketplace": "AI工具市场", + "A marketplace for AI tools and services. Discover and integrate powerful AI solutions for your projects.": "一个AI工具和服务的市场。发现并整合强大的AI解决方案,为您的项目提供支持。", + "Configuration": "配置", + "Featured Products": "推荐产品", + "Search": "搜索", + "Change Password": "修改密码", + "Enter new password": "输入新密码", + "Re-enter new password": "重新输入新密码", + "Confirm new password": "确认新密码", + "New password and confirm password do not match": "新密码和确认密码不匹配", + "New password must be at least 8 characters long": "新密码至少需要8个字符", + "New password and confirm password must be the same": "新密码和确认密码必须相同", + "New Password": "新密码", + "Confirm New Password": "确认新密码", + "Theme changed successfully": "主题切换成功", + "Failed to change theme": "主题切换失败", + "About page saved successfully": "关于页面保存成功", + "Failed to save about page": "关于页面保存失败" } diff --git a/frontend/src/app/about/page.tsx b/frontend/src/app/about/page.tsx new file mode 100644 index 0000000..f4d4aae --- /dev/null +++ b/frontend/src/app/about/page.tsx @@ -0,0 +1,13 @@ +import React from "react"; +import type { Metadata } from "next"; +import { createBaseMetadata, getDynamicTitle } from "@/shared/utils/metadata"; +import { AboutThemeSelector } from "@/components/theme/AboutThemeSelector"; + +export async function generateMetadata(): Promise { + const title = await getDynamicTitle("About"); + return createBaseMetadata(title); +} + +export default async function AboutPage() { + return ; +} diff --git a/frontend/src/app/admin-signin/components/AdminLoginForm.tsx b/frontend/src/app/admin/components/AdminLoginForm.tsx similarity index 100% rename from frontend/src/app/admin-signin/components/AdminLoginForm.tsx rename to frontend/src/app/admin/components/AdminLoginForm.tsx diff --git a/frontend/src/app/admin-signin/components/AdminSignIn.tsx b/frontend/src/app/admin/components/AdminSignIn.tsx similarity index 100% rename from frontend/src/app/admin-signin/components/AdminSignIn.tsx rename to frontend/src/app/admin/components/AdminSignIn.tsx diff --git a/frontend/src/app/admin-signin/page.tsx b/frontend/src/app/admin/page.tsx similarity index 52% rename from frontend/src/app/admin-signin/page.tsx rename to frontend/src/app/admin/page.tsx index 14f2b01..47b6ec9 100644 --- a/frontend/src/app/admin-signin/page.tsx +++ b/frontend/src/app/admin/page.tsx @@ -1,30 +1,40 @@ "use client"; -import React, { Suspense } from "react"; +import React, { Suspense, useEffect } from "react"; import { Spinner } from "@nextui-org/react"; import { Toaster } from "react-hot-toast"; import AdminSignInComponent from "./components/AdminSignIn"; import { useTranslation } from "@/shared/lib/useTranslation"; import { DynamicLogo } from "@/shared/components/DynamicLogo"; +import { useRouter } from "next/navigation"; +import { useAdminStore } from "@/store/admin"; const AdminLoginHeader = () => { const { t } = useTranslation(); return (
- +

{t("Admin Portal")}

-

- {t("Log in to admin console")} -

+

{t("Log in to admin console")}

); }; const AdminLoginPageContent = () => { + const [getAdminUser] = useAdminStore((state) => [state.getAdminUser]); + const router = useRouter(); + + const handleCheckLogin = async () => { + const res = await getAdminUser(); + if (res.success) { + router.push("/console"); + } + }; + + useEffect(() => { + handleCheckLogin(); + }, []); return ( <>
@@ -38,10 +48,16 @@ const AdminLoginPageContent = () => { const AdminLoginPage = () => { return ( -
}> + + + + } + > ); }; -export default AdminLoginPage; \ No newline at end of file +export default AdminLoginPage; diff --git a/frontend/src/app/globals.css b/frontend/src/app/globals.css index 8e7c108..34b39c0 100644 --- a/frontend/src/app/globals.css +++ b/frontend/src/app/globals.css @@ -2,6 +2,9 @@ @tailwind components; @tailwind utilities; +/* Import theme styles */ +@import '../styles/themes.css'; + html, body { padding: 0; diff --git a/frontend/src/app/marketplace/[id]/page.tsx b/frontend/src/app/marketplace/[id]/page.tsx index c95e2b6..b1c602a 100644 --- a/frontend/src/app/marketplace/[id]/page.tsx +++ b/frontend/src/app/marketplace/[id]/page.tsx @@ -1,6 +1,6 @@ import React, { cache } from "react"; import { notFound } from "next/navigation"; -import { ProductDetailClient } from "@/shared/components/marketplace/ProductDetail"; +import { ProductDetailThemeSelector } from "@/components/theme/ProductDetailThemeSelector"; import type { Metadata } from "next"; import { createBaseMetadata, getDynamicTitle } from "@/shared/utils/metadata"; import { fetchServiceById } from "@/services/marketplaceService"; @@ -8,20 +8,21 @@ import type { ServiceData } from "@/shared/types/marketplace"; import { Footer } from "@/shared/components/Footer"; import { Navigation } from "@/shared/components/Navigation"; - interface ProductPageProps { params: Promise<{ id: string }>; } -const getProductById = cache(async (id: string): Promise => { - try { - const product = await fetchServiceById(id); - return product; - } catch (error) { - console.error(`Error fetching product ${id}:`, error); - return null; +const getProductById = cache( + async (id: string): Promise => { + try { + const product = await fetchServiceById(id); + return product; + } catch (error) { + console.error(`Error fetching product ${id}:`, error); + return null; + } } -}); +); // Generate metadata for SEO export async function generateMetadata({ @@ -36,7 +37,9 @@ export async function generateMetadata({ const title = await getDynamicTitle(product.name); return { ...createBaseMetadata(title), - description: product.short_description || `Discover ${product.name} and its powerful tools`, + description: + product.short_description || + `Discover ${product.name} and its powerful tools`, }; } @@ -55,13 +58,5 @@ export default async function ProductPage({ params }: ProductPageProps) { notFound(); } - return ( -
- -
- -
-
-
- ) + return ; } diff --git a/frontend/src/app/page.tsx b/frontend/src/app/page.tsx index 71899e6..bb01125 100644 --- a/frontend/src/app/page.tsx +++ b/frontend/src/app/page.tsx @@ -6,6 +6,7 @@ import { Navigation } from "@/shared/components/Navigation"; import { Footer } from "@/shared/components/Footer"; import { fetchServices } from "@/services/marketplaceService"; import type { ServiceData } from "@/shared/types/marketplace"; +import { ThemeSelector } from "@/components/theme/ThemeSelector"; export async function generateMetadata(): Promise { const title = await getDynamicTitle("Marketplace"); @@ -43,23 +44,13 @@ export default async function HomePage({ } return ( -
- -
- - - -
-
-
-
-
+ ); } diff --git a/frontend/src/app/signin/components/LoginEmailFrom.tsx b/frontend/src/app/signin/components/LoginEmailFrom.tsx index e2d553f..c400fc0 100644 --- a/frontend/src/app/signin/components/LoginEmailFrom.tsx +++ b/frontend/src/app/signin/components/LoginEmailFrom.tsx @@ -1,14 +1,17 @@ "use client"; import { Button, Input } from "@nextui-org/react"; -import { useForm } from "react-hook-form"; +import { useForm, Controller } from "react-hook-form"; import { zodResolver } from "@hookform/resolvers/zod"; import { z } from "zod"; import { StepState } from "../page"; import { useTranslation } from "@/shared/lib/useTranslation"; const emailSchema = z.object({ - email: z.string().email("Invalid email address"), + email: z + .string() + .email({ message: "Invalid email address" }) + .min(1, { message: "Email is required" }), }); type EmailFormData = z.infer; @@ -20,13 +23,14 @@ interface LoginEmailFromProps { export const LoginEmailFrom = ({ setEmail, setStep }: LoginEmailFromProps) => { const { t } = useTranslation(); - + const { - register, + control, handleSubmit, - formState: { errors, isSubmitting }, + formState: { errors, isSubmitting, isValid }, } = useForm({ resolver: zodResolver(emailSchema), + mode: "all", }); const onSubmit = async (data: EmailFormData) => { @@ -36,14 +40,22 @@ export const LoginEmailFrom = ({ setEmail, setStep }: LoginEmailFromProps) => { return (
- ( + + )} />
); -}; \ No newline at end of file +}; diff --git a/frontend/src/app/signin/components/LoginEmailPasswordForm.tsx b/frontend/src/app/signin/components/LoginEmailPasswordForm.tsx new file mode 100644 index 0000000..fb37fa3 --- /dev/null +++ b/frontend/src/app/signin/components/LoginEmailPasswordForm.tsx @@ -0,0 +1,114 @@ +"use client"; + +import { Button, Input } from "@nextui-org/react"; +import { useForm, Controller } from "react-hook-form"; +import { zodResolver } from "@hookform/resolvers/zod"; +import { z } from "zod"; +import { useState } from "react"; +import { Eye, EyeOff } from "lucide-react"; +import { useTranslation } from "@/shared/lib/useTranslation"; +import { useLogin } from "@/hooks/useLogin"; +import { md5Encrypt } from "@/shared/utils/crypto"; + +const emailPasswordSchema = z.object({ + email: z + .string() + .email({ message: "Invalid email address" }) + .min(1, { message: "Email is required" }), + password: z.string().min(6, "Password must be at least 6 characters"), +}); + +type EmailPasswordFormData = z.infer; + +interface LoginEmailPasswordFormProps { + onSuccess?: () => void; +} + +export const LoginEmailPasswordForm = ({ + onSuccess, +}: LoginEmailPasswordFormProps) => { + const { t } = useTranslation(); + const [showPassword, setShowPassword] = useState(false); + const { emailPasswordLogin } = useLogin(); + + const { + control, + handleSubmit, + formState: { errors, isSubmitting, isValid }, + } = useForm({ + resolver: zodResolver(emailPasswordSchema), + mode: "all", + }); + + const onSubmit = async (data: EmailPasswordFormData) => { + try { + await emailPasswordLogin({ + user_email: data.email, + password: md5Encrypt(data.password), + }); + onSuccess?.(); + } catch (error) { + console.error("Login failed:", error); + } + }; + + return ( +
+ ( + + )} + /> + ( + setShowPassword(!showPassword)} + className="focus:outline-none" + > + {showPassword ? ( + + ) : ( + + )} + + } + /> + )} + /> + + + ); +}; diff --git a/frontend/src/app/signin/components/SignIn.tsx b/frontend/src/app/signin/components/SignIn.tsx index cf27805..8b43192 100644 --- a/frontend/src/app/signin/components/SignIn.tsx +++ b/frontend/src/app/signin/components/SignIn.tsx @@ -6,8 +6,10 @@ import { LoginButton } from "./LoginButton"; import { useLogin } from "@/hooks/useLogin"; import { EmailVerificationForm } from "./VerifyEmail"; import { LoginEmailFrom } from "./LoginEmailFrom"; +import { LoginEmailPasswordForm } from "./LoginEmailPasswordForm"; import { useTranslation } from "@/shared/lib/useTranslation"; import { usePlatformConfig } from "@/shared/contexts/PlatformConfigContext"; +import { EmailMode } from "@/shared/types/system"; export type StepState = "init" | "emailForm" | "verifyEmail"; @@ -16,10 +18,17 @@ const SignInComponent = () => { const [email, setEmail] = useState(""); const [step, setStep] = useState("init"); const { googleLoginOrSignUp } = useLogin(); - const { googleAuthConfig } = usePlatformConfig(); + const { loginConfig } = usePlatformConfig(); // 检查是否启用了 Google 登录 - const isGoogleLoginEnabled = googleAuthConfig?.is_enabled && googleAuthConfig?.client_id; + const isGoogleLoginEnabled = + loginConfig?.google?.is_enabled && loginConfig?.google?.client_id; + + // 检查是否启用了邮箱登录 + const isEmailEnabled = loginConfig?.email?.is_enabled ?? true; + + // 获取邮箱登录模式 + const emailMode = loginConfig?.email?.mode ?? EmailMode.PASSWORD; return ( <> @@ -34,8 +43,8 @@ const SignInComponent = () => { onClick={googleLoginOrSignUp} /> )} - {/* OR - 只有在启用 Google 登录时才显示分隔符 */} - {isGoogleLoginEnabled && ( + {/* OR - 只有在启用 Google 登录且有其他登录方式时才显示分隔符 */} + {isGoogleLoginEnabled && isEmailEnabled && (

{t("OR")}

@@ -43,8 +52,18 @@ const SignInComponent = () => {
)} {/* Login With Email */} - {step === "init" && ( - + {step === "init" && isEmailEnabled && ( +
+ {/* 邮箱/密码登录表单 */} + {emailMode === EmailMode.PASSWORD && ( + + )} + + {/* 邮箱/验证码登录表单 */} + {emailMode === EmailMode.CAPTCHA && ( + + )} +
)} {step !== "init" && isGoogleLoginEnabled && ( ); -} \ No newline at end of file +} diff --git a/frontend/src/components/about/AboutContent.tsx b/frontend/src/components/about/AboutContent.tsx new file mode 100644 index 0000000..02ba96a --- /dev/null +++ b/frontend/src/components/about/AboutContent.tsx @@ -0,0 +1,42 @@ +"use client"; + +import React from "react"; +import ReactMarkdown from "react-markdown"; +import { usePlatformConfig } from "@/shared/contexts/PlatformConfigContext"; +import { Card, CardBody } from "@nextui-org/react"; +import { useTranslation } from "@/shared/lib/useTranslation"; + +export const AboutContent: React.FC = () => { + const { platformConfig } = usePlatformConfig(); + const { t } = useTranslation(); + + return ( + + +

{t("About Us")}

+
+ {platformConfig.about_page ? ( + {platformConfig.about_page} + ) : ( + + {` +${t("**XPack** is a lightweight, open-source marketplace framework for MCP (Model Context Protocol) services.")} +${t("It allows you to transform any OpenAPI into a monetizable MCP service and build your own API store in just minutes.")} + + +${t("✨ With XPack, you can:")} +${t("- ✅ **One-click OpenAPI → MCP service config**")} +${t("- 🧾 **SEO-friendly homepage + mcp service page**")} +${t("- 💳 **Built-in billing (per-call)**")} +${t("- 👥 **User account management**")} +${t("- 🛠 **Support Stripe Payment**")} +${t("- 🔐 **Support Email & Google OAuth Sign in**")} + +${t("Everything is open-source and licensed under **Apache 2.0** — ready for commercial use.")}`} + + )} +
+
+
+ ); +}; diff --git a/frontend/src/components/common/ChangePasswordModal.tsx b/frontend/src/components/common/ChangePasswordModal.tsx new file mode 100644 index 0000000..cc8a4d9 --- /dev/null +++ b/frontend/src/components/common/ChangePasswordModal.tsx @@ -0,0 +1,159 @@ +"use client"; + +import React, { useState } from "react"; +import { + Modal, + ModalContent, + ModalHeader, + ModalBody, + ModalFooter, + Button, + Input, +} from "@nextui-org/react"; +import { Eye, EyeOff } from "lucide-react"; +import { useTranslation } from "react-i18next"; +import toast from "react-hot-toast"; +import { useGlobalStore } from "@/shared/store/global"; +import { useSharedStore } from "@/shared/store/share"; + +interface ChangePasswordModalProps { + isOpen: boolean; + onClose: () => void; +} + +export const ChangePasswordModal: React.FC = ({ + isOpen, + onClose, +}) => { + const { t } = useTranslation(); + const [newPassword, setNewPassword] = useState(""); + const [confirmPassword, setConfirmPassword] = useState(""); + const [showNewPassword, setShowNewPassword] = useState(false); + const [showConfirmPassword, setShowConfirmPassword] = useState(false); + const { changePassword } = useGlobalStore(); + const { setUserToken } = useSharedStore(); + + const handleClose = () => { + setNewPassword(""); + setConfirmPassword(""); + setShowNewPassword(false); + setShowConfirmPassword(false); + onClose(); + }; + + const handleSubmit = async () => { + // 验证表单 + if (!newPassword.trim()) { + toast.error(t("Please enter new password")); + return; + } + + if (newPassword.length < 8) { + toast.error(t("Password must be at least 8 characters long")); + return; + } + + if (newPassword !== confirmPassword) { + toast.error(t("New passwords do not match")); + return; + } + + const result = await changePassword(newPassword); + + if (result.success) { + toast.success(t("Password changed successfully")); + setUserToken(result.data.user_token || ""); + handleClose(); + return; + } + toast.error(result.error_message || t("Failed to change password")); + }; + + const isFormValid = + newPassword.trim() !== "" && + confirmPassword.trim() !== "" && + newPassword === confirmPassword && + newPassword.length >= 8; + + return ( + + + + {t("Change Password")} + + +
+ {/* New Password */} + setNewPassword(e.target.value)} + description={t("Password must be at least 8 characters long")} + endContent={ + + } + isRequired + /> + + {/* Confirm New Password */} + setConfirmPassword(e.target.value)} + color={ + confirmPassword && newPassword !== confirmPassword + ? "danger" + : "default" + } + errorMessage={ + confirmPassword && newPassword !== confirmPassword + ? t("Passwords do not match") + : undefined + } + endContent={ + + } + isRequired + /> +
+
+ + + + +
+
+ ); +}; diff --git a/frontend/src/components/console/LoginSettingsContent.tsx b/frontend/src/components/console/LoginSettingsContent.tsx new file mode 100644 index 0000000..4e6ee4e --- /dev/null +++ b/frontend/src/components/console/LoginSettingsContent.tsx @@ -0,0 +1,106 @@ +"use client"; + +import React from "react"; +import { EmailConfigForm } from "@/components/login-setting/EmailConfigForm"; +import { GoogleAuthConfigForm } from "@/components/login-setting/GoogleAuthConfigForm"; +import { useSystemConfigManagement } from "@/hooks/useSystemConfigManagement"; +import { usePlatformConfig } from "@/shared/contexts/PlatformConfigContext"; +import { LoginConfig, GoogleAuthConfig } from "@/shared/types/system"; +import { TabKey } from "@/shared/types/dashboard"; +import { useTranslation } from "@/shared/lib/useTranslation"; +import { toast } from "react-hot-toast"; + +interface LoginSettingsContentProps { + onTabNavigate?: (tab: TabKey) => void; +} + +export const LoginSettingsContent: React.FC = ({ + onTabNavigate, +}) => { + const { t } = useTranslation(); + const { updateClientConfig } = usePlatformConfig(); + + const { + // login config + loginConfig, + loginLoading, + saveLoginConfig, + + // email config + emailConfig, + + // platform config + platformConfig, + } = useSystemConfigManagement(); + + // 验证至少有一种登录方式启用 + const validateLoginMethods = (config: LoginConfig): boolean => { + const isGoogleEnabled = + config.google?.is_enabled && config.google?.client_id; + const isEmailEnabled = config.email?.is_enabled; + + const enabledCount = [isGoogleEnabled, isEmailEnabled].filter( + Boolean + ).length; + + if (enabledCount === 0) { + toast.error(t("At least one login method must be enabled")); + return false; + } + + return true; + }; + + // save login config + const handleSaveLoginConfig = async (config: LoginConfig) => { + if (!validateLoginMethods(config)) { + return; + } + + const result = await saveLoginConfig(config); + if (!result) return; + updateClientConfig({ + platform: platformConfig, + login: config, + }); + }; + + // save google auth config + const handleSaveGoogleAuthConfig = async (config: GoogleAuthConfig) => { + const updatedLoginConfig = { + ...loginConfig, + google: config, + }; + + if (!validateLoginMethods(updatedLoginConfig)) { + return; + } + + const result = await saveLoginConfig(updatedLoginConfig); + if (!result) return; + updateClientConfig({ + platform: platformConfig, + login: updatedLoginConfig, + }); + }; + + return ( +
+ {/* email config */} + + + {/* google auth config */} + +
+ ); +}; diff --git a/frontend/src/components/console/Main.tsx b/frontend/src/components/console/Main.tsx index ec852fd..d8f4d4b 100644 --- a/frontend/src/components/console/Main.tsx +++ b/frontend/src/components/console/Main.tsx @@ -14,179 +14,219 @@ import { useAdminLogin } from "@/hooks/useAdminLogin"; import { MCPServicesManagement } from "@/components/mcp-services/MCPServicesManagement"; import UserManagement from "@/components/user-management/UserManagement"; import RevenueManagement from "@/components/revenue-management/RevenueManagement"; -import { Cog, CreditCard, DollarSign, Home, Settings, Users } from "lucide-react"; +import { + Cog, + CreditCard, + DollarSign, + Home, + Settings, + Users, + LogIn, +} from "lucide-react"; +import { LoginSettingsContent } from "@/components/console/LoginSettingsContent"; +import { Button } from "@nextui-org/react"; +import { FaDiscord } from "react-icons/fa"; const ConsoleContent: React.FC = () => { - const { t } = useTranslation(); - const router = useRouter(); - const searchParams = useSearchParams(); - const [admin_token] = useAdminStore((state) => [state.admin_token]); + const { t } = useTranslation(); + const router = useRouter(); + const searchParams = useSearchParams(); + const [admin_token] = useAdminStore((state) => [state.admin_token]); - const getInitialTab = (): TabKey => { - const tabFromUrl = searchParams.get("tab") as TabKey; - if ( - tabFromUrl && - [ - "mcp-services", - "user-management", - "revenue-management", - "payment-channels", - "system-settings", - ].includes(tabFromUrl) - ) { - return tabFromUrl; - } - return "console"; - }; + const getInitialTab = (): TabKey => { + const tabFromUrl = searchParams.get("tab") as TabKey; + if ( + tabFromUrl && + [ + "mcp-services", + "user-management", + "revenue-management", + "payment-channels", + "login-settings", + "system-settings", + ].includes(tabFromUrl) + ) { + return tabFromUrl; + } + return TabKey.CONSOLE; + }; - const [activeTab, setActiveTab] = useState(getInitialTab); - const sidebarItems: SidebarItem[] = [ - { - key: "console", - icon: , - label: t("Dashboard"), - description: t("Overview and analytics"), - }, - { - key: "mcp-services", - icon: , - label: t("MCP Services"), - description: t("Manage MCP services and API tools"), - }, - { - key: "user-management", - icon: , - label: t("User Management"), - description: t("Manage registered users"), - }, - { - key: "revenue-management", - icon: , - label: t("Revenue Management"), - description: t("View user recharge history"), - }, - { - key: "payment-channels", - icon: , - label: t("Payment Channels"), - description: t("Configure payment channels"), - }, - { - key: "system-settings", - icon: , - label: t("System Settings"), - description: t("Platform basic configuration"), - }, - ]; + const [activeTab, setActiveTab] = useState(getInitialTab); + const sidebarItems: SidebarItem[] = [ + { + key: TabKey.CONSOLE, + icon: , + label: t("Dashboard"), + description: t("Overview and analytics"), + }, + { + key: TabKey.MCP_SERVICES, + icon: , + label: t("MCP Services"), + description: t("Manage MCP services and API tools"), + }, + { + key: TabKey.USER_MANAGEMENT, + icon: , + label: t("User Management"), + description: t("Manage registered users"), + }, + { + key: TabKey.REVENUE_MANAGEMENT, + icon: , + label: t("Revenue Management"), + description: t("View user recharge history"), + }, + { + key: TabKey.PAYMENT_CHANNELS, + icon: , + label: t("Payment Channels"), + description: t("Configure payment channels"), + }, + { + key: TabKey.LOGIN_SETTINGS, + icon: , + label: t("Login Settings"), + description: t("Configure authentication methods"), + }, + { + key: TabKey.SYSTEM_SETTINGS, + icon: , + label: t("System Settings"), + description: t("Platform basic configuration"), + }, + ]; + // If admin is not logged in, redirect to admin login page + useEffect(() => { + if (!admin_token) { + router.push("/admin"); + } + }, [admin_token, router]); - // If admin is not logged in, redirect to admin login page - useEffect(() => { - if (!admin_token) { - router.push("/admin-signin"); - } - }, [admin_token, router]); + const handleTabNavigate = (tab: TabKey) => { + setActiveTab(tab); + // update url params + if (tab === TabKey.CONSOLE) { + // when switch to dashboard, clear all query params, only keep base path + router.push("/console", { scroll: false }); + } else { + // other tabs set corresponding tab params + const params = new URLSearchParams(); + params.set("tab", tab); + router.push(`/console?${params.toString()}`, { scroll: false }); + } + }; - const handleTabNavigate = (tab: TabKey) => { - setActiveTab(tab); - // update url params - if (tab === "console") { - // when switch to dashboard, clear all query params, only keep base path - router.push("/console", { scroll: false }); - } else { - // other tabs set corresponding tab params - const params = new URLSearchParams(); - params.set("tab", tab); - router.push(`/console?${params.toString()}`, { scroll: false }); - } - }; + const { adminLogout } = useAdminLogin(); - const { adminLogout } = useAdminLogin(); + const handleLogout = () => { + // use admin logout method + adminLogout(); + }; - const handleLogout = () => { - // use admin logout method - adminLogout(); - }; + // render different content based on activeTab + const renderContent = () => { + switch (activeTab) { + case TabKey.MCP_SERVICES: + return ; + case TabKey.USER_MANAGEMENT: + return ( +
+ +
+ ); + case TabKey.REVENUE_MANAGEMENT: + return ( +
+ +
+ ); + case TabKey.PAYMENT_CHANNELS: + return ( + + + + ); + case "login-settings": + return ( + + + + ); + case "system-settings": + return ( + + + + ); + default: + return ( + + + + ); + } + }; - // render different content based on activeTab - const renderContent = () => { - switch (activeTab) { - case "mcp-services": - return ; - case "user-management": - return ( -
- -
- ); - case "revenue-management": - return ( -
- -
- ); - case "payment-channels": - return ( - - - - ); - case "system-settings": - return ( - - - - ); - default: - return ( - - - - ); - } - }; + return ( +
+
+ {/* Sidebar */} + } + className="w-full justify-start h-auto p-3" + onPress={() => { + window.open("https://discord.gg/cyZfcdCXkW", "_blank"); + }} + > +
+ {t("Discord")} +
+ + } + /> - return ( -
-
- {/* Sidebar */} - - - {/* Main Content */} -
{renderContent()}
-
-
- ); + {/* Main Content */} +
{renderContent()}
+
+
+ ); }; const ConsoleMain: React.FC = () => { - const { t } = useTranslation(); + const { t } = useTranslation(); - return ( - - {t("Loading...")} - - } - > - - - ); + return ( + + {t("Loading...")} + + } + > + + + ); }; export default ConsoleMain; diff --git a/frontend/src/components/console/SystemSettingsContent.tsx b/frontend/src/components/console/SystemSettingsContent.tsx index bd3bee7..ac814bb 100644 --- a/frontend/src/components/console/SystemSettingsContent.tsx +++ b/frontend/src/components/console/SystemSettingsContent.tsx @@ -1,16 +1,17 @@ -'use client'; +"use client"; -import React from 'react'; -import { PlatformConfigForm } from '@/components/system-setting/PlatformConfigForm'; -import { AdminConfigForm } from '@/components/system-setting/AdminConfigForm'; -import { EmailConfigForm } from '@/components/system-setting/EmailConfigForm'; -import { GoogleAuthConfigForm } from '@/components/system-setting/GoogleAuthConfigForm'; -import { useSystemConfigManagement } from '@/hooks/useSystemConfigManagement'; -import { usePlatformConfig } from '@/shared/contexts/PlatformConfigContext'; -import i18n from '@/shared/lib/i18n'; +import React, { useState } from "react"; +import { PlatformConfigForm } from "@/components/system-setting/PlatformConfigForm"; +import { AdminConfigForm } from "@/components/system-setting/AdminConfigForm"; +import { EmailConfigForm } from "@/components/system-setting/EmailConfigForm"; +import { useSystemConfigManagement } from "@/hooks/useSystemConfigManagement"; +import { usePlatformConfig } from "@/shared/contexts/PlatformConfigContext"; +import { Theme } from "@/shared/types/system"; +import i18n from "@/shared/lib/i18n"; export const SystemSettingsContent: React.FC = () => { const { updateClientConfig } = usePlatformConfig(); + const [isAboutLoading, setIsAboutLoading] = useState(false); const { // platform config @@ -28,11 +29,8 @@ export const SystemSettingsContent: React.FC = () => { emailLoading, saveEmailConfig, - // google auth config - googleAuthConfig, - googleAuthLoading, - saveGoogleAuthConfig, - + // image upload + uploadImage, } = useSystemConfigManagement(); // save admin config @@ -45,22 +43,10 @@ export const SystemSettingsContent: React.FC = () => { await saveEmailConfig(config); }; - // save google auth config - const handleSaveGoogleAuthConfig = async (config: typeof googleAuthConfig) => { - const result = await saveGoogleAuthConfig(config); - if (!result) return - updateClientConfig({ - platform: platformConfig, - login: { - google: config, - }, - }); - }; - // save platform config const handleSavePlatformConfig = async (config: typeof platformConfig) => { const result = await savePlatformConfig(config); - if (!result) return + if (!result) return; updateClientConfig({ platform: config, }); @@ -69,6 +55,27 @@ export const SystemSettingsContent: React.FC = () => { } }; + // handle theme change + const handleThemeChange = async (theme: Theme) => { + const updatedConfig = { ...platformConfig, theme }; + const result = await savePlatformConfig(updatedConfig, "theme"); + if (!result) return; + updateClientConfig({ + platform: updatedConfig, + }); + }; + + // handle about save + const handleAboutSave = async (aboutContent: string) => { + setIsAboutLoading(true); + const updatedConfig = { ...platformConfig, about_page: aboutContent }; + const result = await savePlatformConfig(updatedConfig, "about"); + setIsAboutLoading(false); + if (!result) return; + updateClientConfig({ + platform: updatedConfig, + }); + }; return (
@@ -76,7 +83,11 @@ export const SystemSettingsContent: React.FC = () => { {/* admin config */} @@ -92,15 +103,8 @@ export const SystemSettingsContent: React.FC = () => { onSave={handleSaveEmailConfig} isLoading={emailLoading} /> - - {/* google auth config */} -
); }; -export default SystemSettingsContent; \ No newline at end of file +export default SystemSettingsContent; diff --git a/frontend/src/components/dashboard/Main.tsx b/frontend/src/components/dashboard/Main.tsx index 8c5c94c..42d30e9 100644 --- a/frontend/src/components/dashboard/Main.tsx +++ b/frontend/src/components/dashboard/Main.tsx @@ -6,22 +6,26 @@ import { useGlobalStore } from "@/shared/store/global"; import DashboardSidebar from "@/shared/components/DashboardSidebar"; import { SidebarItem, TabKey } from "@/shared/types/dashboard"; import { useSharedStore } from "@/shared/store/share"; -import { formatCurrency } from '@/shared/utils/currency'; +import { formatCurrency } from "@/shared/utils/currency"; // Import dashboard content components import DashboardOverview from "@/components/dashboard/DashboardOverview"; import WalletManagement from "@/components/wallet/WalletManagement"; -import { Home, Wallet } from "lucide-react"; +import { Home, Key, Wallet } from "lucide-react"; import { Avatar, Card, CardBody, Button, Divider } from "@nextui-org/react"; import { RechargeModal } from "@/shared/components/modal/RechargeModal"; import { useTranslation } from "@/shared/lib/useTranslation"; +import { ChangePasswordModal } from "@/components/common/ChangePasswordModal"; const DashboardContent: React.FC = () => { const { t } = useTranslation(); const router = useRouter(); const searchParams = useSearchParams(); - const [user_token, user] = useSharedStore((state) => [state.user_token, state.user]); + const [user_token, user] = useSharedStore((state) => [ + state.user_token, + state.user, + ]); const [logOut, useGetUser] = useGlobalStore((state) => [ state.logOut, @@ -33,20 +37,23 @@ const DashboardContent: React.FC = () => { const [isRechargeModalOpen, setIsRechargeModalOpen] = useState(false); const getInitialTab = (): TabKey => { const tabFromUrl = searchParams.get("tab") as TabKey; - if ( - tabFromUrl && - [ - "overview", - "wallet" - ].includes(tabFromUrl) - ) { + if (tabFromUrl && [TabKey.OVERVIEW, TabKey.WALLET].includes(tabFromUrl)) { return tabFromUrl; } - return "overview"; + return TabKey.OVERVIEW; }; const [activeTab, setActiveTab] = useState(getInitialTab); + const [isChangePasswordModalOpen, setIsChangePasswordModalOpen] = + React.useState(false); + const handleChangePassword = () => { + setIsChangePasswordModalOpen(true); + }; + + const handleChangePasswordClose = () => { + setIsChangePasswordModalOpen(false); + }; useEffect(() => { if (!data) return; if (data.code === "1000001") { @@ -55,8 +62,6 @@ const DashboardContent: React.FC = () => { } }, [data]); - - // If user is not logged in, redirect to login page useEffect(() => { if (!user_token) { @@ -64,7 +69,6 @@ const DashboardContent: React.FC = () => { } }, [user_token]); - const handleLogout = () => { // use global store logout method logOut(); @@ -78,24 +82,17 @@ const DashboardContent: React.FC = () => { const sidebarItems: SidebarItem[] = [ { - key: "overview", + key: TabKey.OVERVIEW, icon: , label: "Dashboard", description: "Manage your integration and auth key", }, - - // { - // key: "wallet", - // icon: , - // label: "My Wallet", - // description: "Manage your balance and recharge history", - // }, ]; const handleTabNavigate = (tab: TabKey) => { setActiveTab(tab); // update url params - if (tab === "overview") { + if (tab === TabKey.OVERVIEW) { // when switch to dashboard, clear all query params, only keep base path router.push("/dashboard", { scroll: false }); } else { @@ -115,6 +112,17 @@ const DashboardContent: React.FC = () => { onTabNavigate={handleTabNavigate} onLogout={handleLogout} sidebarItems={sidebarItems} + bottomPanel={ + + } userProfilePanel={ user && (
@@ -142,7 +150,11 @@ const DashboardContent: React.FC = () => {
- {t("Balance: {{amount}}", { amount: formatCurrency(user?.wallet?.balance || 0) })} + + {t("Balance: {{amount}}", { + amount: formatCurrency(user?.wallet?.balance || 0), + })} +
-
) } @@ -164,8 +175,8 @@ const DashboardContent: React.FC = () => { {/* Main Content */}
- {activeTab === "overview" && } - {activeTab === "wallet" && ( + {activeTab === TabKey.OVERVIEW && } + {activeTab === TabKey.WALLET && ( setIsRechargeModalOpen(true)} /> )}
@@ -176,6 +187,11 @@ const DashboardContent: React.FC = () => { isOpen={isRechargeModalOpen} onClose={() => setIsRechargeModalOpen(false)} /> + {/* Change Password Modal */} + ); }; @@ -194,4 +210,4 @@ const DashboardMain: React.FC = () => { ); }; -export default DashboardMain; \ No newline at end of file +export default DashboardMain; diff --git a/frontend/src/components/login-setting/EmailConfigForm.tsx b/frontend/src/components/login-setting/EmailConfigForm.tsx new file mode 100644 index 0000000..76d12ed --- /dev/null +++ b/frontend/src/components/login-setting/EmailConfigForm.tsx @@ -0,0 +1,210 @@ +"use client"; + +import React, { useEffect, useState } from "react"; +import { + Switch, + AccordionItem, + Accordion, + Select, + SelectItem, + Button, + Alert, + Link, +} from "@nextui-org/react"; +import { useTranslation } from "@/shared/lib/useTranslation"; +import { EmailMode, LoginConfig } from "@/shared/types/system"; +import { EmailConfig } from "@/types/system"; +import { TabKey } from "@/shared/types/dashboard"; + +interface EmailConfigFormProps { + config: LoginConfig; + emailConfig: EmailConfig; + onSave: (config: LoginConfig) => Promise; + isLoading?: boolean; + onTabNavigate?: (tab: TabKey) => void; +} + +export const EmailConfigForm: React.FC = ({ + config, + emailConfig, + onSave, + isLoading = false, + onTabNavigate, +}) => { + const { t } = useTranslation(); + const [formData, setFormData] = useState(config); + + useEffect(() => { + setFormData(config); + }, [config]); + + const handleToggleEnabled = async (enabled: boolean) => { + const updatedConfig = { + ...config, + email: { + ...config.email, + is_enabled: enabled, + mode: config.email?.mode || EmailMode.PASSWORD, + }, + }; + // when toggle the switch, save directly, same as GoogleAuthConfigForm + await onSave(updatedConfig); + }; + + const handleModeChange = (mode: EmailMode) => { + // no longer save directly, but update the local state + setFormData((prev) => ({ + ...prev, + email: { + ...prev.email, + is_enabled: prev.email?.is_enabled || false, + mode, + }, + })); + }; + + const handleSave = async () => { + await onSave(formData); + }; + + const isEmailConfigured = !!emailConfig?.smtp_host; + const isCaptchaMode = formData.email?.mode === EmailMode.CAPTCHA; + const isEmailEnabled = formData.email?.is_enabled || false; + + return ( + + +
+

{t("Email Login")}

+

+ {t("Configure email-based authentication")} +

+
+ + } + > +
+ {/* enable email login */} +
+
+ + {t("Enable Email Login")} + + + {t("Allow users to sign in with email")} + +
+ +
+ + {/* authentication mode selection */} +
+
+
+ + {t("Authentication Mode")} + + + {t("Choose how users authenticate with email")} + +
+ +
+
+ + {/* email configuration hint - only show in captcha mode */} + {isEmailEnabled && isCaptchaMode && !isEmailConfigured && ( + +
+ + {t( + "Email service is not configured. Please configure email settings first." + )} + + { + onTabNavigate?.(TabKey.SYSTEM_SETTINGS); + }} + > + {t("Go to Settings")} + +
+
+ )} + + {/* save button - only show in enabled state */} + {isEmailEnabled && ( +
+ +
+ )} +
+
+
+ ); +}; diff --git a/frontend/src/components/login-setting/GoogleAuthConfigForm.tsx b/frontend/src/components/login-setting/GoogleAuthConfigForm.tsx new file mode 100644 index 0000000..116f0d8 --- /dev/null +++ b/frontend/src/components/login-setting/GoogleAuthConfigForm.tsx @@ -0,0 +1,161 @@ +"use client"; + +import React, { useEffect, useState } from "react"; +import { + Input, + Button, + Switch, + AccordionItem, + Accordion, +} from "@nextui-org/react"; +import { Eye, EyeOff } from "lucide-react"; +import { useTranslation } from "@/shared/lib/useTranslation"; +import { getGoogleRedirectUri } from "@/hooks/useLogin"; +import { GoogleAuthConfig } from "@/shared/types/system"; + +interface GoogleAuthConfigFormProps { + config: GoogleAuthConfig; + onSave: (config: GoogleAuthConfig) => void; + isLoading?: boolean; +} + +export const GoogleAuthConfigForm: React.FC = ({ + config, + onSave, + isLoading = false, +}) => { + const { t } = useTranslation(); + const [formData, setFormData] = useState(config); + const [showClientSecret, setShowClientSecret] = useState(false); + useEffect(() => { + setFormData(config); + }, [config]); + const handleInputChange = ( + field: keyof GoogleAuthConfig, + value: string | boolean + ) => { + setFormData((prev) => ({ + ...prev, + [field]: value, + })); + }; + + const handleSave = () => { + onSave(formData); + }; + + const isFormValid = formData.client_id.trim() !== ""; + + return ( + + +

+ {t("Google Login Settings")} +

+

+ {t("Configure Google OAuth integration")} +

+ + } + > +
+ {/* enable google login */} +
+
+ + {t("Enable Google Login")} + + + {t("Allow users to sign in with Google")} + +
+ { + onSave({ + ...formData, + is_enabled: value, + }); + }} + color="primary" + size="sm" + /> +
+ + {/* Google Client ID */} + handleInputChange("client_id", e.target.value)} + isRequired + isDisabled={!formData.is_enabled} + /> + + {/* Google Client Secret */} + handleInputChange("client_secret", e.target.value)} + type={showClientSecret ? "text" : "password"} + endContent={ + + } + isDisabled={!formData.is_enabled} + /> + + {/* Redirect URI */} + +
+ + {/* Action Buttons */} + {formData.is_enabled && ( +
+ +
+ )} +
+
+ ); +}; diff --git a/frontend/src/components/system-setting/GoogleAuthConfigForm.tsx b/frontend/src/components/system-setting/GoogleAuthConfigForm.tsx deleted file mode 100644 index 6f29f5b..0000000 --- a/frontend/src/components/system-setting/GoogleAuthConfigForm.tsx +++ /dev/null @@ -1,136 +0,0 @@ -'use client'; - -import React, { useEffect, useState } from 'react'; -import { Input, Button, Switch, AccordionItem, Accordion } from '@nextui-org/react'; -import { Eye, EyeOff } from 'lucide-react'; -import { useTranslation } from "@/shared/lib/useTranslation"; -import { getGoogleRedirectUri } from '@/hooks/useLogin'; -import { GoogleAuthConfig } from '@/shared/types/system'; - -interface GoogleAuthConfigFormProps { - config: GoogleAuthConfig; - onSave: (config: GoogleAuthConfig) => void; - isLoading?: boolean; -} - -export const GoogleAuthConfigForm: React.FC = ({ - config, - onSave, - isLoading = false, -}) => { - const { t } = useTranslation(); - const [formData, setFormData] = useState(config); - const [showClientSecret, setShowClientSecret] = useState(false); - useEffect(() => { - setFormData(config); - }, [config]); - const handleInputChange = (field: keyof GoogleAuthConfig, value: string | boolean) => { - setFormData(prev => ({ - ...prev, - [field]: value - })); - }; - - const handleSave = () => { - onSave(formData); - }; - - const isFormValid = formData.client_id.trim() !== ''; - - return ( - - -

{t('Google Login Settings')}

-

{t('Configure Google OAuth integration')}

- - }> -
- {/* enable google login */} -
-
- {t('Enable Google Login')} - {t('Allow users to sign in with Google')} -
- { - handleInputChange('is_enabled', value); - onSave({ - ...formData, - is_enabled: value - }); - }} - color="primary" - size='sm' - /> -
- - {/* Google Client ID */} - handleInputChange('client_id', e.target.value)} - isRequired - isDisabled={!formData.is_enabled} - /> - - {/* Google Client Secret */} - handleInputChange('client_secret', e.target.value)} - type={showClientSecret ? "text" : "password"} - endContent={ - - } - isDisabled={!formData.is_enabled} - /> - - {/* Redirect URI */} - - -
- - {/* Action Buttons */} - { - formData.is_enabled && ( -
- -
- ) - } -
-
- ); -}; \ No newline at end of file diff --git a/frontend/src/components/system-setting/PlatformConfigForm.tsx b/frontend/src/components/system-setting/PlatformConfigForm.tsx index 82d8527..8e2eef3 100644 --- a/frontend/src/components/system-setting/PlatformConfigForm.tsx +++ b/frontend/src/components/system-setting/PlatformConfigForm.tsx @@ -1,21 +1,41 @@ -'use client'; +"use client"; -import React, { useState, useEffect } from 'react'; -import { Input, Button, AccordionItem, Accordion, Select, SelectItem } from '@nextui-org/react'; -import { PlatformConfig } from '@/shared/types/system'; +import React, { useState, useEffect } from "react"; +import { calculateFileSha256 } from "@/shared/utils/crypto"; +import { + Input, + Button, + AccordionItem, + Accordion, + Select, + SelectItem, +} from "@nextui-org/react"; +import MDEditor, { commands } from "@uiw/react-md-editor"; +import { PlatformConfig, Theme } from "@/shared/types/system"; import { useTranslation } from "@/shared/lib/useTranslation"; -import { SUPPORTED_LANGUAGES } from '@/shared/lib/i18n'; +import { SUPPORTED_LANGUAGES } from "@/shared/lib/i18n"; +import { ThemeSelector } from "./ThemeSelector"; +import "@uiw/react-md-editor/markdown-editor.css"; +import "@uiw/react-markdown-preview/markdown.css"; interface PlatformConfigFormProps { config: PlatformConfig; onSave: (config: PlatformConfig) => void; + onThemeChange?: (theme: Theme) => Promise; + onAboutSave?: (aboutContent: string) => Promise; + onImageUpload?: (file: File, sha256?: string) => Promise; isLoading?: boolean; + isAboutLoading?: boolean; } export const PlatformConfigForm: React.FC = ({ config, onSave, + onThemeChange, + onAboutSave, + onImageUpload, isLoading = false, + isAboutLoading = false, }) => { const { t } = useTranslation(); const [formData, setFormData] = useState(config); @@ -26,9 +46,9 @@ export const PlatformConfigForm: React.FC = ({ }, [config]); const handleInputChange = (field: keyof PlatformConfig, value: string) => { - setFormData(prev => ({ + setFormData((prev) => ({ ...prev, - [field]: value + [field]: value, })); }; @@ -36,122 +56,277 @@ export const PlatformConfigForm: React.FC = ({ onSave(formData); }; - const isFormValid = formData.name.trim() !== '' && formData.currency?.trim() !== ''; + const handleThemeChange = async (theme: Theme) => { + handleInputChange("theme", theme); + onThemeChange?.(theme); + }; + + const handleAboutSave = async () => { + onAboutSave?.(formData.about_page || ""); + }; + + const handleImageUpload = async (file: File): Promise => { + try { + // 计算文件的 SHA256 哈希值 + const sha256 = await calculateFileSha256(file); + return await onImageUpload!(file, sha256); + } catch (error) { + console.error("Image upload failed:", error); + throw error; + } + }; return ( - - -

{t('Platform Information')}

-

{t('Configure platform logo, name, titles, language')}

- - }> -
- {/* platform name */} - handleInputChange('name', e.target.value)} - isRequired - /> +
+ {/* Platform Information Accordion */} + + +

+ {t("Platform Information")} +

+

+ {t("Configure platform logo, name, titles, and language")} +

+
+ } + > +
+ {/* platform name */} + handleInputChange("name", e.target.value)} + /> - {/* platform logo */} - handleInputChange('logo', e.target.value)} - /> + {/* platform logo */} + handleInputChange("logo", e.target.value)} + /> - {/* website title */} - handleInputChange('website_title', e.target.value)} - /> - - {/* homepage headline */} - handleInputChange('headline', e.target.value)} - /> - - {/* homepage subheadline */} - handleInputChange('subheadline', e.target.value)} - /> - - {/* platform language */} - + handleInputChange("website_title", e.target.value) } - }} - > - {SUPPORTED_LANGUAGES.map((language) => ( - - {language.label} - - ))} - + /> - {/* comming soon:currency unit */} - {/* handleInputChange("headline", e.target.value)} + /> + + {/* homepage subheadline */} + handleInputChange("subheadline", e.target.value)} + /> + + {/* platform language */} + +
+ + {/* Action Buttons */} +
+ +
+ + + + {/* About Page Accordion */} + + +

+ {t("About Page Content")} +

+

+ {t("Configure about page content")} +

+
+ } + > +
+ + handleInputChange("about_page", value || "") } - }} - isRequired - > - {getCurrencyOptions().map((currency) => ( - - {currency.label} - - ))} - */} -
+ preview="live" + hideToolbar={false} + visibleDragbar={false} + data-color-mode="light" + textareaProps={{ + placeholder: t("Enter about page content (supports Markdown)"), + style: { + fontSize: 14, + lineHeight: 1.6, + fontFamily: + 'ui-monospace, SFMono-Regular, "SF Mono", Monaco, Consolas, "Liberation Mono", "Courier New", monospace', + }, + }} + height={300} + commands={[ + // 默认命令 + commands.bold, + commands.italic, + commands.strikethrough, + commands.hr, + commands.title, + commands.divider, + commands.link, + commands.quote, + commands.code, + commands.codeBlock, + commands.comment, + commands.divider, + commands.unorderedListCommand, + commands.orderedListCommand, + commands.checkedListCommand, + commands.divider, + // 自定义图片上传命令 + { + name: "image-upload", + keyCommand: "image-upload", + buttonProps: { + "aria-label": "Upload image", + title: "Upload image", + }, + icon: ( + + + + ), + execute: (state, api) => { + const input = document.createElement("input"); + input.type = "file"; + input.accept = "image/*"; + input.onchange = async (e) => { + const file = (e.target as HTMLInputElement).files?.[0]; + if (file) { + try { + const dataUrl = await handleImageUpload(file); + const imageMarkdown = `![${file.name}](${window.location.origin}${dataUrl})`; + api.replaceSelection(imageMarkdown); + } catch (error) { + console.error("Image upload failed:", error); + } + } + }; + input.click(); + }, + }, + ]} + /> + - {/* Action Buttons */} -
- + {/* About Save Button */} +
+ +
+ + - -
-
-
+ {/* Theme Accordion */} + + +

{t("Theme")}

+

+ {t("Choose your preferred theme style")} +

+ + } + > +
+ +
+
+
+ ); -}; \ No newline at end of file +}; diff --git a/frontend/src/components/system-setting/ThemeCardPanel.css b/frontend/src/components/system-setting/ThemeCardPanel.css new file mode 100644 index 0000000..bf5f1cc --- /dev/null +++ b/frontend/src/components/system-setting/ThemeCardPanel.css @@ -0,0 +1,5 @@ +.xpack-theme-card-panel-grid { + display: grid; + grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); + max-width: 100%; +} diff --git a/frontend/src/components/system-setting/ThemeSelector.tsx b/frontend/src/components/system-setting/ThemeSelector.tsx new file mode 100644 index 0000000..801ab2a --- /dev/null +++ b/frontend/src/components/system-setting/ThemeSelector.tsx @@ -0,0 +1,111 @@ +"use client"; + +import React from "react"; +import { Card, CardBody, CardFooter } from "@nextui-org/react"; +import { Theme } from "@/shared/types/system"; +import DefaultDemo from "../theme/default/Demo"; +import ModernDemo from "../theme/modern/Demo"; +import ClassicDemo from "../theme/classic/Demo"; +import CreativeDemo from "../theme/creative/Demo"; +import TemuDemo from "../theme/temu/Demo"; +import "./ThemeCardPanel.css"; +import { useTranslation } from "react-i18next"; + +// Available theme options +export const THEME_OPTIONS = [ + { + value: Theme.DEFAULT, + label: "Default", + description: "Standard layout with clean and simple design", + component: DefaultDemo, + }, + { + value: Theme.MODERN, + label: "Modern", + description: "Clean and minimalist design with modern UI elements", + component: ModernDemo, + }, + { + value: Theme.CLASSIC, + label: "Classic", + description: "Traditional layout with professional appearance", + component: ClassicDemo, + }, + { + value: Theme.CREATIVE, + label: "Creative", + description: "Bold and artistic design with vibrant colors", + component: CreativeDemo, + }, + { + value: Theme.TEMU, + label: "Temu", + description: "E-commerce style with vibrant orange gradient background", + component: TemuDemo, + }, +] as const; + +interface ThemeSelectorProps { + value: Theme; + onChange: (theme: Theme) => void; +} + +export const ThemeSelector: React.FC = ({ + value, + onChange, +}) => { + const { t } = useTranslation(); + return ( +
+ {THEME_OPTIONS.map((theme) => { + const DemoComponent = theme.component; + const isSelected = value === theme.value; + return ( + onChange(theme.value)} + className={`transition-all duration-200 border-1 hover:border-blue-300 ${ + isSelected + ? "border-blue-200 ring-1 ring-blue-200" + : "border-gray-200" + }`} + shadow="none" + radius="lg" + > + + {/* Theme Preview */} +
+
+ +
+
+
+ + {/* Theme Info */} +
+
+

+ {t(theme.label)} +

+
+ {isSelected && ( +
+ )} +
+
+

{t(theme.description)}

+
+
+
+ ); + })} +
+ ); +}; diff --git a/frontend/src/components/theme/AboutThemeSelector.tsx b/frontend/src/components/theme/AboutThemeSelector.tsx new file mode 100644 index 0000000..15bccd6 --- /dev/null +++ b/frontend/src/components/theme/AboutThemeSelector.tsx @@ -0,0 +1,43 @@ +"use client"; + +import React from "react"; +import { usePlatformConfig } from "@/shared/contexts/PlatformConfigContext"; +import { Theme } from "@/shared/types/system"; +import { About as ModernAbout } from "@/components/theme/modern/About"; +import { About as ClassicAbout } from "@/components/theme/classic/About"; +import { About as CreativeAbout } from "@/components/theme/creative/About"; +import { About as TemuAbout } from "@/components/theme/temu/About"; +import { Navigation } from "@/shared/components/Navigation"; +import { Footer } from "@/shared/components/Footer"; +import { NavigationItems } from "@/components/theme/Theme.const"; +import { AboutContent } from "@/components/about/AboutContent"; + +export const AboutThemeSelector: React.FC = () => { + const { platformConfig } = usePlatformConfig(); + const currentTheme = platformConfig.theme || Theme.DEFAULT; + + // Render the About page based on the current theme + switch (currentTheme) { + case Theme.MODERN: + return ; + case Theme.CLASSIC: + return ; + case Theme.CREATIVE: + return ; + case Theme.TEMU: + return ; + case Theme.DEFAULT: + default: + return ( +
+ +
+ +
+
+
+
+
+ ); + } +}; diff --git a/frontend/src/components/theme/ProductDetailThemeSelector.tsx b/frontend/src/components/theme/ProductDetailThemeSelector.tsx new file mode 100644 index 0000000..f7bda2f --- /dev/null +++ b/frontend/src/components/theme/ProductDetailThemeSelector.tsx @@ -0,0 +1,87 @@ +"use client"; + +import React, { useEffect, useState } from "react"; +import { usePlatformConfig } from "@/shared/contexts/PlatformConfigContext"; +import { Theme } from "@/shared/types/system"; +import { Detail as ModernDetail } from "./modern/Detail"; +import { Detail as ClassicDetail } from "./classic/Detail"; +import { Detail as CreativeDetail } from "./creative/Detail"; +import { Detail as TemuDetail } from "./temu/Detail"; +import { ServiceData } from "@/shared/types/marketplace"; +import { ProductDetailClient } from "@/shared/components/marketplace/ProductDetail"; +import { Navigation } from "@/shared/components/Navigation"; +import { Footer } from "@/shared/components/Footer"; +import { NavigationItems } from "./Theme.const"; + +interface ProductDetailThemeSelectorProps { + product: ServiceData; + breadcrumbs?: { + link: string; + name: string; + }[]; +} + +export const ProductDetailThemeSelector: React.FC< + ProductDetailThemeSelectorProps +> = ({ product, breadcrumbs }) => { + const { platformConfig } = usePlatformConfig(); + const currentTheme = platformConfig.theme || Theme.DEFAULT; + const [url, setUrl] = useState(process.env.NEXT_PUBLIC_MCP_URL || ""); + useEffect(() => { + if (url || !product.slug_name) return; + setUrl(`${window.location.origin}/mcp/${product.slug_name}`); + }, [product.slug_name]); + + //Render the About page based on the current theme + switch (currentTheme) { + case Theme.MODERN: + return ( + + ); + case Theme.CLASSIC: + return ( + + ); + case Theme.CREATIVE: + return ( + + ); + case Theme.TEMU: + return ( + + ); + case Theme.DEFAULT: + default: + return ( +
+ +
+ +
+
+
+
+
+ ); + } +}; diff --git a/frontend/src/components/theme/Theme.const.ts b/frontend/src/components/theme/Theme.const.ts new file mode 100644 index 0000000..ef95f52 --- /dev/null +++ b/frontend/src/components/theme/Theme.const.ts @@ -0,0 +1,12 @@ +import { NavigationItem } from "@/shared/components/Navigation"; + +export const NavigationItems: NavigationItem[] = [ + { + label: "Home", + href: "/", + }, + { + label: "About", + href: "/about", + }, +]; diff --git a/frontend/src/components/theme/ThemeSelector.tsx b/frontend/src/components/theme/ThemeSelector.tsx new file mode 100644 index 0000000..829a8cc --- /dev/null +++ b/frontend/src/components/theme/ThemeSelector.tsx @@ -0,0 +1,200 @@ +"use client"; + +import React, { useState, useEffect } from "react"; +import { useRouter } from "next/navigation"; +import { usePlatformConfig } from "@/shared/contexts/PlatformConfigContext"; +import { Theme } from "@/shared/types/system"; +import { Home as ModernHome } from "./modern/Home"; +import { Home as ClassicHome } from "./classic/Home"; +import { Home as CreativeHome } from "./creative/Home"; +import { Home as TemuHome } from "./temu/Home"; +import { ServiceData } from "@/shared/types/marketplace"; +import { fetchServices } from "@/services/marketplaceService"; +import { Navigation } from "@/shared/components/Navigation"; +import { MarketplaceMain } from "../marketplace/Main"; +import { Footer } from "@/shared/components/Footer"; +import { NavigationItems } from "./Theme.const"; + +interface ThemeSelectorProps { + initialServices: ServiceData[]; + initialTotal: number; + initialPage: number; + initialSearch: string; + pageSize: number; + error: string | null; +} + +export const ThemeSelector: React.FC = ({ + initialServices, + initialTotal, + initialPage, + initialSearch, + pageSize, + error, +}) => { + const router = useRouter(); + const { platformConfig } = usePlatformConfig(); + const currentTheme = platformConfig.theme || Theme.DEFAULT; + + // state management for services, search query, pagination, and loading state + const [searchQuery, setSearchQuery] = useState(initialSearch); + const [services, setServices] = useState(initialServices); + const [currentPage, setCurrentPage] = useState(initialPage); + const [total, setTotal] = useState(initialTotal); + const [loading, setLoading] = useState(false); + + // search suggestion + const searchSuggestions = ["Search services..."]; + + // loading service data + const loadServices = async (page: number, search: string) => { + try { + setLoading(true); + const result = await fetchServices({ + page, + page_size: pageSize, + keyword: search, + }); + + setServices(result.data.services); + setTotal(result.page.total); + setCurrentPage(page); + } catch (error) { + console.error("Failed to load services:", error); + } finally { + setLoading(false); + } + }; + + // when search and page change,scrolling to the page top + useEffect(() => { + window.scrollTo({ top: 0, behavior: "smooth" }); + }, [currentPage, searchQuery]); + + // update url param + const updateURL = (page: number, search: string) => { + const params = new URLSearchParams(); + + if (page > 1) { + params.set("page", page.toString()); + } + + if (search.trim()) { + params.set("search", search.trim()); + } + + const queryString = params.toString(); + const newURL = queryString ? `?${queryString}` : window.location.pathname; + + router.push(newURL); + }; + + // page change handler + const handlePageChange = (page: number) => { + updateURL(page, searchQuery); + loadServices(page, searchQuery); + }; + + // search submit handler + const handleSearch = () => { + updateURL(1, searchQuery); + loadServices(1, searchQuery); + }; + + // search input change handler + const handleSearchChange = (value: string) => { + setSearchQuery(value); + }; + + // render the theme page based on the current theme + switch (currentTheme) { + case Theme.MODERN: + return ( + + ); + case Theme.CLASSIC: + return ( + + ); + case Theme.CREATIVE: + return ( + + ); + case Theme.TEMU: + return ( + + ); + case Theme.DEFAULT: + default: + return ( +
+ +
+ +
+
+
+
+
+ ); + } +}; diff --git a/frontend/src/components/theme/classic/About.tsx b/frontend/src/components/theme/classic/About.tsx new file mode 100644 index 0000000..5561320 --- /dev/null +++ b/frontend/src/components/theme/classic/About.tsx @@ -0,0 +1,34 @@ +"use client"; + +import React from "react"; +import { Card, CardBody } from "@nextui-org/react"; +import { AboutContent } from "@/components/about/AboutContent"; +import { Navigation } from "./Navigation"; +import { Footer } from "./Footer"; +import { NavigationItem } from "@/shared/components/Navigation"; + +interface AboutProps { + navItems?: NavigationItem[]; +} + +export const About: React.FC = ({ navItems = [] }) => { + return ( +
+
+ +
+ +
+
+ + + + + +
+
+ +
+
+ ); +}; diff --git a/frontend/src/components/theme/classic/Demo.tsx b/frontend/src/components/theme/classic/Demo.tsx new file mode 100644 index 0000000..70c2d3d --- /dev/null +++ b/frontend/src/components/theme/classic/Demo.tsx @@ -0,0 +1,92 @@ +import React from "react"; + +const ClassicDemo: React.FC = () => { + return ( +
+ {/* Header */} +
+
+
+
+ PLATFORM +
+
+
+
+
+
+
+
+ + {/* Navigation */} +
+
+
Home
+
Services
+
About
+
+
+ + {/* Hero Section */} +
+
+

+ Professional Platform +

+

+ Traditional & Reliable Business Solution +

+ + {/* CTA Button */} +
+ Learn More +
+
+
+ + {/* Content Section */} +
+
+ {/* Service Item */} +
+
+
+
+
+ Business Service +
+
+ Professional solutions for enterprise +
+
+
+
+ + {/* Service Item */} +
+
+
+
+
+ Consulting +
+
+ Expert guidance and support +
+
+
+
+
+
+ + {/* Footer */} +
+
+
© 2025 Platform
+
+
+
+ ); +}; + +export default ClassicDemo; diff --git a/frontend/src/components/theme/classic/Detail.tsx b/frontend/src/components/theme/classic/Detail.tsx new file mode 100644 index 0000000..e3aa7bf --- /dev/null +++ b/frontend/src/components/theme/classic/Detail.tsx @@ -0,0 +1,259 @@ +"use client"; + +import React, { useState } from "react"; +import { useTranslation } from "@/shared/lib/useTranslation"; +import { Tabs, Tab, Chip, Card, CardBody } from "@nextui-org/react"; +import { ServiceData } from "@/shared/types/marketplace"; +import { ProductOverview } from "@/shared/components/marketplace/ProductOverview"; +import { ProductNotFound } from "@/shared/components/marketplace/ProductNotFound"; +import { FileText, Wrench, Cog } from "lucide-react"; +import { Navigation } from "./Navigation"; +import { Footer } from "./Footer"; +import Link from "next/link"; +import { Price } from "@/shared/components/marketplace/Price"; +import { usePlatformConfig } from "@/shared/contexts/PlatformConfigContext"; +import { NavigationItem } from "@/shared/components/Navigation"; + +interface DetailProps { + product: ServiceData; + breadcrumbs?: { + link: string; + name: string; + }[]; + url?: string; + + // navigation items + navItems?: NavigationItem[]; +} + +export const Detail: React.FC = ({ + product, + breadcrumbs, + url, + navItems = [], +}) => { + const { t } = useTranslation(); + const [activeTab, setActiveTab] = useState("overview"); + const { platformConfig } = usePlatformConfig(); + + if (!product) { + return ; + } + + return ( +
+ +
+ {/* Classic Product Header */} +
+
+
+ + + {/* Breadcrumb */} + + + {/* Header with title and price */} +
+
+

+ {product.name} +

+ + {/* Tags */} + {product.tags && product.tags.length > 0 && ( +
+ {product.tags.map((tag, index) => ( + + {tag} + + ))} +
+ )} +

+ {product.short_description || + t("No description available")} +

+
+
+ + {/* Price section */} + {product.charge_type && ( +
+ {t("Price")}: + +
+ )} +
+
+
+
+
+ + {/* Main Content */} +
+
+ {/* Left side - Main content */} +
+ + + setActiveTab(key as string)} + variant="underlined" + color="primary" + className="px-6 pt-6" + classNames={{ + tabList: + "gap-6 w-full relative rounded-none p-0 border-b border-gray-200", + cursor: "w-full bg-red-600", + tab: "max-w-fit px-0 h-12", + tabContent: + "group-data-[selected=true]:text-red-600 font-semibold text-gray-700", + }} + > + + + {t("Overview")} +
+ } + > +
+ +
+ + + + {t("Tools")} + + {product.tools.length} + +
+ } + > +
+
+ {product.tools.length > 0 ? ( + product.tools.map((tool, index) => ( + + +

+ {tool.name} +

+

+ {tool.description || + t("No description available")} +

+
+
+ )) + ) : ( + + +

+ {t("No tools available in this service.")} +

+
+
+ )} +
+
+ + + + +
+ + {/* Right side - Server Config */} +
+ + +
+
+ +
+

+ {t("Configuration")} +

+
+ {/* Code Snippet */} + +
+ + {platformConfig?.name} MCP + +
+                        
+                          {`{
+  "mcpServers": {
+    "xpack-mcp-market": {
+      "type": "sse",
+      "autoApprove"":"all",
+      "url": "${url}?apikey=`}
+                          {`{Your-${platformConfig?.name}-API-Key}`}
+                          {`"
+    }
+  }
+}`}
+                        
+                      
+
+
+
+
+
+
+ + {/* SEO-friendly: Simple text content for search engines */} + +
+ +
+
+
+ + ); +}; diff --git a/frontend/src/components/theme/classic/Footer.tsx b/frontend/src/components/theme/classic/Footer.tsx new file mode 100644 index 0000000..6b5d45d --- /dev/null +++ b/frontend/src/components/theme/classic/Footer.tsx @@ -0,0 +1,32 @@ +"use client"; + +import React from "react"; +import { usePlatformConfig } from "@/shared/contexts/PlatformConfigContext"; +import Link from "next/link"; + +interface FooterProps {} + +export const Footer: React.FC = ({}) => { + const { platformConfig } = usePlatformConfig(); + return ( + <> + {/* Classic Footer */} +
+
+
+ + © 2025 {platformConfig?.name} + + + + Powered By XPack.AI + +
+
+
+ + ); +}; diff --git a/frontend/src/components/theme/classic/Home.tsx b/frontend/src/components/theme/classic/Home.tsx new file mode 100644 index 0000000..847cfd2 --- /dev/null +++ b/frontend/src/components/theme/classic/Home.tsx @@ -0,0 +1,254 @@ +"use client"; + +import React from "react"; +import { Spinner } from "@nextui-org/react"; +import { Search, Star, Grid, ArrowRight } from "lucide-react"; +import { + Input, + Button, + Pagination, + Card, + CardBody, + CardFooter, +} from "@nextui-org/react"; +import { useTranslation } from "react-i18next"; +import Link from "next/link"; +import { ServiceData } from "@/shared/types/marketplace"; +import { Price } from "@/shared/components/marketplace/Price"; +import { + _DefaultPlatformConfig, + usePlatformConfig, +} from "@/shared/contexts/PlatformConfigContext"; + +import { Footer } from "./Footer"; +import { Navigation } from "./Navigation"; +import { NavigationItem } from "@/shared/components/Navigation"; + +interface HomeProps { + // 状态 + searchQuery: string; + services: ServiceData[]; + currentPage: number; + total: number; + pageSize: number; + loading: boolean; + error: string | null; + + // 事件处理函数 + onSearchChange: (value: string) => void; + onSearch: () => void; + onPageChange: (page: number) => void; + + // 可选配置 + searchSuggestions?: string[]; + + // navigation items + navItems?: NavigationItem[]; +} + +export const Home: React.FC = ({ + searchQuery, + services, + currentPage, + total, + pageSize, + loading, + error, + onSearchChange, + onSearch, + onPageChange, + searchSuggestions = [], + navItems = [], +}) => { + const { platformConfig } = usePlatformConfig(); + const { t } = useTranslation(); + const totalPages = Math.ceil(total / pageSize); + + // 如果有错误,显示错误信息 + if (error) { + return ( +
+
+
+ Error: {error} +
+
+
+ ); + } + + return ( +
+ +
+ {/* Classic Hero Section */} +
+
+
+ {/* Classic Icon */} +
+
+ +
+
+ + {/* Classic Title */} +

+ {t( + platformConfig.headline || + _DefaultPlatformConfig.headline || + "" + )} +

+ + {/* Classic Subtitle */} +

+ {t( + platformConfig.subheadline || + _DefaultPlatformConfig.subheadline || + "" + )} +

+
+ + {/* Classic Search Bar */} +
+
+
+
+ 0 + ? t(searchSuggestions[0]) + : t("Search services...") + } + value={searchQuery} + onChange={(e) => onSearchChange(e.target.value)} + onKeyDown={(e) => e.key === "Enter" && onSearch()} + startContent={ + + } + className="w-full" + classNames={{ + input: + "text-lg text-gray-900 placeholder:text-gray-500", + inputWrapper: "h-14 shadow-none px-4 bg-white border-0", + }} + variant="flat" + radius="none" + /> +
+ +
+
+
+
+
+ + {/* Service List Section */} + {loading ? ( +
+
+ +
+
+ ) : ( +
+
+ {/* Services Grid */} +
+ {services.map((service) => ( + + + + {/* Header */} +
+
+
+ +
+
+

+ {service.name} +

+
+
+ +
+ + {/* Description */} +

+ {service.short_description || + t("No description available")} +

+
+ + {/* Footer */} + +
+ {/* Tools count */} +
+
+ + {t("{{count}} Tools", { + count: service.tools.length, + })} + +
+ + {/* Price */} +
+ +
+
+
+
+ + ))} +
+ + {/* Classic Pagination */} + {totalPages > 1 && ( +
+ +
+ )} +
+
+ )} +
+
+
+
+
+ ); +}; diff --git a/frontend/src/components/theme/classic/Navigation.tsx b/frontend/src/components/theme/classic/Navigation.tsx new file mode 100644 index 0000000..70df4a9 --- /dev/null +++ b/frontend/src/components/theme/classic/Navigation.tsx @@ -0,0 +1,55 @@ +"use client"; + +import React from "react"; +import { Button } from "@nextui-org/react"; +import { useTranslation } from "react-i18next"; + +import { DynamicLogo } from "@/shared/components/DynamicLogo"; +import { useAuth } from "@/shared/lib/useAuth"; +import Link from "next/link"; +import { NavigationItem } from "@/shared/components/Navigation"; + +interface NavigationProps { + items?: NavigationItem[]; +} + +export const Navigation: React.FC = ({ items }) => { + const { t } = useTranslation(); + const { handleLogin } = useAuth(); + + return ( +
+ {/* Classic Header */} +
+
+
+ +
+
+ +
+
+
+ + {/* Classic Navigation */} +
+
+
+ {items?.map((item) => ( + + {t(item.label)} + + ))} +
+
+
+
+ ); +}; diff --git a/frontend/src/components/theme/creative/About.tsx b/frontend/src/components/theme/creative/About.tsx new file mode 100644 index 0000000..d2744df --- /dev/null +++ b/frontend/src/components/theme/creative/About.tsx @@ -0,0 +1,41 @@ +"use client"; + +import React from "react"; +import { Card, CardBody } from "@nextui-org/react"; +import { AboutContent } from "@/components/about/AboutContent"; +import { Navigation } from "./Navigation"; +import { Footer } from "./Footer"; +import { NavigationItem } from "@/shared/components/Navigation"; + +interface AboutProps { + navItems?: NavigationItem[]; +} + +export const About: React.FC = ({ navItems = [] }) => { + return ( +
+ + +
+ {/* Creative background elements */} +
+
+
+
+
+ +
+ + + + + +
+
+ +
+
+
+
+ ); +}; diff --git a/frontend/src/components/theme/creative/Demo.tsx b/frontend/src/components/theme/creative/Demo.tsx new file mode 100644 index 0000000..40f5555 --- /dev/null +++ b/frontend/src/components/theme/creative/Demo.tsx @@ -0,0 +1,69 @@ +import React from 'react'; + +const CreativeDemo: React.FC = () => { + return ( +
+ {/* Header */} +
+
+
+
+ Creative +
+
+
+
+
+
+
+
+ + {/* Hero Section */} +
+
+

+ Creative Platform +

+

Bold & Artistic Design Experience

+
+ + {/* CTA Button */} +
+
+ Explore Now +
+
+
+ + {/* Feature Cards */} +
+
+
+
+
Creative Tools
+
Artistic Design
+
+
+
+
Innovation
+
Bold Ideas
+
+
+
+ + {/* Floating Elements */} +
+
+
+
+ + {/* Decorative Shapes */} +
+
+
+
+
+ ); +}; + +export default CreativeDemo; \ No newline at end of file diff --git a/frontend/src/components/theme/creative/Detail.tsx b/frontend/src/components/theme/creative/Detail.tsx new file mode 100644 index 0000000..2abd095 --- /dev/null +++ b/frontend/src/components/theme/creative/Detail.tsx @@ -0,0 +1,191 @@ +"use client"; + +import React, { useState } from "react"; +import { useTranslation } from "@/shared/lib/useTranslation"; +import { Tabs, Tab, Chip, Card, CardBody } from "@nextui-org/react"; +import { ServiceData } from "@/shared/types/marketplace"; +import { ProductHeader } from "@/shared/components/marketplace/ProductHeader"; +import { ProductOverview } from "@/shared/components/marketplace/ProductOverview"; +import { ProductTools } from "@/shared/components/marketplace/ProductTools"; +import { ProductNotFound } from "@/shared/components/marketplace/ProductNotFound"; +import { Sparkles, Zap, Settings2 } from "lucide-react"; +import { Navigation } from "./Navigation"; +import { Footer } from "./Footer"; +import { usePlatformConfig } from "@/shared/contexts/PlatformConfigContext"; +import { NavigationItem } from "@/shared/components/Navigation"; + +interface DetailProps { + product: ServiceData; + breadcrumbs?: { + link: string; + name: string; + }[]; + url?: string; + + // navigation items + navItems?: NavigationItem[]; +} + +export const Detail: React.FC = ({ + product, + breadcrumbs, + url, + navItems = [], +}) => { + const { t } = useTranslation(); + const [activeTab, setActiveTab] = useState("overview"); + const { platformConfig } = usePlatformConfig(); + + if (!product) { + return ; + } + + return ( +
+ + {/* Creative Background */} +
+ {/* Artistic decorative elements */} +
+
+
+
+ + {/* Additional artistic elements */} +
+
+
+ +
+ {/* Creative Product Header */} +
+
+
+ +
+
+
+ + {/* Main Content */} +
+
+ {/* Left side - Main content */} +
+ +
+ + setActiveTab(key as string)} + variant="underlined" + color="secondary" + className="px-6 pt-6" + classNames={{ + tabList: + "gap-6 w-full relative rounded-none p-0 border-b border-pink-200/50", + cursor: + "w-full bg-gradient-to-r from-pink-500 via-red-500 to-orange-500", + tab: "max-w-fit px-0 h-12", + tabContent: + "group-data-[selected=true]:text-pink-600 font-semibold", + }} + > + + + {t("Overview")} +
+ } + > +
+ +
+ + + + {t("Tools")} + + {product.tools.length} + +
+ } + > +
+ +
+ + + + +
+ + {/* Right side - Server Config */} +
+ +
+ +
+
+ +
+

+ {t("Configuration")} +

+
+ {/* Code Snippet */} + +
+ + {platformConfig?.name} MCP + +
+                        
+                          {`{
+  "mcpServers": {
+    "xpack-mcp-market": {
+      "type": "sse",
+      "autoApprove"":"all",
+      "url": "${url}?apikey=`}
+                          {`{Your-${platformConfig?.name}-API-Key}`}
+                          {`"
+    }
+  }
+}`}
+                        
+                      
+
+
+
+ +
+
+ + {/* SEO-friendly: Simple text content for search engines */} + +
+
+
+
+ ); +}; diff --git a/frontend/src/components/theme/creative/Footer.tsx b/frontend/src/components/theme/creative/Footer.tsx new file mode 100644 index 0000000..436639c --- /dev/null +++ b/frontend/src/components/theme/creative/Footer.tsx @@ -0,0 +1,23 @@ +"use client"; + +import React from "react"; +import { usePlatformConfig } from "@/shared/contexts/PlatformConfigContext"; + +interface FooterProps {} + +export const Footer: React.FC = ({}) => { + const { platformConfig } = usePlatformConfig(); + return ( + <> + {/* Creative Footer */} + + + ); +}; diff --git a/frontend/src/components/theme/creative/Home.tsx b/frontend/src/components/theme/creative/Home.tsx new file mode 100644 index 0000000..46bad2a --- /dev/null +++ b/frontend/src/components/theme/creative/Home.tsx @@ -0,0 +1,323 @@ +"use client"; + +import React from "react"; +import { Spinner } from "@nextui-org/react"; +import { Sparkles, Palette, SearchIcon } from "lucide-react"; +import { + Input, + Button, + Pagination, + Card, + CardBody, + CardFooter, +} from "@nextui-org/react"; +import { useTranslation } from "react-i18next"; +import Link from "next/link"; +import { ServiceData } from "@/shared/types/marketplace"; +import { Price } from "@/shared/components/marketplace/Price"; +import { + _DefaultPlatformConfig, + usePlatformConfig, +} from "@/shared/contexts/PlatformConfigContext"; + +import { Footer } from "./Footer"; +import { Navigation } from "./Navigation"; +import { NavigationItem } from "@/shared/components/Navigation"; + +interface HomeProps { + // 状态 + searchQuery: string; + services: ServiceData[]; + currentPage: number; + total: number; + pageSize: number; + loading: boolean; + error: string | null; + + // 事件处理函数 + onSearchChange: (value: string) => void; + onSearch: () => void; + onPageChange: (page: number) => void; + + // 可选配置 + searchSuggestions?: string[]; + + // navigation items + navItems?: NavigationItem[]; +} + +export const Home: React.FC = ({ + searchQuery, + services, + currentPage, + total, + pageSize, + loading, + onSearchChange, + onSearch, + onPageChange, + searchSuggestions = [], + navItems = [], +}) => { + const { platformConfig } = usePlatformConfig(); + const { t } = useTranslation(); + const totalPages = Math.ceil(total / pageSize); + + return ( +
+ + + {/* Creative Background decorative elements */} +
+ {/* 主要装饰圆圈 */} +
+
+ + {/* 小装饰圆圈 */} +
+
+
+
+ + {/* 微小装饰点 */} +
+
+
+
+ + {/* Creative Hero Section */} +
+
+
+ {/* Creative Icon */} +
+
+ +
+
+ + {/* Creative Title */} +

+ + {t( + platformConfig.headline || + _DefaultPlatformConfig.headline || + "" + )} + +

+ + {/* Creative Subtitle */} +

+ {t( + platformConfig.subheadline || + _DefaultPlatformConfig.subheadline || + "" + )} +

+
+ + {/* Creative Search Bar */} +
+
+ {/* Search container */} +
+
+
+ 0 + ? t(searchSuggestions[0]) + : t("✨ 发现神奇的服务...") + } + value={searchQuery} + onChange={(e) => onSearchChange(e.target.value)} + onKeyDown={(e) => e.key === "Enter" && onSearch()} + startContent={ +
+ +
+ } + className="w-full" + classNames={{ + input: + "text-lg text-gray-800 placeholder:text-gray-500 font-medium", + inputWrapper: + "h-16 shadow-none px-4 bg-transparent border-0", + }} + variant="flat" + /> +
+ +
+
+
+
+
+
+ + {/* Creative Service List Section */} + {loading ? ( +
+
+
+ + + ✨ 加载魔法中... + +
+
+
+ ) : ( +
+
+ {/* Creative Services Grid */} +
+ {services.map((service, index) => { + const gradientBorders = [ + "border-pink-200/50", + "border-orange-200/50", + "border-yellow-200/50", + "border-red-200/50", + "border-purple-200/50", + "border-blue-200/50", + ]; + const iconGradients = [ + "bg-gradient-to-r from-pink-500 via-red-500 to-orange-500", + "bg-gradient-to-r from-orange-400 to-yellow-400", + "bg-gradient-to-r from-yellow-400 to-pink-400", + "bg-gradient-to-r from-red-400 to-pink-500", + "bg-gradient-to-r from-purple-400 to-pink-400", + "bg-gradient-to-r from-blue-400 to-purple-400", + ]; + const iconRotations = [ + "transform rotate-12", + "transform -rotate-12", + "transform rotate-6", + "transform -rotate-6", + "transform rotate-12", + "transform -rotate-12", + ]; + + return ( + + + + {/* 创意图标 */} +
+ + {/* 服务标题 */} +
+ {service.name} +
+ + {/* 服务描述 */} +
+ {service.short_description || "探索精彩服务"} +
+ + {/* 装饰性元素 */} +
+
+ + {/* Footer */} + +
+ {/* Tools count */} +
+
+ + {t("{{count}} Tools", { + count: service.tools.length, + })} + +
+ + {/* Price */} +
+ +
+
+
+
+ + ); + })} +
+ + {/* Creative Pagination */} + {totalPages > 1 && ( +
+
+ +
+
+ )} +
+ + +
+ )} +
+
+ ); +}; diff --git a/frontend/src/components/theme/creative/Navigation.tsx b/frontend/src/components/theme/creative/Navigation.tsx new file mode 100644 index 0000000..f7a6f52 --- /dev/null +++ b/frontend/src/components/theme/creative/Navigation.tsx @@ -0,0 +1,119 @@ +"use client"; + +import React from "react"; +import { Button } from "@nextui-org/react"; +import { useTranslation } from "react-i18next"; +import Link from "next/link"; +import { useState } from "react"; +import { + Navbar, + NavbarContent, + NavbarMenuToggle, + NavbarMenu, + NavbarMenuItem, +} from "@nextui-org/react"; +import { ArrowRightIcon } from "lucide-react"; +import { DynamicLogo } from "@/shared/components/DynamicLogo"; +import { useAuth } from "@/shared/lib/useAuth"; +import { NavigationItem } from "@/shared/components/Navigation"; + +interface NavigationProps { + items?: NavigationItem[]; +} + +export const Navigation: React.FC = ({ items }) => { + const { t } = useTranslation(); + const { handleLogin } = useAuth(); + const [isMenuOpen, setIsMenuOpen] = useState(false); + + return ( + <> + {/* Creative Navigation */} + + + +
+ + + +
+
+ {items?.map((item) => ( + + {t(item.label)} + + ))} +
+
+ +
+ +
+
+ +
+
+ + + + + + {/* Floating Elements - Demo Style */} +
+
+
+
+ {/* Decorative Shapes - Demo Style */} +
+
+
+
+
+ + ); +}; diff --git a/frontend/src/components/theme/default/Demo.tsx b/frontend/src/components/theme/default/Demo.tsx new file mode 100644 index 0000000..b7b6165 --- /dev/null +++ b/frontend/src/components/theme/default/Demo.tsx @@ -0,0 +1,118 @@ +"use client"; + +import React from "react"; +import { Search } from "lucide-react"; + +const DefaultDemo: React.FC = () => { + return ( +
+ {/* Header */} +
+
+
+
+ M +
+ + MCP Store + +
+
+ Get Started +
+
+
+ + {/* Main Content */} +
+ {/* Hero Section */} +
+

+ Default Platform +

+

Clean & Simple Design

+ + {/* Search Bar */} +
+
+ + +
+
+
+ + {/* Services Grid */} +
+ {/* Service Card 1 */} +
+

测试1

+

xpack-opensource-1

+
+ + Beta + + Free +
+
+ + {/* Service Card 2 */} +
+

+ xpack-opensource +

+

xpack-opensource-1

+
+ + Beta + + $0.02 /Per Call +
+
+ + {/* Service Card 3 */} +
+

+ xpack-opensource +

+

xpack-opensource

+
+ + Beta + + $0.02 /Per Call +
+
+ + {/* Service Card 4 */} +
+

+ Pet Store API +

+

+ A comprehensive API for managing pet store... +

+
+ + Beta + + Free +
+
+
+
+ + {/* Footer */} +
+
+ © 2025 Platform +
+
+
+ ); +}; + +export default DefaultDemo; diff --git a/frontend/src/components/theme/modern/About.tsx b/frontend/src/components/theme/modern/About.tsx new file mode 100644 index 0000000..0e51633 --- /dev/null +++ b/frontend/src/components/theme/modern/About.tsx @@ -0,0 +1,43 @@ +"use client"; + +import React from "react"; +import { Card, CardBody } from "@nextui-org/react"; +import { AboutContent } from "@/components/about/AboutContent"; +import { Navigation } from "./Navigation"; +import { Footer } from "./Footer"; +import { NavigationItem } from "@/shared/components/Navigation"; + +interface AboutProps { + navItems?: NavigationItem[]; +} + +export const About: React.FC = ({ navItems = [] }) => { + return ( +
+ +
+ {/* Clean Background Pattern */} +
+
+
+ + {/* Main Content */} +
+
+ + + + + +
+
+
+
+
+ ); +}; diff --git a/frontend/src/components/theme/modern/Demo.tsx b/frontend/src/components/theme/modern/Demo.tsx new file mode 100644 index 0000000..fe9b8ea --- /dev/null +++ b/frontend/src/components/theme/modern/Demo.tsx @@ -0,0 +1,59 @@ +import React from 'react'; + +const ModernDemo: React.FC = () => { + return ( +
+ {/* Header */} +
+
+
+
+ Platform +
+
+
+
+
+
+
+
+ + {/* Hero Section */} +
+
+

Modern Platform

+

Clean & Minimalist Design

+
+ + {/* CTA Button */} +
+
+ Get Started +
+
+
+ + {/* Feature Cards */} +
+
+
+
+
Feature 1
+
Modern UI
+
+
+
+
Feature 2
+
Clean Design
+
+
+
+ + {/* Decorative Elements */} +
+
+
+ ); +}; + +export default ModernDemo; \ No newline at end of file diff --git a/frontend/src/components/theme/modern/Detail.tsx b/frontend/src/components/theme/modern/Detail.tsx new file mode 100644 index 0000000..13b1f33 --- /dev/null +++ b/frontend/src/components/theme/modern/Detail.tsx @@ -0,0 +1,188 @@ +"use client"; + +import React, { useState } from "react"; +import { useTranslation } from "@/shared/lib/useTranslation"; +import { Tabs, Tab, Chip, Card, CardBody } from "@nextui-org/react"; +import { ServiceData } from "@/shared/types/marketplace"; +import { ProductHeader } from "@/shared/components/marketplace/ProductHeader"; +import { ProductOverview } from "@/shared/components/marketplace/ProductOverview"; +import { ProductTools } from "@/shared/components/marketplace/ProductTools"; +import { ProductNotFound } from "@/shared/components/marketplace/ProductNotFound"; +import { Monitor, Code, Settings } from "lucide-react"; +import { Navigation } from "./Navigation"; +import { Footer } from "./Footer"; +import { usePlatformConfig } from "@/shared/contexts/PlatformConfigContext"; +import { NavigationItem } from "@/shared/components/Navigation"; + +interface DetailProps { + product: ServiceData; + breadcrumbs?: { + link: string; + name: string; + }[]; + url?: string; + + // navigation items + navItems?: NavigationItem[]; +} + +export const Detail: React.FC = ({ + product, + breadcrumbs, + url, + navItems = [], +}) => { + const { t } = useTranslation(); + const [activeTab, setActiveTab] = useState("overview"); + const { platformConfig } = usePlatformConfig(); + if (!product) { + return ; + } + + return ( +
+ +
+ {/* Clean Background */} +
+
+
+ +
+ {/* Modern Product Header */} +
+
+
+ +
+
+
+ + {/* Main Content */} +
+
+ {/* Left side - Main content */} +
+ + + setActiveTab(key as string)} + variant="underlined" + color="primary" + className="px-6 pt-6" + classNames={{ + tabList: + "gap-6 w-full relative rounded-none p-0 border-b border-gray-200", + cursor: "w-full bg-blue-600", + tab: "max-w-fit px-0 h-12", + tabContent: + "group-data-[selected=true]:text-blue-600 font-semibold text-gray-600", + }} + > + + + {t("Overview")} +
+ } + > +
+ +
+ + + + {t("Tools")} + + {product.tools.length} + +
+ } + > +
+ +
+ + + + +
+ + {/* Right side - Server Config */} +
+ + +
+
+ +
+

+ {t("Configuration")} +

+
+ {/* Code Snippet */} + +
+ + {platformConfig?.name} MCP + +
+                          
+                            {`{
+  "mcpServers": {
+    "xpack-mcp-market": {
+      "type": "sse",
+      "autoApprove"":"all",
+      "url": "${url}?apikey=`}
+                            {`{Your-${platformConfig?.name}-API-Key}`}
+                            {`"
+    }
+  }
+}`}
+                          
+                        
+
+
+
+
+
+
+ + {/* SEO-friendly: Simple text content for search engines */} + +
+
+
+
+
+
+
+ ); +}; diff --git a/frontend/src/components/theme/modern/Footer.tsx b/frontend/src/components/theme/modern/Footer.tsx new file mode 100644 index 0000000..36de844 --- /dev/null +++ b/frontend/src/components/theme/modern/Footer.tsx @@ -0,0 +1,36 @@ +"use client"; + +import { Sparkles } from "lucide-react"; +import React from "react"; +import { usePlatformConfig } from "@/shared/contexts/PlatformConfigContext"; + +interface FooterProps {} + +export const Footer: React.FC = ({}) => { + const { platformConfig } = usePlatformConfig(); + return ( + <> + {/* Modern Footer */} + + + ); +}; diff --git a/frontend/src/components/theme/modern/Home.tsx b/frontend/src/components/theme/modern/Home.tsx new file mode 100644 index 0000000..84741bf --- /dev/null +++ b/frontend/src/components/theme/modern/Home.tsx @@ -0,0 +1,239 @@ +"use client"; + +import React from "react"; +import { Spinner } from "@nextui-org/react"; +import { Search, Sparkles, Zap } from "lucide-react"; +import { + Input, + Button, + Pagination, + Card, + CardBody, + CardFooter, + Chip, +} from "@nextui-org/react"; +import { useTranslation } from "react-i18next"; +import Link from "next/link"; +import { ServiceData } from "@/shared/types/marketplace"; +import { Price } from "@/shared/components/marketplace/Price"; +import { ArrowRight } from "lucide-react"; +import { + _DefaultPlatformConfig, + usePlatformConfig, +} from "@/shared/contexts/PlatformConfigContext"; + +import { Navigation } from "./Navigation"; +import { Footer } from "./Footer"; +import { NavigationItem } from "@/shared/components/Navigation"; + +interface HomeProps { + // 状态 + searchQuery: string; + services: ServiceData[]; + currentPage: number; + total: number; + pageSize: number; + loading: boolean; + error: string | null; + + // 事件处理函数 + onSearchChange: (value: string) => void; + onSearch: () => void; + onPageChange: (page: number) => void; + + // 可选配置 + searchSuggestions?: string[]; + + // navigation items + navItems?: NavigationItem[]; +} + +export const Home: React.FC = ({ + searchQuery, + services, + currentPage, + total, + pageSize, + loading, + onSearchChange, + onSearch, + onPageChange, + searchSuggestions = [], + navItems = [], +}) => { + const { platformConfig } = usePlatformConfig(); + const { t } = useTranslation(); + const totalPages = Math.ceil(total / pageSize); + + return ( +
+ {/* Decorative Elements */} +
+
+
+
+ + {/* Modern Navigation */} + + {/* Modern Hero Section */} +
+
+
+ {/* Modern Icon */} +
+
+ +
+
+ + {/* Modern Title */} +

+ {t( + platformConfig.headline || _DefaultPlatformConfig.headline || "" + )} +

+ + {/* Modern Subtitle */} +

+ {t( + platformConfig.subheadline || + _DefaultPlatformConfig.subheadline || + "" + )} +

+
+ + {/* Modern Search Bar */} +
+
+
+
+ 0 + ? t(searchSuggestions[0]) + : t("Search services...") + } + value={searchQuery} + onChange={(e) => onSearchChange(e.target.value)} + onKeyDown={(e) => e.key === "Enter" && onSearch()} + startContent={} + className="w-full" + classNames={{ + input: + "text-base text-gray-900 placeholder:text-gray-500", + inputWrapper: "h-12 shadow-none px-4 bg-white border-0", + }} + variant="flat" + /> +
+ +
+
+
+
+
+ + {/* Service List Section */} + {loading ? ( +
+
+ +
+
+ ) : ( +
+
+ {/* Services Grid */} +
+ {services.map((service) => ( + + + + {/* Header */} +
+
+
+ +
+
+

+ {service.name} +

+
+
+ +
+ + {/* Description */} +

+ {service.short_description || + t("No description available")} +

+
+ + {/* Footer */} + +
+ {/* Tools count */} +
+
+ + {t("{{count}} Tools", { + count: service.tools.length, + })} + +
+ + {/* Price */} +
+ +
+
+
+
+ + ))} +
+ + {/* Pagination */} + {totalPages > 1 && ( +
+ +
+ )} +
+
+ )} + +
+
+ ); +}; diff --git a/frontend/src/components/theme/modern/Navigation.tsx b/frontend/src/components/theme/modern/Navigation.tsx new file mode 100644 index 0000000..a0f8eca --- /dev/null +++ b/frontend/src/components/theme/modern/Navigation.tsx @@ -0,0 +1,105 @@ +"use client"; + +import React from "react"; +import { Button } from "@nextui-org/react"; +import { useTranslation } from "react-i18next"; +import Link from "next/link"; +import { useState } from "react"; +import { + Navbar, + NavbarContent, + NavbarMenuToggle, + NavbarMenu, + NavbarMenuItem, +} from "@nextui-org/react"; +import { ArrowRightIcon } from "lucide-react"; +import { DynamicLogo } from "@/shared/components/DynamicLogo"; +import { useAuth } from "@/shared/lib/useAuth"; +import { NavigationItem } from "@/shared/components/Navigation"; + +interface NavigationProps { + items?: NavigationItem[]; +} + +export const Navigation: React.FC = ({ items }) => { + const { t } = useTranslation(); + const { handleLogin } = useAuth(); + const [isMenuOpen, setIsMenuOpen] = useState(false); + + return ( + <> + {/* Modern Navigation */} + + + +
+ + + +
+
+ {items?.map((item) => ( + + {t(item.label)} + + ))} +
+
+ +
+ +
+
+ +
+
+ + + + + +
+ + ); +}; diff --git a/frontend/src/components/theme/temu/About.tsx b/frontend/src/components/theme/temu/About.tsx new file mode 100644 index 0000000..ad36736 --- /dev/null +++ b/frontend/src/components/theme/temu/About.tsx @@ -0,0 +1,27 @@ +"use client"; + +import React from "react"; +import { AboutContent } from "@/components/about/AboutContent"; +import { Navigation } from "./Navigation"; +import { Footer } from "./Footer"; +import { NavigationItem } from "@/shared/components/Navigation"; + +interface AboutProps { + navItems?: NavigationItem[]; +} + +export const About: React.FC = ({ navItems = [] }) => { + return ( +
+ + +
+
+ +
+
+ +
+
+ ); +}; diff --git a/frontend/src/components/theme/temu/Demo.tsx b/frontend/src/components/theme/temu/Demo.tsx new file mode 100644 index 0000000..4954c9d --- /dev/null +++ b/frontend/src/components/theme/temu/Demo.tsx @@ -0,0 +1,103 @@ +"use client"; + +import React from "react"; +import { ShoppingBag, Search, Tag, Star } from "lucide-react"; + +const TemuDemo: React.FC = () => { + return ( +
+ {/* Header */} +
+
+
+ + MCP Store +
+
+
+
+
+
+
+
+ + {/* Hero Section */} +
+
+ {/* Title */} +

+ Discover Amazing Services +

+ + {/* Subtitle */} +

+ Find the perfect MCP service for your needs +

+ + {/* Search Bar */} +
+
+ + Search... +
+
+ Go +
+
+
+
+ + {/* Products Section */} +
+ {/* Section Header */} +
+ + Featured +
+ + {/* Products Grid */} +
+ {/* Product 1 */} +
+
+

+ AI Assistant +

+

+ Smart AI helper +

+
+
+ $9.99 +
+ + 4.8 +
+
+
+ + {/* Product 2 */} +
+
+

+ Data Analyzer +

+

+ Powerful analytics +

+
+
+ $14.99 +
+ + 4.9 +
+
+
+
+
+
+ ); +}; + +export default TemuDemo; \ No newline at end of file diff --git a/frontend/src/components/theme/temu/Detail.tsx b/frontend/src/components/theme/temu/Detail.tsx new file mode 100644 index 0000000..8c62cf3 --- /dev/null +++ b/frontend/src/components/theme/temu/Detail.tsx @@ -0,0 +1,195 @@ +"use client"; + +import React, { useState } from "react"; +import { useTranslation } from "@/shared/lib/useTranslation"; +import { Tabs, Tab, Chip, Card, CardBody } from "@nextui-org/react"; +import { ServiceData } from "@/shared/types/marketplace"; +import { ProductHeader } from "@/shared/components/marketplace/ProductHeader"; +import { ProductOverview } from "@/shared/components/marketplace/ProductOverview"; +import { ProductTools } from "@/shared/components/marketplace/ProductTools"; +import { ProductNotFound } from "@/shared/components/marketplace/ProductNotFound"; +import { FileText, Wrench, Cog } from "lucide-react"; +import { Navigation } from "./Navigation"; +import { Footer } from "./Footer"; +import { usePlatformConfig } from "@/shared/contexts/PlatformConfigContext"; +import { NavigationItem } from "@/shared/components/Navigation"; + +interface DetailProps { + product: ServiceData; + breadcrumbs?: { + link: string; + name: string; + }[]; + url?: string; + + // navigation items + navItems?: NavigationItem[]; +} + +export const Detail: React.FC = ({ + product, + breadcrumbs, + url, + navItems = [], +}) => { + const { t } = useTranslation(); + const [activeTab, setActiveTab] = useState("overview"); + const { platformConfig } = usePlatformConfig(); + if (!product) { + return ; + } + + return ( +
+ +
+ {/* Temu Style Product Header */} +
+
+ {/* Breadcrumbs */} + {breadcrumbs && breadcrumbs.length > 0 && ( + + )} + + +
+
+ + {/* Main Content */} +
+ + + setActiveTab(key as string)} + variant="underlined" + color="warning" + className="px-6 pt-6" + classNames={{ + tabList: + "gap-6 w-full relative rounded-none p-0 border-b border-gray-200", + cursor: "w-full bg-orange-500", + tab: "max-w-fit px-0 h-12", + tabContent: + "group-data-[selected=true]:text-orange-600 font-medium text-gray-700", + }} + > + + + {t("Overview")} +
+ } + > +
+ +
+ + + + {t("Tools")} +
+ } + > +
+
+ {product.tools.length > 0 ? ( + product.tools.map((tool, index) => ( + + +

+ {tool.name} +

+

+ {tool.description || + t("No description available")} +

+
+
+ )) + ) : ( + + +

+ {t("No tools available in this service.")} +

+
+
+ )} +
+
+ + + + {t("Configuration")} +
+ } + > +
+ {/* Code Snippet */} + +
+ + {platformConfig?.name} MCP + +
+                          
+                            {`{
+  "mcpServers": {
+    "xpack-mcp-market": {
+      "type": "sse",
+      "autoApprove"":"all",
+      "url": "${url}?apikey=`}
+                            {`{Your-${platformConfig?.name}-API-Key}`}
+                            {`"
+    }
+  }
+}`}
+                          
+                        
+
+
+
+ + + + +
+
+
+
+ ); +}; diff --git a/frontend/src/components/theme/temu/Footer.tsx b/frontend/src/components/theme/temu/Footer.tsx new file mode 100644 index 0000000..2e988ae --- /dev/null +++ b/frontend/src/components/theme/temu/Footer.tsx @@ -0,0 +1,68 @@ +"use client"; + +import React from "react"; +import { usePlatformConfig } from "@/shared/contexts/PlatformConfigContext"; +import { ShoppingBag, Star, Heart } from "lucide-react"; +import { useTranslation } from "react-i18next"; + +interface FooterProps {} + +export const Footer: React.FC = ({}) => { + const { platformConfig } = usePlatformConfig(); + const { t } = useTranslation(); + return ( + <> + {/* Temu Style Footer */} +
+
+
+ {/* Company Info */} +
+

+ {platformConfig?.name} +

+

+ {t( + "A marketplace for AI tools and services. Discover and integrate powerful AI solutions for your projects." + )} +

+
+ + + {t("AI Tools Marketplace")} + +
+
+
+ + {/* Bottom Section */} +
+
+ {/* Copyright */} +
+ + © 2025 {platformConfig?.name}. All rights reserved. + +
+ + {/* Powered By */} + +
+
+
+
+ + ); +}; diff --git a/frontend/src/components/theme/temu/Home.tsx b/frontend/src/components/theme/temu/Home.tsx new file mode 100644 index 0000000..f1c301a --- /dev/null +++ b/frontend/src/components/theme/temu/Home.tsx @@ -0,0 +1,220 @@ +"use client"; + +import React from "react"; +import { CardFooter, Spinner } from "@nextui-org/react"; +import { Search, ShoppingBag, Tag, TrendingUp } from "lucide-react"; +import { + Input, + Button, + Pagination, + Card, + CardBody, + Chip, +} from "@nextui-org/react"; +import { useTranslation } from "react-i18next"; +import Link from "next/link"; +import { ServiceData } from "@/shared/types/marketplace"; +import { Price } from "@/shared/components/marketplace/Price"; +import { + _DefaultPlatformConfig, + usePlatformConfig, +} from "@/shared/contexts/PlatformConfigContext"; +import { Footer } from "./Footer"; +import { Navigation } from "./Navigation"; +import { NavigationItem } from "@/shared/components/Navigation"; + +interface HomeProps { + // 状态 + searchQuery: string; + services: ServiceData[]; + currentPage: number; + total: number; + pageSize: number; + loading: boolean; + error: string | null; + + // 事件处理函数 + onSearchChange: (value: string) => void; + onSearch: () => void; + onPageChange: (page: number) => void; + + // 可选配置 + searchSuggestions?: string[]; + + // navigation items + navItems?: NavigationItem[]; +} + +export const Home: React.FC = ({ + searchQuery, + services, + currentPage, + total, + pageSize, + loading, + error, + onSearchChange, + onSearch, + onPageChange, + navItems = [], +}) => { + const { platformConfig } = usePlatformConfig(); + const { t } = useTranslation(); + const totalPages = Math.ceil(total / pageSize); + + // 如果有错误,显示错误信息 + if (error) { + return ( +
+
+
+ Error: {error} +
+
+
+ ); + } + + return ( +
+ + + {/* Temu Style Hero Section */} +
+
+
+ {/* Icon */} +
+
+ +
+
+ + {/* Title */} +

+ {t( + platformConfig.headline || _DefaultPlatformConfig.headline || "" + )} +

+ + {/* Subtitle */} +

+ {t( + platformConfig.subheadline || + _DefaultPlatformConfig.subheadline || + "" + )} +

+ + {/* Search Bar */} +
+
+ onSearchChange(e.target.value)} + onKeyDown={(e) => e.key === "Enter" && onSearch()} + startContent={} + className="flex-1" + classNames={{ + input: "text-lg", + inputWrapper: "h-14 bg-white shadow-lg border-0", + }} + radius="lg" + /> + +
+
+
+
+
+ + {/* Products Section */} +
+ {/* Section Header */} +
+
+ +

+ {searchQuery ? t("Search Results") : t("Featured Products")} +

+ {searchQuery && ( + + {total} {t("results")} + + )} +
+
+ + {/* Loading State */} + {loading && ( +
+ +
+ )} + + {/* Products Grid */} + {!loading && ( + <> +
+ {services.map((service) => ( + + + + {/* Product Info */} +
+

+ {service.name} +

+

+ {service.short_description || + service.long_description || + "No description available"} +

+
+
+ + {/* Price */} +
+ +
+
+
+ + ))} +
+ + {/* Pagination */} + {totalPages > 1 && ( +
+ +
+ )} + + )} +
+ +
+
+ ); +}; diff --git a/frontend/src/components/theme/temu/Navigation.tsx b/frontend/src/components/theme/temu/Navigation.tsx new file mode 100644 index 0000000..6d8952f --- /dev/null +++ b/frontend/src/components/theme/temu/Navigation.tsx @@ -0,0 +1,113 @@ +"use client"; + +import React from "react"; +import { Button } from "@nextui-org/react"; +import { useTranslation } from "react-i18next"; +import Link from "next/link"; +import { useState } from "react"; +import { + Navbar, + NavbarContent, + NavbarMenuToggle, + NavbarMenu, + NavbarMenuItem, +} from "@nextui-org/react"; +import { ArrowRightIcon, ShoppingCart } from "lucide-react"; +import { DynamicLogo } from "@/shared/components/DynamicLogo"; +import { useAuth } from "@/shared/lib/useAuth"; +import { NavigationItem } from "@/shared/components/Navigation"; + +interface NavigationProps { + items?: NavigationItem[]; +} + +export const Navigation: React.FC = ({ items }) => { + const { t } = useTranslation(); + const { handleLogin } = useAuth(); + const [isMenuOpen, setIsMenuOpen] = useState(false); + + return ( + <> + {/* Temu Style Navigation */} + + + +
+ + + +
+
+ {items?.map((item) => ( + + {t(item.label)} + + ))} +
+
+ +
+ +
+
+ +
+
+ + + + Home + + + + + Marketplace + + + + + + +
+ + ); +}; diff --git a/frontend/src/components/user-management/UserManagement.tsx b/frontend/src/components/user-management/UserManagement.tsx index 8767749..31108f5 100644 --- a/frontend/src/components/user-management/UserManagement.tsx +++ b/frontend/src/components/user-management/UserManagement.tsx @@ -12,15 +12,8 @@ const UserManagement: React.FC = () => { const { t } = useTranslation(); // use custom hook to manage user data - const { - users, - loading, - searchQuery, - pagination, - handleDeleteUser, - setSearch, - setPage, - } = useUserManagement(); + const { users, loading, pagination, handleDeleteUser, setPage } = + useUserManagement(); // Modal states const [deleteModal, setDeleteModal] = useState({ @@ -57,15 +50,11 @@ const UserManagement: React.FC = () => { return (
- {/* comming soon:Filters */} - {/* */} - { onClose={handleCloseDeleteModal} onConfirm={handleConfirmDelete} title={t("Delete User")} - description={t( - "Are you sure you want to delete this user? " - )} + description={t("Are you sure you want to delete this user? ")} /> ); diff --git a/frontend/src/hooks/useAdminLogin.tsx b/frontend/src/hooks/useAdminLogin.tsx index 269e868..39ef6b8 100644 --- a/frontend/src/hooks/useAdminLogin.tsx +++ b/frontend/src/hooks/useAdminLogin.tsx @@ -44,7 +44,7 @@ export const useAdminLogin = () => { // call store logout method adminLogOut(); // redirect to login page - router.push("/admin-signin"); + router.push("/admin"); toast.success(i18n.t("Logged out successfully")); }; @@ -53,4 +53,4 @@ export const useAdminLogin = () => { adminLogin, adminLogout, }; -}; \ No newline at end of file +}; diff --git a/frontend/src/hooks/useLogin.tsx b/frontend/src/hooks/useLogin.tsx index 2aac82b..932cebc 100644 --- a/frontend/src/hooks/useLogin.tsx +++ b/frontend/src/hooks/useLogin.tsx @@ -11,9 +11,11 @@ import { usePlatformConfig } from "@/shared/contexts/PlatformConfigContext"; // get redirect uri export const getGoogleRedirectUri = () => { - if (typeof window !== 'undefined') { - const isDevelopment = process.env.NODE_ENV === 'development'; - const baseUrl = isDevelopment ? "http://localhost:3000" : window.location.origin; + if (typeof window !== "undefined") { + const isDevelopment = process.env.NODE_ENV === "development"; + const baseUrl = isDevelopment + ? "http://localhost:3000" + : window.location.origin; return `${baseUrl}/loginSuccess`; } return ""; @@ -21,7 +23,7 @@ export const getGoogleRedirectUri = () => { export const useLogin = () => { const [loading, setLoading] = useState(false); - const { googleAuthConfig } = usePlatformConfig(); + const { loginConfig } = usePlatformConfig(); const [user, setUserToken] = useSharedStore((state: any) => [ state.user, state.setUserToken, @@ -30,8 +32,6 @@ export const useLogin = () => { const { isOpen, onOpen, onClose } = useDisclosure(); const router = useRouter(); - - const login = () => { if (user) { router.push("/dashboard"); @@ -82,9 +82,13 @@ export const useLogin = () => { const googleLoginOrSignUp = () => { // check if google login is enabled and configured properly - if (!googleAuthConfig?.is_enabled || !googleAuthConfig?.client_id) { + if (!loginConfig?.google?.is_enabled || !loginConfig?.google?.client_id) { console.error("Google login is not enabled or not configured properly"); - toast.error(i18n.t("Google login is not available. Please contact the administrator.")); + toast.error( + i18n.t( + "Google login is not available. Please contact the administrator." + ) + ); return; } @@ -94,7 +98,7 @@ export const useLogin = () => { form.setAttribute("action", oauth2Endpoint); const params: { [key: string]: string } = { - client_id: googleAuthConfig.client_id, + client_id: loginConfig.google.client_id, redirect_uri: getGoogleRedirectUri(), scope: "https://www.googleapis.com/auth/userinfo.email", state: new URLSearchParams({ @@ -118,7 +122,7 @@ export const useLogin = () => { const googleLoginRedirect = async () => { setLoading(true); - if (typeof window === 'undefined') { + if (typeof window === "undefined") { setLoading(false); return; } @@ -180,17 +184,53 @@ export const useLogin = () => { } }; + const emailPasswordLogin = async (data: { + user_email: string; + password: string; + }) => { + setLoading(true); + + try { + const result = await fetchAPI("/api/auth/email/sign", { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify(data), + }); + + setLoading(false); + + if (!result.success) { + setStatus("error"); + toast.error(result.error_message || i18n.t("Login failed")); + return result; + } + + const searchParams = new URLSearchParams(window.location.search); + afterLoginSuccess(searchParams, result.data); + toast.success(i18n.t("Login successful")); + return result; + } catch (error) { + setLoading(false); + setStatus("error"); + console.error("Email password login error:", error); + toast.error(i18n.t("Login failed")); + return { success: false, error }; + } + }; + return { loading, status, isOpen, onOpen, onClose, - googleAuthConfig, afterLoginSuccess, login, googleLoginOrSignUp, googleLoginRedirect, emailLoginOrSignUp, + emailPasswordLogin, }; -}; \ No newline at end of file +}; diff --git a/frontend/src/hooks/useSystemConfigManagement.ts b/frontend/src/hooks/useSystemConfigManagement.ts index 2b66d76..187e5b9 100644 --- a/frontend/src/hooks/useSystemConfigManagement.ts +++ b/frontend/src/hooks/useSystemConfigManagement.ts @@ -1,5 +1,5 @@ import { useState, useCallback, useEffect } from "react"; -import { GoogleAuthConfig, PlatformConfig } from "@/shared/types/system"; +import { PlatformConfig, LoginConfig, EmailMode } from "@/shared/types/system"; import { systemConfigService } from "@/services/systemConfigService"; import { AdminConfig, EmailConfig } from "@/types/system"; import { md5Encrypt } from "@/shared/utils/crypto"; @@ -34,14 +34,20 @@ export const useSystemConfigManagement = () => { const [emailLoading, setEmailLoading] = useState(false); const [emailError, setEmailError] = useState(null); - // google auth config - const [googleAuthConfig, setGoogleAuthConfig] = useState({ - client_id: "", - client_secret: "", - is_enabled: false, + // login config + const [loginConfig, setLoginConfig] = useState({ + google: { + client_id: "", + client_secret: "", + is_enabled: false, + }, + email: { + is_enabled: true, // 默认启用邮箱登录 + mode: EmailMode.PASSWORD, // 默认使用密码模式 + }, }); - const [googleAuthLoading, setGoogleAuthLoading] = useState(false); - const [googleAuthError, setGoogleAuthError] = useState(null); + const [loginLoading, setLoginLoading] = useState(false); + const [loginError, setLoginError] = useState(null); // global loading const [isLoading, setIsLoading] = useState(false); @@ -63,7 +69,17 @@ export const useSystemConfigManagement = () => { smtp_sender: "", } ); - setGoogleAuthConfig(response.login?.google); + setLoginConfig({ + google: response.login?.google || { + client_id: "", + client_secret: "", + is_enabled: false, + }, + email: response.login?.email || { + is_enabled: true, + mode: EmailMode.PASSWORD, + }, + }); } catch (error) { console.error("Failed to load configurations:", error); } finally { @@ -72,25 +88,31 @@ export const useSystemConfigManagement = () => { }, []); // save platform config - const savePlatformConfig = useCallback(async (config: PlatformConfig) => { - setPlatformLoading(true); - setPlatformError(null); - const result = await systemConfigService.updateSystemConfig({ - platform: config, - }); - if (result) { - setPlatformConfig(config); - // 重新验证平台配置缓存 - try { - await revalidatePlatformConfig(); - console.info("Platform config cache revalidated successfully"); - } catch (error) { - console.error("Failed to revalidate platform config cache:", error); + const savePlatformConfig = useCallback( + async (config: PlatformConfig, key?: "theme" | "about") => { + if (!key) setPlatformLoading(true); + setPlatformError(null); + const result = await systemConfigService.updateSystemConfig( + { + platform: config, + }, + key + ); + if (result) { + setPlatformConfig(config); + // 重新验证平台配置缓存 + try { + await revalidatePlatformConfig(); + console.info("Platform config cache revalidated successfully"); + } catch (error) { + console.error("Failed to revalidate platform config cache:", error); + } } - } - setPlatformLoading(false); - return result; - }, []); + setPlatformLoading(false); + return result; + }, + [] + ); // save admin config const saveAdminConfig = useCallback(async (config: AdminConfig) => { @@ -123,20 +145,18 @@ export const useSystemConfigManagement = () => { return result; }, []); - // save google auth config - const saveGoogleAuthConfig = useCallback(async (config: GoogleAuthConfig) => { - setGoogleAuthLoading(true); - setGoogleAuthError(null); + // save login config + const saveLoginConfig = useCallback(async (config: LoginConfig) => { + setLoginLoading(true); + setLoginError(null); const result = await systemConfigService.updateSystemConfig({ - login: { - google: config, - }, + login: config, }); if (result) { - setGoogleAuthConfig(config); + setLoginConfig(config); await revalidatePlatformConfig(); } - setGoogleAuthLoading(false); + setLoginLoading(false); return result; }, []); @@ -144,13 +164,26 @@ export const useSystemConfigManagement = () => { const clearPlatformError = useCallback(() => setPlatformError(null), []); const clearAdminError = useCallback(() => setAdminError(null), []); const clearEmailError = useCallback(() => setEmailError(null), []); - const clearGoogleAuthError = useCallback(() => setGoogleAuthError(null), []); + const clearLoginError = useCallback(() => setLoginError(null), []); // load configs on init useEffect(() => { loadConfigurations(); }, [loadConfigurations]); + // upload image + const uploadImage = useCallback( + async (file: File, sha256?: string): Promise => { + try { + return await systemConfigService.uploadImage(file, sha256); + } catch (error) { + console.error("Failed to upload image:", error); + throw error; + } + }, + [] + ); + return { // platform config platformConfig, @@ -176,13 +209,16 @@ export const useSystemConfigManagement = () => { saveEmailConfig, clearEmailError, - // google auth config - googleAuthConfig, - setGoogleAuthConfig, - googleAuthLoading, - googleAuthError, - saveGoogleAuthConfig, - clearGoogleAuthError, + // login config + loginConfig, + setLoginConfig, + loginLoading, + loginError, + saveLoginConfig, + clearLoginError, + + // image upload + uploadImage, // global operations isLoading, diff --git a/frontend/src/services/systemConfigService.ts b/frontend/src/services/systemConfigService.ts index 9f8acdb..bd27320 100644 --- a/frontend/src/services/systemConfigService.ts +++ b/frontend/src/services/systemConfigService.ts @@ -1,6 +1,6 @@ import { fetchAdminAPI } from "@/rpc/admin-api"; import i18n from "@/shared/lib/i18n"; -import { GoogleAuthConfig, PlatformConfig } from "@/shared/types/system"; +import { PlatformConfig, LoginConfig } from "@/shared/types/system"; import { AdminConfig, EmailConfig, SystemConfigApiData } from "@/types/system"; import toast from "react-hot-toast"; @@ -23,14 +23,15 @@ export class SystemConfigService { } // update system config - async updateSystemConfig(config: { - platform?: PlatformConfig; - account?: AdminConfig; - email?: EmailConfig; - login?: { - google?: GoogleAuthConfig; - }; - }): Promise { + async updateSystemConfig( + config: { + platform?: PlatformConfig; + account?: AdminConfig; + email?: EmailConfig; + login?: LoginConfig; + }, + key?: "theme" | "about" + ): Promise { const response = await fetchAdminAPI("/api/sysconfig/info", { method: "PUT", body: config as unknown as BodyInit, @@ -42,9 +43,45 @@ export class SystemConfigService { ); return false; } - toast.success(i18n.t("System config updated successfully")); + switch (key) { + case "theme": + toast.success(i18n.t("Theme changed successfully")); + break; + case "about": + toast.success(i18n.t("About page saved successfully")); + break; + default: { + toast.success(i18n.t("System config updated successfully")); + break; + } + } return true; } + + // upload image + async uploadImage(file: File, sha256?: string): Promise { + const formData = new FormData(); + formData.append("img", file); + + // add sha256 parameter for image uniqueness verification + if (sha256) { + formData.append("sha256", sha256); + } + + const response = await fetchAdminAPI<{ file_path: string }>( + "/api/upload/image", + { + method: "POST", + body: formData, + } + ); + + if (!response.success) { + toast.error(response.error_message || i18n.t("Failed to upload image")); + throw new Error(response.error_message || "Failed to upload image"); + } + return response.data.file_path; + } } export const systemConfigService = new SystemConfigService(); diff --git a/frontend/src/shared/components/ClientI18nProvider.tsx b/frontend/src/shared/components/ClientI18nProvider.tsx index fc016fd..cdd4eeb 100644 --- a/frontend/src/shared/components/ClientI18nProvider.tsx +++ b/frontend/src/shared/components/ClientI18nProvider.tsx @@ -1,6 +1,6 @@ "use client"; -import React, { useEffect } from "react"; +import React, { useEffect, useState } from "react"; import { I18nextProvider } from "react-i18next"; import i18n, { i18nPromise } from "@/shared/lib/i18n"; @@ -11,25 +11,30 @@ interface ClientI18nProviderProps { export const ClientI18nProvider: React.FC = ({ children, }) => { + const [isInitialized, setIsInitialized] = useState(false); const initAll = async () => { - if (i18n.isInitialized) return - await i18nPromise; - const storedLang = localStorage.getItem("i18nextLng"); - // only switch when the stored language is different from the current language - if (storedLang && storedLang !== i18n.language) { - await i18n.changeLanguage(storedLang); + if (!i18n.isInitialized) { + await i18nPromise; + const storedLang = localStorage.getItem("i18nextLng"); + // only switch when the stored language is different from the current language + if (storedLang && storedLang !== i18n.language) { + await i18n.changeLanguage(storedLang); + } } + setIsInitialized(true); }; useEffect(() => { initAll(); }, []); return ( -
+
{children}
); diff --git a/frontend/src/shared/components/ClientRootProviders.tsx b/frontend/src/shared/components/ClientRootProviders.tsx index 01d5163..5b63468 100644 --- a/frontend/src/shared/components/ClientRootProviders.tsx +++ b/frontend/src/shared/components/ClientRootProviders.tsx @@ -9,12 +9,11 @@ import { PlatformConfigResponse } from "@/shared/types/system"; export default function ClientRootProviders({ children, - initConfig + initConfig, }: { children: React.ReactNode; - initConfig: PlatformConfigResponse; + initConfig?: PlatformConfigResponse; }) { - return ( diff --git a/frontend/src/shared/components/DashboardSidebar.tsx b/frontend/src/shared/components/DashboardSidebar.tsx index 10dba32..13b45fb 100644 --- a/frontend/src/shared/components/DashboardSidebar.tsx +++ b/frontend/src/shared/components/DashboardSidebar.tsx @@ -2,23 +2,18 @@ import React from "react"; import { useTranslation } from "@/shared/lib/useTranslation"; -import { - Button, - Divider, - Link, -} from "@nextui-org/react"; -import { - LogOut, -} from "lucide-react"; +import { Button, Divider, Link } from "@nextui-org/react"; +import { LogOut } from "lucide-react"; import { DashboardSidebarProps } from "@/shared/types/dashboard"; import { DynamicLogo } from "@/shared/components/DynamicLogo"; - const DashboardSidebar: React.FC = ({ activeTab, onTabNavigate, onLogout, - sidebarItems, userProfilePanel + bottomPanel, + sidebarItems, + userProfilePanel, }) => { const { t } = useTranslation(); @@ -29,10 +24,7 @@ const DashboardSidebar: React.FC = ({
- +

@@ -64,16 +56,20 @@ const DashboardSidebar: React.FC = ({ - {/* Logout */} - +

+ {bottomPanel} + + {/* Logout */} + +
); diff --git a/frontend/src/shared/components/Footer.tsx b/frontend/src/shared/components/Footer.tsx index b16c817..1a93c8a 100644 --- a/frontend/src/shared/components/Footer.tsx +++ b/frontend/src/shared/components/Footer.tsx @@ -2,14 +2,18 @@ import React from "react"; import { usePlatformConfig } from "@/shared/contexts/PlatformConfigContext"; import { Link } from "@nextui-org/react"; - -export function Footer() { +interface FooterProps { + showPoweredBy?: boolean; +} +export function Footer({ showPoweredBy=true }: FooterProps) { const { platformConfig } = usePlatformConfig(); return (
© 2025 {platformConfig?.name}. All rights reserved. - Powered By XPack.AI + {showPoweredBy && ( + Powered By XPack.AI + )}
); } diff --git a/frontend/src/shared/components/Navigation.tsx b/frontend/src/shared/components/Navigation.tsx index 8c4fcb1..4a5c538 100644 --- a/frontend/src/shared/components/Navigation.tsx +++ b/frontend/src/shared/components/Navigation.tsx @@ -15,22 +15,23 @@ import { useAuth } from "@/shared/lib/useAuth"; import { ArrowRightIcon } from "lucide-react"; import { DynamicLogo } from "@/shared/components/DynamicLogo"; import Link from "next/link"; +export type NavigationItem = { + label: string; + href: string; + target?: string; +}; interface NavigationProps { - items?: { - label: string; - href: string; - }[]; + items?: NavigationItem[]; + langNode?: React.ReactNode; } // Client-side wrapper for interactive functionality -function NavigationClient({ items = [] }: NavigationProps) { +function NavigationClient({ items = [], langNode }: NavigationProps) { const [isMenuOpen, setIsMenuOpen] = useState(false); const { t } = useTranslation(); const { handleLogin } = useAuth(); - - return ( <> {/* Main Navigation */} @@ -53,10 +54,7 @@ function NavigationClient({ items = [] }: NavigationProps) {
{/* Logo using dynamic platform config */} - + {t(item.label)} @@ -82,7 +82,7 @@ function NavigationClient({ items = [] }: NavigationProps) { {/* Right Side Actions */} - + {langNode} {/* Desktop Auth Button */}
@@ -118,6 +118,8 @@ function NavigationClient({ items = [] }: NavigationProps) { color="foreground" href={item.href} className="w-full py-2 font-medium text-sm" + target={item?.target || "_self"} + prefetch={!item.target} > {t(item.label)} diff --git a/frontend/src/shared/components/marketplace/HeroSection.tsx b/frontend/src/shared/components/marketplace/HeroSection.tsx index 065e5c0..e17d762 100644 --- a/frontend/src/shared/components/marketplace/HeroSection.tsx +++ b/frontend/src/shared/components/marketplace/HeroSection.tsx @@ -2,20 +2,23 @@ import React, { useState, useEffect, useRef } from "react"; import { Input, Button } from "@nextui-org/react"; import { Search } from "lucide-react"; import { useTranslation } from "react-i18next"; -import { _DefaultPlatformConfig, usePlatformConfig } from "@/shared/contexts/PlatformConfigContext"; +import { + _DefaultPlatformConfig, + usePlatformConfig, +} from "@/shared/contexts/PlatformConfigContext"; interface HeroSectionProps { searchQuery: string; onSearchChange: (value: string) => void; onSearch?: () => void; + searchSuggestions?: string[]; } - - export const HeroSection: React.FC = ({ searchQuery, onSearchChange, onSearch, + searchSuggestions = [], }) => { const { platformConfig } = usePlatformConfig(); const { t } = useTranslation(); @@ -24,22 +27,13 @@ export const HeroSection: React.FC = ({ const [currentSuggestionIndex, setCurrentSuggestionIndex] = useState(0); const [isTyping, setIsTyping] = useState(true); const inputRef = useRef(null); - const searchSuggestions = [ - t("get latest documentation for libraries"), - t("execute terminal commands safely"), - t("find latest scientific research papers"), - t("tools to enhance thinking and reasoning"), - t("find flight tickets and airbnb listings"), - t("automate web browser interactions"), - t("send messages and receive notifications") - ]; useEffect(() => { if (isFocused || searchQuery) { return; } - const currentSuggestion = searchSuggestions[currentSuggestionIndex]; + const currentSuggestion = t(searchSuggestions[currentSuggestionIndex]); let timeoutId: NodeJS.Timeout; if (isTyping) { @@ -62,7 +56,9 @@ export const HeroSection: React.FC = ({ }, 50); } else { // deleting completed, switch to next suggestion - setCurrentSuggestionIndex((prev) => (prev + 1) % searchSuggestions.length); + setCurrentSuggestionIndex( + (prev) => (prev + 1) % searchSuggestions.length + ); setIsTyping(true); } } @@ -71,7 +67,7 @@ export const HeroSection: React.FC = ({ }, [animatedText, currentSuggestionIndex, isTyping, isFocused, searchQuery]); const handleKeyPress = (e: React.KeyboardEvent) => { - if (e.key === 'Enter') { + if (e.key === "Enter") { onSearch?.(); } }; @@ -84,10 +80,14 @@ export const HeroSection: React.FC = ({

- {platformConfig.headline || t(_DefaultPlatformConfig.headline || "")} + {t(platformConfig.headline || _DefaultPlatformConfig.headline || "")}

- {platformConfig.subheadline || t(_DefaultPlatformConfig.subheadline || "")} + {t( + platformConfig.subheadline || + _DefaultPlatformConfig.subheadline || + "" + )}

@@ -96,7 +96,13 @@ export const HeroSection: React.FC = ({ 0 + ? animatedText + : t("Search services...") + } value={searchQuery} onChange={(e) => onSearchChange(e.target.value)} onFocus={() => setIsFocused(true)} @@ -124,4 +130,4 @@ export const HeroSection: React.FC = ({
); -}; \ No newline at end of file +}; diff --git a/frontend/src/shared/components/marketplace/Price.tsx b/frontend/src/shared/components/marketplace/Price.tsx index c3d8114..262aa65 100644 --- a/frontend/src/shared/components/marketplace/Price.tsx +++ b/frontend/src/shared/components/marketplace/Price.tsx @@ -7,44 +7,44 @@ import { Zap } from "lucide-react"; import React from "react"; interface PriceProps { - price?: string; - charge_type: ChargeType; + price?: string; + charge_type?: ChargeType; } -export const Price: React.FC = ({ - price, - charge_type -}) => { - const { t } = useTranslation(); +export const Price: React.FC = ({ price, charge_type }) => { + const { t } = useTranslation(); + if (!charge_type) { + return null; + } - if (charge_type === ChargeType.Free) { - return ( - - {t('Free')} - - ); - } + if (charge_type === ChargeType.Free) { + return ( + + {t("Free")} + + ); + } - const priceText = parseFloat(price || '0'); + const priceText = parseFloat(price || "0"); - if (charge_type === ChargeType.PerCall) { - return ( -
- - ${priceText.toFixed(2)} - - /{t('Per Call')} -
- ); - } else { - return ( -
- - - ${priceText.toFixed(2)} - - /{t('token')} -
- ); - } + if (charge_type === ChargeType.PerCall) { + return ( +
+ + ${priceText.toFixed(2)} + + /{t("Per Call")} +
+ ); + } else { + return ( +
+ + + ${priceText.toFixed(2)} + + /{t("token")} +
+ ); + } }; diff --git a/frontend/src/shared/components/marketplace/ProductHeader.tsx b/frontend/src/shared/components/marketplace/ProductHeader.tsx index 55d0d89..10af91f 100644 --- a/frontend/src/shared/components/marketplace/ProductHeader.tsx +++ b/frontend/src/shared/components/marketplace/ProductHeader.tsx @@ -2,11 +2,7 @@ import React from "react"; import { useTranslation } from "@/shared/lib/useTranslation"; -import { - Card, - CardBody, - Chip, -} from "@nextui-org/react"; +import { Card, CardBody, Chip } from "@nextui-org/react"; import { ChargeType, ServiceData } from "@/shared/types/marketplace"; import Link from "next/link"; import { Price } from "./Price"; @@ -15,7 +11,7 @@ interface ProductHeaderProps { product: ServiceData; breadcrumbs?: { link: string; - name: string + name: string; }[]; } @@ -48,9 +44,7 @@ export const ProductHeader: React.FC = ({ {/* Header with title and price */}
-

- {product.name} -

+

{product.name}

{/* Tags */} {product.tags && product.tags.length > 0 && ( @@ -73,16 +67,16 @@ export const ProductHeader: React.FC = ({ {product.short_description || t("No description available")}

-
{/* Price section */} -
- {t("Price")}: - - -
+ {product.charge_type && ( +
+ {t("Price")}: + +
+ )} ); -}; \ No newline at end of file +}; diff --git a/frontend/src/shared/components/marketplace/ProductOverview.tsx b/frontend/src/shared/components/marketplace/ProductOverview.tsx index d4d28b3..9adeb87 100644 --- a/frontend/src/shared/components/marketplace/ProductOverview.tsx +++ b/frontend/src/shared/components/marketplace/ProductOverview.tsx @@ -16,7 +16,7 @@ export const ProductOverview: React.FC = ({ const { t } = useTranslation(); return ( - +
{product.long_description ? ( @@ -28,4 +28,4 @@ export const ProductOverview: React.FC = ({ ); -}; \ No newline at end of file +}; diff --git a/frontend/src/shared/components/marketplace/ServiceCard.tsx b/frontend/src/shared/components/marketplace/ServiceCard.tsx index 393dba1..650c25d 100644 --- a/frontend/src/shared/components/marketplace/ServiceCard.tsx +++ b/frontend/src/shared/components/marketplace/ServiceCard.tsx @@ -35,8 +35,6 @@ export const ServiceCard: React.FC = ({ service }) => {

{service.short_description || t("No description available")}

- - {/* Footer with tools count */} @@ -50,7 +48,7 @@ export const ServiceCard: React.FC = ({ service }) => { {t("{{count}} Tools", { count: service.tools.length })}
- +
diff --git a/frontend/src/shared/contexts/PlatformConfigContext.tsx b/frontend/src/shared/contexts/PlatformConfigContext.tsx index e0a2e7e..41181af 100644 --- a/frontend/src/shared/contexts/PlatformConfigContext.tsx +++ b/frontend/src/shared/contexts/PlatformConfigContext.tsx @@ -1,7 +1,12 @@ -'use client'; +"use client"; -import React, { createContext, useContext, useState, ReactNode, useEffect } from 'react'; -import { PlatformConfig, PlatformConfigResponse, GoogleAuthConfig } from '@/shared/types/system'; +import React, { createContext, useContext, useState, ReactNode } from "react"; +import { + PlatformConfig, + PlatformConfigResponse, + Theme, + LoginConfig, +} from "@/shared/types/system"; export const _DefaultPlatformConfig: PlatformConfig = { name: "XPack", logo: "/static/logo/logo.png", @@ -9,34 +14,43 @@ export const _DefaultPlatformConfig: PlatformConfig = { language: "en", website_title: "Connect Your AI Agent to the Real World - XPack", headline: "Connect Your AI Agent to the Real World", - subheadline: "Open‑source MCP marketplace — publish or consume APIs in minutes.", + subheadline: + "Open‑source MCP marketplace — publish or consume APIs in minutes.", + theme: Theme.DEFAULT, }; interface PlatformConfigContextType { platformConfig: PlatformConfig; - googleAuthConfig: GoogleAuthConfig | null; + loginConfig: LoginConfig | null; updateClientConfig: (config: PlatformConfigResponse) => void; } - -const PlatformConfigContext = createContext(undefined); +const PlatformConfigContext = createContext< + PlatformConfigContextType | undefined +>(undefined); interface PlatformConfigProviderProps { children: ReactNode; - initConfig: PlatformConfigResponse; + initConfig?: PlatformConfigResponse; } export const PlatformConfigProvider: React.FC = ({ children, initConfig, }) => { - const [platformConfig, setPlatformConfig] = useState(initConfig.platform || _DefaultPlatformConfig); - const [googleAuthConfig, setGoogleAuthConfig] = useState(initConfig.login?.google || null); + const [platformConfig, setPlatformConfig] = useState( + initConfig?.platform || _DefaultPlatformConfig + ); + const [loginConfig, setLoginConfig] = useState( + initConfig?.login || null + ); const updateClientConfig = (config: PlatformConfigResponse) => { if (config.platform) setPlatformConfig(config.platform); - if (config.login?.google) setGoogleAuthConfig(config.login?.google); + if (config.login) setLoginConfig(config.login); }; return ( - + {children} ); @@ -45,7 +59,9 @@ export const PlatformConfigProvider: React.FC = ({ export const usePlatformConfig = () => { const context = useContext(PlatformConfigContext); if (context === undefined) { - throw new Error('usePlatformConfig must be used within a PlatformConfigProvider'); + throw new Error( + "usePlatformConfig must be used within a PlatformConfigProvider" + ); } return context; -}; \ No newline at end of file +}; diff --git a/frontend/src/shared/lib/i18n.ts b/frontend/src/shared/lib/i18n.ts index e3bc6b2..c82a9b0 100644 --- a/frontend/src/shared/lib/i18n.ts +++ b/frontend/src/shared/lib/i18n.ts @@ -3,10 +3,17 @@ import { initReactI18next } from "react-i18next"; import LanguageDetector from "i18next-browser-languagedetector"; import Backend from "i18next-http-backend"; import { getDefaultLanguage } from "@/shared/utils/i18n"; -import en from "../../../public/locales/en/translation.json"; -import enConfig from "../../../public/locales/en/config.json"; -import zhCN from "../../../public/locales/zh-CN/translation.json"; -import zhCNConfig from "../../../public/locales/zh-CN/config.json"; +let resources = {}; +if(typeof window !== "undefined" && !window._BACKEND_LOAD_LANG__){ + let en=require("../../../public/locales/en/translation.json"); + let enConfig=require("../../../public/locales/en/config.json"); + let zhCN=require("../../../public/locales/zh-CN/translation.json"); + let zhCNConfig=require("../../../public/locales/zh-CN/config.json"); + resources = { + en: { translation: en, config: enConfig }, + "zh-CN": { translation: zhCN, config: zhCNConfig }, + }; +} // Try to read the preferred language from multiple sources: // 1. URL parameters (lang=zh-CN) @@ -25,10 +32,20 @@ export const i18nPromise = i18n .use(LanguageDetector) .use(initReactI18next) .init({ - resources: { - en: { translation: en, config: enConfig }, - "zh-CN": { translation: zhCN, config: zhCNConfig }, - }, + ...(typeof window !== "undefined" && window._BACKEND_LOAD_LANG__ + ? { + backend: { + // Allow loading multiple namespaces (e.g. translation.json, config.json) + loadPath: `${process.env.NEXT_PUBLIC_STATIC_URL_PREFIX || ""}/locales/{{lng}}/{{ns}}.json`, + // add request options to improve loading speed + requestOptions: { + cache: "default", + }, + }, + } + : { + resources, + }), ns: ["translation", "config"], defaultNS: "translation", fallbackNS: "config", diff --git a/frontend/src/shared/rpc/adapter.ts b/frontend/src/shared/rpc/adapter.ts index c7ea09b..405dca9 100644 --- a/frontend/src/shared/rpc/adapter.ts +++ b/frontend/src/shared/rpc/adapter.ts @@ -4,7 +4,7 @@ export const SOURCE_TYPE = SourceType.SSG; // Define base URLs for API requests export const API_BASE_URL = - process.env.NEXT_PUBLIC_API_URL || "http://127.0.0.1:8100"; + process.env.NEXT_PUBLIC_API_URL || "http://127.0.0.1:8001"; // Helper function for constructing API URLs export const getApiUrl = (endpoint: string) => { diff --git a/frontend/src/shared/store/global.ts b/frontend/src/shared/store/global.ts index 5c6718a..43eef29 100644 --- a/frontend/src/shared/store/global.ts +++ b/frontend/src/shared/store/global.ts @@ -10,6 +10,7 @@ import { import { fetchAPI } from "../rpc/common-function"; import { shallow } from "zustand/shallow"; import { useSharedStore } from "./share"; +import { md5Encrypt } from "@/shared/utils/crypto"; export const StorageGlobalName = "XPack_Global"; @@ -22,6 +23,7 @@ export type GlobalStore = { getUser: () => Promise; useGetUser: () => SWRResponse; logOut: () => void; + changePassword: (password: string) => Promise; }; export const useGlobalStore = createWithEqualityFn()( @@ -99,6 +101,13 @@ export const useGlobalStore = createWithEqualityFn()( console.error("log out error", e); } }, + changePassword: async (password: string) => { + const res = await fetchAPI("/api/user/password", { + method: "PUT", + body: { password: md5Encrypt(password) } as unknown as BodyInit, + }); + return res; + }, }) ) ), diff --git a/frontend/src/shared/types/dashboard.ts b/frontend/src/shared/types/dashboard.ts index 790aaa0..62ec7fc 100644 --- a/frontend/src/shared/types/dashboard.ts +++ b/frontend/src/shared/types/dashboard.ts @@ -1,13 +1,15 @@ -export type TabKey = - | "console" - | "mcp-services" - | "user-management" - | "revenue-management" - | "payment-channels" - | "system-settings" - | "overview" - | "wallet" - | "account"; +export enum TabKey { + CONSOLE = "console", + MCP_SERVICES = "mcp-services", + USER_MANAGEMENT = "user-management", + REVENUE_MANAGEMENT = "revenue-management", + PAYMENT_CHANNELS = "payment-channels", + LOGIN_SETTINGS = "login-settings", + SYSTEM_SETTINGS = "system-settings", + OVERVIEW = "overview", + WALLET = "wallet", + ACCOUNT = "account", +} export interface SidebarItem { key: TabKey; @@ -20,6 +22,7 @@ export interface DashboardSidebarProps { activeTab: TabKey; onTabNavigate?: (tab: TabKey) => void; onLogout: () => void; + bottomPanel?: React.ReactNode; sidebarItems: SidebarItem[]; userProfilePanel?: React.ReactNode; } diff --git a/frontend/src/shared/types/system.ts b/frontend/src/shared/types/system.ts index 3124faf..1a9990c 100644 --- a/frontend/src/shared/types/system.ts +++ b/frontend/src/shared/types/system.ts @@ -1,3 +1,16 @@ +// Theme enum +export enum Theme { + DEFAULT = "default", + MODERN = "modern", + CLASSIC = "classic", + CREATIVE = "creative", + TEMU = "temu", +} +export enum EmailMode { + PASSWORD = "password", + CAPTCHA = "captcha", +} + export interface PlatformConfig { logo?: string; // platform logo url name: string; // platform name @@ -6,15 +19,14 @@ export interface PlatformConfig { website_title?: string; // website title headline?: string; // homepage headline subheadline?: string; // homepage subheadline + theme?: Theme; // platform theme for homepage and marketplace templates + about_page?: string; // about page content (markdown) } + +export type ThemeType = Theme; export interface PlatformConfigResponse { platform: PlatformConfig; - login?: { - google?: { - client_id: string; - is_enabled: boolean; - }; - }; + login?: LoginConfig; } // google auth config @@ -23,3 +35,15 @@ export interface GoogleAuthConfig { client_secret?: string; // Google Client Secret (optional, for server-side validation) is_enabled: boolean; // whether to enable google login } + +// email login config +export interface EmailLoginConfig { + is_enabled: boolean; // whether to enable email login + mode: EmailMode; // authentication mode +} + +// login config +export interface LoginConfig { + google: GoogleAuthConfig; + email?: EmailLoginConfig; +} diff --git a/frontend/src/shared/utils/crypto.ts b/frontend/src/shared/utils/crypto.ts index 00d088a..9614ed7 100644 --- a/frontend/src/shared/utils/crypto.ts +++ b/frontend/src/shared/utils/crypto.ts @@ -8,3 +8,38 @@ import CryptoJS from "crypto-js"; export const md5Encrypt = (text: string): string => { return CryptoJS.MD5(text).toString(); }; + +/** + * SHA256 encrypt function + * @param text text to encrypt + * @returns SHA256 encrypted string + */ +export const sha256Encrypt = (text: string): string => { + return CryptoJS.SHA256(text).toString(); +}; + +/** + * Calculate SHA256 hash of a file + * @param file File to calculate hash for + * @returns Promise resolving to SHA256 hash string + */ +export const calculateFileSha256 = (file: File): Promise => { + return new Promise((resolve, reject) => { + const reader = new FileReader(); + reader.onload = (event) => { + try { + const binary = event.target?.result; + if (binary) { + const hash = CryptoJS.SHA256(CryptoJS.lib.WordArray.create(binary as any)).toString(); + resolve(hash); + } else { + reject(new Error("Failed to read file")); + } + } catch (error) { + reject(error); + } + }; + reader.onerror = (error) => reject(error); + reader.readAsArrayBuffer(file); + }); +}; diff --git a/frontend/src/store/admin.ts b/frontend/src/store/admin.ts index 5959a01..c64f653 100644 --- a/frontend/src/store/admin.ts +++ b/frontend/src/store/admin.ts @@ -27,6 +27,7 @@ export type AdminStore = { // Admin operations adminLogOut: () => void; adminLogin: (username: string, password: string) => Promise; + getAdminUser: () => Promise; }; const fn: StateCreator = (set, get) => { @@ -115,6 +116,14 @@ const fn: StateCreator = (set, get) => { }; } }, + getAdminUser: async () => { + const { setAdmin } = get(); + const res = await fetchAdminAPI("/api/user/info"); + if (res.success) { + setAdmin(res.data); + } + return res; + }, }; }; diff --git a/frontend/src/styles/themes.css b/frontend/src/styles/themes.css new file mode 100644 index 0000000..d77dd8a --- /dev/null +++ b/frontend/src/styles/themes.css @@ -0,0 +1,235 @@ +/* Theme Styles */ + +/* Modern Theme - 现代简约风格 */ +.theme-modern { + --theme-primary-bg: linear-gradient(135deg, #667eea 0%, #764ba2 100%); + --theme-secondary-bg: #f8fafc; + --theme-accent-color: #3b82f6; + --theme-text-primary: #1e293b; + --theme-text-secondary: #64748b; + --theme-border-radius: 12px; + --theme-shadow: 0 10px 25px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05); + --theme-card-bg: #ffffff; + --theme-hero-pattern: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23f1f5f9' fill-opacity='0.4'%3E%3Ccircle cx='30' cy='30' r='2'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E"); +} + +/* Classic Theme - 经典商务风格 */ +.theme-classic { + --theme-primary-bg: linear-gradient(135deg, #2c3e50 0%, #34495e 100%); + --theme-secondary-bg: #ecf0f1; + --theme-accent-color: #e74c3c; + --theme-text-primary: #2c3e50; + --theme-text-secondary: #7f8c8d; + --theme-border-radius: 6px; + --theme-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06); + --theme-card-bg: #ffffff; + --theme-hero-pattern: url("data:image/svg+xml,%3Csvg width='40' height='40' viewBox='0 0 40 40' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='%23bdc3c7' fill-opacity='0.3'%3E%3Cpath d='M20 20h20v20H20V20zm-20 0h20v20H0V20z'/%3E%3C/g%3E%3C/svg%3E"); +} + +/* Creative Theme - 创意活力风格 */ +.theme-creative { + --theme-primary-bg: linear-gradient(135deg, #ff6b6b 0%, #feca57 50%, #48dbfb 100%); + --theme-secondary-bg: #fff5f5; + --theme-accent-color: #ff6b6b; + --theme-text-primary: #2d3748; + --theme-text-secondary: #718096; + --theme-border-radius: 20px; + --theme-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04); + --theme-card-bg: #ffffff; + --theme-hero-pattern: url("data:image/svg+xml,%3Csvg width='80' height='80' viewBox='0 0 80 80' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ff6b6b' fill-opacity='0.1'%3E%3Cpath d='M0 0h40v40H0V0zm40 40h40v40H40V40z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E"); +} + +/* Theme-specific component styles */ + +/* Hero Section Styles */ +.theme-modern .hero-section { + background: var(--theme-primary-bg); + background-attachment: fixed; + position: relative; +} + +.theme-modern .hero-section::before { + content: ''; + position: absolute; + top: 0; + left: 0; + right: 0; + bottom: 0; + background: var(--theme-hero-pattern); + opacity: 0.1; +} + +.theme-classic .hero-section { + background: var(--theme-primary-bg); + position: relative; +} + +.theme-classic .hero-section::before { + content: ''; + position: absolute; + top: 0; + left: 0; + right: 0; + bottom: 0; + background: var(--theme-hero-pattern); + opacity: 0.05; +} + +.theme-creative .hero-section { + background: var(--theme-primary-bg); + position: relative; + overflow: hidden; +} + +.theme-creative .hero-section::before { + content: ''; + position: absolute; + top: 0; + left: 0; + right: 0; + bottom: 0; + background: var(--theme-hero-pattern); + opacity: 0.1; + animation: float 6s ease-in-out infinite; +} + +@keyframes float { + 0%, 100% { transform: translateY(0px); } + 50% { transform: translateY(-10px); } +} + +/* Card Styles */ +.theme-modern .themed-card { + background: var(--theme-card-bg); + border-radius: var(--theme-border-radius); + box-shadow: var(--theme-shadow); + transition: all 0.3s ease; +} + +.theme-modern .themed-card:hover { + transform: translateY(-4px); + box-shadow: 0 20px 40px -7px rgba(0, 0, 0, 0.1); +} + +.theme-classic .themed-card { + background: var(--theme-card-bg); + border-radius: var(--theme-border-radius); + box-shadow: var(--theme-shadow); + border: 1px solid #e1e8ed; + transition: all 0.2s ease; +} + +.theme-classic .themed-card:hover { + border-color: var(--theme-accent-color); + box-shadow: 0 8px 16px -4px rgba(0, 0, 0, 0.1); +} + +.theme-creative .themed-card { + background: var(--theme-card-bg); + border-radius: var(--theme-border-radius); + box-shadow: var(--theme-shadow); + position: relative; + overflow: hidden; + transition: all 0.4s ease; +} + +.theme-creative .themed-card::before { + content: ''; + position: absolute; + top: 0; + left: -100%; + width: 100%; + height: 100%; + background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent); + transition: left 0.5s; +} + +.theme-creative .themed-card:hover::before { + left: 100%; +} + +.theme-creative .themed-card:hover { + transform: translateY(-8px) scale(1.02); + box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.15); +} + +/* Button Styles */ +.theme-modern .themed-button { + background: var(--theme-accent-color); + border-radius: var(--theme-border-radius); + transition: all 0.3s ease; +} + +.theme-classic .themed-button { + background: var(--theme-accent-color); + border-radius: var(--theme-border-radius); + transition: all 0.2s ease; +} + +.theme-creative .themed-button { + background: var(--theme-accent-color); + border-radius: var(--theme-border-radius); + transition: all 0.4s ease; + position: relative; + overflow: hidden; +} + +/* Text Styles */ +.themed-text-primary { + color: var(--theme-text-primary); +} + +.themed-text-secondary { + color: var(--theme-text-secondary); +} + +/* Layout Styles */ +.theme-modern .themed-container { + max-width: 1200px; + margin: 0 auto; + padding: 0 24px; +} + +.theme-classic .themed-container { + max-width: 1140px; + margin: 0 auto; + padding: 0 20px; +} + +.theme-creative .themed-container { + max-width: 1280px; + margin: 0 auto; + padding: 0 32px; +} + +/* Themed Pagination Styles */ +.themed-pagination { + transform: scale(1.1); +} + +.themed-pagination [data-slot="item"] { + background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); + color: white; + border-radius: 12px; + font-weight: 600; + transition: all 0.3s ease; +} + +.themed-pagination [data-slot="item"]:hover { + transform: translateY(-2px); + box-shadow: 0 8px 25px -8px rgba(102, 126, 234, 0.6); +} + +.themed-pagination [data-slot="prev"], +.themed-pagination [data-slot="next"] { + background: linear-gradient(135deg, #ff6b6b 0%, #feca57 100%); + color: white; + border-radius: 50%; + font-weight: bold; +} + +.themed-pagination [data-slot="prev"]:hover, +.themed-pagination [data-slot="next"]:hover { + transform: scale(1.1) rotate(5deg); + box-shadow: 0 8px 25px -8px rgba(255, 107, 107, 0.6); +} \ No newline at end of file diff --git a/frontend/src/types/global.d.ts b/frontend/src/types/global.d.ts index 0b7ca77..ce946a9 100644 --- a/frontend/src/types/global.d.ts +++ b/frontend/src/types/global.d.ts @@ -3,6 +3,7 @@ import { PlatformConfigResponse } from "@/shared/types/system"; declare global { interface Window { __PLATFORM_CONFIG__?: PlatformConfigResponse | null; + _BACKEND_LOAD_LANG__?: boolean; } } diff --git a/frontend/src/types/system.ts b/frontend/src/types/system.ts index e4a2499..e9d61c4 100644 --- a/frontend/src/types/system.ts +++ b/frontend/src/types/system.ts @@ -1,15 +1,17 @@ // 系统设置相关类型定义 -import { GoogleAuthConfig, PlatformConfig } from "@/shared/types/system"; +import { + GoogleAuthConfig, + PlatformConfig, + LoginConfig, +} from "@/shared/types/system"; // API return system config data structure export interface SystemConfigApiData { platform: PlatformConfig; account: AdminConfig; email: EmailConfig; - login: { - google: GoogleAuthConfig; - }; + login: LoginConfig; } // admin config export interface AdminConfig {