feature/ui:1.0 feature,like mcp price method support use token and set more config about home page

This commit is contained in:
lethe committed 2025-07-30 15:59:10 +08:00
1 parent 2262a7f49a
commit 8946be619d
69 files changed
+4189 -1021

No files matched your search

@@ -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>
+13 -1
View File
@@ -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[];
+2
View File
@@ -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 {
+37 -1
View File
@@ -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