feature/ui:1.0 feature,like mcp price method support use token and set more config about home page
This commit is contained in:
1 parent
2262a7f49a
commit
8946be619d
69 files changed
+4189
-1021
No files matched your search
@@ -32,6 +32,13 @@ export default async function RootLayout({
|
||||
`,
|
||||
}}
|
||||
/>
|
||||
{platformConfig?.embeded_html?.is_enabled && platformConfig?.embeded_html?.html && (
|
||||
<div
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: platformConfig.embeded_html.html,
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</head>
|
||||
<body className={redHatDisplay.className} suppressHydrationWarning>
|
||||
<ClientRootProviders initConfig={platformConfig}>
|
||||
|
||||
@@ -1,38 +1,33 @@
|
||||
"use client";
|
||||
|
||||
import React from "react";
|
||||
import React, { useState } 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";
|
||||
import { EmailConfig } from "@/types/system";
|
||||
|
||||
interface LoginSettingsContentProps {
|
||||
onTabNavigate?: (tab: TabKey) => void;
|
||||
loginConfig: LoginConfig;
|
||||
saveLoginConfig: (config: LoginConfig) => Promise<boolean>;
|
||||
emailConfig: EmailConfig;
|
||||
}
|
||||
|
||||
export const LoginSettingsContent: React.FC<LoginSettingsContentProps> = ({
|
||||
onTabNavigate,
|
||||
loginConfig,
|
||||
saveLoginConfig,
|
||||
emailConfig,
|
||||
}) => {
|
||||
const [googleSubmitLoading, setGoogleSubmitLoading] = useState(false);
|
||||
const [emailSubmitLoading, setEmailSubmitLoading] = useState(false);
|
||||
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 =
|
||||
@@ -57,12 +52,13 @@ export const LoginSettingsContent: React.FC<LoginSettingsContentProps> = ({
|
||||
return;
|
||||
}
|
||||
|
||||
setEmailSubmitLoading(true);
|
||||
const result = await saveLoginConfig(config);
|
||||
if (!result) return;
|
||||
updateClientConfig({
|
||||
platform: platformConfig,
|
||||
login: config,
|
||||
});
|
||||
setEmailSubmitLoading(false);
|
||||
};
|
||||
|
||||
// save google auth config
|
||||
@@ -76,22 +72,23 @@ export const LoginSettingsContent: React.FC<LoginSettingsContentProps> = ({
|
||||
return;
|
||||
}
|
||||
|
||||
setGoogleSubmitLoading(true);
|
||||
const result = await saveLoginConfig(updatedLoginConfig);
|
||||
if (!result) return;
|
||||
updateClientConfig({
|
||||
platform: platformConfig,
|
||||
login: updatedLoginConfig,
|
||||
});
|
||||
setGoogleSubmitLoading(false);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="space-y-6 w-full">
|
||||
<div className="space-y-4 w-full">
|
||||
{/* email config */}
|
||||
<EmailConfigForm
|
||||
config={loginConfig}
|
||||
emailConfig={emailConfig}
|
||||
onSave={handleSaveLoginConfig}
|
||||
isLoading={loginLoading}
|
||||
isLoading={emailSubmitLoading}
|
||||
onTabNavigate={onTabNavigate}
|
||||
/>
|
||||
|
||||
@@ -99,7 +96,7 @@ export const LoginSettingsContent: React.FC<LoginSettingsContentProps> = ({
|
||||
<GoogleAuthConfigForm
|
||||
config={loginConfig.google}
|
||||
onSave={handleSaveGoogleAuthConfig}
|
||||
isLoading={loginLoading}
|
||||
isLoading={googleSubmitLoading}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -4,7 +4,6 @@ import React, { useEffect, useState, Suspense } from "react";
|
||||
import { useRouter, useSearchParams } from "next/navigation";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { useAdminStore } from "@/store/admin";
|
||||
import DashboardSidebar from "@/shared/components/DashboardSidebar";
|
||||
import DashboardDemoContent from "@/shared/components/DashboardDemoContent";
|
||||
import ConsoleStats from "@/components/console/ConsoleStats";
|
||||
import PaymentChannelsContent from "@/components/console/PaymentChannelsContent";
|
||||
@@ -15,17 +14,16 @@ import { MCPServicesManagement } from "@/components/mcp-services/MCPServicesMana
|
||||
import UserManagement from "@/components/user-management/UserManagement";
|
||||
import RevenueManagement from "@/components/revenue-management/RevenueManagement";
|
||||
import {
|
||||
Cog,
|
||||
CreditCard,
|
||||
DollarSign,
|
||||
Home,
|
||||
Settings,
|
||||
Users,
|
||||
LogIn,
|
||||
ServerIcon,
|
||||
} from "lucide-react";
|
||||
import { LoginSettingsContent } from "@/components/console/LoginSettingsContent";
|
||||
import { Button } from "@nextui-org/react";
|
||||
import { FaDiscord } from "react-icons/fa";
|
||||
import ConsoleSidebar from "./Sidebar";
|
||||
|
||||
const ConsoleContent: React.FC = () => {
|
||||
const { t } = useTranslation();
|
||||
@@ -33,6 +31,8 @@ const ConsoleContent: React.FC = () => {
|
||||
const searchParams = useSearchParams();
|
||||
const [admin_token] = useAdminStore((state) => [state.admin_token]);
|
||||
|
||||
const _DefaultSubTab = "general";
|
||||
|
||||
const getInitialTab = (): TabKey => {
|
||||
const tabFromUrl = searchParams.get("tab") as TabKey;
|
||||
if (
|
||||
@@ -51,49 +51,79 @@ const ConsoleContent: React.FC = () => {
|
||||
return TabKey.CONSOLE;
|
||||
};
|
||||
|
||||
const getInitialSubTab = (): string | undefined => {
|
||||
const subTabFromUrl = searchParams.get("subtab");
|
||||
return subTabFromUrl || _DefaultSubTab;
|
||||
};
|
||||
|
||||
const [activeTab, setActiveTab] = useState<TabKey>(getInitialTab);
|
||||
const [activeSubTab, setActiveSubTab] = useState<string | undefined>(
|
||||
getInitialSubTab
|
||||
);
|
||||
const sidebarItems: SidebarItem[] = [
|
||||
{
|
||||
key: TabKey.CONSOLE,
|
||||
icon: <Home className="w-5 h-5" />,
|
||||
icon: <Home size={18} />,
|
||||
label: t("Dashboard"),
|
||||
description: t("Overview and analytics"),
|
||||
},
|
||||
{
|
||||
key: TabKey.MCP_SERVICES,
|
||||
icon: <Settings className="w-5 h-5" />,
|
||||
icon: <ServerIcon size={18} />,
|
||||
label: t("MCP Services"),
|
||||
description: t("Manage MCP services and API tools"),
|
||||
},
|
||||
{
|
||||
key: TabKey.USER_MANAGEMENT,
|
||||
icon: <Users className="w-5 h-5" />,
|
||||
icon: <Users size={18} />,
|
||||
label: t("User Management"),
|
||||
description: t("Manage registered users"),
|
||||
},
|
||||
{
|
||||
key: TabKey.REVENUE_MANAGEMENT,
|
||||
icon: <DollarSign className="w-5 h-5" />,
|
||||
icon: <DollarSign size={18} />,
|
||||
label: t("Revenue Management"),
|
||||
description: t("View user recharge history"),
|
||||
},
|
||||
{
|
||||
key: TabKey.PAYMENT_CHANNELS,
|
||||
icon: <CreditCard className="w-5 h-5" />,
|
||||
icon: <CreditCard size={18} />,
|
||||
label: t("Payment Channels"),
|
||||
description: t("Configure payment channels"),
|
||||
},
|
||||
{
|
||||
key: TabKey.LOGIN_SETTINGS,
|
||||
icon: <LogIn className="w-5 h-5" />,
|
||||
label: t("Login Settings"),
|
||||
description: t("Configure authentication methods"),
|
||||
},
|
||||
{
|
||||
key: TabKey.SYSTEM_SETTINGS,
|
||||
icon: <Cog className="w-5 h-5" />,
|
||||
icon: <Settings size={18} />,
|
||||
label: t("System Settings"),
|
||||
description: t("Platform basic configuration"),
|
||||
// Sub-menu items for System Settings
|
||||
subItems: [
|
||||
{
|
||||
key: "general",
|
||||
label: "General",
|
||||
description: "Platform basic configuration",
|
||||
},
|
||||
{
|
||||
key: "login-settings",
|
||||
label: "Login Settings",
|
||||
description: "Configure authentication methods",
|
||||
},
|
||||
{
|
||||
key: "homepage",
|
||||
label: "Homepage",
|
||||
description: "Homepage content and theme settings",
|
||||
},
|
||||
{
|
||||
key: "about-page",
|
||||
label: "About Page",
|
||||
description: "About page content configuration",
|
||||
},
|
||||
{
|
||||
key: "email-admin",
|
||||
label: "Email & Admin",
|
||||
description: "Email and administrator settings",
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
@@ -104,8 +134,10 @@ const ConsoleContent: React.FC = () => {
|
||||
}
|
||||
}, [admin_token, router]);
|
||||
|
||||
const handleTabNavigate = (tab: TabKey) => {
|
||||
const handleTabNavigate = (tab: TabKey, subTab?: string) => {
|
||||
setActiveTab(tab);
|
||||
setActiveSubTab(subTab || _DefaultSubTab);
|
||||
|
||||
// update url params
|
||||
if (tab === TabKey.CONSOLE) {
|
||||
// when switch to dashboard, clear all query params, only keep base path
|
||||
@@ -114,6 +146,12 @@ const ConsoleContent: React.FC = () => {
|
||||
// other tabs set corresponding tab params
|
||||
const params = new URLSearchParams();
|
||||
params.set("tab", tab);
|
||||
|
||||
// add subtab parameter if provided
|
||||
if (subTab) {
|
||||
params.set("subtab", subTab);
|
||||
}
|
||||
|
||||
router.push(`/console?${params.toString()}`, { scroll: false });
|
||||
}
|
||||
};
|
||||
@@ -151,23 +189,15 @@ const ConsoleContent: React.FC = () => {
|
||||
<PaymentChannelsContent />
|
||||
</DashboardDemoContent>
|
||||
);
|
||||
case "login-settings":
|
||||
return (
|
||||
<DashboardDemoContent
|
||||
title={t("Login Settings")}
|
||||
description={t("Configure authentication methods")}
|
||||
>
|
||||
<LoginSettingsContent onTabNavigate={handleTabNavigate} />
|
||||
</DashboardDemoContent>
|
||||
);
|
||||
case "system-settings":
|
||||
return (
|
||||
<DashboardDemoContent
|
||||
title={t("System Settings")}
|
||||
description={t("Platform basic configuration")}
|
||||
>
|
||||
<SystemSettingsContent />
|
||||
</DashboardDemoContent>
|
||||
<SystemSettingsContent
|
||||
activeSubTab={activeSubTab}
|
||||
subTab={sidebarItems
|
||||
.find((item) => item.key === activeTab)
|
||||
?.subItems?.find((item) => item.key === activeSubTab)}
|
||||
onTabNavigate={handleTabNavigate}
|
||||
/>
|
||||
);
|
||||
default:
|
||||
return (
|
||||
@@ -185,25 +215,12 @@ const ConsoleContent: React.FC = () => {
|
||||
<div className="min-h-screen bg-background">
|
||||
<div className="flex">
|
||||
{/* Sidebar */}
|
||||
<DashboardSidebar
|
||||
<ConsoleSidebar
|
||||
activeTab={activeTab}
|
||||
activeSubTab={activeSubTab}
|
||||
onTabNavigate={handleTabNavigate}
|
||||
onLogout={handleLogout}
|
||||
sidebarItems={sidebarItems}
|
||||
bottomPanel={
|
||||
<Button
|
||||
variant="light"
|
||||
startContent={<FaDiscord className="w-5 h-5" />}
|
||||
className="w-full justify-start h-auto p-3"
|
||||
onPress={() => {
|
||||
window.open("https://discord.gg/cyZfcdCXkW", "_blank");
|
||||
}}
|
||||
>
|
||||
<div className="flex justify-between items-center w-full">
|
||||
<span className="font-medium">{t("Discord")}</span>
|
||||
</div>
|
||||
</Button>
|
||||
}
|
||||
/>
|
||||
|
||||
{/* Main Content */}
|
||||
|
||||
@@ -1,46 +1,56 @@
|
||||
'use client';
|
||||
"use client";
|
||||
|
||||
import React from 'react';
|
||||
import { StripeConfigForm } from './StripeConfigForm';
|
||||
import { useTranslation } from "@/shared/lib/useTranslation";
|
||||
import React from "react";
|
||||
import { StripeConfigForm } from "../payment/StripeConfigForm";
|
||||
import { AlipayConfigForm } from "../payment/AlipayConfigForm";
|
||||
import { WechatConfigForm } from "../payment/WechatConfigForm";
|
||||
import { usePaymentChannelManagement } from "@/hooks/usePaymentChannelManagement";
|
||||
import { StripeConfig } from "@/types/payment";
|
||||
import { toast } from "react-hot-toast";
|
||||
|
||||
export const PaymentChannelsContent: React.FC = () => {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const {
|
||||
stripeConfig,
|
||||
isSaving,
|
||||
alipayConfig,
|
||||
wechatConfig,
|
||||
isWechatSaving,
|
||||
isStripeSaving,
|
||||
isAlipaySaving,
|
||||
saveStripeConfig,
|
||||
testStripeConnection,
|
||||
saveAlipayConfig,
|
||||
saveWechatConfig,
|
||||
enableChannel,
|
||||
disableChannel,
|
||||
} = usePaymentChannelManagement();
|
||||
|
||||
|
||||
// test stripe connection
|
||||
const handleTestStripeConnection = async (config: StripeConfig) => {
|
||||
const result = await testStripeConnection(config);
|
||||
|
||||
if (result.success) {
|
||||
toast.success(t("Stripe connection test successful"));
|
||||
} else {
|
||||
toast.error(result.message || t("Stripe connection test failed"));
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="space-y-6 w-full">
|
||||
{/* stripe configuration */}
|
||||
<StripeConfigForm
|
||||
config={stripeConfig}
|
||||
onSave={saveStripeConfig}
|
||||
onTest={handleTestStripeConnection}
|
||||
isLoading={isSaving}
|
||||
isTestLoading={false}
|
||||
onEnable={enableChannel}
|
||||
onDisable={disableChannel}
|
||||
isLoading={isStripeSaving}
|
||||
/>
|
||||
{/* coming soon */}
|
||||
{/* alipay configuration */}
|
||||
{/* <AlipayConfigForm
|
||||
config={alipayConfig}
|
||||
onSave={saveAlipayConfig}
|
||||
onEnable={enableChannel}
|
||||
onDisable={disableChannel}
|
||||
isLoading={isAlipaySaving}
|
||||
/> */}
|
||||
{/* coming soon */}
|
||||
{/* wechat configuration */}
|
||||
{/* <WechatConfigForm
|
||||
config={wechatConfig}
|
||||
onSave={saveWechatConfig}
|
||||
onEnable={enableChannel}
|
||||
onDisable={disableChannel}
|
||||
isLoading={isWechatSaving}
|
||||
/> */}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default PaymentChannelsContent;
|
||||
export default PaymentChannelsContent;
|
||||
@@ -0,0 +1,161 @@
|
||||
"use client";
|
||||
|
||||
import React from "react";
|
||||
import { useTranslation } from "@/shared/lib/useTranslation";
|
||||
import { Button, Divider, Link, Tooltip } from "@nextui-org/react";
|
||||
import { LogOut } from "lucide-react";
|
||||
import { DashboardSidebarProps } from "@/shared/types/dashboard";
|
||||
import { DynamicLogo } from "@/shared/components/DynamicLogo";
|
||||
import { FaDiscord } from "react-icons/fa";
|
||||
|
||||
const ConsoleSidebar: React.FC<DashboardSidebarProps> = ({
|
||||
activeTab,
|
||||
activeSubTab,
|
||||
onTabNavigate,
|
||||
onLogout,
|
||||
sidebarItems,
|
||||
}) => {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const handleSubItemClick = (parentKey: string, subKey: string) => {
|
||||
onTabNavigate?.(parentKey as any, subKey);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="flex h-screen">
|
||||
{/* Main Sidebar */}
|
||||
<div className="py-2 px-2 w-[70px] overflow-hidden border-r border-divider flex flex-col justify-between">
|
||||
{/* Header */}
|
||||
<div className="mb-6 mt-4 flex flex-col items-center gap-2">
|
||||
<Link href={process.env.NEXT_PUBLIC_DOMAIN || "/"}>
|
||||
<DynamicLogo
|
||||
alt="Platform Logo"
|
||||
className="max-w-full h-auto max-h-[30px]"
|
||||
/>
|
||||
</Link>
|
||||
</div>
|
||||
|
||||
{/* Navigation */}
|
||||
<div className="flex flex-col gap-2 flex-1">
|
||||
{sidebarItems.map((item) => (
|
||||
<React.Fragment key={item.key}>
|
||||
<Tooltip
|
||||
content={t(item.label)}
|
||||
closeDelay={0}
|
||||
disableAnimation
|
||||
placement="right"
|
||||
>
|
||||
<Button
|
||||
key={item.key}
|
||||
variant={activeTab === item.key ? "flat" : "light"}
|
||||
color={activeTab === item.key ? "primary" : "default"}
|
||||
startContent={item.icon}
|
||||
className="w-full h-auto p-4"
|
||||
onPress={() => onTabNavigate?.(item.key)}
|
||||
isIconOnly
|
||||
></Button>
|
||||
</Tooltip>
|
||||
</React.Fragment>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<Divider className="my-2" />
|
||||
|
||||
<div className="space-y-2">
|
||||
<Tooltip
|
||||
content={t("Discord")}
|
||||
closeDelay={0}
|
||||
disableAnimation
|
||||
placement="right"
|
||||
>
|
||||
<Button
|
||||
variant="light"
|
||||
startContent={<FaDiscord size={18} />}
|
||||
className="w-full h-auto p-4"
|
||||
onPress={() => {
|
||||
window.open("https://discord.gg/cyZfcdCXkW", "_blank");
|
||||
}}
|
||||
isIconOnly
|
||||
></Button>
|
||||
</Tooltip>
|
||||
|
||||
{/* Logout */}
|
||||
<Tooltip
|
||||
content={t("Log Out")}
|
||||
closeDelay={0}
|
||||
disableAnimation
|
||||
placement="right"
|
||||
>
|
||||
<Button
|
||||
variant="light"
|
||||
color="danger"
|
||||
startContent={<LogOut size={18} />}
|
||||
className="w-full h-auto p-4"
|
||||
onPress={onLogout}
|
||||
isIconOnly
|
||||
></Button>
|
||||
</Tooltip>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Sub Menu Panel */}
|
||||
{(() => {
|
||||
const activeItem = sidebarItems.find((item) => item.key === activeTab);
|
||||
if (!activeItem?.subItems?.length) return null;
|
||||
|
||||
return (
|
||||
<div className="relative bg-content2/50 border-r overflow-hidden w-[240px] p-3">
|
||||
<div className="mb-3 pb-2 border-b">
|
||||
<h4 className="font-medium text-sm text-default-700">
|
||||
{t(activeItem.label)}
|
||||
</h4>
|
||||
<p className="text-xs text-default-500 mt-1">
|
||||
{t(activeItem.description)}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="space-y-1">
|
||||
{activeItem.subItems?.map((subItem) => {
|
||||
const isSubActive = activeSubTab === subItem.key;
|
||||
|
||||
return (
|
||||
<React.Fragment key={subItem.key}>
|
||||
<Button
|
||||
key={subItem.key}
|
||||
variant={isSubActive ? "flat" : "light"}
|
||||
color={isSubActive ? "primary" : "default"}
|
||||
size="sm"
|
||||
className={`w-full justify-start h-auto p-2 text-left ${
|
||||
isSubActive
|
||||
? "bg-primary/10 border border-primary/20"
|
||||
: "hover:bg-default-100"
|
||||
}`}
|
||||
onPress={() =>
|
||||
handleSubItemClick(activeItem.key, subItem.key)
|
||||
}
|
||||
>
|
||||
<div className="flex flex-col items-start w-full">
|
||||
<div className="font-medium text-xs">
|
||||
{t(subItem.label)}
|
||||
</div>
|
||||
{subItem.description && (
|
||||
<div className="text-xs opacity-60 mt-0.5 truncate w-full">
|
||||
{t(subItem.description)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</Button>
|
||||
</React.Fragment>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})()}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default ConsoleSidebar;
|
||||
@@ -1,121 +0,0 @@
|
||||
'use client';
|
||||
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { Input, Button, AccordionItem, Accordion } from '@nextui-org/react';
|
||||
import { Eye, EyeOff } from 'lucide-react';
|
||||
import { StripeConfig } from '@/types/payment';
|
||||
import { useTranslation } from "@/shared/lib/useTranslation";
|
||||
|
||||
interface StripeConfigFormProps {
|
||||
config: StripeConfig;
|
||||
onSave: (config: StripeConfig) => void;
|
||||
onTest: (config: StripeConfig) => void;
|
||||
isLoading?: boolean;
|
||||
isTestLoading?: boolean;
|
||||
}
|
||||
|
||||
export const StripeConfigForm: React.FC<StripeConfigFormProps> = ({
|
||||
config,
|
||||
onSave,
|
||||
isLoading = false,
|
||||
}) => {
|
||||
const { t } = useTranslation();
|
||||
const [formData, setFormData] = useState<StripeConfig>(config);
|
||||
const [showSecretKey, setShowSecretKey] = useState(false);
|
||||
const [showWebhookSecret, setShowWebhookSecret] = useState(false);
|
||||
useEffect(() => {
|
||||
console.log("config", config);
|
||||
setFormData(config);
|
||||
}, [config]);
|
||||
|
||||
const handleInputChange = (field: keyof StripeConfig, value: string) => {
|
||||
setFormData(prev => ({
|
||||
...prev,
|
||||
[field]: value
|
||||
}));
|
||||
};
|
||||
|
||||
const handleSave = () => {
|
||||
onSave(formData);
|
||||
};
|
||||
|
||||
|
||||
const isFormValid = formData.secret.trim() !== '' && formData.webhook_secret.trim() !== '';
|
||||
|
||||
return (
|
||||
<Accordion variant='splitted' itemClasses={{
|
||||
base: 'shadow-none border-1',
|
||||
}} defaultExpandedKeys={['stripe-config']} className='px-0'>
|
||||
<AccordionItem key="stripe-config" title={
|
||||
<div className="flex flex-col justify-between">
|
||||
<h3 className="text-lg font-semibold">{t('Stripe Configuration')}</h3>
|
||||
<p className="text-sm text-gray-500">{t('Configure Stripe payment interface')}</p>
|
||||
</div>
|
||||
} >
|
||||
<div className="space-y-4">
|
||||
{/* Secret Key */}
|
||||
<Input
|
||||
label={t('Secret Key')}
|
||||
placeholder="sk_test_... or sk_live_..."
|
||||
description={t('Stripe secret key for server-side API calls')}
|
||||
value={formData.secret}
|
||||
onChange={(e) => handleInputChange('secret', e.target.value)}
|
||||
type={showSecretKey ? "text" : "password"}
|
||||
endContent={
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setShowSecretKey(!showSecretKey)}
|
||||
className="focus:outline-none"
|
||||
>
|
||||
{showSecretKey ? (
|
||||
<EyeOff className="w-4 h-4 text-gray-400" />
|
||||
) : (
|
||||
<Eye className="w-4 h-4 text-gray-400" />
|
||||
)}
|
||||
</button>
|
||||
}
|
||||
isRequired
|
||||
/>
|
||||
|
||||
{/* Webhook Secret (Optional) */}
|
||||
<Input
|
||||
label={t('Webhook Secret')}
|
||||
placeholder="whsec_..."
|
||||
description={t('Webhook signing secret for verifying Stripe events')}
|
||||
value={formData.webhook_secret || ''}
|
||||
onChange={(e) => handleInputChange('webhook_secret', e.target.value)}
|
||||
type={showWebhookSecret ? "text" : "password"}
|
||||
isRequired
|
||||
endContent={
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setShowWebhookSecret(!showWebhookSecret)}
|
||||
className="focus:outline-none"
|
||||
>
|
||||
{showWebhookSecret ? (
|
||||
<EyeOff className="w-4 h-4 text-gray-400" />
|
||||
) : (
|
||||
<Eye className="w-4 h-4 text-gray-400" />
|
||||
)}
|
||||
</button>
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Action Buttons */}
|
||||
<div className="flex gap-3 py-4">
|
||||
<Button
|
||||
color="primary"
|
||||
variant="solid"
|
||||
onPress={handleSave}
|
||||
isLoading={isLoading}
|
||||
isDisabled={!isFormValid}
|
||||
size='sm'
|
||||
>
|
||||
{t('Save')}
|
||||
</Button>
|
||||
</div>
|
||||
</AccordionItem>
|
||||
</Accordion>
|
||||
);
|
||||
};
|
||||
@@ -1,18 +1,33 @@
|
||||
"use client";
|
||||
|
||||
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 { HomepageSettings } from "@/components/system-setting/HomepageSettings";
|
||||
import { AboutPageSettings } from "@/components/system-setting/AboutPageSettings";
|
||||
import { EmailAndAdminSettings } from "@/components/system-setting/EmailAndAdminSettings";
|
||||
import { useSystemConfigManagement } from "@/hooks/useSystemConfigManagement";
|
||||
import { usePlatformConfig } from "@/shared/contexts/PlatformConfigContext";
|
||||
import { Theme } from "@/shared/types/system";
|
||||
import i18n from "@/shared/lib/i18n";
|
||||
import { PlatformConfigForm } from "../system-setting/PlatformConfigForm";
|
||||
import DashboardDemoContent from "@/shared/components/DashboardDemoContent";
|
||||
import { useTranslation } from "@/shared/lib/useTranslation";
|
||||
import { SidebarSubItem, TabKey } from "@/shared/types/dashboard";
|
||||
import { LoginSettingsContent } from "./LoginSettingsContent";
|
||||
|
||||
export const SystemSettingsContent: React.FC = () => {
|
||||
interface SystemSettingsContentProps {
|
||||
activeSubTab?: string;
|
||||
subTab?: SidebarSubItem;
|
||||
onTabNavigate: (tab: TabKey, subTab?: string) => void;
|
||||
}
|
||||
|
||||
export const SystemSettingsContent: React.FC<SystemSettingsContentProps> = ({
|
||||
activeSubTab,
|
||||
subTab,
|
||||
onTabNavigate,
|
||||
}) => {
|
||||
const { updateClientConfig } = usePlatformConfig();
|
||||
const [isAboutLoading, setIsAboutLoading] = useState(false);
|
||||
|
||||
const { t } = useTranslation();
|
||||
const {
|
||||
// platform config
|
||||
platformConfig,
|
||||
@@ -31,6 +46,10 @@ export const SystemSettingsContent: React.FC = () => {
|
||||
|
||||
// image upload
|
||||
uploadImage,
|
||||
|
||||
// login config
|
||||
loginConfig,
|
||||
saveLoginConfig,
|
||||
} = useSystemConfigManagement();
|
||||
|
||||
// save admin config
|
||||
@@ -77,33 +96,60 @@ export const SystemSettingsContent: React.FC = () => {
|
||||
});
|
||||
};
|
||||
|
||||
// Render content based on active sub tab
|
||||
const renderSubTabContent = () => {
|
||||
switch (activeSubTab) {
|
||||
case "homepage":
|
||||
return <HomepageSettings />;
|
||||
case "about-page":
|
||||
return (
|
||||
<AboutPageSettings
|
||||
config={platformConfig}
|
||||
onAboutSave={handleAboutSave}
|
||||
onImageUpload={uploadImage}
|
||||
isAboutLoading={isAboutLoading}
|
||||
/>
|
||||
);
|
||||
case "email-admin":
|
||||
return (
|
||||
<EmailAndAdminSettings
|
||||
emailConfig={emailConfig}
|
||||
adminConfig={adminConfig}
|
||||
onSaveEmailConfig={handleSaveEmailConfig}
|
||||
onSaveAdminConfig={handleSaveAdminConfig}
|
||||
isLoading={emailLoading}
|
||||
isAdminLoading={adminLoading}
|
||||
/>
|
||||
);
|
||||
case "login-settings":
|
||||
return (
|
||||
<LoginSettingsContent
|
||||
onTabNavigate={onTabNavigate}
|
||||
loginConfig={loginConfig}
|
||||
saveLoginConfig={saveLoginConfig}
|
||||
emailConfig={emailConfig}
|
||||
/>
|
||||
);
|
||||
case "general":
|
||||
default:
|
||||
return (
|
||||
<PlatformConfigForm
|
||||
config={platformConfig}
|
||||
onSave={handleSavePlatformConfig}
|
||||
onThemeChange={handleThemeChange}
|
||||
isLoading={platformLoading}
|
||||
/>
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="space-y-6 w-full">
|
||||
{/* platform config */}
|
||||
<PlatformConfigForm
|
||||
config={platformConfig}
|
||||
onSave={handleSavePlatformConfig}
|
||||
onThemeChange={handleThemeChange}
|
||||
onAboutSave={handleAboutSave}
|
||||
isLoading={platformLoading}
|
||||
isAboutLoading={isAboutLoading}
|
||||
onImageUpload={uploadImage}
|
||||
/>
|
||||
|
||||
{/* admin config */}
|
||||
<AdminConfigForm
|
||||
config={adminConfig}
|
||||
onSave={handleSaveAdminConfig}
|
||||
isLoading={adminLoading}
|
||||
/>
|
||||
|
||||
{/* email config */}
|
||||
<EmailConfigForm
|
||||
config={emailConfig}
|
||||
onSave={handleSaveEmailConfig}
|
||||
isLoading={emailLoading}
|
||||
/>
|
||||
</div>
|
||||
<DashboardDemoContent
|
||||
title={t(subTab?.label || "System Settings")}
|
||||
description={t(subTab?.description || "Platform basic configuration")}
|
||||
>
|
||||
{renderSubTabContent()}
|
||||
</DashboardDemoContent>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ const DashboardContent: React.FC = () => {
|
||||
state.user_token,
|
||||
state.user,
|
||||
]);
|
||||
const { loginConfig } = usePlatformConfig();
|
||||
const { loginConfig, paymentChannels } = usePlatformConfig();
|
||||
|
||||
const [logOut, useGetUser] = useGlobalStore((state) => [
|
||||
state.logOut,
|
||||
@@ -163,14 +163,16 @@ const DashboardContent: React.FC = () => {
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<Button
|
||||
variant="bordered"
|
||||
onPress={handleRecharge}
|
||||
aria-label="Recharge wallet"
|
||||
size="sm"
|
||||
>
|
||||
{t("Recharge")}
|
||||
</Button>
|
||||
{paymentChannels.length > 0 && (
|
||||
<Button
|
||||
variant="bordered"
|
||||
onPress={handleRecharge}
|
||||
aria-label="Recharge wallet"
|
||||
size="sm"
|
||||
>
|
||||
{t("Recharge")}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</CardBody>
|
||||
</Card>
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
"use client";
|
||||
|
||||
import React from "react";
|
||||
import { Accordion, AccordionItem } from "@nextui-org/react";
|
||||
import { Plus } from "lucide-react";
|
||||
import { useTranslation } from "@/shared/lib/useTranslation";
|
||||
import { usePlatformConfig } from "@/shared/contexts/PlatformConfigContext";
|
||||
|
||||
function FaqClient() {
|
||||
const { faqItems } = usePlatformConfig();
|
||||
const { t } = useTranslation();
|
||||
// Custom indicator component with plus sign that fades out when expanded
|
||||
const CustomIndicator = ({ isOpen }: { isOpen?: boolean }) => (
|
||||
<Plus
|
||||
className={`text-black transition-all duration-300 ${
|
||||
isOpen ? "rotate-0 opacity-0" : "rotate-0 opacity-100"
|
||||
}`}
|
||||
size={16}
|
||||
/>
|
||||
);
|
||||
if (faqItems.length === 0) return null;
|
||||
|
||||
return (
|
||||
<section className="py-12 sm:py-20 px-4 sm:px-6" id="faqs">
|
||||
<div className="max-w-7xl mx-auto">
|
||||
<h2 className="text-2xl sm:text-3xl font-bold mb-8 sm:mb-12 text-center">
|
||||
{t("FAQs")}
|
||||
</h2>
|
||||
{/**content */}
|
||||
<div className="relative bg-white rounded-lg">
|
||||
<Accordion variant="light">
|
||||
{faqItems.map((faq, index) => (
|
||||
<AccordionItem
|
||||
key={index}
|
||||
aria-label={faq.question}
|
||||
title={
|
||||
<span className="text-base sm:text-lg font-medium">
|
||||
{faq.question}
|
||||
</span>
|
||||
}
|
||||
className="pt-2 px-2"
|
||||
indicator={({ isOpen }) => <CustomIndicator isOpen={isOpen} />}
|
||||
>
|
||||
<div className="text-sm sm:text-base text-foreground-600 leading-relaxed space-y-2">
|
||||
{faq.answer}
|
||||
</div>
|
||||
</AccordionItem>
|
||||
))}
|
||||
</Accordion>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
export function Faq() {
|
||||
return <FaqClient />;
|
||||
}
|
||||
@@ -66,9 +66,9 @@ export const BasicInfoTab: React.FC<BasicInfoTabProps> = ({
|
||||
onInputChange('auth_token', '');
|
||||
}}
|
||||
>
|
||||
<SelectItem key="none" value={AuthMethod.None}>{t('None')}</SelectItem>
|
||||
<SelectItem key="apikey" value={AuthMethod.APIKey}>{t('API Key')}</SelectItem>
|
||||
<SelectItem key="token" value={AuthMethod.BearerToken}>{t('Bearer Token')}</SelectItem>
|
||||
<SelectItem key="none" value="none">{t('None')}</SelectItem>
|
||||
<SelectItem key="apikey" value="apikey">{t('API Key')}</SelectItem>
|
||||
<SelectItem key="token" value="token">{t('Bearer Token')}</SelectItem>
|
||||
</Select>
|
||||
|
||||
{/* auth config input fields */}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
"use client";
|
||||
|
||||
import React from 'react';
|
||||
import { useTranslation } from '@/shared/lib/useTranslation';
|
||||
import { MCPServiceFormData } from '@/types/mcp-service';
|
||||
import dynamic from 'next/dynamic';
|
||||
import React from "react";
|
||||
import { useTranslation } from "@/shared/lib/useTranslation";
|
||||
import { MCPServiceFormData } from "@/types/mcp-service";
|
||||
import dynamic from "next/dynamic";
|
||||
|
||||
// dynamic import MDEditor to avoid SSR problem
|
||||
const MDEditor = dynamic(
|
||||
() => import('@uiw/react-md-editor').then((mod) => mod.default),
|
||||
() => import("@uiw/react-md-editor").then((mod) => mod.default),
|
||||
{ ssr: false }
|
||||
);
|
||||
|
||||
@@ -18,29 +18,30 @@ interface DescriptionTabProps {
|
||||
|
||||
export const DescriptionTab: React.FC<DescriptionTabProps> = ({
|
||||
formData,
|
||||
onInputChange
|
||||
onInputChange,
|
||||
}) => {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const handleMarkdownChange = (value?: string) => {
|
||||
onInputChange('long_description', value || '');
|
||||
onInputChange("long_description", value || "");
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="space-y-4 h-full">
|
||||
<div className="w-full h-full">
|
||||
<MDEditor
|
||||
value={formData.long_description || ''}
|
||||
value={formData.long_description || ""}
|
||||
onChange={handleMarkdownChange}
|
||||
preview="live"
|
||||
hideToolbar={false}
|
||||
visibleDragbar={true}
|
||||
textareaProps={{
|
||||
placeholder: t('Detailed description of the service (supports Markdown)'),
|
||||
placeholder: t("Detailed description of the service"),
|
||||
style: {
|
||||
fontSize: 14,
|
||||
lineHeight: 1.5,
|
||||
fontFamily: 'ui-monospace, SFMono-Regular, "SF Mono", Consolas, "Liberation Mono", Menlo, monospace',
|
||||
fontFamily:
|
||||
'ui-monospace, SFMono-Regular, "SF Mono", Consolas, "Liberation Mono", Menlo, monospace',
|
||||
},
|
||||
}}
|
||||
height="100%"
|
||||
@@ -49,4 +50,4 @@ export const DescriptionTab: React.FC<DescriptionTabProps> = ({
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
};
|
||||
@@ -1,15 +1,11 @@
|
||||
"use client";
|
||||
|
||||
import React from 'react';
|
||||
import {
|
||||
Input,
|
||||
Select,
|
||||
SelectItem,
|
||||
} from '@nextui-org/react';
|
||||
import { useTranslation } from '@/shared/lib/useTranslation';
|
||||
import { MCPServiceFormData } from '@/types/mcp-service';
|
||||
import { getCurrencySymbol } from '@/shared/utils/currency';
|
||||
import { ChargeType } from '@/shared/types/marketplace';
|
||||
import React from "react";
|
||||
import { Input, Select, SelectItem } from "@nextui-org/react";
|
||||
import { useTranslation } from "@/shared/lib/useTranslation";
|
||||
import { MCPServiceFormData } from "@/types/mcp-service";
|
||||
import { getCurrencySymbol } from "@/shared/utils/currency";
|
||||
import { ChargeType } from "@/shared/types/marketplace";
|
||||
|
||||
interface PricingTabProps {
|
||||
formData: MCPServiceFormData;
|
||||
@@ -18,52 +14,111 @@ interface PricingTabProps {
|
||||
|
||||
export const PricingTab: React.FC<PricingTabProps> = ({
|
||||
formData,
|
||||
onInputChange
|
||||
onInputChange,
|
||||
}) => {
|
||||
const { t } = useTranslation();
|
||||
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<Select
|
||||
label={t('Charge Type')}
|
||||
label={t("Charge Type")}
|
||||
selectedKeys={formData.charge_type ? [formData.charge_type] : []}
|
||||
onSelectionChange={(keys) => {
|
||||
const selectedKey = Array.from(keys)[0] as string;
|
||||
onInputChange('charge_type', selectedKey);
|
||||
onInputChange("charge_type", selectedKey);
|
||||
}}
|
||||
renderValue={() => {
|
||||
const selectedKey = formData.charge_type || ChargeType.PerCall;
|
||||
if (selectedKey === ChargeType.Free) return t('Free');
|
||||
return t(selectedKey === ChargeType.PerCall ? 'Per Call' : 'Per Token');
|
||||
if (selectedKey === ChargeType.Free) return t("Free");
|
||||
return t(
|
||||
selectedKey === ChargeType.PerCall
|
||||
? "Per Call"
|
||||
: "Per Million Tokens"
|
||||
);
|
||||
}}
|
||||
>
|
||||
<SelectItem key="free" value={ChargeType.Free}>
|
||||
<div className="flex flex-col">
|
||||
<span>{t('Free')}</span>
|
||||
<span className="text-xs text-gray-500">{t('No charge for API calls')}</span>
|
||||
<span>{t("Free")}</span>
|
||||
<span className="text-xs text-gray-500">
|
||||
{t("No charge for API calls")}
|
||||
</span>
|
||||
</div>
|
||||
</SelectItem>
|
||||
<SelectItem key="per_call" value={ChargeType.PerCall}>
|
||||
<div className="flex flex-col">
|
||||
<span>{t('Per Call')}</span>
|
||||
<span className="text-xs text-gray-500">{t('Fixed price per API call')}</span>
|
||||
<span>{t("Per Call")}</span>
|
||||
<span className="text-xs text-gray-500">
|
||||
{t("Fixed price per API call")}
|
||||
</span>
|
||||
</div>
|
||||
</SelectItem>
|
||||
|
||||
<SelectItem key="per_token" value={ChargeType.PerToken}>
|
||||
<div className="flex flex-col">
|
||||
<span>{t("Per Million Tokens")}</span>
|
||||
<span className="text-xs text-gray-500">
|
||||
{t("Price per million tokens consumed")}
|
||||
</span>
|
||||
</div>
|
||||
</SelectItem>
|
||||
</Select>
|
||||
|
||||
{formData.charge_type !== ChargeType.Free && (
|
||||
<Input
|
||||
label={t('Price')}
|
||||
type="number"
|
||||
min="0"
|
||||
step="0.01"
|
||||
value={formData.price || ''}
|
||||
onChange={(e) => onInputChange('price', e.target.value)}
|
||||
description={t('Price per unit (call or token)')}
|
||||
startContent={<span className="text-gray-500 leading-[20px]">{getCurrencySymbol()}</span>}
|
||||
/>
|
||||
<>
|
||||
{formData.charge_type === ChargeType.PerToken ? (
|
||||
<div className="flex gap-2">
|
||||
<Input
|
||||
type="number"
|
||||
step="0.01"
|
||||
min="0"
|
||||
label={t("Input Token Price")}
|
||||
value={formData.input_token_price || ""}
|
||||
onChange={(e) =>
|
||||
onInputChange("input_token_price", e.target.value)
|
||||
}
|
||||
placeholder={t("Price per million input tokens")}
|
||||
startContent={
|
||||
<span className="text-gray-500 leading-[20px]">
|
||||
{getCurrencySymbol()}
|
||||
</span>
|
||||
}
|
||||
/>
|
||||
<Input
|
||||
type="number"
|
||||
step="0.01"
|
||||
min="0"
|
||||
label={t("Output Token Price")}
|
||||
value={formData.output_token_price || ""}
|
||||
onChange={(e) =>
|
||||
onInputChange("output_token_price", e.target.value)
|
||||
}
|
||||
placeholder={t("Price per million output tokens")}
|
||||
startContent={
|
||||
<span className="text-gray-500 leading-[20px]">
|
||||
{getCurrencySymbol()}
|
||||
</span>
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
) : (
|
||||
<Input
|
||||
label={t("Price")}
|
||||
type="number"
|
||||
min="0"
|
||||
step="0.01"
|
||||
value={formData.price || ""}
|
||||
onChange={(e) => onInputChange("price", e.target.value)}
|
||||
description={t("Price per API call")}
|
||||
startContent={
|
||||
<span className="text-gray-500 leading-[20px]">
|
||||
{getCurrencySymbol()}
|
||||
</span>
|
||||
}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
};
|
||||
@@ -1,10 +1,10 @@
|
||||
"use client";
|
||||
|
||||
import React from 'react';
|
||||
import { Input, Select, SelectItem, Button } from '@nextui-org/react';
|
||||
import { useTranslation } from '@/shared/lib/useTranslation';
|
||||
import { ServiceFilters } from '@/types/mcp-service';
|
||||
import { Search, Plus } from 'lucide-react';
|
||||
import React from "react";
|
||||
import { Input, Select, SelectItem, Button } from "@nextui-org/react";
|
||||
import { useTranslation } from "@/shared/lib/useTranslation";
|
||||
import { ServiceFilters } from "@/types/mcp-service";
|
||||
import { Search, Plus } from "lucide-react";
|
||||
|
||||
interface ServiceFiltersBarProps {
|
||||
filters: ServiceFilters;
|
||||
@@ -16,7 +16,7 @@ interface ServiceFiltersBarProps {
|
||||
export const ServiceFiltersBar: React.FC<ServiceFiltersBarProps> = ({
|
||||
filters,
|
||||
onFiltersChange,
|
||||
onImportOpenAPI
|
||||
onImportOpenAPI,
|
||||
}) => {
|
||||
const { t } = useTranslation();
|
||||
|
||||
@@ -24,20 +24,20 @@ export const ServiceFiltersBar: React.FC<ServiceFiltersBarProps> = ({
|
||||
onFiltersChange({ ...filters, search: value });
|
||||
};
|
||||
|
||||
|
||||
const handleStatusChange = (value: string) => {
|
||||
onFiltersChange({ ...filters, status: value });
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="flex flex-col sm:flex-row gap-4 mb-6">
|
||||
<div className="flex flex-col sm:flex-row gap-4">
|
||||
<div className="flex-1">
|
||||
<Button
|
||||
color="primary"
|
||||
onPress={onImportOpenAPI}
|
||||
startContent={<Plus size={16} />}
|
||||
size="sm"
|
||||
>
|
||||
{t('Add Service')}
|
||||
{t("Add Service")}
|
||||
</Button>
|
||||
{/* <Input
|
||||
placeholder={t('Search services...')}
|
||||
@@ -74,10 +74,7 @@ export const ServiceFiltersBar: React.FC<ServiceFiltersBarProps> = ({
|
||||
</SelectItem>
|
||||
))}
|
||||
</Select> */}
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
};
|
||||
@@ -1,6 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import React from 'react';
|
||||
import React from "react";
|
||||
import {
|
||||
Table,
|
||||
TableHeader,
|
||||
@@ -12,19 +12,19 @@ import {
|
||||
Button,
|
||||
Tooltip,
|
||||
Pagination,
|
||||
Spinner
|
||||
} from '@nextui-org/react';
|
||||
import { useTranslation } from '@/shared/lib/useTranslation';
|
||||
import { EnabledEnum, MCPService } from '@/types/mcp-service';
|
||||
Spinner,
|
||||
} from "@nextui-org/react";
|
||||
import { useTranslation } from "@/shared/lib/useTranslation";
|
||||
import { EnabledEnum, MCPService } from "@/types/mcp-service";
|
||||
import {
|
||||
Trash2,
|
||||
Zap,
|
||||
PencilIcon,
|
||||
CircleCheckIcon,
|
||||
BanIcon,
|
||||
} from 'lucide-react';
|
||||
import { ChargeType } from '@/shared/types/marketplace';
|
||||
import { Price } from '@/shared/components/marketplace/Price';
|
||||
} from "lucide-react";
|
||||
import { ChargeType } from "@/shared/types/marketplace";
|
||||
import { Price } from "@/shared/components/marketplace/Price";
|
||||
|
||||
interface ServiceTableProps {
|
||||
services: MCPService[];
|
||||
@@ -58,22 +58,29 @@ export const ServiceTable: React.FC<ServiceTableProps> = ({
|
||||
const items = services;
|
||||
|
||||
const getStatusColor = (enabled: number) => {
|
||||
return enabled === EnabledEnum.Online ? 'success' : 'danger';
|
||||
return enabled === EnabledEnum.Online ? "success" : "danger";
|
||||
};
|
||||
|
||||
const handleEdit = React.useCallback(
|
||||
(service: MCPService) => {
|
||||
onEdit(service);
|
||||
},
|
||||
[onEdit]
|
||||
);
|
||||
|
||||
const handleEdit = React.useCallback((service: MCPService) => {
|
||||
onEdit(service);
|
||||
}, [onEdit]);
|
||||
|
||||
const handleDelete = React.useCallback((service: MCPService) => {
|
||||
onDelete(service);
|
||||
}, [onDelete]);
|
||||
|
||||
const handleToggleStatus = React.useCallback((service: MCPService) => {
|
||||
onToggleStatus(service);
|
||||
}, [onToggleStatus]);
|
||||
const handleDelete = React.useCallback(
|
||||
(service: MCPService) => {
|
||||
onDelete(service);
|
||||
},
|
||||
[onDelete]
|
||||
);
|
||||
|
||||
const handleToggleStatus = React.useCallback(
|
||||
(service: MCPService) => {
|
||||
onToggleStatus(service);
|
||||
},
|
||||
[onToggleStatus]
|
||||
);
|
||||
|
||||
if (loading && services.length === 0) {
|
||||
return (
|
||||
@@ -96,7 +103,7 @@ export const ServiceTable: React.FC<ServiceTableProps> = ({
|
||||
<div className="flex w-full justify-center">
|
||||
<Pagination
|
||||
showControls
|
||||
variant='light'
|
||||
variant="light"
|
||||
color="primary"
|
||||
page={currentPage}
|
||||
total={pages}
|
||||
@@ -107,17 +114,17 @@ export const ServiceTable: React.FC<ServiceTableProps> = ({
|
||||
}
|
||||
>
|
||||
<TableHeader>
|
||||
<TableColumn>{t('Service Name')}</TableColumn>
|
||||
<TableColumn>{t('API Endpoint')}</TableColumn>
|
||||
<TableColumn>{t('Status')}</TableColumn>
|
||||
<TableColumn>{t('Pricing')}</TableColumn>
|
||||
<TableColumn className='w-20'>{t('Actions')}</TableColumn>
|
||||
<TableColumn>{t("Service Name")}</TableColumn>
|
||||
<TableColumn>{t("API Endpoint")}</TableColumn>
|
||||
<TableColumn>{t("Status")}</TableColumn>
|
||||
<TableColumn>{t("Pricing")}</TableColumn>
|
||||
<TableColumn className="w-20">{t("Actions")}</TableColumn>
|
||||
</TableHeader>
|
||||
<TableBody
|
||||
items={items}
|
||||
isLoading={loading}
|
||||
loadingContent={<Spinner />}
|
||||
emptyContent={t('No services found')}
|
||||
emptyContent={t("No services found")}
|
||||
>
|
||||
{(service) => (
|
||||
<TableRow key={service.id}>
|
||||
@@ -134,17 +141,22 @@ export const ServiceTable: React.FC<ServiceTableProps> = ({
|
||||
size="sm"
|
||||
variant="flat"
|
||||
>
|
||||
{t(service.enabled === 1 ? 'Online' : 'Offline')}
|
||||
{t(service.enabled === 1 ? "Online" : "Offline")}
|
||||
</Chip>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<div className="flex flex-col gap-1">
|
||||
<Price price={service.price} charge_type={service.charge_type} />
|
||||
<Price
|
||||
price={service.price}
|
||||
charge_type={service.charge_type}
|
||||
input_token_price={service.input_token_price}
|
||||
output_token_price={service.output_token_price}
|
||||
/>
|
||||
</div>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<div className="relative flex items-center gap-2">
|
||||
<Tooltip content={t('Edit')} closeDelay={0}>
|
||||
<Tooltip content={t("Edit")} closeDelay={0} disableAnimation>
|
||||
<Button
|
||||
isIconOnly
|
||||
size="sm"
|
||||
@@ -155,22 +167,40 @@ export const ServiceTable: React.FC<ServiceTableProps> = ({
|
||||
</Button>
|
||||
</Tooltip>
|
||||
|
||||
<Tooltip content={service.enabled === EnabledEnum.Online ? t('Take Offline') : t('Bring Online')} closeDelay={0} >
|
||||
<Tooltip
|
||||
content={
|
||||
service.enabled === EnabledEnum.Online
|
||||
? t("Take Offline")
|
||||
: t("Bring Online")
|
||||
}
|
||||
closeDelay={0}
|
||||
disableAnimation
|
||||
>
|
||||
<Button
|
||||
isIconOnly
|
||||
size="sm"
|
||||
variant="light"
|
||||
color={service.enabled === EnabledEnum.Online ? 'danger' : 'success'}
|
||||
color={
|
||||
service.enabled === EnabledEnum.Online
|
||||
? "danger"
|
||||
: "success"
|
||||
}
|
||||
onPress={() => handleToggleStatus(service)}
|
||||
>
|
||||
{service.enabled === EnabledEnum.Online ?
|
||||
<BanIcon className="w-4 h-4" /> :
|
||||
{service.enabled === EnabledEnum.Online ? (
|
||||
<BanIcon className="w-4 h-4" />
|
||||
) : (
|
||||
<CircleCheckIcon className="w-4 h-4" />
|
||||
}
|
||||
)}
|
||||
</Button>
|
||||
</Tooltip>
|
||||
|
||||
<Tooltip content={t('Delete Service')} color="danger" closeDelay={0}>
|
||||
<Tooltip
|
||||
content={t("Delete Service")}
|
||||
color="danger"
|
||||
closeDelay={0}
|
||||
disableAnimation
|
||||
>
|
||||
<Button
|
||||
isIconOnly
|
||||
size="sm"
|
||||
@@ -189,4 +219,4 @@ export const ServiceTable: React.FC<ServiceTableProps> = ({
|
||||
</Table>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
};
|
||||
@@ -38,7 +38,8 @@ export const ToolsTab: React.FC<ToolsTabProps> = ({
|
||||
removeWrapper
|
||||
>
|
||||
<TableHeader>
|
||||
<TableColumn className='w-1/3'>{t('Tool Name')}</TableColumn>
|
||||
<TableColumn className='w-1/4'>{t('Tool Name')}</TableColumn>
|
||||
<TableColumn className='w-1/4'>{t('Tool URL')}</TableColumn>
|
||||
<TableColumn>{t('Description')}</TableColumn>
|
||||
</TableHeader>
|
||||
<TableBody emptyContent={t('No tools added yet. Add your first tool using the input above.')}>
|
||||
@@ -49,7 +50,13 @@ export const ToolsTab: React.FC<ToolsTabProps> = ({
|
||||
<TableCell>
|
||||
<Input
|
||||
value={tool.name}
|
||||
// onChange={(e) => handleToolChange(index, 'name', e.target.value)}
|
||||
size="sm"
|
||||
isDisabled
|
||||
/>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<Input
|
||||
value={tool.url}
|
||||
size="sm"
|
||||
isDisabled
|
||||
/>
|
||||
|
||||
@@ -0,0 +1,188 @@
|
||||
"use client";
|
||||
|
||||
import React, { useEffect, useState } from "react";
|
||||
import {
|
||||
Input,
|
||||
Button,
|
||||
AccordionItem,
|
||||
Accordion,
|
||||
Switch,
|
||||
} from "@nextui-org/react";
|
||||
import { Eye, EyeOff } from "lucide-react";
|
||||
import { AlipayConfig } from "@/types/payment";
|
||||
import { useTranslation } from "@/shared/lib/useTranslation";
|
||||
|
||||
interface AlipayConfigFormProps {
|
||||
config: AlipayConfig;
|
||||
onSave: (config: AlipayConfig) => void;
|
||||
onEnable: (channelId: string) => Promise<boolean>;
|
||||
onDisable: (channelId: string) => Promise<boolean>;
|
||||
isLoading?: boolean;
|
||||
}
|
||||
|
||||
export const AlipayConfigForm: React.FC<AlipayConfigFormProps> = ({
|
||||
config,
|
||||
onSave,
|
||||
onEnable,
|
||||
onDisable,
|
||||
isLoading = false,
|
||||
}) => {
|
||||
const { t } = useTranslation();
|
||||
const [formData, setFormData] = useState<AlipayConfig>(config);
|
||||
const [showAppPrivateKey, setShowAppPrivateKey] = useState(false);
|
||||
const [showAlipayPublicKey, setShowAlipayPublicKey] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
setFormData(config);
|
||||
}, [config]);
|
||||
|
||||
const handleInputChange = (
|
||||
field: keyof AlipayConfig,
|
||||
value: string | boolean
|
||||
) => {
|
||||
setFormData((prev) => ({
|
||||
...prev,
|
||||
[field]: value,
|
||||
}));
|
||||
};
|
||||
const handleEnableDisable = async (value: boolean) => {
|
||||
let result: boolean | null = null;
|
||||
if (value) {
|
||||
result = await onEnable("alipay");
|
||||
} else {
|
||||
result = await onDisable("alipay");
|
||||
}
|
||||
if (result) {
|
||||
setFormData((prev) => ({
|
||||
...prev,
|
||||
is_enabled: value,
|
||||
}));
|
||||
}
|
||||
};
|
||||
|
||||
const handleSave = () => {
|
||||
onSave(formData);
|
||||
};
|
||||
|
||||
const isFormValid =
|
||||
formData.app_id.trim() !== "" &&
|
||||
formData.app_private_key.trim() !== "" &&
|
||||
formData.alipay_public_key.trim() !== "";
|
||||
|
||||
return (
|
||||
<Accordion
|
||||
variant="splitted"
|
||||
itemClasses={{
|
||||
base: "shadow-none border-1",
|
||||
}}
|
||||
defaultExpandedKeys={["alipay-config"]}
|
||||
className="px-0"
|
||||
>
|
||||
<AccordionItem
|
||||
key="alipay-config"
|
||||
title={
|
||||
<div className="flex flex-col justify-between">
|
||||
<div className="flex items-center justify-between w-full">
|
||||
<div>
|
||||
<h3 className="text-lg font-semibold">
|
||||
{t("Alipay Configuration")}
|
||||
</h3>
|
||||
<p className="text-sm text-gray-500">
|
||||
{t("Configure Alipay payment interface")}
|
||||
</p>
|
||||
</div>
|
||||
<Switch
|
||||
isSelected={formData.is_enabled || false}
|
||||
onValueChange={handleEnableDisable}
|
||||
size="sm"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
>
|
||||
<div className="space-y-4">
|
||||
{/* App ID */}
|
||||
<Input
|
||||
label={t("App ID")}
|
||||
placeholder={t("Alipay App ID")}
|
||||
value={formData.app_id}
|
||||
onChange={(e) => handleInputChange("app_id", e.target.value)}
|
||||
isRequired
|
||||
autoComplete="off"
|
||||
isDisabled={!formData.is_enabled}
|
||||
/>
|
||||
|
||||
{/* App Private Key */}
|
||||
<Input
|
||||
label={t("App Private Key")}
|
||||
placeholder={t("Alipay App Private Key")}
|
||||
value={formData.app_private_key}
|
||||
onChange={(e) =>
|
||||
handleInputChange("app_private_key", e.target.value)
|
||||
}
|
||||
type={showAppPrivateKey ? "text" : "password"}
|
||||
endContent={
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setShowAppPrivateKey(!showAppPrivateKey)}
|
||||
className="focus:outline-none"
|
||||
>
|
||||
{showAppPrivateKey ? (
|
||||
<EyeOff className="w-4 h-4 text-gray-400" />
|
||||
) : (
|
||||
<Eye className="w-4 h-4 text-gray-400" />
|
||||
)}
|
||||
</button>
|
||||
}
|
||||
isRequired
|
||||
autoComplete="off"
|
||||
isDisabled={!formData.is_enabled}
|
||||
/>
|
||||
|
||||
{/* Alipay Public Key */}
|
||||
<Input
|
||||
label={t("Alipay Public Key")}
|
||||
placeholder={t("Alipay public key for verification")}
|
||||
value={formData.alipay_public_key || ""}
|
||||
onChange={(e) =>
|
||||
handleInputChange("alipay_public_key", e.target.value)
|
||||
}
|
||||
type={showAlipayPublicKey ? "text" : "password"}
|
||||
isRequired
|
||||
endContent={
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setShowAlipayPublicKey(!showAlipayPublicKey)}
|
||||
className="focus:outline-none"
|
||||
>
|
||||
{showAlipayPublicKey ? (
|
||||
<EyeOff className="w-4 h-4 text-gray-400" />
|
||||
) : (
|
||||
<Eye className="w-4 h-4 text-gray-400" />
|
||||
)}
|
||||
</button>
|
||||
}
|
||||
autoComplete="off"
|
||||
isDisabled={!formData.is_enabled}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Action Buttons */}
|
||||
{formData.is_enabled && (
|
||||
<div className="flex gap-3 py-4">
|
||||
<Button
|
||||
color="primary"
|
||||
variant="solid"
|
||||
onPress={handleSave}
|
||||
isLoading={isLoading}
|
||||
isDisabled={!isFormValid}
|
||||
size="sm"
|
||||
>
|
||||
{t("Save")}
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
</AccordionItem>
|
||||
</Accordion>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,177 @@
|
||||
"use client";
|
||||
|
||||
import React, { useEffect, useState } from "react";
|
||||
import {
|
||||
Input,
|
||||
Button,
|
||||
AccordionItem,
|
||||
Accordion,
|
||||
Switch,
|
||||
} from "@nextui-org/react";
|
||||
import { Eye, EyeOff } from "lucide-react";
|
||||
import { StripeConfig } from "@/types/payment";
|
||||
import { useTranslation } from "@/shared/lib/useTranslation";
|
||||
|
||||
interface StripeConfigFormProps {
|
||||
config: StripeConfig;
|
||||
onSave: (config: StripeConfig) => void;
|
||||
onEnable: (channelId: string) => Promise<boolean>;
|
||||
onDisable: (channelId: string) => Promise<boolean>;
|
||||
isLoading?: boolean;
|
||||
}
|
||||
|
||||
export const StripeConfigForm: React.FC<StripeConfigFormProps> = ({
|
||||
config,
|
||||
onSave,
|
||||
onEnable,
|
||||
onDisable,
|
||||
isLoading = false,
|
||||
}) => {
|
||||
const { t } = useTranslation();
|
||||
const [formData, setFormData] = useState<StripeConfig>(config);
|
||||
const [showSecretKey, setShowSecretKey] = useState(false);
|
||||
const [showWebhookSecret, setShowWebhookSecret] = useState(false);
|
||||
useEffect(() => {
|
||||
setFormData(config);
|
||||
}, [config]);
|
||||
|
||||
const handleInputChange = (
|
||||
field: keyof StripeConfig,
|
||||
value: string | boolean
|
||||
) => {
|
||||
setFormData((prev) => ({
|
||||
...prev,
|
||||
[field]: value,
|
||||
}));
|
||||
};
|
||||
|
||||
const handleEnableDisable = async (value: boolean) => {
|
||||
let result: boolean | null = null;
|
||||
if (value) {
|
||||
result = await onEnable("stripe");
|
||||
} else {
|
||||
result = await onDisable("stripe");
|
||||
}
|
||||
if (result) {
|
||||
setFormData((prev) => ({
|
||||
...prev,
|
||||
is_enabled: value,
|
||||
}));
|
||||
}
|
||||
};
|
||||
|
||||
const handleSave = () => {
|
||||
onSave(formData);
|
||||
};
|
||||
|
||||
const isFormValid =
|
||||
formData.secret.trim() !== "" && formData.webhook_secret.trim() !== "";
|
||||
|
||||
return (
|
||||
<Accordion
|
||||
variant="splitted"
|
||||
itemClasses={{
|
||||
base: "shadow-none border-1",
|
||||
}}
|
||||
defaultExpandedKeys={["stripe-config"]}
|
||||
className="px-0"
|
||||
>
|
||||
<AccordionItem
|
||||
key="stripe-config"
|
||||
title={
|
||||
<div className="flex flex-col justify-between">
|
||||
<div className="flex items-center justify-between w-full">
|
||||
<div>
|
||||
<h3 className="text-lg font-semibold">
|
||||
{t("Stripe Configuration")}
|
||||
</h3>
|
||||
<p className="text-sm text-gray-500">
|
||||
{t("Configure Stripe payment interface")}
|
||||
</p>
|
||||
</div>
|
||||
<Switch
|
||||
isSelected={formData.is_enabled || false}
|
||||
onValueChange={handleEnableDisable}
|
||||
size="sm"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
>
|
||||
<div className="space-y-4">
|
||||
{/* Secret Key */}
|
||||
<Input
|
||||
label={t("Secret Key")}
|
||||
placeholder="sk_test_... or sk_live_..."
|
||||
description={t("Stripe secret key for server-side API calls")}
|
||||
value={formData.secret}
|
||||
onChange={(e) => handleInputChange("secret", e.target.value)}
|
||||
type={showSecretKey ? "text" : "password"}
|
||||
endContent={
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setShowSecretKey(!showSecretKey)}
|
||||
className="focus:outline-none"
|
||||
>
|
||||
{showSecretKey ? (
|
||||
<EyeOff className="w-4 h-4 text-gray-400" />
|
||||
) : (
|
||||
<Eye className="w-4 h-4 text-gray-400" />
|
||||
)}
|
||||
</button>
|
||||
}
|
||||
isRequired
|
||||
autoComplete="off"
|
||||
isDisabled={!formData.is_enabled}
|
||||
/>
|
||||
|
||||
{/* Webhook Secret (Optional) */}
|
||||
<Input
|
||||
label={t("Webhook Secret")}
|
||||
placeholder="whsec_..."
|
||||
description={t(
|
||||
"Webhook signing secret for verifying Stripe events"
|
||||
)}
|
||||
value={formData.webhook_secret || ""}
|
||||
onChange={(e) =>
|
||||
handleInputChange("webhook_secret", e.target.value)
|
||||
}
|
||||
type={showWebhookSecret ? "text" : "password"}
|
||||
isRequired
|
||||
endContent={
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setShowWebhookSecret(!showWebhookSecret)}
|
||||
className="focus:outline-none"
|
||||
>
|
||||
{showWebhookSecret ? (
|
||||
<EyeOff className="w-4 h-4 text-gray-400" />
|
||||
) : (
|
||||
<Eye className="w-4 h-4 text-gray-400" />
|
||||
)}
|
||||
</button>
|
||||
}
|
||||
autoComplete="off"
|
||||
isDisabled={!formData.is_enabled}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Action Buttons */}
|
||||
{formData.is_enabled && (
|
||||
<div className="flex gap-3 py-4">
|
||||
<Button
|
||||
color="primary"
|
||||
variant="solid"
|
||||
onPress={handleSave}
|
||||
isLoading={isLoading}
|
||||
isDisabled={!isFormValid}
|
||||
size="sm"
|
||||
>
|
||||
{t("Save")}
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
</AccordionItem>
|
||||
</Accordion>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,140 @@
|
||||
"use client";
|
||||
|
||||
import React, { useEffect, useState } from "react";
|
||||
import {
|
||||
Input,
|
||||
Button,
|
||||
AccordionItem,
|
||||
Accordion,
|
||||
Switch,
|
||||
} from "@nextui-org/react";
|
||||
import { WechatConfig } from "@/types/payment";
|
||||
import { useTranslation } from "@/shared/lib/useTranslation";
|
||||
|
||||
interface WechatConfigFormProps {
|
||||
config: WechatConfig;
|
||||
onSave: (config: WechatConfig) => void;
|
||||
onEnable: (channelId: string) => Promise<boolean>;
|
||||
onDisable: (channelId: string) => Promise<boolean>;
|
||||
isLoading?: boolean;
|
||||
}
|
||||
|
||||
export const WechatConfigForm: React.FC<WechatConfigFormProps> = ({
|
||||
config,
|
||||
onSave,
|
||||
onEnable,
|
||||
onDisable,
|
||||
isLoading = false,
|
||||
}) => {
|
||||
const { t } = useTranslation();
|
||||
const [formData, setFormData] = useState<WechatConfig>(config);
|
||||
|
||||
useEffect(() => {
|
||||
setFormData(config);
|
||||
}, [config]);
|
||||
|
||||
const handleInputChange = (
|
||||
field: keyof WechatConfig,
|
||||
value: string | boolean
|
||||
) => {
|
||||
setFormData((prev) => ({
|
||||
...prev,
|
||||
[field]: value,
|
||||
}));
|
||||
};
|
||||
const handleEnableDisable = async (value: boolean) => {
|
||||
let result: boolean | null = null;
|
||||
if (value) {
|
||||
result = await onEnable("wechat");
|
||||
} else {
|
||||
result = await onDisable("wechat");
|
||||
}
|
||||
if (result) {
|
||||
setFormData((prev) => ({
|
||||
...prev,
|
||||
is_enabled: value,
|
||||
}));
|
||||
}
|
||||
};
|
||||
|
||||
const handleSave = () => {
|
||||
onSave(formData);
|
||||
};
|
||||
|
||||
const isFormValid =
|
||||
formData.app_id.trim() !== "" && formData.mch_id.trim() !== "";
|
||||
|
||||
return (
|
||||
<Accordion
|
||||
variant="splitted"
|
||||
itemClasses={{
|
||||
base: "shadow-none border-1",
|
||||
}}
|
||||
defaultExpandedKeys={["wechat-config"]}
|
||||
className="px-0"
|
||||
>
|
||||
<AccordionItem
|
||||
key="wechat-config"
|
||||
title={
|
||||
<div className="flex flex-col justify-between">
|
||||
<div className="flex items-center justify-between w-full">
|
||||
<div>
|
||||
<h3 className="text-lg font-semibold">
|
||||
{t("WeChat Configuration")}
|
||||
</h3>
|
||||
<p className="text-sm text-gray-500">
|
||||
{t("Configure WeChat payment interface")}
|
||||
</p>
|
||||
</div>
|
||||
<Switch
|
||||
isSelected={formData.is_enabled || false}
|
||||
onValueChange={handleEnableDisable}
|
||||
size="sm"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
>
|
||||
<div className="space-y-4">
|
||||
{/* App ID */}
|
||||
<Input
|
||||
label={t("App ID")}
|
||||
placeholder={t("WeChat App ID")}
|
||||
value={formData.app_id}
|
||||
onChange={(e) => handleInputChange("app_id", e.target.value)}
|
||||
isRequired
|
||||
autoComplete="off"
|
||||
isDisabled={!formData.is_enabled}
|
||||
/>
|
||||
|
||||
{/* Merchant ID */}
|
||||
<Input
|
||||
label={t("Merchant ID")}
|
||||
placeholder={t("WeChat Merchant ID")}
|
||||
value={formData.mch_id}
|
||||
onChange={(e) => handleInputChange("mch_id", e.target.value)}
|
||||
isRequired
|
||||
autoComplete="off"
|
||||
isDisabled={!formData.is_enabled}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Action Buttons */}
|
||||
{formData.is_enabled && (
|
||||
<div className="flex gap-3 py-4">
|
||||
<Button
|
||||
color="primary"
|
||||
variant="solid"
|
||||
onPress={handleSave}
|
||||
isLoading={isLoading}
|
||||
isDisabled={!isFormValid}
|
||||
size="sm"
|
||||
>
|
||||
{t("Save")}
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
</AccordionItem>
|
||||
</Accordion>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,138 @@
|
||||
"use client";
|
||||
|
||||
import React, { useState, useEffect } from "react";
|
||||
import { Button, AccordionItem, Accordion } from "@nextui-org/react";
|
||||
import MDEditor, { commands } from "@uiw/react-md-editor";
|
||||
import { PlatformConfig } from "@/shared/types/system";
|
||||
import { useTranslation } from "@/shared/lib/useTranslation";
|
||||
import { calculateFileSha256 } from "@/shared/utils/crypto";
|
||||
import "@uiw/react-md-editor/markdown-editor.css";
|
||||
import "@uiw/react-markdown-preview/markdown.css";
|
||||
|
||||
interface AboutPageSettingsProps {
|
||||
config: PlatformConfig;
|
||||
onAboutSave: (aboutContent: string) => Promise<void>;
|
||||
onImageUpload?: (file: File, sha256?: string) => Promise<string>;
|
||||
isAboutLoading?: boolean;
|
||||
}
|
||||
|
||||
export const AboutPageSettings: React.FC<AboutPageSettingsProps> = ({
|
||||
config,
|
||||
onAboutSave,
|
||||
onImageUpload,
|
||||
isAboutLoading = false,
|
||||
}) => {
|
||||
const { t } = useTranslation();
|
||||
const [aboutContent, setAboutContent] = useState(config.about_page || "");
|
||||
|
||||
useEffect(() => {
|
||||
setAboutContent(config.about_page || "");
|
||||
}, [config.about_page]);
|
||||
|
||||
const handleAboutSave = async () => {
|
||||
await onAboutSave(aboutContent);
|
||||
};
|
||||
|
||||
const handleImageUpload = async (file: File): Promise<string> => {
|
||||
try {
|
||||
// 计算文件的 SHA256 哈希值
|
||||
const sha256 = await calculateFileSha256(file);
|
||||
return await onImageUpload!(file, sha256);
|
||||
} catch (error) {
|
||||
console.error("Image upload failed:", error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-4 justify-between h-full">
|
||||
<div className="flex-1">
|
||||
<MDEditor
|
||||
value={aboutContent}
|
||||
onChange={(value?: string) => setAboutContent(value || "")}
|
||||
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="100%"
|
||||
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: (
|
||||
<svg width="12" height="12" viewBox="0 0 20 20">
|
||||
<path
|
||||
fill="currentColor"
|
||||
d="M15 9c1.1 0 2-.9 2-2s-.9-2-2-2-2 .9-2 2 .9 2 2 2zm4-7H1c-.55 0-1 .45-1 1v14c0 .55.45 1 1 1h18c.55 0 1-.45 1-1V3c0-.55-.45-1-1-1zM2 17l4.5-6 3.5 4.51 2.5-3.01L17 17H2z"
|
||||
/>
|
||||
</svg>
|
||||
),
|
||||
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 = ``;
|
||||
api.replaceSelection(imageMarkdown);
|
||||
} catch (error) {
|
||||
console.error("Image upload failed:", error);
|
||||
}
|
||||
}
|
||||
};
|
||||
input.click();
|
||||
},
|
||||
},
|
||||
]}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* About Save Button */}
|
||||
<div className="flex gap-3 pb-4">
|
||||
<Button
|
||||
color="primary"
|
||||
variant="solid"
|
||||
onPress={handleAboutSave}
|
||||
isLoading={isAboutLoading}
|
||||
size="sm"
|
||||
>
|
||||
{t("Save")}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -1,9 +1,9 @@
|
||||
'use client';
|
||||
"use client";
|
||||
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { Input, Button, AccordionItem, Accordion } from '@nextui-org/react';
|
||||
import { Eye, EyeOff } from 'lucide-react';
|
||||
import { AdminConfig } from '@/types/system';
|
||||
import React, { useEffect, useState } from "react";
|
||||
import { Input, Button, AccordionItem, Accordion } from "@nextui-org/react";
|
||||
import { Eye, EyeOff } from "lucide-react";
|
||||
import { AdminConfig } from "@/types/system";
|
||||
import { useTranslation } from "@/shared/lib/useTranslation";
|
||||
|
||||
interface AdminConfigFormProps {
|
||||
@@ -20,20 +20,20 @@ export const AdminConfigForm: React.FC<AdminConfigFormProps> = ({
|
||||
const { t } = useTranslation();
|
||||
const [formData, setFormData] = useState<AdminConfig>(config);
|
||||
const [showPassword, setShowPassword] = useState(false);
|
||||
const [confirmPassword, setConfirmPassword] = useState('');
|
||||
const [confirmPassword, setConfirmPassword] = useState("");
|
||||
const [showConfirmPassword, setShowConfirmPassword] = useState(false);
|
||||
useEffect(() => {
|
||||
setFormData({
|
||||
...config,
|
||||
password: '',
|
||||
password: "",
|
||||
});
|
||||
setConfirmPassword('');
|
||||
setConfirmPassword("");
|
||||
}, [config]);
|
||||
|
||||
const handleInputChange = (field: keyof AdminConfig, value: string) => {
|
||||
setFormData(prev => ({
|
||||
setFormData((prev) => ({
|
||||
...prev,
|
||||
[field]: value
|
||||
[field]: value,
|
||||
}));
|
||||
};
|
||||
|
||||
@@ -42,41 +42,53 @@ export const AdminConfigForm: React.FC<AdminConfigFormProps> = ({
|
||||
};
|
||||
|
||||
const isFormValid =
|
||||
formData.username.trim() !== '' &&
|
||||
formData.password.trim() !== '' &&
|
||||
formData.username.trim() !== "" &&
|
||||
formData.password?.trim() !== "" &&
|
||||
formData.password === confirmPassword &&
|
||||
formData.password.length >= 8;
|
||||
formData.password?.length >= 8;
|
||||
|
||||
const passwordsMatch = formData.password === confirmPassword;
|
||||
|
||||
return (
|
||||
<Accordion variant='splitted' itemClasses={{
|
||||
base: 'shadow-none border-1',
|
||||
}} defaultExpandedKeys={['admin-config']} className='px-0'>
|
||||
<AccordionItem key="admin-config" title={
|
||||
<div className="flex flex-col justify-between">
|
||||
<h3 className="text-lg font-semibold">{t('Administrator Account')}</h3>
|
||||
<p className="text-sm text-gray-500">{t('Configure administrator login credentials')}</p>
|
||||
</div>
|
||||
}>
|
||||
<Accordion
|
||||
variant="splitted"
|
||||
itemClasses={{
|
||||
base: "shadow-none border-1",
|
||||
}}
|
||||
defaultExpandedKeys={["admin-config"]}
|
||||
className="px-0"
|
||||
>
|
||||
<AccordionItem
|
||||
key="admin-config"
|
||||
title={
|
||||
<div className="flex flex-col justify-between">
|
||||
<h3 className="text-lg font-semibold">
|
||||
{t("Administrator Account")}
|
||||
</h3>
|
||||
<p className="text-sm text-gray-500">
|
||||
{t("Configure administrator login credentials")}
|
||||
</p>
|
||||
</div>
|
||||
}
|
||||
>
|
||||
<div className="space-y-4">
|
||||
{/* admin username */}
|
||||
<Input
|
||||
label={t('Administrator Username')}
|
||||
placeholder={t('Enter administrator username')}
|
||||
description={t('Username for administrator login')}
|
||||
label={t("Administrator Username")}
|
||||
placeholder={t("Enter administrator username")}
|
||||
description={t("Username for administrator login")}
|
||||
value={formData.username}
|
||||
onChange={(e) => handleInputChange('username', e.target.value)}
|
||||
onChange={(e) => handleInputChange("username", e.target.value)}
|
||||
isRequired
|
||||
/>
|
||||
|
||||
{/* admin password */}
|
||||
<Input
|
||||
label={t('Administrator Password')}
|
||||
placeholder={t('Enter administrator password')}
|
||||
description={t('Password must be at least 8 characters long')}
|
||||
label={t("Administrator Password")}
|
||||
placeholder={t("Enter administrator password")}
|
||||
description={t("Password must be at least 8 characters long")}
|
||||
value={formData.password}
|
||||
onChange={(e) => handleInputChange('password', e.target.value)}
|
||||
onChange={(e) => handleInputChange("password", e.target.value)}
|
||||
type={showPassword ? "text" : "password"}
|
||||
endContent={
|
||||
<button
|
||||
@@ -92,16 +104,24 @@ export const AdminConfigForm: React.FC<AdminConfigFormProps> = ({
|
||||
</button>
|
||||
}
|
||||
isRequired
|
||||
autoComplete='new-password'
|
||||
color={formData.password.length > 0 && formData.password.length < 8 ? "danger" : "default"}
|
||||
errorMessage={formData.password.length > 0 && formData.password.length < 8 ? t('Password must be at least 8 characters') : ""}
|
||||
autoComplete="new-password"
|
||||
color={
|
||||
formData.password?.length > 0 && formData.password?.length < 8
|
||||
? "danger"
|
||||
: "default"
|
||||
}
|
||||
errorMessage={
|
||||
formData.password?.length > 0 && formData.password?.length < 8
|
||||
? t("Password must be at least 8 characters")
|
||||
: ""
|
||||
}
|
||||
/>
|
||||
|
||||
{/* confirm password */}
|
||||
<Input
|
||||
label={t('Confirm Password')}
|
||||
placeholder={t('Confirm administrator password')}
|
||||
description={t('Re-enter the password to confirm')}
|
||||
label={t("Confirm Password")}
|
||||
placeholder={t("Confirm administrator password")}
|
||||
description={t("Re-enter the password to confirm")}
|
||||
value={confirmPassword}
|
||||
onChange={(e) => setConfirmPassword(e.target.value)}
|
||||
type={showConfirmPassword ? "text" : "password"}
|
||||
@@ -118,10 +138,18 @@ export const AdminConfigForm: React.FC<AdminConfigFormProps> = ({
|
||||
)}
|
||||
</button>
|
||||
}
|
||||
autoComplete='new-password'
|
||||
autoComplete="new-password"
|
||||
isRequired
|
||||
color={confirmPassword.length > 0 && !passwordsMatch ? "danger" : "default"}
|
||||
errorMessage={confirmPassword.length > 0 && !passwordsMatch ? t('Passwords do not match') : ""}
|
||||
color={
|
||||
confirmPassword?.length > 0 && !passwordsMatch
|
||||
? "danger"
|
||||
: "default"
|
||||
}
|
||||
errorMessage={
|
||||
confirmPassword?.length > 0 && !passwordsMatch
|
||||
? t("Passwords do not match")
|
||||
: ""
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -133,12 +161,12 @@ export const AdminConfigForm: React.FC<AdminConfigFormProps> = ({
|
||||
onPress={handleSave}
|
||||
isLoading={isLoading}
|
||||
isDisabled={!isFormValid}
|
||||
size='sm'
|
||||
size="sm"
|
||||
>
|
||||
{t('Save')}
|
||||
{t("Save")}
|
||||
</Button>
|
||||
</div>
|
||||
</AccordionItem>
|
||||
</Accordion>
|
||||
);
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,39 @@
|
||||
"use client";
|
||||
|
||||
import React from "react";
|
||||
import { EmailConfigForm } from "./EmailConfigForm";
|
||||
import { AdminConfig, EmailConfig } from "@/types/system";
|
||||
import { AdminConfigForm } from "./AdminConfigForm";
|
||||
|
||||
interface EmailAndAdminSettingsProps {
|
||||
emailConfig: EmailConfig;
|
||||
adminConfig: AdminConfig;
|
||||
onSaveEmailConfig: (config: EmailConfig) => void;
|
||||
onSaveAdminConfig: (config: AdminConfig) => void;
|
||||
isLoading?: boolean;
|
||||
isAdminLoading?: boolean;
|
||||
}
|
||||
|
||||
export const EmailAndAdminSettings: React.FC<EmailAndAdminSettingsProps> = ({
|
||||
emailConfig,
|
||||
adminConfig,
|
||||
onSaveEmailConfig,
|
||||
onSaveAdminConfig,
|
||||
isLoading = false,
|
||||
isAdminLoading = false,
|
||||
}) => {
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<EmailConfigForm
|
||||
config={emailConfig}
|
||||
onSave={onSaveEmailConfig}
|
||||
isLoading={isLoading}
|
||||
/>
|
||||
<AdminConfigForm
|
||||
config={adminConfig}
|
||||
onSave={onSaveAdminConfig}
|
||||
isLoading={isAdminLoading}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,165 @@
|
||||
"use client";
|
||||
|
||||
import React, { useEffect, useState } from "react";
|
||||
import {
|
||||
AccordionItem,
|
||||
Accordion,
|
||||
Textarea,
|
||||
Button,
|
||||
Switch,
|
||||
Alert,
|
||||
} from "@nextui-org/react";
|
||||
import { useTranslation } from "@/shared/lib/useTranslation";
|
||||
import { EmbeddedHtmlConfig } from "@/shared/types/system";
|
||||
|
||||
interface EmbeddedHtmlSettingsProps {
|
||||
onSave?: (config: EmbeddedHtmlConfig) => void;
|
||||
config?: EmbeddedHtmlConfig;
|
||||
}
|
||||
|
||||
export const EmbeddedHtmlSettings: React.FC<EmbeddedHtmlSettingsProps> = ({
|
||||
onSave,
|
||||
config = { html: "", is_enabled: false },
|
||||
}) => {
|
||||
const { t } = useTranslation();
|
||||
const [htmlData, setHtmlData] = useState<EmbeddedHtmlConfig>(config);
|
||||
const [isSaving, setIsSaving] = useState(false);
|
||||
useEffect(() => {
|
||||
setHtmlData(config);
|
||||
}, [config]);
|
||||
|
||||
const handleSave = async () => {
|
||||
setIsSaving(true);
|
||||
try {
|
||||
await onSave?.(htmlData);
|
||||
} finally {
|
||||
setIsSaving(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleHtmlChange = (value: string) => {
|
||||
setHtmlData((prev) => ({ ...prev, html: value }));
|
||||
};
|
||||
const handleToggleEnabled = async (enabled: boolean) => {
|
||||
const updatedConfig = {
|
||||
...htmlData,
|
||||
is_enabled: enabled,
|
||||
};
|
||||
// when toggle the switch, save directly, same as GoogleAuthConfigForm
|
||||
const result = await onSave?.(updatedConfig);
|
||||
if (result) {
|
||||
setHtmlData((prev) => ({ ...prev, is_enabled: enabled }));
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Accordion
|
||||
variant="splitted"
|
||||
itemClasses={{
|
||||
base: "shadow-none border-1",
|
||||
}}
|
||||
className="px-0"
|
||||
defaultExpandedKeys={["embedded-html"]}
|
||||
>
|
||||
<AccordionItem
|
||||
key="embedded-html"
|
||||
title={
|
||||
<div className="flex flex-col justify-between">
|
||||
<h3 className="text-lg font-semibold flex items-center gap-2">
|
||||
{t("Embedded HTML")}
|
||||
</h3>
|
||||
<p className="text-sm text-gray-500">
|
||||
{t("Configure custom HTML content for global injection")}
|
||||
</p>
|
||||
</div>
|
||||
}
|
||||
>
|
||||
<div className="space-y-4">
|
||||
{/* Enable/Disable Toggle */}
|
||||
<div className="flex items-center justify-between p-4 bg-gray-50 rounded-lg">
|
||||
<div className="flex flex-col gap-1">
|
||||
<span className="text-sm font-medium">
|
||||
{t("Enable Custom HTML")}
|
||||
</span>
|
||||
<span className="text-xs text-gray-500">
|
||||
{t("Toggle to enable or disable custom HTML injection")}
|
||||
</span>
|
||||
</div>
|
||||
<Switch
|
||||
isSelected={htmlData.is_enabled}
|
||||
onValueChange={handleToggleEnabled}
|
||||
color="primary"
|
||||
size="sm"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* HTML Editor */}
|
||||
<div className="space-y-2">
|
||||
<Textarea
|
||||
placeholder={t(
|
||||
"Enter your custom HTML, CSS, or JavaScript code here...\n\nExample:\n<script>\n // Google Analytics\n gtag('config', 'GA_MEASUREMENT_ID');\n</script>\n\n<style>\n .custom-style {\n color: #333;\n }\n</style>"
|
||||
)}
|
||||
value={htmlData.html}
|
||||
onValueChange={handleHtmlChange}
|
||||
minRows={10}
|
||||
maxRows={20}
|
||||
description={t(
|
||||
"This HTML will be injected globally into the application. You can include script tags, CSS styles, or any valid HTML."
|
||||
)}
|
||||
radius="sm"
|
||||
className="text-xs"
|
||||
isDisabled={!htmlData.is_enabled}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Action Buttons */}
|
||||
{htmlData.is_enabled && (
|
||||
<div className="flex gap-3 py-4">
|
||||
<Button
|
||||
color="primary"
|
||||
variant="solid"
|
||||
onPress={handleSave}
|
||||
isLoading={isSaving}
|
||||
isDisabled={!htmlData.html.trim()}
|
||||
size="sm"
|
||||
>
|
||||
{t("Save")}
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Usage Instructions */}
|
||||
<Alert
|
||||
color="primary"
|
||||
variant="flat"
|
||||
title={t("Usage Instructions")}
|
||||
description={
|
||||
<ul className="text-sm space-y-1 mt-2">
|
||||
<li>
|
||||
•{" "}
|
||||
{t(
|
||||
"You can include Google Analytics, custom CSS, or any tracking scripts"
|
||||
)}
|
||||
</li>
|
||||
<li>
|
||||
•{" "}
|
||||
{t("The HTML will be injected into the document head section")}
|
||||
</li>
|
||||
<li>
|
||||
•{" "}
|
||||
{t(
|
||||
"Make sure your code is valid to avoid breaking the application"
|
||||
)}
|
||||
</li>
|
||||
<li>
|
||||
•{" "}
|
||||
{t("Changes take effect immediately after saving and enabling")}
|
||||
</li>
|
||||
</ul>
|
||||
}
|
||||
/>
|
||||
</AccordionItem>
|
||||
</Accordion>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,242 @@
|
||||
"use client";
|
||||
|
||||
import React, { useState, useRef, useEffect } from "react";
|
||||
import {
|
||||
AccordionItem,
|
||||
Accordion,
|
||||
Table,
|
||||
TableHeader,
|
||||
TableColumn,
|
||||
TableBody,
|
||||
TableRow,
|
||||
TableCell,
|
||||
Button,
|
||||
Input,
|
||||
Textarea,
|
||||
Tooltip,
|
||||
} from "@nextui-org/react";
|
||||
import { useTranslation } from "@/shared/lib/useTranslation";
|
||||
import { GripVertical, Trash2, Plus } from "lucide-react";
|
||||
import { FaqItem } from "@/shared/types/system";
|
||||
|
||||
interface FaqSettingsProps {
|
||||
onSave?: (config: FaqItem[]) => void;
|
||||
config?: FaqItem[];
|
||||
}
|
||||
|
||||
export const FaqSettings: React.FC<FaqSettingsProps> = ({
|
||||
onSave,
|
||||
config = [],
|
||||
}) => {
|
||||
const { t } = useTranslation();
|
||||
const [faqs, setFaqs] = useState<FaqItem[]>(config || []);
|
||||
const [isSaving, setIsSaving] = useState(false);
|
||||
const [focusedAnswer, setFocusedAnswer] = useState<number | null>(null);
|
||||
const draggedItem = useRef<number | null>(null);
|
||||
const draggedOverItem = useRef<number | null>(null);
|
||||
useEffect(() => {
|
||||
setFaqs(config);
|
||||
}, [config]);
|
||||
|
||||
const handleQuestionChange = (index: number, value: string) => {
|
||||
setFaqs((prev) =>
|
||||
prev.map((faq, idx) =>
|
||||
idx === index ? { ...faq, question: value } : faq
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
const handleAnswerChange = (index: number, value: string) => {
|
||||
setFaqs((prev) =>
|
||||
prev.map((faq, idx) => (idx === index ? { ...faq, answer: value } : faq))
|
||||
);
|
||||
};
|
||||
|
||||
const handleDelete = (index: number) => {
|
||||
setFaqs((prev) => {
|
||||
return prev.filter((_, idx) => idx !== index);
|
||||
});
|
||||
};
|
||||
|
||||
const handleInsertBelow = (index: number) => {
|
||||
setFaqs((prev) => {
|
||||
const newFaqs = [...prev];
|
||||
newFaqs.splice(index + 1, 0, {
|
||||
question: "",
|
||||
answer: "",
|
||||
});
|
||||
return newFaqs;
|
||||
});
|
||||
};
|
||||
|
||||
const handleDragStart = (index: number) => {
|
||||
draggedItem.current = index;
|
||||
};
|
||||
|
||||
const handleDragEnter = (index: number) => {
|
||||
draggedOverItem.current = index;
|
||||
};
|
||||
|
||||
const handleDragEnd = () => {
|
||||
if (draggedItem.current !== null && draggedOverItem.current !== null) {
|
||||
const draggedItemIndex = draggedItem.current;
|
||||
const draggedOverItemIndex = draggedOverItem.current;
|
||||
|
||||
if (draggedItemIndex !== draggedOverItemIndex) {
|
||||
setFaqs((prev) => {
|
||||
const newFaqs = [...prev];
|
||||
const draggedItemContent = newFaqs[draggedItemIndex];
|
||||
newFaqs.splice(draggedItemIndex, 1);
|
||||
newFaqs.splice(draggedOverItemIndex, 0, draggedItemContent);
|
||||
return newFaqs;
|
||||
});
|
||||
}
|
||||
}
|
||||
draggedItem.current = null;
|
||||
draggedOverItem.current = null;
|
||||
};
|
||||
|
||||
const handleSaveAll = async () => {
|
||||
setIsSaving(true);
|
||||
try {
|
||||
await onSave?.(faqs.filter((faq) => faq.question && faq.answer));
|
||||
} finally {
|
||||
setIsSaving(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Accordion
|
||||
variant="splitted"
|
||||
itemClasses={{
|
||||
base: "shadow-none border-1",
|
||||
}}
|
||||
className="px-0"
|
||||
defaultExpandedKeys={["faq"]}
|
||||
>
|
||||
<AccordionItem
|
||||
key="faq"
|
||||
title={
|
||||
<div className="flex flex-col justify-between">
|
||||
<h3 className="text-lg font-semibold flex items-center gap-2">
|
||||
{t("FAQ Management")}
|
||||
</h3>
|
||||
<p className="text-sm text-gray-500">
|
||||
{t("Configure frequently asked questions for your users")}
|
||||
</p>
|
||||
</div>
|
||||
}
|
||||
>
|
||||
<div className="space-y-4">
|
||||
{/* FAQ Table */}
|
||||
<Table
|
||||
aria-label="FAQ management table"
|
||||
className="border-1 rounded-lg p-2"
|
||||
removeWrapper
|
||||
>
|
||||
<TableHeader>
|
||||
<TableColumn className="w-16">{t("Order")}</TableColumn>
|
||||
<TableColumn className="w-1/3">{t("Question")}</TableColumn>
|
||||
<TableColumn>{t("Answer")}</TableColumn>
|
||||
<TableColumn className="w-32">{t("Actions")}</TableColumn>
|
||||
</TableHeader>
|
||||
<TableBody emptyContent={t("No FAQ items available.")}>
|
||||
{faqs.map((faq, index) => (
|
||||
<TableRow
|
||||
key={index}
|
||||
draggable
|
||||
onDragStart={() => handleDragStart(index)}
|
||||
onDragEnter={() => handleDragEnter(index)}
|
||||
onDragEnd={handleDragEnd}
|
||||
onDragOver={(e) => e.preventDefault()}
|
||||
className="cursor-move"
|
||||
>
|
||||
<TableCell>
|
||||
<div className="flex items-center gap-2">
|
||||
<GripVertical className="w-4 h-4 text-gray-400" />
|
||||
</div>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<Input
|
||||
value={faq.question}
|
||||
onValueChange={(value) =>
|
||||
handleQuestionChange(index, value)
|
||||
}
|
||||
placeholder={t("Enter question")}
|
||||
size="sm"
|
||||
/>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<div className="relative">
|
||||
<Input
|
||||
value={faq.answer}
|
||||
onValueChange={(value) =>
|
||||
handleAnswerChange(index, value)
|
||||
}
|
||||
onFocus={() => setFocusedAnswer(index)}
|
||||
placeholder={t("Enter answer")}
|
||||
size="sm"
|
||||
/>
|
||||
{focusedAnswer === index && (
|
||||
<div className="absolute top-0 left-0 right-0 z-50">
|
||||
<Textarea
|
||||
value={faq.answer}
|
||||
onValueChange={(value) =>
|
||||
handleAnswerChange(index, value)
|
||||
}
|
||||
placeholder={t("Enter answer")}
|
||||
size="sm"
|
||||
minRows={3}
|
||||
onBlur={() => setFocusedAnswer(null)}
|
||||
autoFocus
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<div className="flex gap-1">
|
||||
<Tooltip content={t("Insert below")}>
|
||||
<Button
|
||||
isIconOnly
|
||||
size="sm"
|
||||
variant="light"
|
||||
onPress={() => handleInsertBelow(index)}
|
||||
>
|
||||
<Plus className="w-4 h-4" />
|
||||
</Button>
|
||||
</Tooltip>
|
||||
<Tooltip content={t("Delete")} color="danger">
|
||||
<Button
|
||||
isIconOnly
|
||||
size="sm"
|
||||
variant="light"
|
||||
color="danger"
|
||||
onPress={() => handleDelete(index)}
|
||||
>
|
||||
<Trash2 className="w-4 h-4" />
|
||||
</Button>
|
||||
</Tooltip>
|
||||
</div>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
|
||||
<div className="flex ">
|
||||
<Button
|
||||
color="primary"
|
||||
onPress={handleSaveAll}
|
||||
isLoading={isSaving}
|
||||
isDisabled={faqs.length === 0}
|
||||
size="sm"
|
||||
>
|
||||
{t("Save")}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</AccordionItem>
|
||||
</Accordion>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,50 @@
|
||||
"use client";
|
||||
|
||||
import React, { useEffect } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { toast } from "react-hot-toast";
|
||||
import { FaqSettings } from "./FaqSettings";
|
||||
import { TopNavigationSettings } from "./TopNavigationSettings";
|
||||
import { EmbeddedHtmlSettings } from "./EmbeddedHtmlSettings";
|
||||
import { useHomepageConfigManagement } from "@/hooks/useHomepageConfigManagement";
|
||||
|
||||
interface HomepageSettingsProps {
|
||||
// 预留接口,后续扩展
|
||||
}
|
||||
|
||||
export const HomepageSettings: React.FC<HomepageSettingsProps> = () => {
|
||||
const { t } = useTranslation();
|
||||
const {
|
||||
homepageConfig,
|
||||
error,
|
||||
saveFaqConfig,
|
||||
saveNavigationConfig,
|
||||
saveEmbeddedHtmlConfig,
|
||||
} = useHomepageConfigManagement();
|
||||
|
||||
// 显示错误提示
|
||||
useEffect(() => {
|
||||
if (error) {
|
||||
toast.error(t("Failed to load homepage config"));
|
||||
}
|
||||
}, [error, t]);
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
{/* FAQ Management */}
|
||||
<FaqSettings onSave={saveFaqConfig} config={homepageConfig.faq} />
|
||||
|
||||
{/* Top Navigation */}
|
||||
<TopNavigationSettings
|
||||
onSave={saveNavigationConfig}
|
||||
config={homepageConfig.top_navigation}
|
||||
/>
|
||||
|
||||
{/* Embedded HTML */}
|
||||
<EmbeddedHtmlSettings
|
||||
onSave={saveEmbeddedHtmlConfig}
|
||||
config={homepageConfig.embeded_html}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -1,7 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import React, { useState, useEffect } from "react";
|
||||
import { calculateFileSha256 } from "@/shared/utils/crypto";
|
||||
import {
|
||||
Input,
|
||||
Button,
|
||||
@@ -9,43 +8,107 @@ import {
|
||||
Accordion,
|
||||
Select,
|
||||
SelectItem,
|
||||
Switch,
|
||||
} 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 { ThemeSelector } from "./ThemeSelector";
|
||||
import "@uiw/react-md-editor/markdown-editor.css";
|
||||
import "@uiw/react-markdown-preview/markdown.css";
|
||||
import toast from "react-hot-toast";
|
||||
|
||||
interface PlatformConfigFormProps {
|
||||
config: PlatformConfig;
|
||||
onSave: (config: PlatformConfig) => void;
|
||||
onThemeChange?: (theme: Theme) => Promise<void>;
|
||||
onAboutSave?: (aboutContent: string) => Promise<void>;
|
||||
onImageUpload?: (file: File, sha256?: string) => Promise<string>;
|
||||
isLoading?: boolean;
|
||||
isAboutLoading?: boolean;
|
||||
}
|
||||
|
||||
export const PlatformConfigForm: React.FC<PlatformConfigFormProps> = ({
|
||||
config,
|
||||
onSave,
|
||||
onThemeChange,
|
||||
onAboutSave,
|
||||
onImageUpload,
|
||||
isLoading = false,
|
||||
isAboutLoading = false,
|
||||
}) => {
|
||||
const { t } = useTranslation();
|
||||
const [formData, setFormData] = useState<PlatformConfig>(config);
|
||||
const [validationErrors, setValidationErrors] = useState<{
|
||||
domain?: string;
|
||||
mcp_server_prefix?: string;
|
||||
}>({});
|
||||
|
||||
// when context config updated, sync to form
|
||||
useEffect(() => {
|
||||
setFormData(config);
|
||||
}, [config]);
|
||||
|
||||
// URL validation function with strict regex
|
||||
const validateUrl = (url: string): boolean => {
|
||||
if (!url.trim()) return true; // Empty is valid (optional field)
|
||||
|
||||
// Strict regex for domain validation
|
||||
const domainRegex = /^https?:\/\/(?:[-\w.])+(?:\:[0-9]+)?(?:\/.*)?$/;
|
||||
|
||||
// First check with regex
|
||||
if (!domainRegex.test(url)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Then validate with URL constructor for additional checks
|
||||
try {
|
||||
const urlObj = new URL(url);
|
||||
return (urlObj.protocol === 'http:' || urlObj.protocol === 'https:') &&
|
||||
urlObj.hostname.length > 0 &&
|
||||
urlObj.hostname.includes('.');
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
// Validate field and update errors
|
||||
const validateField = (field: 'domain' | 'mcp_server_prefix', value: string) => {
|
||||
const isValid = validateUrl(value);
|
||||
setValidationErrors(prev => ({
|
||||
...prev,
|
||||
[field]: isValid ? undefined : t('Please enter a valid URL with http:// or https://')
|
||||
}));
|
||||
return isValid;
|
||||
};
|
||||
|
||||
const handleInputChange = (field: keyof PlatformConfig, value: string) => {
|
||||
// Validate URL fields
|
||||
if (field === 'domain' || field === 'mcp_server_prefix') {
|
||||
validateField(field, value);
|
||||
}
|
||||
|
||||
setFormData((prev) => {
|
||||
const newData = {
|
||||
...prev,
|
||||
[field]: value,
|
||||
};
|
||||
|
||||
// Auto-enable showcase when domain is filled and showcase is not explicitly set
|
||||
if (
|
||||
field === "domain" &&
|
||||
value.trim() &&
|
||||
prev.is_showcased === undefined
|
||||
) {
|
||||
newData.is_showcased = true;
|
||||
}
|
||||
|
||||
return newData;
|
||||
});
|
||||
};
|
||||
|
||||
const handleBooleanChange = (field: keyof PlatformConfig, value: boolean) => {
|
||||
// Check domain requirement for is_showcased
|
||||
if (field === "is_showcased" && value && !formData.domain?.trim()) {
|
||||
// Show error message or prevent enabling
|
||||
toast.error(t("Please enter a platform domain before enabling showcase"));
|
||||
return;
|
||||
}
|
||||
|
||||
setFormData((prev) => ({
|
||||
...prev,
|
||||
[field]: value,
|
||||
@@ -53,6 +116,15 @@ export const PlatformConfigForm: React.FC<PlatformConfigFormProps> = ({
|
||||
};
|
||||
|
||||
const handleSave = async () => {
|
||||
// Validate all URL fields before saving
|
||||
const domainValid = validateField('domain', formData.domain || '');
|
||||
const mcpServerValid = validateField('mcp_server_prefix', formData.mcp_server_prefix || '');
|
||||
|
||||
if (!domainValid || !mcpServerValid) {
|
||||
toast.error(t('Please fix validation errors before saving'));
|
||||
return;
|
||||
}
|
||||
|
||||
onSave(formData);
|
||||
};
|
||||
|
||||
@@ -61,21 +133,6 @@ export const PlatformConfigForm: React.FC<PlatformConfigFormProps> = ({
|
||||
onThemeChange?.(theme);
|
||||
};
|
||||
|
||||
const handleAboutSave = async () => {
|
||||
onAboutSave?.(formData.about_page || "");
|
||||
};
|
||||
|
||||
const handleImageUpload = async (file: File): Promise<string> => {
|
||||
try {
|
||||
// 计算文件的 SHA256 哈希值
|
||||
const sha256 = await calculateFileSha256(file);
|
||||
return await onImageUpload!(file, sha256);
|
||||
} catch (error) {
|
||||
console.error("Image upload failed:", error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
{/* Platform Information Accordion */}
|
||||
@@ -170,6 +227,56 @@ export const PlatformConfigForm: React.FC<PlatformConfigFormProps> = ({
|
||||
</SelectItem>
|
||||
))}
|
||||
</Select>
|
||||
|
||||
{/* platform domain */}
|
||||
<Input
|
||||
label={t("Platform Domain")}
|
||||
placeholder={t(
|
||||
"Enter platform domain (e.g., https://example.com)"
|
||||
)}
|
||||
description={t("The domain name of your platform")}
|
||||
value={formData.domain || ""}
|
||||
onChange={(e) => handleInputChange("domain", e.target.value)}
|
||||
isInvalid={!!validationErrors.domain}
|
||||
errorMessage={validationErrors.domain}
|
||||
/>
|
||||
|
||||
{/* mcp server prefix */}
|
||||
<Input
|
||||
label={t("MCP Server Domain")}
|
||||
placeholder={t(
|
||||
"Enter MCP server domain (e.g., https://mcp.example.com)"
|
||||
)}
|
||||
description={t("The domain for MCP server API calls")}
|
||||
value={formData.mcp_server_prefix || ""}
|
||||
onChange={(e) =>
|
||||
handleInputChange("mcp_server_prefix", e.target.value)
|
||||
}
|
||||
isInvalid={!!validationErrors.mcp_server_prefix}
|
||||
errorMessage={validationErrors.mcp_server_prefix}
|
||||
/>
|
||||
|
||||
{/* showcase in xpack */}
|
||||
<div className="flex items-center justify-between p-4 bg-gray-50 rounded-lg">
|
||||
<div className="flex flex-col gap-1">
|
||||
<span className="text-sm font-medium">
|
||||
{t("Featured in the XPack showcase")}
|
||||
</span>
|
||||
<span className="text-xs text-gray-500">
|
||||
{t(
|
||||
"Enable this option to feature your site in the XPack global showcase and reach users worldwide."
|
||||
)}
|
||||
</span>
|
||||
</div>
|
||||
<Switch
|
||||
isSelected={formData.is_showcased ?? false}
|
||||
onValueChange={(value) => {
|
||||
handleBooleanChange("is_showcased", value);
|
||||
}}
|
||||
color="primary"
|
||||
size="sm"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Action Buttons */}
|
||||
@@ -187,120 +294,6 @@ export const PlatformConfigForm: React.FC<PlatformConfigFormProps> = ({
|
||||
</AccordionItem>
|
||||
</Accordion>
|
||||
|
||||
{/* About Page Accordion */}
|
||||
<Accordion
|
||||
variant="splitted"
|
||||
itemClasses={{
|
||||
base: "shadow-none border-1",
|
||||
}}
|
||||
className="px-0"
|
||||
defaultExpandedKeys={["about-config"]}
|
||||
>
|
||||
<AccordionItem
|
||||
key="about-config"
|
||||
title={
|
||||
<div className="flex flex-col justify-between">
|
||||
<h3 className="text-lg font-semibold">
|
||||
{t("About Page Content")}
|
||||
</h3>
|
||||
<p className="text-sm text-gray-500">
|
||||
{t("Configure about page content")}
|
||||
</p>
|
||||
</div>
|
||||
}
|
||||
>
|
||||
<div className="space-y-4">
|
||||
<MDEditor
|
||||
value={formData.about_page || ""}
|
||||
onChange={(value?: string) =>
|
||||
handleInputChange("about_page", value || "")
|
||||
}
|
||||
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: (
|
||||
<svg width="12" height="12" viewBox="0 0 20 20">
|
||||
<path
|
||||
fill="currentColor"
|
||||
d="M15 9c1.1 0 2-.9 2-2s-.9-2-2-2-2 .9-2 2 .9 2 2 2zm4-7H1c-.55 0-1 .45-1 1v14c0 .55.45 1 1 1h18c.55 0 1-.45 1-1V3c0-.55-.45-1-1-1zM2 17l4.5-6 3.5 4.51 2.5-3.01L17 17H2z"
|
||||
/>
|
||||
</svg>
|
||||
),
|
||||
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 = ``;
|
||||
api.replaceSelection(imageMarkdown);
|
||||
} catch (error) {
|
||||
console.error("Image upload failed:", error);
|
||||
}
|
||||
}
|
||||
};
|
||||
input.click();
|
||||
},
|
||||
},
|
||||
]}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* About Save Button */}
|
||||
<div className="flex gap-3 py-4">
|
||||
<Button
|
||||
color="primary"
|
||||
variant="solid"
|
||||
onPress={handleAboutSave}
|
||||
isLoading={isAboutLoading}
|
||||
size="sm"
|
||||
>
|
||||
{t("Save")}
|
||||
</Button>
|
||||
</div>
|
||||
</AccordionItem>
|
||||
</Accordion>
|
||||
|
||||
{/* Theme Accordion */}
|
||||
<Accordion
|
||||
variant="splitted"
|
||||
|
||||
@@ -0,0 +1,262 @@
|
||||
"use client";
|
||||
|
||||
import React, { useState, useRef, useEffect } from "react";
|
||||
import {
|
||||
AccordionItem,
|
||||
Accordion,
|
||||
Table,
|
||||
TableHeader,
|
||||
TableColumn,
|
||||
TableBody,
|
||||
TableRow,
|
||||
TableCell,
|
||||
Button,
|
||||
Input,
|
||||
Tooltip,
|
||||
Select,
|
||||
SelectItem,
|
||||
} from "@nextui-org/react";
|
||||
import { useTranslation } from "@/shared/lib/useTranslation";
|
||||
import { Plus, Trash2, GripVertical } from "lucide-react";
|
||||
import {
|
||||
TopNavigationItem,
|
||||
TopNavigationTargetEnum,
|
||||
} from "@/shared/types/system";
|
||||
|
||||
interface TopNavigationSettingsProps {
|
||||
onSave?: (config: TopNavigationItem[]) => void;
|
||||
config?: TopNavigationItem[];
|
||||
}
|
||||
|
||||
export const TopNavigationSettings: React.FC<TopNavigationSettingsProps> = ({
|
||||
onSave,
|
||||
config = [],
|
||||
}) => {
|
||||
const { t } = useTranslation();
|
||||
const [navigationItems, setNavigationItems] =
|
||||
useState<TopNavigationItem[]>(config);
|
||||
const [isSaving, setIsSaving] = useState(false);
|
||||
const draggedItem = useRef<number | null>(null);
|
||||
const draggedOverItem = useRef<number | null>(null);
|
||||
useEffect(() => {
|
||||
setNavigationItems(config);
|
||||
}, [config]);
|
||||
|
||||
const handleTitleChange = (index: number, value: string) => {
|
||||
setNavigationItems((prev) =>
|
||||
prev.map((item, idx) =>
|
||||
idx === index ? { ...item, title: value } : item
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
const handleHrefChange = (index: number, value: string) => {
|
||||
setNavigationItems((prev) =>
|
||||
prev.map((item, idx) => (idx === index ? { ...item, link: value } : item))
|
||||
);
|
||||
};
|
||||
|
||||
const handleTargetChange = (
|
||||
index: number,
|
||||
target: TopNavigationTargetEnum
|
||||
) => {
|
||||
setNavigationItems((prev) =>
|
||||
prev.map((item, idx) => (idx === index ? { ...item, target } : item))
|
||||
);
|
||||
};
|
||||
|
||||
const handleDelete = (index: number) => {
|
||||
setNavigationItems((prev) => {
|
||||
return prev.filter((_, idx) => idx !== index);
|
||||
});
|
||||
};
|
||||
|
||||
const handleInsertBelow = (index: number) => {
|
||||
setNavigationItems((prev) => {
|
||||
const newItem: TopNavigationItem = {
|
||||
title: "",
|
||||
link: "",
|
||||
target: TopNavigationTargetEnum.BLANK,
|
||||
};
|
||||
const newItems = [...prev];
|
||||
newItems.splice(index + 1, 0, newItem);
|
||||
return newItems;
|
||||
});
|
||||
};
|
||||
|
||||
const handleDragStart = (index: number) => {
|
||||
draggedItem.current = index;
|
||||
};
|
||||
|
||||
const handleDragEnter = (index: number) => {
|
||||
draggedOverItem.current = index;
|
||||
};
|
||||
|
||||
const handleDragEnd = () => {
|
||||
if (draggedItem.current !== null && draggedOverItem.current !== null) {
|
||||
const draggedItemIndex = draggedItem.current;
|
||||
const draggedOverItemIndex = draggedOverItem.current;
|
||||
|
||||
if (draggedItemIndex !== draggedOverItemIndex) {
|
||||
setNavigationItems((prev) => {
|
||||
const newItems = [...prev];
|
||||
const draggedItemContent = newItems[draggedItemIndex];
|
||||
newItems.splice(draggedItemIndex, 1);
|
||||
newItems.splice(draggedOverItemIndex, 0, draggedItemContent);
|
||||
return newItems;
|
||||
});
|
||||
}
|
||||
}
|
||||
draggedItem.current = null;
|
||||
draggedOverItem.current = null;
|
||||
};
|
||||
|
||||
const handleSaveAll = async () => {
|
||||
setIsSaving(true);
|
||||
try {
|
||||
await onSave?.(navigationItems.filter((item) => item.title && item.link));
|
||||
} finally {
|
||||
setIsSaving(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Accordion
|
||||
variant="splitted"
|
||||
itemClasses={{
|
||||
base: "shadow-none border-1",
|
||||
}}
|
||||
className="px-0"
|
||||
defaultExpandedKeys={["top-navigation"]}
|
||||
>
|
||||
<AccordionItem
|
||||
key="top-navigation"
|
||||
title={
|
||||
<div className="flex flex-col justify-between">
|
||||
<h3 className="text-lg font-semibold flex items-center gap-2">
|
||||
{t("Top Navigation")}
|
||||
</h3>
|
||||
<p className="text-sm text-gray-500">
|
||||
{t("Configure top navigation menu items and links")}
|
||||
</p>
|
||||
</div>
|
||||
}
|
||||
>
|
||||
<div className="space-y-4">
|
||||
{/* Navigation Table */}
|
||||
<Table
|
||||
aria-label="Navigation items management table"
|
||||
className="border-1 rounded-lg p-2"
|
||||
removeWrapper
|
||||
>
|
||||
<TableHeader>
|
||||
<TableColumn className="w-16">{t("Order")}</TableColumn>
|
||||
<TableColumn className="w-1/4">{t("Title")}</TableColumn>
|
||||
<TableColumn className="w-1/3">{t("Link")}</TableColumn>
|
||||
<TableColumn className="w-32">{t("Target")}</TableColumn>
|
||||
<TableColumn className="w-32">{t("Actions")}</TableColumn>
|
||||
</TableHeader>
|
||||
<TableBody emptyContent={t("No navigation items available.")}>
|
||||
{navigationItems.map((item, index) => (
|
||||
<TableRow
|
||||
key={index}
|
||||
draggable
|
||||
onDragStart={() => handleDragStart(index)}
|
||||
onDragEnter={() => handleDragEnter(index)}
|
||||
onDragEnd={handleDragEnd}
|
||||
onDragOver={(e) => e.preventDefault()}
|
||||
className="cursor-move"
|
||||
>
|
||||
<TableCell>
|
||||
<div className="flex items-center gap-2">
|
||||
<GripVertical className="w-4 h-4 text-gray-400" />
|
||||
</div>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<Input
|
||||
value={item.title}
|
||||
onValueChange={(value) => handleTitleChange(index, value)}
|
||||
placeholder={t("Enter title")}
|
||||
size="sm"
|
||||
/>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<Input
|
||||
value={item.link}
|
||||
onValueChange={(value) => handleHrefChange(index, value)}
|
||||
placeholder={t("Enter link URL")}
|
||||
size="sm"
|
||||
/>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<Select
|
||||
selectedKeys={[item.target]}
|
||||
onSelectionChange={(keys) => {
|
||||
const target = Array.from(keys)[0] as
|
||||
| TopNavigationTargetEnum.SELF
|
||||
| TopNavigationTargetEnum.BLANK;
|
||||
handleTargetChange(index, target);
|
||||
}}
|
||||
size="sm"
|
||||
className="min-w-24"
|
||||
>
|
||||
<SelectItem
|
||||
key={TopNavigationTargetEnum.SELF}
|
||||
value={TopNavigationTargetEnum.SELF}
|
||||
>
|
||||
{t("Same Tab")}
|
||||
</SelectItem>
|
||||
<SelectItem
|
||||
key={TopNavigationTargetEnum.BLANK}
|
||||
value={TopNavigationTargetEnum.BLANK}
|
||||
>
|
||||
{t("New Tab")}
|
||||
</SelectItem>
|
||||
</Select>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<div className="flex gap-1">
|
||||
<Tooltip content={t("Insert below")}>
|
||||
<Button
|
||||
isIconOnly
|
||||
size="sm"
|
||||
variant="light"
|
||||
onPress={() => handleInsertBelow(index)}
|
||||
>
|
||||
<Plus className="w-4 h-4" />
|
||||
</Button>
|
||||
</Tooltip>
|
||||
<Tooltip content={t("Delete")} color="danger">
|
||||
<Button
|
||||
isIconOnly
|
||||
size="sm"
|
||||
variant="light"
|
||||
color="danger"
|
||||
onPress={() => handleDelete(index)}
|
||||
>
|
||||
<Trash2 className="w-4 h-4" />
|
||||
</Button>
|
||||
</Tooltip>
|
||||
</div>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
|
||||
<div className="flex">
|
||||
<Button
|
||||
color="primary"
|
||||
onPress={handleSaveAll}
|
||||
isLoading={isSaving}
|
||||
isDisabled={navigationItems.length === 0}
|
||||
size="sm"
|
||||
>
|
||||
{t("Save")}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</AccordionItem>
|
||||
</Accordion>
|
||||
);
|
||||
};
|
||||
@@ -13,24 +13,32 @@ import { NavigationItems } from "@/components/theme/Theme.const";
|
||||
import { AboutContent } from "@/components/about/AboutContent";
|
||||
|
||||
export const AboutThemeSelector: React.FC = () => {
|
||||
const { platformConfig } = usePlatformConfig();
|
||||
const { platformConfig, topNavigation } = usePlatformConfig();
|
||||
const currentTheme = platformConfig.theme || Theme.DEFAULT;
|
||||
const navigationItems = [
|
||||
...NavigationItems,
|
||||
...topNavigation.map((item) => ({
|
||||
label: item.title,
|
||||
href: item.link,
|
||||
target: item.target,
|
||||
})),
|
||||
];
|
||||
|
||||
// Render the About page based on the current theme
|
||||
switch (currentTheme) {
|
||||
case Theme.MODERN:
|
||||
return <ModernAbout navItems={NavigationItems} />;
|
||||
return <ModernAbout navItems={navigationItems} />;
|
||||
case Theme.CLASSIC:
|
||||
return <ClassicAbout navItems={NavigationItems} />;
|
||||
return <ClassicAbout navItems={navigationItems} />;
|
||||
case Theme.CREATIVE:
|
||||
return <CreativeAbout navItems={NavigationItems} />;
|
||||
return <CreativeAbout navItems={navigationItems} />;
|
||||
case Theme.TEMU:
|
||||
return <TemuAbout navItems={NavigationItems} />;
|
||||
return <TemuAbout navItems={navigationItems} />;
|
||||
case Theme.DEFAULT:
|
||||
default:
|
||||
return (
|
||||
<div className="min-h-screen bg-background flex flex-col justify-between">
|
||||
<Navigation items={NavigationItems} />
|
||||
<Navigation items={navigationItems} />
|
||||
<main className="flex-1 max-w-7xl mx-auto px-4 py-8">
|
||||
<AboutContent />
|
||||
</main>
|
||||
|
||||
@@ -12,6 +12,9 @@ import { ProductDetailClient } from "@/shared/components/marketplace/ProductDeta
|
||||
import { Navigation } from "@/shared/components/Navigation";
|
||||
import { Footer } from "@/shared/components/Footer";
|
||||
import { NavigationItems } from "./Theme.const";
|
||||
import { copyToClipboard } from "@/shared/utils/clipboard";
|
||||
import toast from "react-hot-toast";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
interface ProductDetailThemeSelectorProps {
|
||||
product: ServiceData;
|
||||
@@ -24,13 +27,26 @@ interface ProductDetailThemeSelectorProps {
|
||||
export const ProductDetailThemeSelector: React.FC<
|
||||
ProductDetailThemeSelectorProps
|
||||
> = ({ product, breadcrumbs }) => {
|
||||
const { platformConfig } = usePlatformConfig();
|
||||
const { platformConfig, topNavigation } = usePlatformConfig();
|
||||
const currentTheme = platformConfig.theme || Theme.DEFAULT;
|
||||
const [url, setUrl] = useState<string>(process.env.NEXT_PUBLIC_MCP_URL || "");
|
||||
const mcpServerPrefix =
|
||||
platformConfig.mcp_server_prefix || process.env.NEXT_PUBLIC_MCP_URL || "";
|
||||
const [url, setUrl] = useState<string>("");
|
||||
const [mcpName, setMcpName] = useState<string>("");
|
||||
const { t } = useTranslation();
|
||||
const navigationItems = [
|
||||
...NavigationItems,
|
||||
...topNavigation.map((item) => ({
|
||||
label: item.title,
|
||||
href: item.link,
|
||||
target: item.target,
|
||||
})),
|
||||
];
|
||||
useEffect(() => {
|
||||
if (url || !product.slug_name) return;
|
||||
setUrl(`${window.location.protocol}//${window.location.hostname}:8002/mcp/${product.slug_name}`);
|
||||
setUrl(
|
||||
`${mcpServerPrefix || `${window.location.protocol}//${window.location.hostname}:8002`}/mcp/${product.slug_name}`
|
||||
);
|
||||
}, [product.slug_name]);
|
||||
function sanitizeMCPServerName(rawName: string | undefined): string {
|
||||
if (!rawName) return "xpack-mcp-service";
|
||||
@@ -47,13 +63,31 @@ export const ProductDetailThemeSelector: React.FC<
|
||||
// Trim leading/trailing hyphens
|
||||
name = name.replace(/^-+/, "").replace(/-+$/, "");
|
||||
|
||||
|
||||
return name || "mcp-service";
|
||||
}
|
||||
useEffect(() => {
|
||||
setMcpName(sanitizeMCPServerName(product.name));
|
||||
}, [product.name]);
|
||||
const getCodeContent = () => {
|
||||
return `{
|
||||
"mcpServers": {
|
||||
"${mcpName || "xpack-mcp-market"}": {
|
||||
"type": "sse",
|
||||
"autoApprove":"all",
|
||||
"url": "${url}?apikey={Your-${platformConfig?.name}-API-Key}"
|
||||
}
|
||||
}
|
||||
}`;
|
||||
};
|
||||
|
||||
const handleCopy = async () => {
|
||||
const result = await copyToClipboard(getCodeContent());
|
||||
if (result.success) {
|
||||
toast.success(t("Copied to clipboard"));
|
||||
} else {
|
||||
toast.error(t("Copy failed, please copy manually"));
|
||||
}
|
||||
};
|
||||
|
||||
//Render the About page based on the current theme
|
||||
switch (currentTheme) {
|
||||
@@ -63,8 +97,9 @@ export const ProductDetailThemeSelector: React.FC<
|
||||
product={product}
|
||||
breadcrumbs={breadcrumbs}
|
||||
url={url}
|
||||
navItems={NavigationItems}
|
||||
navItems={navigationItems}
|
||||
mcpName={mcpName}
|
||||
onCopy={handleCopy}
|
||||
/>
|
||||
);
|
||||
case Theme.CLASSIC:
|
||||
@@ -73,8 +108,9 @@ export const ProductDetailThemeSelector: React.FC<
|
||||
product={product}
|
||||
breadcrumbs={breadcrumbs}
|
||||
url={url}
|
||||
navItems={NavigationItems}
|
||||
navItems={navigationItems}
|
||||
mcpName={mcpName}
|
||||
onCopy={handleCopy}
|
||||
/>
|
||||
);
|
||||
case Theme.CREATIVE:
|
||||
@@ -83,8 +119,9 @@ export const ProductDetailThemeSelector: React.FC<
|
||||
product={product}
|
||||
breadcrumbs={breadcrumbs}
|
||||
url={url}
|
||||
navItems={NavigationItems}
|
||||
navItems={navigationItems}
|
||||
mcpName={mcpName}
|
||||
onCopy={handleCopy}
|
||||
/>
|
||||
);
|
||||
case Theme.TEMU:
|
||||
@@ -93,17 +130,22 @@ export const ProductDetailThemeSelector: React.FC<
|
||||
product={product}
|
||||
breadcrumbs={breadcrumbs}
|
||||
url={url}
|
||||
navItems={NavigationItems}
|
||||
navItems={navigationItems}
|
||||
mcpName={mcpName}
|
||||
onCopy={handleCopy}
|
||||
/>
|
||||
);
|
||||
case Theme.DEFAULT:
|
||||
default:
|
||||
return (
|
||||
<div className="min-h-screen bg-background flex flex-col justify-between">
|
||||
<Navigation items={NavigationItems} />
|
||||
<Navigation items={navigationItems} />
|
||||
<main className="flex-1">
|
||||
<ProductDetailClient product={product} mcpName={mcpName} />
|
||||
<ProductDetailClient
|
||||
product={product}
|
||||
mcpName={mcpName}
|
||||
url={url}
|
||||
/>
|
||||
</main>
|
||||
<div>
|
||||
<Footer />
|
||||
|
||||
@@ -14,6 +14,7 @@ import { Navigation } from "@/shared/components/Navigation";
|
||||
import { MarketplaceMain } from "../marketplace/Main";
|
||||
import { Footer } from "@/shared/components/Footer";
|
||||
import { NavigationItems } from "./Theme.const";
|
||||
import { Faq } from "../marketplace/Faq";
|
||||
|
||||
interface ThemeSelectorProps {
|
||||
initialServices: ServiceData[];
|
||||
@@ -33,8 +34,16 @@ export const ThemeSelector: React.FC<ThemeSelectorProps> = ({
|
||||
error,
|
||||
}) => {
|
||||
const router = useRouter();
|
||||
const { platformConfig } = usePlatformConfig();
|
||||
const { platformConfig, topNavigation } = usePlatformConfig();
|
||||
const currentTheme = platformConfig.theme || Theme.DEFAULT;
|
||||
const navigationItems = [
|
||||
...NavigationItems,
|
||||
...topNavigation.map((item) => ({
|
||||
label: item.title,
|
||||
href: item.link,
|
||||
target: item.target,
|
||||
})),
|
||||
];
|
||||
|
||||
// state management for services, search query, pagination, and loading state
|
||||
const [searchQuery, setSearchQuery] = useState(initialSearch);
|
||||
@@ -122,7 +131,7 @@ export const ThemeSelector: React.FC<ThemeSelectorProps> = ({
|
||||
onSearch={handleSearch}
|
||||
onPageChange={handlePageChange}
|
||||
searchSuggestions={searchSuggestions}
|
||||
navItems={NavigationItems}
|
||||
navItems={navigationItems}
|
||||
/>
|
||||
);
|
||||
case Theme.CLASSIC:
|
||||
@@ -139,7 +148,7 @@ export const ThemeSelector: React.FC<ThemeSelectorProps> = ({
|
||||
onSearch={handleSearch}
|
||||
onPageChange={handlePageChange}
|
||||
searchSuggestions={searchSuggestions}
|
||||
navItems={NavigationItems}
|
||||
navItems={navigationItems}
|
||||
/>
|
||||
);
|
||||
case Theme.CREATIVE:
|
||||
@@ -156,7 +165,7 @@ export const ThemeSelector: React.FC<ThemeSelectorProps> = ({
|
||||
onSearch={handleSearch}
|
||||
onPageChange={handlePageChange}
|
||||
searchSuggestions={searchSuggestions}
|
||||
navItems={NavigationItems}
|
||||
navItems={navigationItems}
|
||||
/>
|
||||
);
|
||||
case Theme.TEMU:
|
||||
@@ -173,14 +182,14 @@ export const ThemeSelector: React.FC<ThemeSelectorProps> = ({
|
||||
onSearch={handleSearch}
|
||||
onPageChange={handlePageChange}
|
||||
searchSuggestions={searchSuggestions}
|
||||
navItems={NavigationItems}
|
||||
navItems={navigationItems}
|
||||
/>
|
||||
);
|
||||
case Theme.DEFAULT:
|
||||
default:
|
||||
return (
|
||||
<div className="min-h-screen bg-background flex flex-col justify-between">
|
||||
<Navigation items={NavigationItems} />
|
||||
<Navigation items={navigationItems} />
|
||||
<main className="flex-1">
|
||||
<MarketplaceMain
|
||||
initialServices={services}
|
||||
@@ -190,6 +199,7 @@ export const ThemeSelector: React.FC<ThemeSelectorProps> = ({
|
||||
pageSize={pageSize}
|
||||
error={error}
|
||||
/>
|
||||
<Faq />
|
||||
</main>
|
||||
<div>
|
||||
<Footer />
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
|
||||
import React, { useState } from "react";
|
||||
import { useTranslation } from "@/shared/lib/useTranslation";
|
||||
import { Tabs, Tab, Chip, Card, CardBody } from "@nextui-org/react";
|
||||
import { Tabs, Tab, Chip, Card, CardBody, Button } 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 { FileText, Wrench, Cog, Copy } from "lucide-react";
|
||||
import { Navigation } from "./Navigation";
|
||||
import { Footer } from "./Footer";
|
||||
import Link from "next/link";
|
||||
@@ -24,14 +24,15 @@ interface DetailProps {
|
||||
mcpName?: string;
|
||||
// navigation items
|
||||
navItems?: NavigationItem[];
|
||||
onCopy: () => void;
|
||||
}
|
||||
|
||||
export const Detail: React.FC<DetailProps> = ({
|
||||
product,
|
||||
breadcrumbs,
|
||||
url,
|
||||
mcpName,
|
||||
navItems = [],
|
||||
onCopy,
|
||||
}) => {
|
||||
const { t } = useTranslation();
|
||||
const [activeTab, setActiveTab] = useState("overview");
|
||||
@@ -98,6 +99,8 @@ export const Detail: React.FC<DetailProps> = ({
|
||||
<Price
|
||||
price={product.price}
|
||||
charge_type={product.charge_type}
|
||||
input_token_price={product.input_token_price}
|
||||
output_token_price={product.output_token_price}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
@@ -210,18 +213,26 @@ export const Detail: React.FC<DetailProps> = ({
|
||||
{/* Code Snippet */}
|
||||
<Card className="w-full max-w-2xl bg-black text-white p-2 sm:p-4 rounded-lg relative z-10">
|
||||
<div className="text-left font-mono">
|
||||
<Chip
|
||||
className="mb-2 text-white"
|
||||
size="sm"
|
||||
variant="flat"
|
||||
>
|
||||
{platformConfig?.name} MCP
|
||||
</Chip>
|
||||
<div className="flex items-center gap-2 mb-2 justify-between">
|
||||
<Chip className="text-white" size="sm" variant="flat">
|
||||
{platformConfig?.name} MCP
|
||||
</Chip>
|
||||
<Button
|
||||
isIconOnly
|
||||
size="sm"
|
||||
variant="flat"
|
||||
className="min-w-6 w-6 h-6 p-0 text-white"
|
||||
onPress={onCopy}
|
||||
aria-label={t("Copy code")}
|
||||
>
|
||||
<Copy size={14} />
|
||||
</Button>
|
||||
</div>
|
||||
<pre className="p-2 sm:p-4 rounded-md text-xs overflow-x-auto">
|
||||
<code className="text-gray-300 whitespace-pre-wrap">
|
||||
{`{
|
||||
"mcpServers": {
|
||||
"${mcpName || "xpack-mcp-market"}": {
|
||||
"${mcpName}": {
|
||||
"type": "sse",
|
||||
"autoApprove":"all",
|
||||
"url": "${url}?apikey=`}
|
||||
|
||||
@@ -23,6 +23,7 @@ import {
|
||||
import { Footer } from "./Footer";
|
||||
import { Navigation } from "./Navigation";
|
||||
import { NavigationItem } from "@/shared/components/Navigation";
|
||||
import { Faq } from "@/components/marketplace/Faq";
|
||||
|
||||
interface HomeProps {
|
||||
// 状态
|
||||
@@ -163,13 +164,14 @@ export const Home: React.FC<HomeProps> = ({
|
||||
<div className="bg-gray-50 py-16">
|
||||
<div className="mx-auto px-6 max-w-7xl">
|
||||
{/* Services Grid */}
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-6 mb-12">
|
||||
<div className="flex flex-wrap justify-center gap-4 mb-12">
|
||||
{services.map((service) => (
|
||||
<Link
|
||||
key={service.service_id}
|
||||
href={`/marketplace/${service.service_id}`}
|
||||
className="w-full md:w-[calc(50%-16px)] lg:w-[calc(33%-16px)] xl:w-[calc(25%-16px)]"
|
||||
>
|
||||
<Card className="group h-[200px] hover:shadow-lg transition-shadow duration-200 cursor-pointer border border-gray-200 bg-white rounded-sm shadow-sm">
|
||||
<Card className="group h-[200px] w-full hover:shadow-lg transition-shadow duration-200 cursor-pointer border border-gray-200 bg-white rounded-sm shadow-sm">
|
||||
<CardBody className="p-4">
|
||||
{/* Header */}
|
||||
<div className="flex items-start justify-between mb-3">
|
||||
@@ -211,6 +213,8 @@ export const Home: React.FC<HomeProps> = ({
|
||||
<Price
|
||||
price={service.price}
|
||||
charge_type={service.charge_type}
|
||||
input_token_price={service.input_token_price}
|
||||
output_token_price={service.output_token_price}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
@@ -245,6 +249,7 @@ export const Home: React.FC<HomeProps> = ({
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
<Faq />
|
||||
</div>
|
||||
<div>
|
||||
<Footer />
|
||||
|
||||
@@ -43,7 +43,12 @@ export const Navigation: React.FC<NavigationProps> = ({ items }) => {
|
||||
<div className="flex items-center justify-between max-w-7xl mx-auto">
|
||||
<div className="flex space-x-6">
|
||||
{items?.map((item) => (
|
||||
<Link href={item.href} className="text-sm text-gray-500">
|
||||
<Link
|
||||
key={item.href}
|
||||
href={item.href}
|
||||
target={item.target}
|
||||
className="text-sm text-gray-500"
|
||||
>
|
||||
{t(item.label)}
|
||||
</Link>
|
||||
))}
|
||||
|
||||
@@ -2,13 +2,12 @@
|
||||
|
||||
import React, { useState } from "react";
|
||||
import { useTranslation } from "@/shared/lib/useTranslation";
|
||||
import { Tabs, Tab, Chip, Card, CardBody } from "@nextui-org/react";
|
||||
import { Tabs, Tab, Chip, Card, CardBody, Button } 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 { Sparkles, Zap, Settings2, Copy } from "lucide-react";
|
||||
import { Navigation } from "./Navigation";
|
||||
import { Footer } from "./Footer";
|
||||
import { usePlatformConfig } from "@/shared/contexts/PlatformConfigContext";
|
||||
@@ -24,6 +23,7 @@ interface DetailProps {
|
||||
mcpName?: string;
|
||||
// navigation items
|
||||
navItems?: NavigationItem[];
|
||||
onCopy: () => void;
|
||||
}
|
||||
|
||||
export const Detail: React.FC<DetailProps> = ({
|
||||
@@ -32,6 +32,7 @@ export const Detail: React.FC<DetailProps> = ({
|
||||
url,
|
||||
mcpName,
|
||||
navItems = [],
|
||||
onCopy,
|
||||
}) => {
|
||||
const { t } = useTranslation();
|
||||
const [activeTab, setActiveTab] = useState("overview");
|
||||
@@ -42,151 +43,190 @@ export const Detail: React.FC<DetailProps> = ({
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-gradient-to-br from-pink-50 via-orange-50 to-yellow-50 relative overflow-hidden">
|
||||
<div className="min-h-screen bg-gradient-to-br from-pink-50 via-orange-50 to-yellow-50 relative overflow-hidden flex flex-col justify-between">
|
||||
<Navigation items={navItems} />
|
||||
{/* Creative Background */}
|
||||
<div className="absolute inset-0">
|
||||
{/* Artistic decorative elements */}
|
||||
<div className="absolute top-20 left-20 w-32 h-32 bg-gradient-to-br from-pink-200/30 to-orange-200/30 rounded-full blur-2xl" />
|
||||
<div className="absolute top-40 right-32 w-24 h-24 bg-gradient-to-br from-orange-200/40 to-yellow-200/40 rounded-2xl rotate-45 blur-xl" />
|
||||
<div className="absolute bottom-32 left-1/4 w-40 h-40 bg-gradient-to-br from-yellow-200/25 to-pink-200/25 rounded-full blur-3xl" />
|
||||
<div className="absolute bottom-20 right-20 w-28 h-28 bg-gradient-to-br from-pink-200/35 to-red-200/35 rounded-2xl rotate-12 blur-xl" />
|
||||
<div className="flex-1 relative">
|
||||
<div className="absolute inset-0">
|
||||
{/* Artistic decorative elements */}
|
||||
<div className="absolute top-20 left-20 w-32 h-32 bg-gradient-to-br from-pink-200/30 to-orange-200/30 rounded-full blur-2xl" />
|
||||
<div className="absolute top-40 right-32 w-24 h-24 bg-gradient-to-br from-orange-200/40 to-yellow-200/40 rounded-2xl rotate-45 blur-xl" />
|
||||
<div className="absolute bottom-32 left-1/4 w-40 h-40 bg-gradient-to-br from-yellow-200/25 to-pink-200/25 rounded-full blur-3xl" />
|
||||
<div className="absolute bottom-20 right-20 w-28 h-28 bg-gradient-to-br from-pink-200/35 to-red-200/35 rounded-2xl rotate-12 blur-xl" />
|
||||
|
||||
{/* Additional artistic elements */}
|
||||
<div className="absolute top-1/3 left-1/3 w-20 h-20 bg-gradient-to-br from-orange-300/20 to-yellow-300/20 rounded-full blur-xl" />
|
||||
<div className="absolute top-2/3 right-1/3 w-16 h-16 bg-gradient-to-br from-pink-300/25 to-orange-300/25 rounded-lg rotate-45 blur-lg" />
|
||||
</div>
|
||||
|
||||
<div className="relative z-10">
|
||||
{/* Creative Product Header */}
|
||||
<div className="pt-24">
|
||||
<div className="mx-auto p-6 max-w-7xl">
|
||||
<div className="bg-white/90 backdrop-blur-sm rounded-2xl p-6 shadow-lg border border-pink-200/50">
|
||||
<ProductHeader product={product} breadcrumbs={breadcrumbs} />
|
||||
</div>
|
||||
</div>
|
||||
{/* Additional artistic elements */}
|
||||
<div className="absolute top-1/3 left-1/3 w-20 h-20 bg-gradient-to-br from-orange-300/20 to-yellow-300/20 rounded-full blur-xl" />
|
||||
<div className="absolute top-2/3 right-1/3 w-16 h-16 bg-gradient-to-br from-pink-300/25 to-orange-300/25 rounded-lg rotate-45 blur-lg" />
|
||||
</div>
|
||||
|
||||
{/* Main Content */}
|
||||
<div className="mx-auto p-6 max-w-7xl">
|
||||
<div className="flex gap-6 mt-6">
|
||||
{/* Left side - Main content */}
|
||||
<div className="flex-1">
|
||||
<Card className="bg-white/95 backdrop-blur-sm border border-pink-200/50 shadow-lg overflow-hidden rounded-2xl">
|
||||
<div className="absolute inset-0 bg-gradient-to-r from-pink-500/5 via-transparent to-orange-500/5" />
|
||||
<CardBody className="p-0 relative">
|
||||
<Tabs
|
||||
selectedKey={activeTab}
|
||||
onSelectionChange={(key) => 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",
|
||||
}}
|
||||
>
|
||||
<Tab
|
||||
key="overview"
|
||||
title={
|
||||
<div className="flex items-center gap-2">
|
||||
<Sparkles className="w-4 h-4" />
|
||||
<span>{t("Overview")}</span>
|
||||
</div>
|
||||
}
|
||||
>
|
||||
<div className="p-6 pt-4">
|
||||
<ProductOverview product={product} />
|
||||
</div>
|
||||
</Tab>
|
||||
<Tab
|
||||
key="tools"
|
||||
title={
|
||||
<div className="flex gap-2 items-center">
|
||||
<Zap className="w-4 h-4" />
|
||||
<span>{t("Tools")}</span>
|
||||
<Chip
|
||||
size="sm"
|
||||
className="h-4 text-xs bg-gradient-to-r from-pink-500 via-red-500 to-orange-500 text-white shadow-lg"
|
||||
>
|
||||
{product.tools.length}
|
||||
</Chip>
|
||||
</div>
|
||||
}
|
||||
>
|
||||
<div className="p-6 pt-4">
|
||||
<ProductTools product={product} />
|
||||
</div>
|
||||
</Tab>
|
||||
</Tabs>
|
||||
</CardBody>
|
||||
</Card>
|
||||
<div className="relative z-10">
|
||||
{/* Creative Product Header */}
|
||||
<div className="pt-24">
|
||||
<div className="mx-auto p-6 max-w-7xl">
|
||||
<div className="bg-white/90 backdrop-blur-sm rounded-2xl p-6 shadow-lg border border-pink-200/50">
|
||||
<ProductHeader product={product} breadcrumbs={breadcrumbs} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Right side - Server Config */}
|
||||
<div className="min-w-[400px] w-[40%] max-w-100 flex-shrink-0">
|
||||
<Card className="bg-white/95 backdrop-blur-sm border border-pink-200/50 shadow-lg overflow-hidden rounded-2xl">
|
||||
<div className="absolute inset-0 bg-gradient-to-br from-orange-500/5 via-transparent to-pink-500/5" />
|
||||
<CardBody className="relative">
|
||||
<div className="flex items-center gap-3 mb-4">
|
||||
<div className="p-2 bg-gradient-to-r from-pink-500 via-red-500 to-orange-500 rounded-lg">
|
||||
<Settings2 className="w-5 h-5 text-white" />
|
||||
</div>
|
||||
<h3 className="font-semibold text-lg bg-gradient-to-r from-pink-600 to-orange-600 bg-clip-text text-transparent">
|
||||
{t("Configuration")}
|
||||
</h3>
|
||||
</div>
|
||||
{/* Code Snippet */}
|
||||
<Card className="w-full max-w-2xl bg-black text-white p-2 sm:p-4 rounded-lg relative z-10">
|
||||
<div className="text-left font-mono">
|
||||
<Chip
|
||||
className="mb-2 text-white"
|
||||
size="sm"
|
||||
variant="flat"
|
||||
{/* Main Content */}
|
||||
<div className="mx-auto p-6 max-w-7xl">
|
||||
<div className="flex gap-6 mt-6">
|
||||
{/* Left side - Main content */}
|
||||
<div className="flex-1">
|
||||
<Card className="bg-white/95 backdrop-blur-sm border border-pink-200/50 shadow-lg overflow-hidden rounded-2xl">
|
||||
<div className="absolute inset-0 bg-gradient-to-r from-pink-500/5 via-transparent to-orange-500/5" />
|
||||
<CardBody className="p-0 relative">
|
||||
<Tabs
|
||||
selectedKey={activeTab}
|
||||
onSelectionChange={(key) => 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",
|
||||
}}
|
||||
>
|
||||
<Tab
|
||||
key="overview"
|
||||
title={
|
||||
<div className="flex items-center gap-2">
|
||||
<Sparkles className="w-4 h-4" />
|
||||
<span>{t("Overview")}</span>
|
||||
</div>
|
||||
}
|
||||
>
|
||||
{platformConfig?.name} MCP
|
||||
</Chip>
|
||||
<pre className="p-2 sm:p-4 rounded-md text-xs overflow-x-auto">
|
||||
<code className="text-gray-300 whitespace-pre-wrap">
|
||||
{`{
|
||||
<div className="p-6 pt-4">
|
||||
<ProductOverview product={product} />
|
||||
</div>
|
||||
</Tab>
|
||||
<Tab
|
||||
key="tools"
|
||||
title={
|
||||
<div className="flex gap-2 items-center">
|
||||
<Zap className="w-4 h-4" />
|
||||
<span>{t("Tools")}</span>
|
||||
<Chip
|
||||
size="sm"
|
||||
className="h-4 text-xs bg-gradient-to-r from-pink-500 via-red-500 to-orange-500 text-white shadow-lg"
|
||||
>
|
||||
{product.tools.length}
|
||||
</Chip>
|
||||
</div>
|
||||
}
|
||||
>
|
||||
<div className="p-6 pt-4">
|
||||
{product.tools.length > 0 ? (
|
||||
product.tools.map((tool, index) => (
|
||||
<Card
|
||||
radius="sm"
|
||||
key={`${product.service_id}-tool-${index}`}
|
||||
shadow="none"
|
||||
className="border-1"
|
||||
>
|
||||
<CardBody>
|
||||
<h4 className="font-semibold text-sm mb-2 text-pink-600">
|
||||
{tool.name}
|
||||
</h4>
|
||||
<p className="text-sm mb-3">
|
||||
{tool.description ||
|
||||
t("No description available")}
|
||||
</p>
|
||||
</CardBody>
|
||||
</Card>
|
||||
))
|
||||
) : (
|
||||
<Card>
|
||||
<CardBody>
|
||||
<p className="text-center">
|
||||
{t("No tools available in this service.")}
|
||||
</p>
|
||||
</CardBody>
|
||||
</Card>
|
||||
)}
|
||||
</div>
|
||||
</Tab>
|
||||
</Tabs>
|
||||
</CardBody>
|
||||
</Card>
|
||||
</div>
|
||||
|
||||
{/* Right side - Server Config */}
|
||||
<div className="min-w-[400px] w-[40%] max-w-100 flex-shrink-0">
|
||||
<Card className="bg-white/95 backdrop-blur-sm border border-pink-200/50 shadow-lg overflow-hidden rounded-2xl">
|
||||
<div className="absolute inset-0 bg-gradient-to-br from-orange-500/5 via-transparent to-pink-500/5" />
|
||||
<CardBody className="relative">
|
||||
<div className="flex items-center gap-3 mb-4">
|
||||
<div className="p-2 bg-gradient-to-r from-pink-500 via-red-500 to-orange-500 rounded-lg">
|
||||
<Settings2 className="w-5 h-5 text-white" />
|
||||
</div>
|
||||
<h3 className="font-semibold text-lg bg-gradient-to-r from-pink-600 to-orange-600 bg-clip-text text-transparent">
|
||||
{t("Configuration")}
|
||||
</h3>
|
||||
</div>
|
||||
{/* Code Snippet */}
|
||||
<Card className="w-full max-w-2xl bg-black text-white p-2 sm:p-4 rounded-lg relative z-10">
|
||||
<div className="text-left font-mono">
|
||||
<div className="flex items-center gap-2 mb-2 justify-between">
|
||||
<Chip className="text-white" size="sm" variant="flat">
|
||||
{platformConfig?.name} MCP
|
||||
</Chip>
|
||||
<Button
|
||||
isIconOnly
|
||||
size="sm"
|
||||
variant="flat"
|
||||
className="min-w-6 w-6 h-6 p-0 text-white"
|
||||
onPress={onCopy}
|
||||
aria-label={t("Copy code")}
|
||||
>
|
||||
<Copy size={14} />
|
||||
</Button>
|
||||
</div>
|
||||
<pre className="p-2 sm:p-4 rounded-md text-xs overflow-x-auto">
|
||||
<code className="text-gray-300 whitespace-pre-wrap">
|
||||
{`{
|
||||
"mcpServers": {
|
||||
"${mcpName || "xpack-mcp-market"}": {
|
||||
"${mcpName}": {
|
||||
"type": "sse",
|
||||
"autoApprove":"all",
|
||||
"url": "${url}?apikey=`}
|
||||
<span className="text-success">{`{Your-${platformConfig?.name}-API-Key}`}</span>
|
||||
{`"
|
||||
<span className="text-success">{`{Your-${platformConfig?.name}-API-Key}`}</span>
|
||||
{`"
|
||||
}
|
||||
}
|
||||
}`}
|
||||
</code>
|
||||
</pre>
|
||||
</div>
|
||||
</Card>
|
||||
</CardBody>
|
||||
</Card>
|
||||
</code>
|
||||
</pre>
|
||||
</div>
|
||||
</Card>
|
||||
</CardBody>
|
||||
</Card>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* SEO-friendly: Simple text content for search engines */}
|
||||
<div className="hidden" aria-hidden="true">
|
||||
<h2>Tools ({product.tools.length})</h2>
|
||||
{product.tools.length > 0 &&
|
||||
product.tools.map((tool, index) => (
|
||||
<div key={`seo-${product.service_id}-tool-${index}`}>
|
||||
<h4>{tool.name}</h4>
|
||||
<p>{tool.description || ""}</p>
|
||||
</div>
|
||||
))}
|
||||
{/* SEO-friendly: Simple text content for search engines */}
|
||||
<div className="hidden" aria-hidden="true">
|
||||
<h2>Tools ({product.tools.length})</h2>
|
||||
{product.tools.length > 0 &&
|
||||
product.tools.map((tool, index) => (
|
||||
<div key={`seo-${product.service_id}-tool-${index}`}>
|
||||
<h4>{tool.name}</h4>
|
||||
<p>{tool.description || ""}</p>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<Footer />
|
||||
<div>
|
||||
<Footer />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -23,6 +23,7 @@ import {
|
||||
import { Footer } from "./Footer";
|
||||
import { Navigation } from "./Navigation";
|
||||
import { NavigationItem } from "@/shared/components/Navigation";
|
||||
import { Faq } from "@/components/marketplace/Faq";
|
||||
|
||||
interface HomeProps {
|
||||
// 状态
|
||||
@@ -69,17 +70,17 @@ export const Home: React.FC<HomeProps> = ({
|
||||
|
||||
{/* Creative Background decorative elements */}
|
||||
<div className="absolute inset-0 overflow-hidden pointer-events-none z-50">
|
||||
{/* 主要装饰圆圈 */}
|
||||
{/* main decorative circles */}
|
||||
<div className="absolute top-1/4 left-1/4 w-64 h-64 bg-gradient-to-r from-pink-400/15 to-orange-400/15 rounded-full blur-3xl animate-pulse"></div>
|
||||
<div className="absolute bottom-1/4 right-1/4 w-96 h-96 bg-gradient-to-r from-orange-400/10 to-yellow-400/10 rounded-full blur-3xl"></div>
|
||||
|
||||
{/* 小装饰圆圈 */}
|
||||
{/* small decorative circles */}
|
||||
<div className="absolute top-10 right-20 w-16 h-16 bg-gradient-to-br from-pink-400/20 to-red-500/20 rounded-full transform rotate-12"></div>
|
||||
<div className="absolute top-32 left-16 w-12 h-12 bg-gradient-to-br from-orange-400/25 to-yellow-400/25 rounded-full transform -rotate-12"></div>
|
||||
<div className="absolute bottom-20 left-1/3 w-20 h-20 bg-gradient-to-br from-yellow-400/15 to-pink-400/15 rounded-full transform rotate-6"></div>
|
||||
<div className="absolute bottom-32 right-16 w-14 h-14 bg-gradient-to-br from-purple-400/20 to-pink-400/20 rounded-full transform -rotate-6"></div>
|
||||
|
||||
{/* 微小装饰点 */}
|
||||
{/* small decorative points */}
|
||||
<div className="absolute top-1/3 right-1/3 w-4 h-4 bg-pink-400/30 rounded-full"></div>
|
||||
<div className="absolute top-2/3 left-1/5 w-3 h-3 bg-orange-400/40 rounded-full"></div>
|
||||
<div className="absolute bottom-1/3 right-1/5 w-5 h-5 bg-yellow-400/25 rounded-full"></div>
|
||||
@@ -129,7 +130,7 @@ export const Home: React.FC<HomeProps> = ({
|
||||
placeholder={
|
||||
searchSuggestions.length > 0
|
||||
? t(searchSuggestions[0])
|
||||
: t("✨ 发现神奇的服务...")
|
||||
: t("✨ Discover amazing services...")
|
||||
}
|
||||
value={searchQuery}
|
||||
onChange={(e) => onSearchChange(e.target.value)}
|
||||
@@ -170,9 +171,6 @@ export const Home: React.FC<HomeProps> = ({
|
||||
<div className="bg-white/90 backdrop-blur-xl p-8 rounded-2xl shadow-lg border border-pink-200/50">
|
||||
<div className="flex items-center gap-4">
|
||||
<Spinner size="lg" color="secondary" />
|
||||
<span className="text-gray-700 text-lg font-bold">
|
||||
✨ 加载魔法中...
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -180,7 +178,7 @@ export const Home: React.FC<HomeProps> = ({
|
||||
<div className="relative z-10">
|
||||
<div className="relative mx-auto px-6 py-16 max-w-8xl">
|
||||
{/* Creative Services Grid */}
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6 max-w-6xl mx-auto">
|
||||
<div className="flex flex-wrap justify-center gap-4 mb-12">
|
||||
{services.map((service, index) => {
|
||||
const gradientBorders = [
|
||||
"border-pink-200/50",
|
||||
@@ -211,7 +209,7 @@ export const Home: React.FC<HomeProps> = ({
|
||||
<Link
|
||||
key={service.service_id}
|
||||
href={`/marketplace/${service.service_id}`}
|
||||
className="block group"
|
||||
className="block group w-full md:w-[calc(50%-16px)] lg:w-[calc(33%-16px)] xl:w-[calc(25%-16px)]"
|
||||
>
|
||||
<Card
|
||||
className={`
|
||||
@@ -220,11 +218,11 @@ export const Home: React.FC<HomeProps> = ({
|
||||
hover:scale-105 hover:shadow-xl
|
||||
transition-all duration-300 ease-out
|
||||
group-hover:bg-white/90 relative
|
||||
h-[200px]
|
||||
h-[200px] w-full
|
||||
`}
|
||||
>
|
||||
<CardBody className="p-6">
|
||||
{/* 创意图标 */}
|
||||
{/* creative icon */}
|
||||
<div
|
||||
className={` absolute -top-2 -left-2
|
||||
w-8 h-8 ${iconGradients[index % 6]}
|
||||
@@ -233,17 +231,18 @@ export const Home: React.FC<HomeProps> = ({
|
||||
`}
|
||||
></div>
|
||||
|
||||
{/* 服务标题 */}
|
||||
{/* service title */}
|
||||
<div className="text-lg font-bold text-gray-800 mb-2 group-hover:text-gray-900 transition-colors">
|
||||
{service.name}
|
||||
</div>
|
||||
|
||||
{/* 服务描述 */}
|
||||
<div className="text-sm text-gray-600 group-hover:text-gray-700 transition-colors flex-1">
|
||||
{service.short_description || "探索精彩服务"}
|
||||
{/* service description */}
|
||||
<div className="text-gray-600 text-sm line-clamp-3 leading-relaxed mb-4">
|
||||
{service.short_description ||
|
||||
t("No description available")}
|
||||
</div>
|
||||
|
||||
{/* 装饰性元素 */}
|
||||
{/* decorative elements */}
|
||||
<div className="absolute top-2 right-2 w-3 h-3 bg-gradient-to-r from-pink-400/30 to-orange-400/30 rounded-full opacity-0 group-hover:opacity-100 transition-opacity duration-300"></div>
|
||||
</CardBody>
|
||||
|
||||
@@ -265,6 +264,8 @@ export const Home: React.FC<HomeProps> = ({
|
||||
<Price
|
||||
price={service.price}
|
||||
charge_type={service.charge_type}
|
||||
input_token_price={service.input_token_price}
|
||||
output_token_price={service.output_token_price}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
@@ -317,6 +318,7 @@ export const Home: React.FC<HomeProps> = ({
|
||||
`}</style>
|
||||
</div>
|
||||
)}
|
||||
<Faq />
|
||||
<Footer />
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -52,7 +52,12 @@ export const Navigation: React.FC<NavigationProps> = ({ items }) => {
|
||||
</div>
|
||||
<div className="hidden lg:flex gap-6 justify-center">
|
||||
{items?.map((item) => (
|
||||
<Link href={item.href} className="text-sm text-gray-500">
|
||||
<Link
|
||||
key={item.href}
|
||||
href={item.href}
|
||||
target={item.target}
|
||||
className="text-sm text-gray-500"
|
||||
>
|
||||
{t(item.label)}
|
||||
</Link>
|
||||
))}
|
||||
|
||||
@@ -2,13 +2,13 @@
|
||||
|
||||
import React, { useState } from "react";
|
||||
import { useTranslation } from "@/shared/lib/useTranslation";
|
||||
import { Tabs, Tab, Chip, Card, CardBody } from "@nextui-org/react";
|
||||
import { Tabs, Tab, Chip, Card, CardBody, Button } 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 { Monitor, Code, Settings, Copy } from "lucide-react";
|
||||
import { Navigation } from "./Navigation";
|
||||
import { Footer } from "./Footer";
|
||||
import { usePlatformConfig } from "@/shared/contexts/PlatformConfigContext";
|
||||
@@ -24,6 +24,7 @@ interface DetailProps {
|
||||
mcpName?: string;
|
||||
// navigation items
|
||||
navItems?: NavigationItem[];
|
||||
onCopy: () => void;
|
||||
}
|
||||
|
||||
export const Detail: React.FC<DetailProps> = ({
|
||||
@@ -32,6 +33,7 @@ export const Detail: React.FC<DetailProps> = ({
|
||||
url,
|
||||
mcpName,
|
||||
navItems = [],
|
||||
onCopy,
|
||||
}) => {
|
||||
const { t } = useTranslation();
|
||||
const [activeTab, setActiveTab] = useState("overview");
|
||||
@@ -138,18 +140,26 @@ export const Detail: React.FC<DetailProps> = ({
|
||||
{/* Code Snippet */}
|
||||
<Card className="w-full max-w-2xl bg-black text-white p-2 sm:p-4 rounded-lg relative z-10">
|
||||
<div className="text-left font-mono">
|
||||
<Chip
|
||||
className="mb-2 text-white"
|
||||
size="sm"
|
||||
variant="flat"
|
||||
>
|
||||
{platformConfig?.name} MCP
|
||||
</Chip>
|
||||
<div className="flex items-center gap-2 mb-2 justify-between">
|
||||
<Chip className="text-white" size="sm" variant="flat">
|
||||
{platformConfig?.name} MCP
|
||||
</Chip>
|
||||
<Button
|
||||
isIconOnly
|
||||
size="sm"
|
||||
variant="flat"
|
||||
className="min-w-6 w-6 h-6 p-0 text-white"
|
||||
onPress={onCopy}
|
||||
aria-label={t("Copy code")}
|
||||
>
|
||||
<Copy size={14} />
|
||||
</Button>
|
||||
</div>
|
||||
<pre className="p-2 sm:p-4 rounded-md text-xs overflow-x-auto">
|
||||
<code className="text-gray-300 whitespace-pre-wrap">
|
||||
{`{
|
||||
"mcpServers": {
|
||||
"${mcpName || "xpack-mcp-market"}": {
|
||||
"${mcpName}": {
|
||||
"type": "sse",
|
||||
"autoApprove":"all",
|
||||
"url": "${url}?apikey=`}
|
||||
|
||||
@@ -25,6 +25,7 @@ import {
|
||||
import { Navigation } from "./Navigation";
|
||||
import { Footer } from "./Footer";
|
||||
import { NavigationItem } from "@/shared/components/Navigation";
|
||||
import { Faq } from "@/components/marketplace/Faq";
|
||||
|
||||
interface HomeProps {
|
||||
// 状态
|
||||
@@ -106,7 +107,7 @@ export const Home: React.FC<HomeProps> = ({
|
||||
{/* Modern Search Bar */}
|
||||
<div className="max-w-2xl mx-auto">
|
||||
<div className="bg-white p-1 rounded-xl shadow-sm border border-gray-100">
|
||||
<div className="flex">
|
||||
<div className="flex gap-1">
|
||||
<div className="flex-1">
|
||||
<Input
|
||||
size="lg"
|
||||
@@ -141,97 +142,103 @@ export const Home: React.FC<HomeProps> = ({
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Service List Section */}
|
||||
{loading ? (
|
||||
<div className="mx-auto h-[200px] flex items-center justify-center">
|
||||
<div className="bg-white p-8 rounded-lg shadow-md">
|
||||
<Spinner size="lg" color="primary" />
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<div className="py-16">
|
||||
<div className="mx-auto px-6 max-w-7xl">
|
||||
{/* Services Grid */}
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-6 mb-12">
|
||||
{services.map((service) => (
|
||||
<Link
|
||||
key={service.service_id}
|
||||
href={`/marketplace/${service.service_id}`}
|
||||
>
|
||||
<Card className="group h-[200px] hover:shadow-lg transition-all duration-200 cursor-pointer bg-white border border-gray-100 rounded-xl shadow-sm">
|
||||
<CardBody className="p-4">
|
||||
{/* Header */}
|
||||
<div className="flex items-start justify-between mb-3">
|
||||
<div className="flex items-center gap-2">
|
||||
<div className="w-8 h-8 bg-blue-100 rounded-lg flex items-center justify-center">
|
||||
<Zap className="w-4 h-4 text-blue-600" />
|
||||
</div>
|
||||
<div className="flex-1 min-w-0">
|
||||
<h3 className="font-semibold text-gray-900 text-base mb-1 truncate group-hover:text-blue-600 transition-colors">
|
||||
{service.name}
|
||||
</h3>
|
||||
</div>
|
||||
</div>
|
||||
<ArrowRight className="w-4 h-4 text-gray-400 group-hover:text-blue-600 transition-colors" />
|
||||
</div>
|
||||
|
||||
{/* Description */}
|
||||
<p className="text-gray-600 text-sm line-clamp-3 leading-relaxed mb-4">
|
||||
{service.short_description ||
|
||||
t("No description available")}
|
||||
</p>
|
||||
</CardBody>
|
||||
|
||||
{/* Footer */}
|
||||
<CardFooter className="pt-0 px-4 pb-4">
|
||||
<div className="flex items-center justify-between w-full">
|
||||
{/* Tools count */}
|
||||
<div className="flex items-center gap-2">
|
||||
<div className="w-2 h-2 bg-blue-600 rounded-full"></div>
|
||||
<span className="text-sm font-medium text-gray-700">
|
||||
{t("{{count}} Tools", {
|
||||
count: service.tools.length,
|
||||
})}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{/* Price */}
|
||||
<div className="flex flex-col items-end">
|
||||
<Price
|
||||
price={service.price}
|
||||
charge_type={service.charge_type}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</CardFooter>
|
||||
</Card>
|
||||
</Link>
|
||||
))}
|
||||
<section>
|
||||
{/* Service List Section */}
|
||||
{loading ? (
|
||||
<div className="mx-auto h-[200px] flex items-center justify-center">
|
||||
<div className="bg-white p-8 rounded-lg shadow-md">
|
||||
<Spinner size="lg" color="primary" />
|
||||
</div>
|
||||
|
||||
{/* Pagination */}
|
||||
{totalPages > 1 && (
|
||||
<div className="flex justify-center">
|
||||
<Pagination
|
||||
total={totalPages}
|
||||
page={currentPage}
|
||||
onChange={onPageChange}
|
||||
showControls
|
||||
color="primary"
|
||||
variant="light"
|
||||
size="lg"
|
||||
classNames={{
|
||||
wrapper: "gap-2",
|
||||
item: "w-10 h-10 text-sm font-medium",
|
||||
cursor:
|
||||
"bg-gradient-to-r from-blue-500 to-indigo-600 shadow-sm",
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
) : (
|
||||
<div className="py-16">
|
||||
<div className="mx-auto px-6 max-w-7xl">
|
||||
{/* Services Grid */}
|
||||
<div className="flex flex-wrap justify-center gap-4 mb-12">
|
||||
{services.map((service) => (
|
||||
<Link
|
||||
key={service.service_id}
|
||||
href={`/marketplace/${service.service_id}`}
|
||||
className="w-full md:w-[calc(50%-16px)] lg:w-[calc(33%-16px)] xl:w-[calc(25%-16px)]"
|
||||
>
|
||||
<Card className="group h-[200px] w-full hover:shadow-lg transition-all duration-200 cursor-pointer bg-white border border-gray-100 rounded-xl shadow-sm">
|
||||
<CardBody className="p-4">
|
||||
{/* Header */}
|
||||
<div className="flex items-start justify-between mb-3">
|
||||
<div className="flex items-center gap-2">
|
||||
<div className="w-8 h-8 bg-blue-100 rounded-lg flex items-center justify-center">
|
||||
<Zap className="w-4 h-4 text-blue-600" />
|
||||
</div>
|
||||
<div className="flex-1 min-w-0">
|
||||
<h3 className="font-semibold text-gray-900 text-base mb-1 truncate group-hover:text-blue-600 transition-colors">
|
||||
{service.name}
|
||||
</h3>
|
||||
</div>
|
||||
</div>
|
||||
<ArrowRight className="w-4 h-4 text-gray-400 group-hover:text-blue-600 transition-colors" />
|
||||
</div>
|
||||
|
||||
{/* Description */}
|
||||
<p className="text-gray-600 text-sm line-clamp-3 leading-relaxed mb-4">
|
||||
{service.short_description ||
|
||||
t("No description available")}
|
||||
</p>
|
||||
</CardBody>
|
||||
|
||||
{/* Footer */}
|
||||
<CardFooter className="pt-0 px-4 pb-4">
|
||||
<div className="flex items-center justify-between w-full">
|
||||
{/* Tools count */}
|
||||
<div className="flex items-center gap-2">
|
||||
<div className="w-2 h-2 bg-blue-600 rounded-full"></div>
|
||||
<span className="text-sm font-medium text-gray-700">
|
||||
{t("{{count}} Tools", {
|
||||
count: service.tools.length,
|
||||
})}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{/* Price */}
|
||||
<div className="flex flex-col items-end">
|
||||
<Price
|
||||
price={service.price}
|
||||
charge_type={service.charge_type}
|
||||
input_token_price={service.input_token_price}
|
||||
output_token_price={service.output_token_price}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</CardFooter>
|
||||
</Card>
|
||||
</Link>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{/* Pagination */}
|
||||
{totalPages > 1 && (
|
||||
<div className="flex justify-center">
|
||||
<Pagination
|
||||
total={totalPages}
|
||||
page={currentPage}
|
||||
onChange={onPageChange}
|
||||
showControls
|
||||
color="primary"
|
||||
variant="light"
|
||||
size="lg"
|
||||
classNames={{
|
||||
wrapper: "gap-2",
|
||||
item: "w-10 h-10 text-sm font-medium",
|
||||
cursor:
|
||||
"bg-gradient-to-r from-blue-500 to-indigo-600 shadow-sm",
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</section>
|
||||
<Faq />
|
||||
|
||||
<Footer />
|
||||
</div>
|
||||
|
||||
@@ -48,7 +48,12 @@ export const Navigation: React.FC<NavigationProps> = ({ items }) => {
|
||||
</div>
|
||||
<div className="hidden lg:flex gap-6 justify-center">
|
||||
{items?.map((item) => (
|
||||
<Link href={item.href} className="text-sm text-gray-500">
|
||||
<Link
|
||||
key={item.href}
|
||||
href={item.href}
|
||||
target={item.target}
|
||||
className="text-sm text-gray-500"
|
||||
>
|
||||
{t(item.label)}
|
||||
</Link>
|
||||
))}
|
||||
|
||||
@@ -2,13 +2,12 @@
|
||||
|
||||
import React, { useState } from "react";
|
||||
import { useTranslation } from "@/shared/lib/useTranslation";
|
||||
import { Tabs, Tab, Chip, Card, CardBody } from "@nextui-org/react";
|
||||
import { Tabs, Tab, Chip, Card, CardBody, Button } 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 { FileText, Wrench, Cog, Copy } from "lucide-react";
|
||||
import { Navigation } from "./Navigation";
|
||||
import { Footer } from "./Footer";
|
||||
import { usePlatformConfig } from "@/shared/contexts/PlatformConfigContext";
|
||||
@@ -24,6 +23,7 @@ interface DetailProps {
|
||||
mcpName?: string;
|
||||
// navigation items
|
||||
navItems?: NavigationItem[];
|
||||
onCopy: () => void;
|
||||
}
|
||||
|
||||
export const Detail: React.FC<DetailProps> = ({
|
||||
@@ -32,6 +32,7 @@ export const Detail: React.FC<DetailProps> = ({
|
||||
url,
|
||||
mcpName,
|
||||
navItems = [],
|
||||
onCopy,
|
||||
}) => {
|
||||
const { t } = useTranslation();
|
||||
const [activeTab, setActiveTab] = useState("overview");
|
||||
@@ -159,18 +160,26 @@ export const Detail: React.FC<DetailProps> = ({
|
||||
{/* Code Snippet */}
|
||||
<Card className="w-full bg-black text-white p-2 sm:p-4 rounded-lg relative z-10">
|
||||
<div className="text-left font-mono">
|
||||
<Chip
|
||||
className="mb-2 text-white"
|
||||
size="sm"
|
||||
variant="flat"
|
||||
>
|
||||
{platformConfig?.name} MCP
|
||||
</Chip>
|
||||
<div className="flex items-center gap-2 mb-2 justify-between">
|
||||
<Chip className="text-white" size="sm" variant="flat">
|
||||
{platformConfig?.name} MCP
|
||||
</Chip>
|
||||
<Button
|
||||
isIconOnly
|
||||
size="sm"
|
||||
variant="flat"
|
||||
className="min-w-6 w-6 h-6 p-0 text-white"
|
||||
onPress={onCopy}
|
||||
aria-label={t("Copy code")}
|
||||
>
|
||||
<Copy size={14} />
|
||||
</Button>
|
||||
</div>
|
||||
<pre className="p-2 sm:p-4 rounded-md text-xs overflow-x-auto">
|
||||
<code className="text-gray-300 whitespace-pre-wrap">
|
||||
{`{
|
||||
"mcpServers": {
|
||||
"${mcpName || "xpack-mcp-market"}": {
|
||||
"${mcpName}": {
|
||||
"type": "sse",
|
||||
"autoApprove":"all",
|
||||
"url": "${url}?apikey=`}
|
||||
|
||||
@@ -22,6 +22,7 @@ import {
|
||||
import { Footer } from "./Footer";
|
||||
import { Navigation } from "./Navigation";
|
||||
import { NavigationItem } from "@/shared/components/Navigation";
|
||||
import { Faq } from "@/components/marketplace/Faq";
|
||||
|
||||
interface HomeProps {
|
||||
// 状态
|
||||
@@ -188,6 +189,8 @@ export const Home: React.FC<HomeProps> = ({
|
||||
<Price
|
||||
price={service.price}
|
||||
charge_type={service.charge_type}
|
||||
input_token_price={service.input_token_price}
|
||||
output_token_price={service.output_token_price}
|
||||
/>
|
||||
</div>
|
||||
</CardFooter>
|
||||
@@ -212,6 +215,7 @@ export const Home: React.FC<HomeProps> = ({
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
<Faq />
|
||||
</div>
|
||||
|
||||
<Footer />
|
||||
|
||||
@@ -52,7 +52,9 @@ export const Navigation: React.FC<NavigationProps> = ({ items }) => {
|
||||
<div className="hidden lg:flex gap-8 justify-center ml-8">
|
||||
{items?.map((item) => (
|
||||
<Link
|
||||
key={item.href}
|
||||
href={item.href}
|
||||
target={item.target}
|
||||
className="text-gray-700 hover:text-orange-500 font-medium transition-colors"
|
||||
>
|
||||
{t(item.label)}
|
||||
|
||||
@@ -0,0 +1,131 @@
|
||||
import React, { useState } from "react";
|
||||
import {
|
||||
Modal,
|
||||
ModalContent,
|
||||
ModalHeader,
|
||||
ModalBody,
|
||||
ModalFooter,
|
||||
Button,
|
||||
Input,
|
||||
} from "@nextui-org/react";
|
||||
import { useTranslation } from "@/shared/lib/useTranslation";
|
||||
import { User } from "@/types/user";
|
||||
|
||||
interface AdminRechargeModalProps {
|
||||
isOpen: boolean;
|
||||
onClose: () => void;
|
||||
user: User | null;
|
||||
onRecharge: (id: string, amount: number) => Promise<boolean>;
|
||||
}
|
||||
|
||||
export const AdminRechargeModal: React.FC<AdminRechargeModalProps> = ({
|
||||
isOpen,
|
||||
onClose,
|
||||
user,
|
||||
onRecharge,
|
||||
}) => {
|
||||
const { t } = useTranslation();
|
||||
const [amount, setAmount] = useState<string>("");
|
||||
const [error, setError] = useState<string>("");
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
const handleAmountChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const value = e.target.value;
|
||||
// 只允许输入数字和小数点
|
||||
if (/^\d*\.?\d*$/.test(value) || value === "") {
|
||||
setAmount(value);
|
||||
setError("");
|
||||
}
|
||||
};
|
||||
|
||||
const handleRecharge = async () => {
|
||||
const numAmount = parseFloat(amount);
|
||||
if (isNaN(numAmount) || numAmount <= 0) {
|
||||
setError(t("Please enter a valid amount"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (numAmount < 1) {
|
||||
setError(t("Minimum recharge amount is $1"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!user) {
|
||||
setError(t("User not selected"));
|
||||
return;
|
||||
}
|
||||
|
||||
setLoading(true);
|
||||
try {
|
||||
const success = await onRecharge(user.id, numAmount);
|
||||
|
||||
if (success) {
|
||||
handleClose();
|
||||
}
|
||||
} catch (error) {
|
||||
setError(t("Network error, please try again"));
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleClose = () => {
|
||||
setAmount("");
|
||||
setError("");
|
||||
onClose();
|
||||
};
|
||||
|
||||
return (
|
||||
<Modal isOpen={isOpen} onClose={handleClose} size="sm">
|
||||
<ModalContent>
|
||||
{() => (
|
||||
<>
|
||||
<ModalHeader className="flex flex-col gap-1">
|
||||
{t("Recharge User")}
|
||||
</ModalHeader>
|
||||
<ModalBody>
|
||||
{user && (
|
||||
<div className="mb-4 p-3 bg-gray-50 rounded-lg">
|
||||
<p className="text-sm text-gray-600">
|
||||
{t("User")}: {user.email}
|
||||
</p>
|
||||
<p className="text-sm text-gray-600">
|
||||
{t("Current Balance")}: ${user.balance.toFixed(2)}
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
<Input
|
||||
autoFocus
|
||||
label={t("Recharge Amount")}
|
||||
placeholder="0.00"
|
||||
value={amount}
|
||||
onChange={handleAmountChange}
|
||||
startContent={
|
||||
<div className="pointer-events-none flex items-center">
|
||||
<span className="text-default-400 text-small">$</span>
|
||||
</div>
|
||||
}
|
||||
isInvalid={!!error}
|
||||
errorMessage={error}
|
||||
type="number"
|
||||
/>
|
||||
</ModalBody>
|
||||
<ModalFooter>
|
||||
<Button color="danger" variant="light" onPress={handleClose}>
|
||||
{t("Cancel")}
|
||||
</Button>
|
||||
<Button
|
||||
color="primary"
|
||||
onPress={handleRecharge}
|
||||
isLoading={loading}
|
||||
isDisabled={!amount || !!error}
|
||||
>
|
||||
{t("Confirm")}
|
||||
</Button>
|
||||
</ModalFooter>
|
||||
</>
|
||||
)}
|
||||
</ModalContent>
|
||||
</Modal>
|
||||
);
|
||||
};
|
||||
@@ -12,8 +12,14 @@ const UserManagement: React.FC = () => {
|
||||
const { t } = useTranslation();
|
||||
|
||||
// use custom hook to manage user data
|
||||
const { users, loading, pagination, handleDeleteUser, setPage } =
|
||||
useUserManagement();
|
||||
const {
|
||||
users,
|
||||
loading,
|
||||
pagination,
|
||||
handleDeleteUser,
|
||||
setPage,
|
||||
handleRechargeUser,
|
||||
} = useUserManagement();
|
||||
|
||||
// Modal states
|
||||
const [deleteModal, setDeleteModal] = useState({
|
||||
@@ -47,6 +53,13 @@ const UserManagement: React.FC = () => {
|
||||
setDeleteModal({ isOpen: false, user: null });
|
||||
}, []);
|
||||
|
||||
const handleRecharge = useCallback(
|
||||
async (id: string, amount: number): Promise<boolean> => {
|
||||
return await handleRechargeUser(id, amount);
|
||||
},
|
||||
[handleRechargeUser]
|
||||
);
|
||||
|
||||
return (
|
||||
<DashboardDemoContent
|
||||
title={t("User Management")}
|
||||
@@ -59,6 +72,7 @@ const UserManagement: React.FC = () => {
|
||||
users={users}
|
||||
loading={loading}
|
||||
onDelete={handleDeleteUserClick}
|
||||
onRecharge={handleRecharge}
|
||||
pagination={pagination}
|
||||
onPageChange={setPage}
|
||||
/>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import React from 'react';
|
||||
import React from "react";
|
||||
import {
|
||||
Table,
|
||||
TableHeader,
|
||||
@@ -11,16 +11,18 @@ import {
|
||||
Button,
|
||||
Pagination,
|
||||
Tooltip,
|
||||
Spinner
|
||||
} from '@nextui-org/react';
|
||||
import { useTranslation } from '@/shared/lib/useTranslation';
|
||||
import { User } from '@/types/user';
|
||||
import { Trash2 } from 'lucide-react';
|
||||
Spinner,
|
||||
} from "@nextui-org/react";
|
||||
import { useTranslation } from "@/shared/lib/useTranslation";
|
||||
import { User } from "@/types/user";
|
||||
import { Trash2, CreditCard } from "lucide-react";
|
||||
import { AdminRechargeModal } from "@/components/user-management/AdminRechargeModal";
|
||||
|
||||
interface UserTableProps {
|
||||
users: User[];
|
||||
loading?: boolean;
|
||||
onDelete: (user: User) => void;
|
||||
onRecharge: (id: string, amount: number) => Promise<boolean>;
|
||||
pagination: {
|
||||
page: number;
|
||||
pageSize: number;
|
||||
@@ -33,6 +35,7 @@ export const UserTable: React.FC<UserTableProps> = ({
|
||||
users,
|
||||
loading = false,
|
||||
onDelete,
|
||||
onRecharge,
|
||||
pagination,
|
||||
onPageChange,
|
||||
}) => {
|
||||
@@ -45,10 +48,25 @@ export const UserTable: React.FC<UserTableProps> = ({
|
||||
// 直接显示传入的用户数据(已经是当前页的数据)
|
||||
const items = users;
|
||||
|
||||
const [isRechargeModalOpen, setIsRechargeModalOpen] = React.useState(false);
|
||||
const [selectedUser, setSelectedUser] = React.useState<User | null>(null);
|
||||
|
||||
const handleDelete = React.useCallback((user: User) => {
|
||||
onDelete(user);
|
||||
}, [onDelete]);
|
||||
const handleDelete = React.useCallback(
|
||||
(user: User) => {
|
||||
onDelete(user);
|
||||
},
|
||||
[onDelete]
|
||||
);
|
||||
|
||||
const handleRecharge = React.useCallback((user: User) => {
|
||||
setSelectedUser(user);
|
||||
setIsRechargeModalOpen(true);
|
||||
}, []);
|
||||
|
||||
const handleRechargeClose = React.useCallback(() => {
|
||||
setIsRechargeModalOpen(false);
|
||||
setSelectedUser(null);
|
||||
}, []);
|
||||
|
||||
if (loading && users.length === 0) {
|
||||
return (
|
||||
@@ -68,33 +86,50 @@ export const UserTable: React.FC<UserTableProps> = ({
|
||||
removeWrapper
|
||||
>
|
||||
<TableHeader>
|
||||
<TableColumn>{t('Email')}</TableColumn>
|
||||
<TableColumn>{t('Register Date')}</TableColumn>
|
||||
<TableColumn>{t('Balance')}</TableColumn>
|
||||
<TableColumn>{t('Actions')}</TableColumn>
|
||||
<TableColumn>{t("Email")}</TableColumn>
|
||||
<TableColumn>{t("Register Date")}</TableColumn>
|
||||
<TableColumn>{t("Balance")}</TableColumn>
|
||||
<TableColumn>{t("Actions")}</TableColumn>
|
||||
</TableHeader>
|
||||
<TableBody
|
||||
items={items}
|
||||
isLoading={loading}
|
||||
loadingContent={<Spinner />}
|
||||
emptyContent={t('No users found')}
|
||||
emptyContent={t("No users found")}
|
||||
>
|
||||
{(user) => (
|
||||
<TableRow key={user.id}>
|
||||
<TableCell>
|
||||
<span className="text-sm">{user.email}</span>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
{user.created_at || '-'}
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
{user.balance.toFixed(2) || "-"}
|
||||
</TableCell>
|
||||
<TableCell>{user.created_at || "-"}</TableCell>
|
||||
<TableCell>{user.balance.toFixed(2) || "-"}</TableCell>
|
||||
|
||||
<TableCell>
|
||||
<div className="relative flex items-center gap-2">
|
||||
<Tooltip
|
||||
content={t("Recharge User")}
|
||||
color="primary"
|
||||
closeDelay={0}
|
||||
disableAnimation
|
||||
>
|
||||
<Button
|
||||
isIconOnly
|
||||
size="sm"
|
||||
variant="light"
|
||||
color="primary"
|
||||
onPress={() => handleRecharge(user)}
|
||||
>
|
||||
<CreditCard className="w-4 h-4" />
|
||||
</Button>
|
||||
</Tooltip>
|
||||
|
||||
<Tooltip content={t('Delete User')} color="danger" closeDelay={0}>
|
||||
<Tooltip
|
||||
content={t("Delete User")}
|
||||
color="danger"
|
||||
closeDelay={0}
|
||||
disableAnimation
|
||||
>
|
||||
<Button
|
||||
isIconOnly
|
||||
size="sm"
|
||||
@@ -124,6 +159,14 @@ export const UserTable: React.FC<UserTableProps> = ({
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Admin Recharge Modal */}
|
||||
<AdminRechargeModal
|
||||
isOpen={isRechargeModalOpen}
|
||||
onClose={handleRechargeClose}
|
||||
user={selectedUser}
|
||||
onRecharge={onRecharge}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,119 @@
|
||||
import { useState, useCallback, useEffect } from "react";
|
||||
import { HomepageConfig } from "@/services/homepageConfigService";
|
||||
import {
|
||||
FaqItem,
|
||||
TopNavigationItem,
|
||||
EmbeddedHtmlConfig,
|
||||
} from "@/shared/types/system";
|
||||
import { homepageConfigService } from "@/services/homepageConfigService";
|
||||
import { usePlatformConfig } from "@/shared/contexts/PlatformConfigContext";
|
||||
import { revalidatePlatformConfig } from "@/app/actions/revalidate";
|
||||
|
||||
export const useHomepageConfigManagement = () => {
|
||||
const { updateClientConfig } = usePlatformConfig();
|
||||
|
||||
// homepage config state
|
||||
const [homepageConfig, setHomepageConfig] = useState<HomepageConfig>({
|
||||
faq: [],
|
||||
top_navigation: [],
|
||||
embeded_html: {
|
||||
is_enabled: false,
|
||||
html: "",
|
||||
},
|
||||
});
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
// load homepage config
|
||||
const loadHomepageConfig = useCallback(async () => {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
try {
|
||||
const config = await homepageConfigService.getHomepageConfig();
|
||||
setHomepageConfig(config);
|
||||
} catch (err) {
|
||||
const errorMessage =
|
||||
err instanceof Error ? err.message : "Failed to load homepage config";
|
||||
setError(errorMessage);
|
||||
console.error("Failed to load homepage config:", err);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}, []);
|
||||
|
||||
// save homepage config
|
||||
const saveHomepageConfig = useCallback(
|
||||
async (config: {
|
||||
faq?: FaqItem[];
|
||||
top_navigation?: TopNavigationItem[];
|
||||
embeded_html?: EmbeddedHtmlConfig;
|
||||
}): Promise<boolean> => {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
try {
|
||||
const result = await homepageConfigService.updateHomepageConfig(config);
|
||||
if (result) {
|
||||
updateClientConfig(config);
|
||||
await revalidatePlatformConfig();
|
||||
}
|
||||
return result;
|
||||
} catch (err) {
|
||||
const errorMessage =
|
||||
err instanceof Error ? err.message : "Failed to save homepage config";
|
||||
setError(errorMessage);
|
||||
console.error("Failed to save homepage config:", err);
|
||||
return false;
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
},
|
||||
[]
|
||||
);
|
||||
|
||||
// save FAQ data
|
||||
const saveFaqConfig = useCallback(
|
||||
async (faqs: FaqItem[]): Promise<boolean> => {
|
||||
return await saveHomepageConfig({ faq: faqs });
|
||||
},
|
||||
[saveHomepageConfig]
|
||||
);
|
||||
|
||||
// save navigation data
|
||||
const saveNavigationConfig = useCallback(
|
||||
async (navigationItems: TopNavigationItem[]): Promise<boolean> => {
|
||||
return await saveHomepageConfig({ top_navigation: navigationItems });
|
||||
},
|
||||
[saveHomepageConfig]
|
||||
);
|
||||
|
||||
// save embedded HTML data
|
||||
const saveEmbeddedHtmlConfig = useCallback(
|
||||
async (htmlData: EmbeddedHtmlConfig): Promise<boolean> => {
|
||||
return await saveHomepageConfig({ embeded_html: htmlData });
|
||||
},
|
||||
[saveHomepageConfig]
|
||||
);
|
||||
|
||||
// clear error
|
||||
const clearError = useCallback(() => setError(null), []);
|
||||
|
||||
// load config on init
|
||||
useEffect(() => {
|
||||
loadHomepageConfig();
|
||||
}, [loadHomepageConfig]);
|
||||
|
||||
return {
|
||||
// state
|
||||
homepageConfig,
|
||||
loading,
|
||||
error,
|
||||
|
||||
// actions
|
||||
loadHomepageConfig,
|
||||
saveHomepageConfig,
|
||||
saveFaqConfig,
|
||||
saveNavigationConfig,
|
||||
saveEmbeddedHtmlConfig,
|
||||
clearError,
|
||||
};
|
||||
};
|
||||
@@ -2,22 +2,41 @@ import { useState, useEffect, useCallback } from "react";
|
||||
import {
|
||||
PaymentChannelApiItem,
|
||||
StripeConfig,
|
||||
AlipayConfig,
|
||||
WechatConfig,
|
||||
PaymentChannelTestResult,
|
||||
} from "@/types/payment";
|
||||
import { paymentChannelService } from "@/services/paymentChannelService";
|
||||
import { usePlatformConfig } from "@/shared/contexts/PlatformConfigContext";
|
||||
import { revalidatePlatformConfig } from "@/app/actions/revalidate";
|
||||
|
||||
export const usePaymentChannelManagement = () => {
|
||||
const { updateClientConfig, paymentChannels } = usePlatformConfig();
|
||||
const [channels, setChannels] = useState<PaymentChannelApiItem[]>([]);
|
||||
const [stripeConfig, setStripeConfig] = useState<StripeConfig>({
|
||||
secret: "",
|
||||
webhook_secret: "",
|
||||
is_enabled: false,
|
||||
});
|
||||
const [alipayConfig, setAlipayConfig] = useState<AlipayConfig>({
|
||||
app_id: "",
|
||||
app_private_key: "",
|
||||
alipay_public_key: "",
|
||||
is_enabled: false,
|
||||
});
|
||||
const [wechatConfig, setWechatConfig] = useState<WechatConfig>({
|
||||
app_id: "",
|
||||
mch_id: "",
|
||||
is_enabled: false,
|
||||
});
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [testResult, setTestResult] = useState<PaymentChannelTestResult | null>(
|
||||
null
|
||||
);
|
||||
const [isSaving, setIsSaving] = useState(false);
|
||||
const [isWechatSaving, setIsWechatSaving] = useState(false);
|
||||
const [isStripeSaving, setIsStripeSaving] = useState(false);
|
||||
const [isAlipaySaving, setIsAlipaySaving] = useState(false);
|
||||
|
||||
// get payment channel list
|
||||
const fetchChannels = useCallback(async () => {
|
||||
@@ -29,12 +48,35 @@ export const usePaymentChannelManagement = () => {
|
||||
|
||||
setChannels(response.data);
|
||||
|
||||
// find stripe channel and get config
|
||||
// find channels and get configs
|
||||
const stripeChannel = response.data.find(
|
||||
(channel) => channel.id === "stripe"
|
||||
);
|
||||
if (stripeChannel) {
|
||||
setStripeConfig(stripeChannel.config);
|
||||
setStripeConfig({
|
||||
...stripeChannel.config,
|
||||
is_enabled: stripeChannel.is_enabled,
|
||||
} as StripeConfig);
|
||||
}
|
||||
|
||||
const alipayChannel = response.data.find(
|
||||
(channel) => channel.id === "alipay"
|
||||
);
|
||||
if (alipayChannel) {
|
||||
setAlipayConfig({
|
||||
...alipayChannel.config,
|
||||
is_enabled: alipayChannel.is_enabled,
|
||||
} as AlipayConfig);
|
||||
}
|
||||
|
||||
const wechatChannel = response.data.find(
|
||||
(channel) => channel.id === "wechat"
|
||||
);
|
||||
if (wechatChannel) {
|
||||
setWechatConfig({
|
||||
...wechatChannel.config,
|
||||
is_enabled: wechatChannel.is_enabled,
|
||||
} as WechatConfig);
|
||||
}
|
||||
} catch (err) {
|
||||
setError(
|
||||
@@ -48,9 +90,103 @@ export const usePaymentChannelManagement = () => {
|
||||
}
|
||||
}, []);
|
||||
|
||||
// test alipay connection
|
||||
const testAlipayConnection = useCallback(async (config: AlipayConfig) => {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
|
||||
try {
|
||||
const result = await paymentChannelService.testAlipayConnection(config);
|
||||
setTestResult(result);
|
||||
return result;
|
||||
} catch (err) {
|
||||
const errorMessage =
|
||||
err instanceof Error ? err.message : "Failed to test alipay connection";
|
||||
const failedResult: PaymentChannelTestResult = {
|
||||
success: false,
|
||||
message: errorMessage,
|
||||
};
|
||||
setTestResult(failedResult);
|
||||
setError(errorMessage);
|
||||
return failedResult;
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}, []);
|
||||
|
||||
// test wechat connection
|
||||
const testWechatConnection = useCallback(async (config: WechatConfig) => {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
|
||||
try {
|
||||
const result = await paymentChannelService.testWechatConnection(config);
|
||||
setTestResult(result);
|
||||
return result;
|
||||
} catch (err) {
|
||||
const errorMessage =
|
||||
err instanceof Error ? err.message : "Failed to test wechat connection";
|
||||
const failedResult: PaymentChannelTestResult = {
|
||||
success: false,
|
||||
message: errorMessage,
|
||||
};
|
||||
setTestResult(failedResult);
|
||||
setError(errorMessage);
|
||||
return failedResult;
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}, []);
|
||||
|
||||
// save alipay config
|
||||
const saveAlipayConfig = useCallback(async (config: AlipayConfig) => {
|
||||
setIsAlipaySaving(true);
|
||||
setError(null);
|
||||
|
||||
try {
|
||||
const result = await paymentChannelService.saveAlipayConfig(config);
|
||||
if (result) {
|
||||
setAlipayConfig(config);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} catch (err) {
|
||||
const errorMessage =
|
||||
err instanceof Error ? err.message : "Failed to save alipay config";
|
||||
setError(errorMessage);
|
||||
return false;
|
||||
} finally {
|
||||
setIsAlipaySaving(false);
|
||||
}
|
||||
}, []);
|
||||
|
||||
// save wechat config
|
||||
const saveWechatConfig = useCallback(async (config: WechatConfig) => {
|
||||
setIsWechatSaving(true);
|
||||
setError(null);
|
||||
|
||||
try {
|
||||
const result = await paymentChannelService.saveWechatConfig(config);
|
||||
if (result) {
|
||||
setWechatConfig(config);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} catch (err) {
|
||||
const errorMessage =
|
||||
err instanceof Error ? err.message : "Failed to save wechat config";
|
||||
setError(errorMessage);
|
||||
return false;
|
||||
} finally {
|
||||
setIsWechatSaving(false);
|
||||
}
|
||||
}, []);
|
||||
|
||||
// save stripe config
|
||||
const saveStripeConfig = useCallback(async (config: StripeConfig) => {
|
||||
setIsSaving(true);
|
||||
setIsStripeSaving(true);
|
||||
setError(null);
|
||||
|
||||
try {
|
||||
@@ -67,7 +203,7 @@ export const usePaymentChannelManagement = () => {
|
||||
setError(errorMessage);
|
||||
return false;
|
||||
} finally {
|
||||
setIsSaving(false);
|
||||
setIsStripeSaving(false);
|
||||
}
|
||||
}, []);
|
||||
|
||||
@@ -102,16 +238,25 @@ export const usePaymentChannelManagement = () => {
|
||||
setError(null);
|
||||
|
||||
try {
|
||||
await paymentChannelService.enablePaymentChannel(channelId);
|
||||
await fetchChannels(); // re-fetch list
|
||||
return { success: true };
|
||||
const result =
|
||||
await paymentChannelService.enablePaymentChannel(channelId);
|
||||
if (result) {
|
||||
updateClientConfig({
|
||||
payment_channels: [
|
||||
...paymentChannels,
|
||||
{ id: channelId, name: channelId },
|
||||
],
|
||||
});
|
||||
await revalidatePlatformConfig();
|
||||
}
|
||||
return result;
|
||||
} catch (err) {
|
||||
const errorMessage =
|
||||
err instanceof Error
|
||||
? err.message
|
||||
: "Failed to enable payment channel";
|
||||
setError(errorMessage);
|
||||
return { success: false, message: errorMessage };
|
||||
return false;
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
@@ -126,16 +271,24 @@ export const usePaymentChannelManagement = () => {
|
||||
setError(null);
|
||||
|
||||
try {
|
||||
await paymentChannelService.disablePaymentChannel(channelId);
|
||||
await fetchChannels(); // re-fetch list
|
||||
return { success: true };
|
||||
const result =
|
||||
await paymentChannelService.disablePaymentChannel(channelId);
|
||||
if (result) {
|
||||
updateClientConfig({
|
||||
payment_channels: paymentChannels.filter(
|
||||
(channel) => channel.id !== channelId
|
||||
),
|
||||
});
|
||||
await revalidatePlatformConfig();
|
||||
}
|
||||
return result;
|
||||
} catch (err) {
|
||||
const errorMessage =
|
||||
err instanceof Error
|
||||
? err.message
|
||||
: "Failed to disable payment channel";
|
||||
setError(errorMessage);
|
||||
return { success: false, message: errorMessage };
|
||||
return false;
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
@@ -161,13 +314,21 @@ export const usePaymentChannelManagement = () => {
|
||||
return {
|
||||
channels,
|
||||
stripeConfig,
|
||||
isSaving,
|
||||
alipayConfig,
|
||||
wechatConfig,
|
||||
isWechatSaving,
|
||||
isStripeSaving,
|
||||
isAlipaySaving,
|
||||
loading,
|
||||
error,
|
||||
testResult,
|
||||
fetchChannels,
|
||||
saveStripeConfig,
|
||||
saveAlipayConfig,
|
||||
saveWechatConfig,
|
||||
testStripeConnection,
|
||||
testAlipayConnection,
|
||||
testWechatConnection,
|
||||
enableChannel,
|
||||
disableChannel,
|
||||
clearTestResult,
|
||||
|
||||
@@ -1,5 +1,13 @@
|
||||
import { useState, useCallback, useEffect } from "react";
|
||||
import { PlatformConfig, LoginConfig, EmailMode } from "@/shared/types/system";
|
||||
import {
|
||||
PlatformConfig,
|
||||
LoginConfig,
|
||||
EmailMode,
|
||||
FaqItem,
|
||||
TopNavigationItem,
|
||||
EmbeddedHtmlConfig,
|
||||
PaymentChannel
|
||||
} from "@/shared/types/system";
|
||||
import { systemConfigService } from "@/services/systemConfigService";
|
||||
import { AdminConfig, EmailConfig } from "@/types/system";
|
||||
import { md5Encrypt } from "@/shared/utils/crypto";
|
||||
@@ -49,6 +57,29 @@ export const useSystemConfigManagement = () => {
|
||||
const [loginLoading, setLoginLoading] = useState(false);
|
||||
const [loginError, setLoginError] = useState<string | null>(null);
|
||||
|
||||
// faq config
|
||||
const [faqItems, setFaqItems] = useState<FaqItem[]>([]);
|
||||
const [faqLoading, setFaqLoading] = useState(false);
|
||||
const [faqError, setFaqError] = useState<string | null>(null);
|
||||
|
||||
// top navigation config
|
||||
const [topNavigation, setTopNavigation] = useState<TopNavigationItem[]>([]);
|
||||
const [navigationLoading, setNavigationLoading] = useState(false);
|
||||
const [navigationError, setNavigationError] = useState<string | null>(null);
|
||||
|
||||
// embedded html config
|
||||
const [embeddedHtml, setEmbeddedHtml] = useState<EmbeddedHtmlConfig | null>(null);
|
||||
const [embeddedHtmlLoading, setEmbeddedHtmlLoading] = useState(false);
|
||||
const [embeddedHtmlError, setEmbeddedHtmlError] = useState<string | null>(null);
|
||||
|
||||
// payment channels config
|
||||
const [paymentChannels, setPaymentChannels] = useState<PaymentChannel[]>([]);
|
||||
const [paymentLoading, setPaymentLoading] = useState(false);
|
||||
const [paymentError, setPaymentError] = useState<string | null>(null);
|
||||
|
||||
// installation status
|
||||
const [isInstalled, setIsInstalled] = useState<boolean>(false);
|
||||
|
||||
// global loading
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
|
||||
@@ -80,6 +111,11 @@ export const useSystemConfigManagement = () => {
|
||||
mode: EmailMode.PASSWORD,
|
||||
},
|
||||
});
|
||||
setFaqItems(response.faq || []);
|
||||
setTopNavigation(response.top_navigation || []);
|
||||
setEmbeddedHtml(response.embeded_html || null);
|
||||
setPaymentChannels(response.payment_channels || []);
|
||||
setIsInstalled(response.is_installed || false);
|
||||
} catch (error) {
|
||||
console.error("Failed to load configurations:", error);
|
||||
} finally {
|
||||
@@ -160,11 +196,71 @@ export const useSystemConfigManagement = () => {
|
||||
return result;
|
||||
}, []);
|
||||
|
||||
// save faq config
|
||||
const saveFaqConfig = useCallback(async (items: FaqItem[]) => {
|
||||
setFaqLoading(true);
|
||||
setFaqError(null);
|
||||
const result = await systemConfigService.updateSystemConfig({
|
||||
faq: items,
|
||||
}, "faq");
|
||||
if (result) {
|
||||
setFaqItems(items);
|
||||
}
|
||||
setFaqLoading(false);
|
||||
return result;
|
||||
}, []);
|
||||
|
||||
// save top navigation config
|
||||
const saveTopNavigationConfig = useCallback(async (items: TopNavigationItem[]) => {
|
||||
setNavigationLoading(true);
|
||||
setNavigationError(null);
|
||||
const result = await systemConfigService.updateSystemConfig({
|
||||
top_navigation: items,
|
||||
}, "navigation");
|
||||
if (result) {
|
||||
setTopNavigation(items);
|
||||
}
|
||||
setNavigationLoading(false);
|
||||
return result;
|
||||
}, []);
|
||||
|
||||
// save embedded html config
|
||||
const saveEmbeddedHtmlConfig = useCallback(async (config: EmbeddedHtmlConfig) => {
|
||||
setEmbeddedHtmlLoading(true);
|
||||
setEmbeddedHtmlError(null);
|
||||
const result = await systemConfigService.updateSystemConfig({
|
||||
embeded_html: config,
|
||||
}, "embedded_html");
|
||||
if (result) {
|
||||
setEmbeddedHtml(config);
|
||||
}
|
||||
setEmbeddedHtmlLoading(false);
|
||||
return result;
|
||||
}, []);
|
||||
|
||||
// save payment channels config
|
||||
const savePaymentChannelsConfig = useCallback(async (channels: PaymentChannel[]) => {
|
||||
setPaymentLoading(true);
|
||||
setPaymentError(null);
|
||||
const result = await systemConfigService.updateSystemConfig({
|
||||
payment_channels: channels,
|
||||
}, "payment");
|
||||
if (result) {
|
||||
setPaymentChannels(channels);
|
||||
}
|
||||
setPaymentLoading(false);
|
||||
return result;
|
||||
}, []);
|
||||
|
||||
// clear errors
|
||||
const clearPlatformError = useCallback(() => setPlatformError(null), []);
|
||||
const clearAdminError = useCallback(() => setAdminError(null), []);
|
||||
const clearEmailError = useCallback(() => setEmailError(null), []);
|
||||
const clearLoginError = useCallback(() => setLoginError(null), []);
|
||||
const clearFaqError = useCallback(() => setFaqError(null), []);
|
||||
const clearNavigationError = useCallback(() => setNavigationError(null), []);
|
||||
const clearEmbeddedHtmlError = useCallback(() => setEmbeddedHtmlError(null), []);
|
||||
const clearPaymentError = useCallback(() => setPaymentError(null), []);
|
||||
|
||||
// load configs on init
|
||||
useEffect(() => {
|
||||
@@ -217,6 +313,42 @@ export const useSystemConfigManagement = () => {
|
||||
saveLoginConfig,
|
||||
clearLoginError,
|
||||
|
||||
// faq config
|
||||
faqItems,
|
||||
setFaqItems,
|
||||
faqLoading,
|
||||
faqError,
|
||||
saveFaqConfig,
|
||||
clearFaqError,
|
||||
|
||||
// top navigation config
|
||||
topNavigation,
|
||||
setTopNavigation,
|
||||
navigationLoading,
|
||||
navigationError,
|
||||
saveTopNavigationConfig,
|
||||
clearNavigationError,
|
||||
|
||||
// embedded html config
|
||||
embeddedHtml,
|
||||
setEmbeddedHtml,
|
||||
embeddedHtmlLoading,
|
||||
embeddedHtmlError,
|
||||
saveEmbeddedHtmlConfig,
|
||||
clearEmbeddedHtmlError,
|
||||
|
||||
// payment channels config
|
||||
paymentChannels,
|
||||
setPaymentChannels,
|
||||
paymentLoading,
|
||||
paymentError,
|
||||
savePaymentChannelsConfig,
|
||||
clearPaymentError,
|
||||
|
||||
// installation status
|
||||
isInstalled,
|
||||
setIsInstalled,
|
||||
|
||||
// image upload
|
||||
uploadImage,
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { useState, useEffect, useCallback } from "react";
|
||||
import { User } from "@/types/user";
|
||||
import { getUserList, deleteUser } from "@/services/userService";
|
||||
import { getUserList, deleteUser, rechargeUser } from "@/services/userService";
|
||||
|
||||
interface PaginationInfo {
|
||||
page: number;
|
||||
@@ -67,6 +67,28 @@ export const useUserManagement = () => {
|
||||
},
|
||||
[fetchUsers]
|
||||
);
|
||||
const handleRechargeUser = async (
|
||||
userId: string,
|
||||
amount: number
|
||||
): Promise<boolean> => {
|
||||
try {
|
||||
const result = await rechargeUser(userId, amount);
|
||||
if (result) {
|
||||
// after recharge, fetch users again
|
||||
setUsers((prevUsers: User[]) =>
|
||||
prevUsers.map((user: User) =>
|
||||
user.id === userId
|
||||
? { ...user, balance: user.balance + amount }
|
||||
: user
|
||||
)
|
||||
);
|
||||
return true;
|
||||
}
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : "Recharge user failed");
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
const setSearch = useCallback((search: string) => {
|
||||
setSearchQuery(search);
|
||||
@@ -88,6 +110,7 @@ export const useUserManagement = () => {
|
||||
|
||||
return {
|
||||
users,
|
||||
handleRechargeUser,
|
||||
loading,
|
||||
error,
|
||||
searchQuery,
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
import { fetchAdminAPI } from "@/rpc/admin-api";
|
||||
import i18n from "@/shared/lib/i18n";
|
||||
import {
|
||||
EmbeddedHtmlConfig,
|
||||
FaqItem,
|
||||
TopNavigationItem,
|
||||
} from "@/shared/types/system";
|
||||
import toast from "react-hot-toast";
|
||||
|
||||
export interface HomepageConfig {
|
||||
faq: FaqItem[];
|
||||
top_navigation: TopNavigationItem[];
|
||||
embeded_html: EmbeddedHtmlConfig;
|
||||
}
|
||||
|
||||
export class HomepageConfigService {
|
||||
// get homepage config
|
||||
async getHomepageConfig(): Promise<HomepageConfig> {
|
||||
const response = await fetchAdminAPI<HomepageConfig>(
|
||||
"/api/sysconfig/homepage",
|
||||
{
|
||||
method: "GET",
|
||||
}
|
||||
);
|
||||
|
||||
if (!response.success) {
|
||||
throw new Error(
|
||||
response.error_message || "Failed to fetch homepage config"
|
||||
);
|
||||
}
|
||||
return response.data;
|
||||
}
|
||||
|
||||
// update homepage config
|
||||
async updateHomepageConfig(config: {
|
||||
faq?: FaqItem[];
|
||||
top_navigation?: TopNavigationItem[];
|
||||
embeded_html?: EmbeddedHtmlConfig;
|
||||
}): Promise<boolean> {
|
||||
const response = await fetchAdminAPI("/api/sysconfig/homepage", {
|
||||
method: "PUT",
|
||||
body: config as unknown as BodyInit,
|
||||
});
|
||||
|
||||
if (!response.success) {
|
||||
toast.error(
|
||||
response.error_message || i18n.t("Failed to update homepage config")
|
||||
);
|
||||
return false;
|
||||
}
|
||||
toast.success(i18n.t("Homepage config updated successfully"));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
export const homepageConfigService = new HomepageConfigService();
|
||||
@@ -1,5 +1,7 @@
|
||||
import {
|
||||
StripeConfig,
|
||||
AlipayConfig,
|
||||
WechatConfig,
|
||||
PaymentChannelApiItem,
|
||||
PaymentChannelListResponse,
|
||||
PaymentChannelTestResult,
|
||||
@@ -52,50 +54,74 @@ export class PaymentChannelService {
|
||||
return response.data;
|
||||
}
|
||||
|
||||
// Save Stripe configuration
|
||||
async saveStripeConfig(config: StripeConfig): Promise<boolean> {
|
||||
const response = await fetchAdminAPI<StripeConfig>(
|
||||
"/api/payment_channel/info",
|
||||
{
|
||||
method: "PUT",
|
||||
body: {
|
||||
id: "stripe",
|
||||
config: config,
|
||||
} as unknown as BodyInit,
|
||||
}
|
||||
);
|
||||
// Generic method to save payment channel configuration
|
||||
async savePaymentChannelConfig<T>(
|
||||
channelId: string,
|
||||
config: T,
|
||||
channelName: string
|
||||
): Promise<boolean> {
|
||||
const response = await fetchAdminAPI<T>("/api/payment_channel/info", {
|
||||
method: "PUT",
|
||||
body: {
|
||||
id: channelId,
|
||||
config: {
|
||||
...config,
|
||||
is_enabled: undefined,
|
||||
},
|
||||
} as unknown as BodyInit,
|
||||
});
|
||||
|
||||
if (!response.success) {
|
||||
toast.error(
|
||||
response.error_message || i18n.t("Failed to save Stripe config")
|
||||
response.error_message ||
|
||||
i18n.t("Failed to save {{channelName}} config", { channelName })
|
||||
);
|
||||
return false;
|
||||
}
|
||||
toast.success(i18n.t("Stripe config saved successfully"));
|
||||
toast.success(
|
||||
i18n.t("{{channelName}} config saved successfully", { channelName })
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Test Stripe connection
|
||||
async testStripeConnection(
|
||||
config: StripeConfig
|
||||
// Save Stripe configuration
|
||||
async saveStripeConfig(config: StripeConfig): Promise<boolean> {
|
||||
return this.savePaymentChannelConfig("stripe", config, "Stripe");
|
||||
}
|
||||
|
||||
// Generic method to test payment channel connection
|
||||
async testPaymentChannelConnection<T>(
|
||||
channelId: string,
|
||||
config: T,
|
||||
channelName: string
|
||||
): Promise<PaymentChannelTestResult> {
|
||||
try {
|
||||
const response = await fetchAdminAPI<any>("/api/payment_channel/info", {
|
||||
method: "PUT",
|
||||
body: JSON.stringify(config),
|
||||
const response = await fetchAdminAPI<any>("/api/payment_channel/test", {
|
||||
method: "POST",
|
||||
body: {
|
||||
id: channelId,
|
||||
config: {
|
||||
...config,
|
||||
is_enabled: undefined,
|
||||
},
|
||||
} as unknown as BodyInit,
|
||||
});
|
||||
|
||||
if (!response.success) {
|
||||
return {
|
||||
success: false,
|
||||
message: response.error_message || "Stripe connection test failed",
|
||||
message:
|
||||
response.error_message ||
|
||||
i18n.t("{{channelName}} connection test failed", { channelName }),
|
||||
details: response.data,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: "Stripe connection test successful",
|
||||
message: i18n.t("{{channelName}} connection test successful", {
|
||||
channelName,
|
||||
}),
|
||||
details: response.data,
|
||||
};
|
||||
} catch (error) {
|
||||
@@ -106,36 +132,73 @@ export class PaymentChannelService {
|
||||
}
|
||||
}
|
||||
|
||||
// Test Stripe connection
|
||||
async testStripeConnection(
|
||||
config: StripeConfig
|
||||
): Promise<PaymentChannelTestResult> {
|
||||
return this.testPaymentChannelConnection("stripe", config, "Stripe");
|
||||
}
|
||||
|
||||
// enable payment channel
|
||||
async enablePaymentChannel(id: string): Promise<void> {
|
||||
async enablePaymentChannel(id: string): Promise<boolean> {
|
||||
const response = await fetchAdminAPI("/api/payment_channel/enable", {
|
||||
method: "POST",
|
||||
method: "PUT",
|
||||
body: {
|
||||
id,
|
||||
} as unknown as BodyInit,
|
||||
});
|
||||
|
||||
if (!response.success) {
|
||||
throw new Error(
|
||||
response.error_message || "Failed to enable payment channel"
|
||||
toast.error(
|
||||
response.error_message || i18n.t("Failed to enable payment channel")
|
||||
);
|
||||
return false;
|
||||
}
|
||||
toast.success(i18n.t("Payment channel enabled successfully"));
|
||||
return true;
|
||||
}
|
||||
|
||||
// disable payment channel
|
||||
async disablePaymentChannel(id: string): Promise<void> {
|
||||
async disablePaymentChannel(id: string): Promise<boolean> {
|
||||
const response = await fetchAdminAPI("/api/payment_channel/disable", {
|
||||
method: "POST",
|
||||
method: "PUT",
|
||||
body: {
|
||||
id,
|
||||
} as unknown as BodyInit,
|
||||
});
|
||||
|
||||
if (!response.success) {
|
||||
throw new Error(
|
||||
response.error_message || "Failed to disable payment channel"
|
||||
toast.error(
|
||||
response.error_message || i18n.t("Failed to disable payment channel")
|
||||
);
|
||||
return false;
|
||||
}
|
||||
toast.success(i18n.t("Payment channel disabled successfully"));
|
||||
return true;
|
||||
}
|
||||
|
||||
// Save Alipay configuration
|
||||
async saveAlipayConfig(config: AlipayConfig): Promise<boolean> {
|
||||
return this.savePaymentChannelConfig("alipay", config, "Alipay");
|
||||
}
|
||||
|
||||
// Save WeChat configuration
|
||||
async saveWechatConfig(config: WechatConfig): Promise<boolean> {
|
||||
return this.savePaymentChannelConfig("wechat", config, "WeChat");
|
||||
}
|
||||
|
||||
// Test Alipay connection
|
||||
async testAlipayConnection(
|
||||
config: AlipayConfig
|
||||
): Promise<PaymentChannelTestResult> {
|
||||
return this.testPaymentChannelConnection("alipay", config, "Alipay");
|
||||
}
|
||||
|
||||
// Test WeChat connection
|
||||
async testWechatConnection(
|
||||
config: WechatConfig
|
||||
): Promise<PaymentChannelTestResult> {
|
||||
return this.testPaymentChannelConnection("wechat", config, "WeChat");
|
||||
}
|
||||
|
||||
// validate stripe config
|
||||
|
||||
@@ -37,10 +37,26 @@ export class PlatformConfigService {
|
||||
console.error(response.error_message);
|
||||
return {
|
||||
platform: _DefaultPlatformConfig,
|
||||
login: undefined,
|
||||
faq: [],
|
||||
top_navigation: [],
|
||||
embeded_html: undefined,
|
||||
payment_channels: [],
|
||||
is_installed: false,
|
||||
};
|
||||
}
|
||||
|
||||
return response.data;
|
||||
// 确保返回的数据结构正确
|
||||
const data = response.data;
|
||||
return {
|
||||
platform: data.platform || _DefaultPlatformConfig,
|
||||
login: data.login,
|
||||
faq: data.faq || [],
|
||||
top_navigation: data.top_navigation || [],
|
||||
embeded_html: data.embeded_html,
|
||||
payment_channels: data.payment_channels || [],
|
||||
is_installed: data.is_installed || false,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,13 @@
|
||||
import { fetchAdminAPI } from "@/rpc/admin-api";
|
||||
import i18n from "@/shared/lib/i18n";
|
||||
import { PlatformConfig, LoginConfig } from "@/shared/types/system";
|
||||
import {
|
||||
PlatformConfig,
|
||||
LoginConfig,
|
||||
FaqItem,
|
||||
TopNavigationItem,
|
||||
EmbeddedHtmlConfig,
|
||||
PaymentChannel
|
||||
} from "@/shared/types/system";
|
||||
import { AdminConfig, EmailConfig, SystemConfigApiData } from "@/types/system";
|
||||
import toast from "react-hot-toast";
|
||||
|
||||
@@ -29,8 +36,13 @@ export class SystemConfigService {
|
||||
account?: AdminConfig;
|
||||
email?: EmailConfig;
|
||||
login?: LoginConfig;
|
||||
faq?: FaqItem[];
|
||||
top_navigation?: TopNavigationItem[];
|
||||
embeded_html?: EmbeddedHtmlConfig;
|
||||
payment_channels?: PaymentChannel[];
|
||||
is_installed?: boolean;
|
||||
},
|
||||
key?: "theme" | "about"
|
||||
key?: "theme" | "about" | "faq" | "navigation" | "embedded_html" | "payment"
|
||||
): Promise<boolean> {
|
||||
const response = await fetchAdminAPI("/api/sysconfig/info", {
|
||||
method: "PUT",
|
||||
@@ -50,6 +62,18 @@ export class SystemConfigService {
|
||||
case "about":
|
||||
toast.success(i18n.t("About page saved successfully"));
|
||||
break;
|
||||
case "faq":
|
||||
toast.success(i18n.t("FAQ updated successfully"));
|
||||
break;
|
||||
case "navigation":
|
||||
toast.success(i18n.t("Navigation updated successfully"));
|
||||
break;
|
||||
case "embedded_html":
|
||||
toast.success(i18n.t("Embedded HTML updated successfully"));
|
||||
break;
|
||||
case "payment":
|
||||
toast.success(i18n.t("Payment channels updated successfully"));
|
||||
break;
|
||||
default: {
|
||||
toast.success(i18n.t("System config updated successfully"));
|
||||
break;
|
||||
|
||||
@@ -3,6 +3,7 @@ import { User } from "@/types/user";
|
||||
import { fetchAdminAPI } from "@/rpc/admin-api";
|
||||
import toast from "react-hot-toast";
|
||||
import i18n from "@/shared/lib/i18n";
|
||||
import { md5Encrypt, sha256Encrypt } from "@/shared/utils/crypto";
|
||||
|
||||
// user list API response interface (according to API document xpack-response-array format)
|
||||
export interface UserListApiResponse extends ApiArrayResponse<User> {}
|
||||
@@ -63,3 +64,42 @@ export const deleteUser = async (userId: string): Promise<boolean> => {
|
||||
toast.success(i18n.t("User deleted successfully"));
|
||||
return true;
|
||||
};
|
||||
|
||||
/**
|
||||
* recharge user balance
|
||||
*/
|
||||
export const rechargeUser = async (
|
||||
userId: string,
|
||||
amount: number
|
||||
): Promise<boolean> => {
|
||||
// Create request body
|
||||
const body = {
|
||||
user_id: userId,
|
||||
balance: amount,
|
||||
type: "incr",
|
||||
};
|
||||
|
||||
// Generate timestamp
|
||||
const timestamp = Date.now().toString();
|
||||
|
||||
// Generate signature: sha256(md5((x-xpack-timestamp){body}))
|
||||
// For this implementation, we're using a simplified approach
|
||||
// In a real implementation, you would use actual crypto functions
|
||||
const bodyString = JSON.stringify(body);
|
||||
const signature = sha256Encrypt(md5Encrypt(`${timestamp}${bodyString}`));
|
||||
const response = await fetchAdminAPI(`/api/user_manager/balance/recharge`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"x-xpack-timestamp": timestamp,
|
||||
"x-xpack-sign": signature,
|
||||
},
|
||||
body: body as unknown as BodyInit,
|
||||
});
|
||||
|
||||
if (!response.success) {
|
||||
toast.error(response.error_message || i18n.t("Failed to recharge user"));
|
||||
return false;
|
||||
}
|
||||
toast.success(i18n.t("User recharged successfully"));
|
||||
return true;
|
||||
};
|
||||
@@ -9,9 +9,16 @@ import React from "react";
|
||||
interface PriceProps {
|
||||
price?: string;
|
||||
charge_type?: ChargeType;
|
||||
input_token_price?: string;
|
||||
output_token_price?: string;
|
||||
}
|
||||
|
||||
export const Price: React.FC<PriceProps> = ({ price, charge_type }) => {
|
||||
export const Price: React.FC<PriceProps> = ({
|
||||
price,
|
||||
charge_type,
|
||||
input_token_price,
|
||||
output_token_price,
|
||||
}) => {
|
||||
const { t } = useTranslation();
|
||||
if (!charge_type) {
|
||||
return null;
|
||||
@@ -37,13 +44,24 @@ export const Price: React.FC<PriceProps> = ({ price, charge_type }) => {
|
||||
</div>
|
||||
);
|
||||
} else {
|
||||
const inputPrice = parseFloat(input_token_price || "0");
|
||||
const outputPrice = parseFloat(output_token_price || "0");
|
||||
return (
|
||||
<div className="flex items-center gap-1">
|
||||
<Zap className="w-3 h-3 text-blue-600" />
|
||||
<span className="text-sm font-medium text-blue-600">
|
||||
${priceText.toFixed(2)}
|
||||
</span>
|
||||
<span className="text-xs text-gray-500">/{t("token")}</span>
|
||||
<div className="flex flex-col gap-1 text-xs ">
|
||||
<div className="flex items-center gap-1">
|
||||
<span className="text-gray-600">{t("Input")}:</span>
|
||||
<span className="font-medium text-green-600">
|
||||
${inputPrice.toFixed(2)}
|
||||
</span>
|
||||
<span className="text-xs text-gray-500">/{t("1M tokens")}</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-1">
|
||||
<span className="text-gray-600">{t("Output")}:</span>
|
||||
<span className="font-medium text-blue-600">
|
||||
${outputPrice.toFixed(2)}
|
||||
</span>
|
||||
<span className="text-xs text-gray-500">/{t("1M tokens")}</span>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -14,15 +14,17 @@ interface ProductDetailClientProps {
|
||||
product: ServiceData;
|
||||
breadcrumbs?: {
|
||||
link: string;
|
||||
name: string
|
||||
name: string;
|
||||
}[];
|
||||
mcpName?: string;
|
||||
url?: string;
|
||||
}
|
||||
|
||||
export const ProductDetailClient: React.FC<ProductDetailClientProps> = ({
|
||||
product,
|
||||
breadcrumbs,
|
||||
mcpName
|
||||
mcpName,
|
||||
url,
|
||||
}) => {
|
||||
const { t } = useTranslation();
|
||||
|
||||
@@ -30,52 +32,58 @@ export const ProductDetailClient: React.FC<ProductDetailClientProps> = ({
|
||||
|
||||
return (
|
||||
<div className="flex flex-col mx-auto p-6 max-w-7xl">
|
||||
{product ? (<>
|
||||
<ProductHeader
|
||||
product={product}
|
||||
breadcrumbs={breadcrumbs}
|
||||
/>
|
||||
{product ? (
|
||||
<>
|
||||
<ProductHeader product={product} breadcrumbs={breadcrumbs} />
|
||||
|
||||
<div className="flex gap-6 mt-6">
|
||||
{/* Left side - Main content */}
|
||||
<div className="flex-1">
|
||||
<Tabs
|
||||
selectedKey={activeTab}
|
||||
onSelectionChange={(key) => setActiveTab(key as string)}
|
||||
variant="underlined"
|
||||
color="primary"
|
||||
>
|
||||
<Tab key="overview" title={t("Overview")}>
|
||||
<ProductOverview product={product} />
|
||||
</Tab>
|
||||
<Tab key="tools" title={<div className="flex gap-2 items-center">
|
||||
<span>{t("Tools")}</span>
|
||||
<Chip size="sm" className="h-4 text-xs"> {product.tools.length}</Chip>
|
||||
</div>}>
|
||||
<ProductTools product={product} />
|
||||
</Tab>
|
||||
</Tabs>
|
||||
<div className="flex gap-6 mt-6">
|
||||
{/* Left side - Main content */}
|
||||
<div className="flex-1">
|
||||
<Tabs
|
||||
selectedKey={activeTab}
|
||||
onSelectionChange={(key) => setActiveTab(key as string)}
|
||||
variant="underlined"
|
||||
color="primary"
|
||||
>
|
||||
<Tab key="overview" title={t("Overview")}>
|
||||
<ProductOverview product={product} />
|
||||
</Tab>
|
||||
<Tab
|
||||
key="tools"
|
||||
title={
|
||||
<div className="flex gap-2 items-center">
|
||||
<span>{t("Tools")}</span>
|
||||
<Chip size="sm" className="h-4 text-xs">
|
||||
{" "}
|
||||
{product.tools.length}
|
||||
</Chip>
|
||||
</div>
|
||||
}
|
||||
>
|
||||
<ProductTools product={product} />
|
||||
</Tab>
|
||||
</Tabs>
|
||||
</div>
|
||||
|
||||
{/* Right side - Server Config */}
|
||||
<ServerConfig mcpName={mcpName} url={url} />
|
||||
</div>
|
||||
|
||||
{/* Right side - Server Config */}
|
||||
<ServerConfig product={product} mcpName={mcpName} />
|
||||
</div>
|
||||
|
||||
{/* SEO-friendly: Simple text content for search engines */}
|
||||
<div className="hidden" aria-hidden="true">
|
||||
<h2>Tools ({product.tools.length})</h2>
|
||||
{product.tools.length > 0 && (
|
||||
product.tools.map((tool, index) => (
|
||||
<div key={`seo-${product.service_id}-tool-${index}`}>
|
||||
<h4>{tool.name}</h4>
|
||||
<p>{tool.description || ""}</p>
|
||||
</div>
|
||||
))
|
||||
)}
|
||||
</div>
|
||||
</>
|
||||
) : (<ProductNotFound />)}
|
||||
|
||||
{/* SEO-friendly: Simple text content for search engines */}
|
||||
<div className="hidden" aria-hidden="true">
|
||||
<h2>Tools ({product.tools.length})</h2>
|
||||
{product.tools.length > 0 &&
|
||||
product.tools.map((tool, index) => (
|
||||
<div key={`seo-${product.service_id}-tool-${index}`}>
|
||||
<h4>{tool.name}</h4>
|
||||
<p>{tool.description || ""}</p>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</>
|
||||
) : (
|
||||
<ProductNotFound />
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -73,7 +73,12 @@ export const ProductHeader: React.FC<ProductHeaderProps> = ({
|
||||
{product.charge_type && (
|
||||
<div className="flex gap-2 items-center">
|
||||
<b className="text-md">{t("Price")}:</b>
|
||||
<Price price={product.price} charge_type={product.charge_type} />
|
||||
<Price
|
||||
price={product.price}
|
||||
charge_type={product.charge_type}
|
||||
input_token_price={product.input_token_price}
|
||||
output_token_price={product.output_token_price}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</CardBody>
|
||||
|
||||
@@ -1,29 +1,48 @@
|
||||
"use client";
|
||||
|
||||
import React, { useEffect, useState } from "react";
|
||||
import { ServiceData } from "@/shared/types/marketplace";
|
||||
import { Card, Chip } from "@nextui-org/react";
|
||||
import React from "react";
|
||||
import { Card, Chip, Button } from "@nextui-org/react";
|
||||
import { FlipButton } from "@/shared/components/FlipButton";
|
||||
import { useAuth } from "@/shared/lib/useAuth";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { usePlatformConfig } from "@/shared/contexts/PlatformConfigContext";
|
||||
import { Copy } from "lucide-react";
|
||||
import { copyToClipboard } from "@/shared/utils/clipboard";
|
||||
import toast from "react-hot-toast";
|
||||
|
||||
interface ServerConfigProps {
|
||||
product: ServiceData;
|
||||
mcpName?: string;
|
||||
url?: string;
|
||||
}
|
||||
|
||||
export const ServerConfig: React.FC<ServerConfigProps> = ({ product, mcpName }) => {
|
||||
|
||||
export const ServerConfig: React.FC<ServerConfigProps> = ({
|
||||
mcpName,
|
||||
url = process.env.NEXT_PUBLIC_MCP_URL,
|
||||
}) => {
|
||||
const { t } = useTranslation();
|
||||
const { handleLogin } = useAuth();
|
||||
const { platformConfig } = usePlatformConfig();
|
||||
const [url, setUrl] = useState<string>(process.env.NEXT_PUBLIC_MCP_URL || "");
|
||||
useEffect(() => {
|
||||
if (url || !product.slug_name) return
|
||||
setUrl(`${window.location.protocol}//${window.location.hostname}:8002/mcp/${product.slug_name}`);
|
||||
}, [product.slug_name]);
|
||||
|
||||
const getCodeContent = () => {
|
||||
return `{
|
||||
"mcpServers": {
|
||||
"${mcpName || "xpack-mcp-market"}": {
|
||||
"type": "sse",
|
||||
"autoApprove":"all",
|
||||
"url": "${url}?apikey={Your-${platformConfig?.name}-API-Key}"
|
||||
}
|
||||
}
|
||||
}`;
|
||||
};
|
||||
|
||||
const handleCopy = async () => {
|
||||
const result = await copyToClipboard(getCodeContent());
|
||||
if (result.success) {
|
||||
toast.success(t("Copied to clipboard"));
|
||||
} else {
|
||||
toast.error(t("Copy failed, please copy manually"));
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="min-w-[400px] w-[40%] max-w-100 flex-shrink-0 mt-12">
|
||||
@@ -38,9 +57,21 @@ export const ServerConfig: React.FC<ServerConfigProps> = ({ product, mcpName })
|
||||
{/* Code Snippet */}
|
||||
<Card className="w-full max-w-2xl bg-black text-white p-2 sm:p-4 rounded-lg relative z-10">
|
||||
<div className="text-left font-mono">
|
||||
<Chip className="mb-2 text-white" size="sm" variant="flat">
|
||||
{platformConfig?.name} MCP
|
||||
</Chip>
|
||||
<div className="flex items-center gap-2 mb-2 justify-between">
|
||||
<Chip className="text-white" size="sm" variant="flat">
|
||||
{platformConfig?.name} MCP
|
||||
</Chip>
|
||||
<Button
|
||||
isIconOnly
|
||||
size="sm"
|
||||
variant="flat"
|
||||
className="min-w-6 w-6 h-6 p-0 text-white"
|
||||
onPress={handleCopy}
|
||||
aria-label={t("Copy code")}
|
||||
>
|
||||
<Copy size={14} />
|
||||
</Button>
|
||||
</div>
|
||||
<pre className="p-2 sm:p-4 rounded-md text-xs overflow-x-auto">
|
||||
<code className="text-gray-300 whitespace-pre-wrap">
|
||||
{`{
|
||||
@@ -60,4 +91,4 @@ export const ServerConfig: React.FC<ServerConfigProps> = ({ product, mcpName })
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
};
|
||||
@@ -17,7 +17,10 @@ export const ServiceCard: React.FC<ServiceCardProps> = ({ service }) => {
|
||||
const { t } = useTranslation();
|
||||
|
||||
return (
|
||||
<Link href={`/marketplace/${service.service_id}`}>
|
||||
<Link
|
||||
href={`/marketplace/${service.service_id}`}
|
||||
className="w-full md:w-[calc(50%-16px)] lg:w-[calc(33%-16px)] xl:w-[calc(25%-16px)]"
|
||||
>
|
||||
<Card
|
||||
className="group w-full h-[180px] hover:border-primary-500 transition-all duration-300 border-1"
|
||||
shadow="none"
|
||||
@@ -48,7 +51,12 @@ export const ServiceCard: React.FC<ServiceCardProps> = ({ service }) => {
|
||||
{t("{{count}} Tools", { count: service.tools.length })}
|
||||
</Chip>
|
||||
<div className="flex flex-col gap-1">
|
||||
<Price price={service.price} charge_type={service.charge_type} />
|
||||
<Price
|
||||
price={service.price}
|
||||
charge_type={service.charge_type}
|
||||
input_token_price={service.input_token_price}
|
||||
output_token_price={service.output_token_price}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</CardFooter>
|
||||
|
||||
@@ -25,7 +25,7 @@ export const ServiceListSection: React.FC<ServiceListSectionProps> = ({
|
||||
return (
|
||||
<div className="mx-auto px-6 py-12 max-w-7xl">
|
||||
{/* Services Grid */}
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4 mb-12">
|
||||
<div className="flex flex-wrap justify-center gap-4 mb-12">
|
||||
{services.map((service) => (
|
||||
<ServiceCard key={service.service_id} service={service} />
|
||||
))}
|
||||
@@ -46,4 +46,4 @@ export const ServiceListSection: React.FC<ServiceListSectionProps> = ({
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
};
|
||||
@@ -1,4 +1,4 @@
|
||||
import React, { useState } from "react";
|
||||
import React, { useEffect, useState } from "react";
|
||||
import {
|
||||
Modal,
|
||||
ModalContent,
|
||||
@@ -7,11 +7,14 @@ import {
|
||||
ModalFooter,
|
||||
Button,
|
||||
Input,
|
||||
RadioGroup,
|
||||
Radio,
|
||||
} from "@nextui-org/react";
|
||||
import { useTranslation } from "@/shared/lib/useTranslation";
|
||||
import { fetchAPI } from "@/shared/rpc/common-function";
|
||||
import toast from "react-hot-toast";
|
||||
import { ConfirmPurchaseModal } from "./ConfirmPurchaseModal";
|
||||
import { usePlatformConfig } from "@/shared/contexts/PlatformConfigContext";
|
||||
|
||||
interface RechargeModalProps {
|
||||
isOpen: boolean;
|
||||
@@ -23,13 +26,16 @@ export const RechargeModal: React.FC<RechargeModalProps> = ({
|
||||
onClose,
|
||||
}) => {
|
||||
const { t } = useTranslation();
|
||||
const { paymentChannels } = usePlatformConfig();
|
||||
const [amount, setAmount] = useState<string>("");
|
||||
const [error, setError] = useState<string>("");
|
||||
const [selectedPaymentChannel, setSelectedPaymentChannel] = useState<string>(
|
||||
paymentChannels[0]?.id || ""
|
||||
);
|
||||
|
||||
const [paymentId, setPaymentId] = useState("");
|
||||
const [isConfirmOpen, setIsConfirmOpen] = useState(false);
|
||||
|
||||
|
||||
const handlePurchase = async () => {
|
||||
const numAmount = parseFloat(amount);
|
||||
if (isNaN(numAmount) || numAmount <= 0) {
|
||||
@@ -41,10 +47,17 @@ export const RechargeModal: React.FC<RechargeModalProps> = ({
|
||||
setError(t("Minimum recharge amount is $1"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!selectedPaymentChannel) {
|
||||
setError(t("Please select a payment method"));
|
||||
return;
|
||||
}
|
||||
|
||||
const response = await fetchAPI("/api/payment/create_payment_link", {
|
||||
method: "POST",
|
||||
body: {
|
||||
amount: numAmount,
|
||||
payment_channel: selectedPaymentChannel,
|
||||
success_url: window.location.origin + "/pay_success",
|
||||
} as unknown as BodyInit,
|
||||
});
|
||||
@@ -93,6 +106,7 @@ export const RechargeModal: React.FC<RechargeModalProps> = ({
|
||||
const handleClose = () => {
|
||||
setAmount("");
|
||||
setError("");
|
||||
setSelectedPaymentChannel(paymentChannels[0]?.id || "");
|
||||
onClose();
|
||||
};
|
||||
|
||||
@@ -119,23 +133,54 @@ export const RechargeModal: React.FC<RechargeModalProps> = ({
|
||||
}
|
||||
type="text"
|
||||
variant="bordered"
|
||||
isInvalid={!!error}
|
||||
errorMessage={error}
|
||||
isInvalid={!!error && !error.includes("payment method")}
|
||||
errorMessage={
|
||||
error && !error.includes("payment method") ? error : ""
|
||||
}
|
||||
labelPlacement="outside"
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === "Enter") {
|
||||
handlePurchase();
|
||||
}
|
||||
}}
|
||||
/>
|
||||
<p className="text-xs text-default-500">
|
||||
{t("Funds will be added to your account balance")}
|
||||
</p>
|
||||
{/**coming soon : select payment channel*/}
|
||||
|
||||
{/* {paymentChannels.length > 0 && (
|
||||
<div className="space-y-2">
|
||||
<label className="text-sm font-medium text-default-700">
|
||||
{t("Payment Method")}
|
||||
</label>
|
||||
<RadioGroup
|
||||
value={selectedPaymentChannel}
|
||||
onValueChange={setSelectedPaymentChannel}
|
||||
isInvalid={!!error && error.includes("payment method")}
|
||||
errorMessage={
|
||||
error && error.includes("payment method") ? error : ""
|
||||
}
|
||||
orientation="horizontal"
|
||||
description={t(
|
||||
"Funds will be added to your account balance"
|
||||
)}
|
||||
>
|
||||
{paymentChannels.map((channel) => (
|
||||
<Radio key={channel.id} value={channel.id}>
|
||||
{channel.name}
|
||||
</Radio>
|
||||
))}
|
||||
</RadioGroup>
|
||||
</div>
|
||||
)} */}
|
||||
</ModalBody>
|
||||
<ModalFooter>
|
||||
<Button variant="light" onPress={handleClose}>
|
||||
{t("Cancel")}
|
||||
</Button>
|
||||
<Button color="primary" onPress={handlePurchase}>
|
||||
<Button
|
||||
color="primary"
|
||||
onPress={handlePurchase}
|
||||
isDisabled={!selectedPaymentChannel || !amount}
|
||||
>
|
||||
{t("Confirm")}
|
||||
</Button>
|
||||
</ModalFooter>
|
||||
@@ -144,7 +189,6 @@ export const RechargeModal: React.FC<RechargeModalProps> = ({
|
||||
</ModalContent>
|
||||
</Modal>
|
||||
|
||||
|
||||
{/**Confirm Purchase Modal */}
|
||||
<ConfirmPurchaseModal
|
||||
isOpen={isConfirmOpen}
|
||||
@@ -154,4 +198,4 @@ export const RechargeModal: React.FC<RechargeModalProps> = ({
|
||||
/>
|
||||
</>
|
||||
);
|
||||
};
|
||||
};
|
||||
@@ -6,6 +6,10 @@ import {
|
||||
PlatformConfigResponse,
|
||||
Theme,
|
||||
LoginConfig,
|
||||
FaqItem,
|
||||
TopNavigationItem,
|
||||
EmbeddedHtmlConfig,
|
||||
PaymentChannel,
|
||||
} from "@/shared/types/system";
|
||||
export const _DefaultPlatformConfig: PlatformConfig = {
|
||||
name: "XPack",
|
||||
@@ -17,10 +21,18 @@ export const _DefaultPlatformConfig: PlatformConfig = {
|
||||
subheadline:
|
||||
"Open‑source MCP marketplace — publish or consume APIs in minutes.",
|
||||
theme: Theme.DEFAULT,
|
||||
domain: "",
|
||||
is_showcased: false,
|
||||
mcp_server_prefix: "",
|
||||
};
|
||||
interface PlatformConfigContextType {
|
||||
platformConfig: PlatformConfig;
|
||||
loginConfig: LoginConfig | null;
|
||||
faqItems: FaqItem[];
|
||||
topNavigation: TopNavigationItem[];
|
||||
embeddedHtml: EmbeddedHtmlConfig | null;
|
||||
paymentChannels: PaymentChannel[];
|
||||
isInstalled: boolean;
|
||||
updateClientConfig: (config: PlatformConfigResponse) => void;
|
||||
}
|
||||
|
||||
@@ -43,13 +55,41 @@ export const PlatformConfigProvider: React.FC<PlatformConfigProviderProps> = ({
|
||||
const [loginConfig, setLoginConfig] = useState<LoginConfig | null>(
|
||||
initConfig?.login || null
|
||||
);
|
||||
const [faqItems, setFaqItems] = useState<FaqItem[]>(initConfig?.faq || []);
|
||||
const [topNavigation, setTopNavigation] = useState<TopNavigationItem[]>(
|
||||
initConfig?.top_navigation || []
|
||||
);
|
||||
const [embeddedHtml, setEmbeddedHtml] = useState<EmbeddedHtmlConfig | null>(
|
||||
initConfig?.embeded_html || null
|
||||
);
|
||||
const [paymentChannels, setPaymentChannels] = useState<PaymentChannel[]>(
|
||||
initConfig?.payment_channels || []
|
||||
);
|
||||
const [isInstalled, setIsInstalled] = useState<boolean>(
|
||||
initConfig?.is_installed || false
|
||||
);
|
||||
|
||||
const updateClientConfig = (config: PlatformConfigResponse) => {
|
||||
if (config.platform) setPlatformConfig(config.platform);
|
||||
if (config.login) setLoginConfig(config.login);
|
||||
if (config.faq) setFaqItems(config.faq);
|
||||
if (config.top_navigation) setTopNavigation(config.top_navigation);
|
||||
if (config.embeded_html) setEmbeddedHtml(config.embeded_html);
|
||||
if (config.payment_channels) setPaymentChannels(config.payment_channels);
|
||||
if (config.is_installed !== undefined) setIsInstalled(config.is_installed);
|
||||
};
|
||||
return (
|
||||
<PlatformConfigContext.Provider
|
||||
value={{ platformConfig, loginConfig, updateClientConfig }}
|
||||
value={{
|
||||
platformConfig,
|
||||
loginConfig,
|
||||
faqItems,
|
||||
topNavigation,
|
||||
embeddedHtml,
|
||||
paymentChannels,
|
||||
isInstalled,
|
||||
updateClientConfig,
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</PlatformConfigContext.Provider>
|
||||
|
||||
@@ -11,16 +11,28 @@ export enum TabKey {
|
||||
ACCOUNT = "account",
|
||||
}
|
||||
|
||||
export interface SidebarSubItem {
|
||||
key: string;
|
||||
label: string;
|
||||
description?: string;
|
||||
}
|
||||
|
||||
export interface SidebarItem {
|
||||
key: TabKey;
|
||||
icon: React.ReactNode;
|
||||
label: string;
|
||||
description: string;
|
||||
subItems?: SidebarSubItem[];
|
||||
}
|
||||
|
||||
export interface SidebarItemWithActive extends SidebarItem {
|
||||
isExpanded?: boolean;
|
||||
}
|
||||
|
||||
export interface DashboardSidebarProps {
|
||||
activeTab: TabKey;
|
||||
onTabNavigate?: (tab: TabKey) => void;
|
||||
activeSubTab?: string;
|
||||
onTabNavigate?: (tab: TabKey, subTab?: string) => void;
|
||||
onLogout: () => void;
|
||||
bottomPanel?: React.ReactNode;
|
||||
sidebarItems: SidebarItem[];
|
||||
|
||||
@@ -8,6 +8,8 @@ export interface ServiceData {
|
||||
tags?: string[];
|
||||
price?: string;
|
||||
charge_type?: ChargeType;
|
||||
input_token_price?: string;
|
||||
output_token_price?: string;
|
||||
}
|
||||
|
||||
export interface ToolData {
|
||||
|
||||
@@ -21,12 +21,48 @@ export interface PlatformConfig {
|
||||
subheadline?: string; // homepage subheadline
|
||||
theme?: Theme; // platform theme for homepage and marketplace templates
|
||||
about_page?: string; // about page content (markdown)
|
||||
domain?: string; // platform domain
|
||||
is_showcased?: boolean; // whether to showcase in xpack official case list
|
||||
mcp_server_prefix?: string; // MCP server domain prefix for API calls
|
||||
}
|
||||
|
||||
export type ThemeType = Theme;
|
||||
// FAQ item
|
||||
export interface FaqItem {
|
||||
question: string;
|
||||
answer: string;
|
||||
}
|
||||
export enum TopNavigationTargetEnum {
|
||||
SELF = "_self",
|
||||
BLANK = "_blank",
|
||||
}
|
||||
// Top navigation item
|
||||
export interface TopNavigationItem {
|
||||
title: string;
|
||||
link: string;
|
||||
target: TopNavigationTargetEnum;
|
||||
}
|
||||
|
||||
// Embedded HTML config
|
||||
export interface EmbeddedHtmlConfig {
|
||||
is_enabled: boolean;
|
||||
html: string;
|
||||
}
|
||||
|
||||
// Payment channel
|
||||
export interface PaymentChannel {
|
||||
id: string;
|
||||
name: string;
|
||||
}
|
||||
|
||||
export interface PlatformConfigResponse {
|
||||
platform: PlatformConfig;
|
||||
platform?: PlatformConfig;
|
||||
login?: LoginConfig;
|
||||
faq?: FaqItem[];
|
||||
top_navigation?: TopNavigationItem[];
|
||||
embeded_html?: EmbeddedHtmlConfig;
|
||||
payment_channels?: PaymentChannel[];
|
||||
is_installed?: boolean;
|
||||
}
|
||||
|
||||
// google auth config
|
||||
|
||||
@@ -19,6 +19,8 @@ export interface BaseMCPService {
|
||||
long_description?: string;
|
||||
charge_type: ChargeType;
|
||||
price?: string;
|
||||
input_token_price?: string;
|
||||
output_token_price?: string;
|
||||
apis: MCPServiceAPIItem[];
|
||||
tags?: string[];
|
||||
}
|
||||
@@ -34,6 +36,7 @@ export interface MCPServiceAPIItem {
|
||||
id: string;
|
||||
name: string;
|
||||
description?: string;
|
||||
url?: string;
|
||||
}
|
||||
|
||||
// form data interface, used to create and edit service
|
||||
@@ -48,6 +51,8 @@ export interface MCPServiceFormData {
|
||||
auth_token?: string;
|
||||
charge_type: ChargeType;
|
||||
price?: string;
|
||||
input_token_price?: string; // Price for input tokens when charge_type is PerToken
|
||||
output_token_price?: string; // Price for output tokens when charge_type is PerToken
|
||||
enabled: EnabledEnum; // API requires string type
|
||||
apis: MCPServiceAPIItem[];
|
||||
tags?: string[];
|
||||
@@ -89,41 +94,6 @@ export interface ServiceDeleteRequest {
|
||||
id: string;
|
||||
}
|
||||
|
||||
// predefined auth methods
|
||||
export const AUTH_METHODS = [
|
||||
{ value: "free", label: "free" },
|
||||
{ value: "apikey", label: "API key" },
|
||||
] as const;
|
||||
|
||||
// predefined charge types
|
||||
export const CHARGE_TYPES = [
|
||||
{ value: "free", label: "free" },
|
||||
{ value: "per_call", label: "per call" },
|
||||
{ value: "per_token", label: "per token" },
|
||||
] as const;
|
||||
|
||||
// predefined service categories
|
||||
export const SERVICE_CATEGORIES = [
|
||||
"Web Services",
|
||||
"Database",
|
||||
"AI/ML",
|
||||
"Authentication",
|
||||
"Payment",
|
||||
"Communication",
|
||||
"Analytics",
|
||||
"Storage",
|
||||
"Security",
|
||||
"Development Tools",
|
||||
"Financial",
|
||||
"Logistics & Transportation",
|
||||
"E-commerce",
|
||||
"Social Media",
|
||||
"Content Management",
|
||||
"Other",
|
||||
] as const;
|
||||
|
||||
export type ServiceCategory = (typeof SERVICE_CATEGORIES)[number];
|
||||
|
||||
// tool function: convert frontend form data to API data
|
||||
export function convertFormToAPI(
|
||||
formData: MCPServiceFormData
|
||||
@@ -138,6 +108,8 @@ export function convertFormToAPI(
|
||||
auth_token: formData.auth_token,
|
||||
charge_type: formData.charge_type,
|
||||
price: formData.price,
|
||||
input_token_price: formData.input_token_price,
|
||||
output_token_price: formData.output_token_price,
|
||||
enabled: formData.enabled,
|
||||
apis: formData.apis,
|
||||
tags: formData.tags,
|
||||
|
||||
@@ -1,18 +1,37 @@
|
||||
// payment channel type
|
||||
export type PaymentChannelType = "stripe";
|
||||
export type PaymentChannelType = "stripe" | "alipay" | "wechat";
|
||||
|
||||
// stripe config - admin need to configure
|
||||
export interface StripeConfig {
|
||||
secret: string;
|
||||
webhook_secret: string;
|
||||
is_enabled?: boolean;
|
||||
}
|
||||
|
||||
// alipay config - admin need to configure
|
||||
export interface AlipayConfig {
|
||||
app_id: string;
|
||||
app_private_key: string;
|
||||
alipay_public_key: string;
|
||||
is_enabled?: boolean;
|
||||
}
|
||||
|
||||
// wechat config - admin need to configure
|
||||
export interface WechatConfig {
|
||||
app_id: string;
|
||||
mch_id: string;
|
||||
is_enabled?: boolean;
|
||||
}
|
||||
|
||||
// union type for all payment configs
|
||||
export type PaymentConfig = StripeConfig | AlipayConfig | WechatConfig;
|
||||
|
||||
// API return payment channel item structure
|
||||
export interface PaymentChannelApiItem {
|
||||
id: PaymentChannelType;
|
||||
name: string;
|
||||
is_enabled: boolean;
|
||||
config: StripeConfig;
|
||||
config: PaymentConfig;
|
||||
update_time: string;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,10 @@ import {
|
||||
GoogleAuthConfig,
|
||||
PlatformConfig,
|
||||
LoginConfig,
|
||||
FaqItem,
|
||||
TopNavigationItem,
|
||||
EmbeddedHtmlConfig,
|
||||
PaymentChannel,
|
||||
} from "@/shared/types/system";
|
||||
|
||||
// API return system config data structure
|
||||
@@ -12,6 +16,11 @@ export interface SystemConfigApiData {
|
||||
account: AdminConfig;
|
||||
email: EmailConfig;
|
||||
login: LoginConfig;
|
||||
faq?: FaqItem[];
|
||||
top_navigation?: TopNavigationItem[];
|
||||
embeded_html?: EmbeddedHtmlConfig;
|
||||
payment_channels?: PaymentChannel[];
|
||||
is_installed?: boolean;
|
||||
}
|
||||
// admin config
|
||||
export interface AdminConfig {
|
||||
|
||||
Reference in new issue
Block a user