First commit to the code repository

This commit is contained in:
Liujian committed 2025-07-20 22:38:52 +08:00
1 parent 692cdee407
commit 0c0dd1cb56
323 files changed
+45712

No files matched your search

@@ -0,0 +1,36 @@
"use client";
import React, { useEffect } from "react";
import { I18nextProvider } from "react-i18next";
import i18n, { i18nPromise } from "@/shared/lib/i18n";
interface ClientI18nProviderProps {
children: React.ReactNode;
}
export const ClientI18nProvider: React.FC<ClientI18nProviderProps> = ({
children,
}) => {
const initAll = async () => {
if (i18n.isInitialized) return
await i18nPromise;
const storedLang = localStorage.getItem("i18nextLng");
// only switch when the stored language is different from the current language
if (storedLang && storedLang !== i18n.language) {
await i18n.changeLanguage(storedLang);
}
};
useEffect(() => {
initAll();
}, []);
return (
<div style={{
opacity: 1,
transition: 'opacity 0.2s ease-in-out'
}}>
<I18nextProvider i18n={i18n}>{children}</I18nextProvider>
</div>
);
};
@@ -0,0 +1,26 @@
"use client";
import React from "react";
import { Providers } from "@/shared/providers/nextui-provider";
import { ClientI18nProvider } from "@/shared/components/ClientI18nProvider";
import { PlatformConfigProvider } from "@/shared/contexts/PlatformConfigContext";
import { Toaster } from "react-hot-toast";
import { PlatformConfigResponse } from "@/shared/types/system";
export default function ClientRootProviders({
children,
initConfig
}: {
children: React.ReactNode;
initConfig: PlatformConfigResponse;
}) {
return (
<ClientI18nProvider>
<PlatformConfigProvider initConfig={initConfig}>
<Toaster position="top-center" />
<Providers>{children}</Providers>
</PlatformConfigProvider>
</ClientI18nProvider>
);
}
@@ -0,0 +1,30 @@
"use client";
import React from "react";
import { useTranslation } from "@/shared/lib/useTranslation";
interface DashboardDemoContentProps {
children: React.ReactNode;
title: string;
description: string;
}
const DashboardDemoContent: React.FC<DashboardDemoContentProps> = ({
children,
title,
description,
}) => {
const { t } = useTranslation();
return (
<div className="flex flex-col h-full overflow-auto p-8">
{/* Header */}
<div className="mb-8">
<h1 className="text-3xl font-bold text-foreground mb-2">{t(title)}</h1>
<p className="text-default-600">{t(description)}</p>
</div>
{children}
</div>
);
};
export default DashboardDemoContent;
@@ -0,0 +1,82 @@
"use client";
import React from "react";
import { useTranslation } from "@/shared/lib/useTranslation";
import {
Button,
Divider,
Link,
} from "@nextui-org/react";
import {
LogOut,
} from "lucide-react";
import { DashboardSidebarProps } from "@/shared/types/dashboard";
import { DynamicLogo } from "@/shared/components/DynamicLogo";
const DashboardSidebar: React.FC<DashboardSidebarProps> = ({
activeTab,
onTabNavigate,
onLogout,
sidebarItems, userProfilePanel
}) => {
const { t } = useTranslation();
return (
<div className="w-[340px] h-screen bg-content1 border-r border-divider overflow-y-auto sidebar-thin">
<div className="p-6">
{/* Header */}
<div className="mb-8 flex flex-col gap-2">
<div className="flex justify-between items-center gap-2">
<Link href={process.env.NEXT_PUBLIC_DOMAIN || "/"}>
<DynamicLogo
alt="Platform Logo"
className="h-[20px]"
/>
</Link>
</div>
<p className="text-default-600 text-sm">
{t("Build incredible AI agents together")}
</p>
</div>
{/* User Profile */}
{userProfilePanel}
{/* Navigation */}
<div className="flex flex-col gap-4">
{sidebarItems.map((item) => (
<Button
key={item.key}
variant={activeTab === item.key ? "solid" : "bordered"}
color={activeTab === item.key ? "primary" : "default"}
startContent={item.icon}
className="w-full justify-start h-auto p-4"
onPress={() => onTabNavigate?.(item.key)}
>
<div className="flex flex-col items-start">
<div className="font-medium">{t(item.label)}</div>
<div className="text-xs opacity-80">{t(item.description)}</div>
</div>
</Button>
))}
</div>
<Divider className="my-6" />
{/* Logout */}
<Button
variant="light"
color="danger"
startContent={<LogOut className="w-4 h-4" />}
className="w-full justify-start"
onPress={onLogout}
>
{t("Log Out")}
</Button>
</div>
</div>
);
};
export default DashboardSidebar;
@@ -0,0 +1,44 @@
'use client';
import React from 'react';
import { usePlatformConfig } from '@/shared/contexts/PlatformConfigContext';
import { getURL } from '@/shared/rpc/adapter';
interface DynamicLogoProps {
className?: string;
alt?: string;
width?: number;
height?: number;
fallbackSrc?: string;
}
export const DynamicLogo: React.FC<DynamicLogoProps> = ({
className = '',
alt,
width,
height,
fallbackSrc = '/static/logo/logo.png'
}) => {
const { platformConfig } = usePlatformConfig();
const logoSrc = getURL(platformConfig.logo || fallbackSrc);
const logoAlt = alt || `Platform Logo`;
if (!platformConfig.logo) return <></>
return (
<img
src={logoSrc}
alt={logoAlt}
className={className}
width={width}
height={height}
onError={(e) => {
// if custom logo loading fails, fallback to default logo
const target = e.target as HTMLImageElement;
if (target.src !== fallbackSrc) {
target.src = fallbackSrc;
}
}}
/>
);
};
@@ -0,0 +1,84 @@
import React, { useState } from "react";
import { Button } from "@nextui-org/react";
import { ArrowRightIcon } from "lucide-react";
interface FlipButtonProps {
text: string;
onPress?: () => void;
className?: string;
}
export const FlipButton: React.FC<FlipButtonProps> = ({
text,
onPress,
className = "",
}) => {
const [isHovered, setIsHovered] = useState(false);
const characters = text.split("");
const STAGGER = 20;
return (
<Button
color="primary"
radius="full"
onPress={onPress}
onMouseEnter={() => setIsHovered(true)}
onMouseLeave={() => setIsHovered(false)}
className={`relative min-w-[200px] bg-black flex items-center justify-between gap-4 pr-1 md:pr-2 h-[40px] md:h-[50px] overflow-hidden ${className}`.trim()}
>
{/* Primary text */}
<div className="text-md md:text-lg font-bold flex items-center">
{characters.map((char, index) => (
<span
key={index}
className="inline-block transition-all duration-500 ease-in-out"
style={{
transitionProperty: "transform, opacity, filter",
transform: isHovered
? `translateY(-18px) rotateX(80deg)`
: "none",
filter: isHovered ? "blur(4px)" : "blur(0px)",
opacity: isHovered ? 0 : 1,
transitionDelay: isHovered
? `${index * STAGGER}ms`
: `${(characters.length - index - 1) * STAGGER}ms`,
}}
>
{char === " " ? "\u00A0" : char}
</span>
))}
</div>
{/* Overlay text (appears on hover) */}
<div
className="absolute left-4 text-md md:text-lg font-bold flex items-center"
aria-hidden="true"
>
{characters.map((char, index) => (
<span
key={index}
className="inline-block transition-all duration-500 ease-in-out"
style={{
transitionProperty: "transform, opacity, filter",
transform: isHovered
? "none"
: `translateY(18px) rotateX(-80deg)`,
filter: isHovered ? "blur(0px)" : "blur(4px)",
opacity: isHovered ? 1 : 0,
transitionDelay: isHovered
? `${index * STAGGER}ms`
: `${(characters.length - index - 1) * STAGGER}ms`,
}}
>
{char === " " ? "\u00A0" : char}
</span>
))}
</div>
{/* Arrow icon */}
<div className="w-8 h-8 min-w-8 min-h-8 bg-gray-100 flex items-center justify-center rounded-full">
<ArrowRightIcon size={16} className="text-default-700" />
</div>
</Button>
);
};
+15
View File
@@ -0,0 +1,15 @@
'use client'
import React from "react";
import { usePlatformConfig } from "@/shared/contexts/PlatformConfigContext";
import { Link } from "@nextui-org/react";
export function Footer() {
const { platformConfig } = usePlatformConfig();
return (
<footer className="py-4 px-4 sm:px-6 text-center sm:text-end max-w-7xl mx-auto text-xs">
<span className="mr-1">© 2025 {platformConfig?.name}. All rights reserved.</span>
<Link className="text-xs" href="https://xpack.ai">Powered By XPack.AI</Link>
</footer>
);
}
@@ -0,0 +1,151 @@
"use client";
import React, { useState } from "react";
import {
Navbar,
NavbarContent,
NavbarItem,
NavbarMenuToggle,
NavbarMenu,
NavbarMenuItem,
Button,
} from "@nextui-org/react";
import { useTranslation } from "@/shared/lib/useTranslation";
import { useAuth } from "@/shared/lib/useAuth";
import { ArrowRightIcon } from "lucide-react";
import { DynamicLogo } from "@/shared/components/DynamicLogo";
import Link from "next/link";
interface NavigationProps {
items?: {
label: string;
href: string;
}[];
}
// Client-side wrapper for interactive functionality
function NavigationClient({ items = [] }: NavigationProps) {
const [isMenuOpen, setIsMenuOpen] = useState(false);
const { t } = useTranslation();
const { handleLogin } = useAuth();
return (
<>
{/* Main Navigation */}
<Navbar
onMenuOpenChange={setIsMenuOpen}
maxWidth="full"
/*
* Rounded-pill navigation container with subtle border & backdrop blur
* Matches the reference design that features a floating white bar with full-round corners.
*/
className="mt-2 sm:mt-5 rounded-full bg-background/50 backdrop-blur-[10px] border-1 border-gray-100 top-2 sm:top-5 max-w-7xl mx-auto"
height="66px"
isBordered={false}
>
<NavbarContent>
<NavbarMenuToggle
aria-label={isMenuOpen ? "Close menu" : "Open menu"}
className="sm:hidden"
/>
<div className="flex justify-start bg-transparent w-max">
{/* Logo using dynamic platform config */}
<Link href="/">
<DynamicLogo
alt="Platform Logo"
className="h-[20px]"
/>
</Link>
<Link
href="https://xpack.ai/techblog"
target="_blank"
className="hidden"
></Link>
</div>
{/* Desktop Navigation */}
<div className="hidden lg:flex gap-6 justify-center">
{items.map((item) => (
<NavbarItem key={item.href}>
<Link
color="foreground"
href={item.href}
className="font-medium text-foreground-600 hover:text-foreground transition-colors px-2 py-1"
>
{t(item.label)}
</Link>
</NavbarItem>
))}
</div>
</NavbarContent>
{/* Right Side Actions */}
<NavbarContent justify="end" className="items-center gap-2 sm:gap-4">
{/* Desktop Auth Button */}
<div className="hidden sm:block">
<Button
color="primary"
className="bg-black flex items-center justify-center gap-4 pr-1 h-[45px]"
radius="full"
onPress={handleLogin}
>
<b className="text-md"> {t("Get Started")}</b>
<div className="w-8 h-8 bg-gradient-to-r from-primary to-[#9ab0f2] flex items-center justify-center rounded-full">
<ArrowRightIcon
size={16}
className="transition-transform duration-200 ease-in-out group-hover:translate-x-[3px]"
/>
</div>
</Button>
</div>
{/* Mobile Auth Button */}
<div className="sm:hidden">
<Button color="primary" onPress={handleLogin} size="sm">
<b className="text-md"> {t("Get Started")}</b>
</Button>
</div>
</NavbarContent>
{/* Mobile Menu */}
<NavbarMenu className="pt-6 pb-6">
{items.map((item, index) => (
<NavbarMenuItem key={`${item.href}-${index}`}>
<Link
color="foreground"
href={item.href}
className="w-full py-2 font-medium text-sm"
>
{t(item.label)}
</Link>
</NavbarMenuItem>
))}
<NavbarMenuItem className="mt-4">
<Button
color="primary"
className="w-full bg-black flex items-center justify-between gap-4 pr-1 h-[45px]"
radius="full"
onPress={handleLogin}
>
<b className="text-md"> {t("Get Started")}</b>
<div className="w-8 h-8 bg-gradient-to-r from-primary to-[#9ab0f2] flex items-center justify-center rounded-full">
<ArrowRightIcon
size={16}
className="transition-transform duration-200 ease-in-out group-hover:translate-x-[3px]"
/>
</div>
</Button>
</NavbarMenuItem>
</NavbarMenu>
</Navbar>
</>
);
}
// Export the client component
export function Navigation(props: NavigationProps) {
return <NavigationClient {...props} />;
}
@@ -0,0 +1,127 @@
import React, { useState, useEffect, useRef } from "react";
import { Input, Button } from "@nextui-org/react";
import { Search } from "lucide-react";
import { useTranslation } from "react-i18next";
import { _DefaultPlatformConfig, usePlatformConfig } from "@/shared/contexts/PlatformConfigContext";
interface HeroSectionProps {
searchQuery: string;
onSearchChange: (value: string) => void;
onSearch?: () => void;
}
export const HeroSection: React.FC<HeroSectionProps> = ({
searchQuery,
onSearchChange,
onSearch,
}) => {
const { platformConfig } = usePlatformConfig();
const { t } = useTranslation();
const [isFocused, setIsFocused] = useState(false);
const [animatedText, setAnimatedText] = useState("");
const [currentSuggestionIndex, setCurrentSuggestionIndex] = useState(0);
const [isTyping, setIsTyping] = useState(true);
const inputRef = useRef<HTMLInputElement>(null);
const searchSuggestions = [
t("get latest documentation for libraries"),
t("execute terminal commands safely"),
t("find latest scientific research papers"),
t("tools to enhance thinking and reasoning"),
t("find flight tickets and airbnb listings"),
t("automate web browser interactions"),
t("send messages and receive notifications")
];
useEffect(() => {
if (isFocused || searchQuery) {
return;
}
const currentSuggestion = searchSuggestions[currentSuggestionIndex];
let timeoutId: NodeJS.Timeout;
if (isTyping) {
// typing effect
if (animatedText.length < currentSuggestion.length) {
timeoutId = setTimeout(() => {
setAnimatedText(currentSuggestion.slice(0, animatedText.length + 1));
}, 100);
} else {
// typing completed, wait for a while then start deleting
timeoutId = setTimeout(() => {
setIsTyping(false);
}, 2000);
}
} else {
// deleting effect
if (animatedText.length > 0) {
timeoutId = setTimeout(() => {
setAnimatedText(animatedText.slice(0, -1));
}, 50);
} else {
// deleting completed, switch to next suggestion
setCurrentSuggestionIndex((prev) => (prev + 1) % searchSuggestions.length);
setIsTyping(true);
}
}
return () => clearTimeout(timeoutId);
}, [animatedText, currentSuggestionIndex, isTyping, isFocused, searchQuery]);
const handleKeyPress = (e: React.KeyboardEvent) => {
if (e.key === 'Enter') {
onSearch?.();
}
};
const handleSearchClick = () => {
onSearch?.();
};
return (
<div className="relative overflow-hidden mx-auto p-6 py-24 max-w-7xl">
<div className="text-center mb-12">
<h1 className="text-5xl lg:text-6xl font-bold mb-6 leading-tight text-primary">
{platformConfig.headline || t(_DefaultPlatformConfig.headline || "")}
</h1>
<p className="text-2xl font-medium max-w-3xl mx-auto leading-relaxed">
{platformConfig.subheadline || t(_DefaultPlatformConfig.subheadline || "")}
</p>
</div>
{/* Search Bar */}
<div className="max-w-4xl mx-auto relative">
<Input
ref={inputRef}
size="lg"
placeholder={isFocused || searchQuery ? "" : animatedText}
value={searchQuery}
onChange={(e) => onSearchChange(e.target.value)}
onFocus={() => setIsFocused(true)}
onBlur={() => setIsFocused(false)}
onKeyDown={handleKeyPress}
endContent={
searchQuery && (
<Button
isIconOnly
onPress={handleSearchClick}
variant="flat"
color="primary"
>
<Search size={20} />
</Button>
)
}
className="w-full"
classNames={{
input: "text-lg text-gray-900 placeholder:text-gray-500",
inputWrapper: "h-16 shadow-none px-4 bg-white",
}}
variant="faded"
/>
</div>
</div>
);
};
@@ -0,0 +1,50 @@
"use client";
import { useTranslation } from "@/shared/lib/useTranslation";
import { ChargeType } from "@/shared/types/marketplace";
import { Chip } from "@nextui-org/react";
import { Zap } from "lucide-react";
import React from "react";
interface PriceProps {
price?: string;
charge_type: ChargeType;
}
export const Price: React.FC<PriceProps> = ({
price,
charge_type
}) => {
const { t } = useTranslation();
if (charge_type === ChargeType.Free) {
return (
<Chip size="sm" variant="flat" color="default">
{t('Free')}
</Chip>
);
}
const priceText = parseFloat(price || '0');
if (charge_type === ChargeType.PerCall) {
return (
<div className="flex items-center gap-1">
<span className="text-sm font-medium text-green-600">
${priceText.toFixed(2)}
</span>
<span className="text-xs text-gray-500">/{t('Per Call')}</span>
</div>
);
} else {
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>
);
}
};
@@ -0,0 +1,79 @@
"use client";
import React, { useState } from "react";
import { useTranslation } from "@/shared/lib/useTranslation";
import { Tabs, Tab, Chip } from "@nextui-org/react";
import { ProductHeader } from "./ProductHeader";
import { ProductOverview } from "./ProductOverview";
import { ProductTools } from "./ProductTools";
import { ProductNotFound } from "./ProductNotFound";
import { ServerConfig } from "./ServerConfig";
import { ServiceData } from "@/shared/types/marketplace";
interface ProductDetailClientProps {
product: ServiceData;
breadcrumbs?: {
link: string;
name: string
}[];
}
export const ProductDetailClient: React.FC<ProductDetailClientProps> = ({
product,
breadcrumbs
}) => {
const { t } = useTranslation();
const [activeTab, setActiveTab] = useState("overview");
return (
<div className="flex flex-col mx-auto p-6 max-w-7xl">
{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>
{/* Right side - Server Config */}
<ServerConfig product={product} />
</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 />)}
</div>
);
};
@@ -0,0 +1,88 @@
"use client";
import React from "react";
import { useTranslation } from "@/shared/lib/useTranslation";
import {
Card,
CardBody,
Chip,
} from "@nextui-org/react";
import { ChargeType, ServiceData } from "@/shared/types/marketplace";
import Link from "next/link";
import { Price } from "./Price";
interface ProductHeaderProps {
product: ServiceData;
breadcrumbs?: {
link: string;
name: string
}[];
}
export const ProductHeader: React.FC<ProductHeaderProps> = ({
product,
breadcrumbs = [],
}) => {
const { t } = useTranslation();
return (
<Card shadow="none">
<CardBody>
{/* Breadcrumb */}
<nav className="text-sm text-default-500 flex items-center gap-1 mb-10">
<Link href="/" className="hover:underline">
{t("Home")}
</Link>
{breadcrumbs.map((item, index) => (
<React.Fragment key={index}>
<span>/</span>
<Link href={item.link} className="hover:underline">
{t(item.name)}
</Link>
</React.Fragment>
))}
<span>/</span>
<b className="text-default-700">{t(product.name)}</b>
</nav>
{/* Header with title and price */}
<div className="flex items-start justify-between mb-4">
<div className="flex-1">
<h1 className="text-3xl font-bold mb-2">
{product.name}
</h1>
{/* Tags */}
{product.tags && product.tags.length > 0 && (
<div className="flex flex-wrap gap-2 my-3">
{product.tags.map((tag, index) => (
<Chip
key={index}
size="sm"
variant="flat"
color="primary"
radius="sm"
className="text-xs h-5"
>
{tag}
</Chip>
))}
</div>
)}
<p className="text-lg mb-4">
{product.short_description || t("No description available")}
</p>
</div>
</div>
{/* Price section */}
<div className="flex gap-2 items-center">
<b className="text-xs">{t("Price")}:</b>
<Price price={product.price} charge_type={product.charge_type || ChargeType.Free} />
</div>
</CardBody>
</Card>
);
};
@@ -0,0 +1,47 @@
"use client";
import React from "react";
import { useTranslation } from "@/shared/lib/useTranslation";
import { useRouter } from "next/navigation";
import {
Card,
CardBody,
Button,
} from "@nextui-org/react";
import { Package } from "lucide-react";
import { Navigation } from "@/shared/components/Navigation";
export const ProductNotFound: React.FC = () => {
const { t } = useTranslation();
const router = useRouter();
return (
<div className="min-h-screen bg-gradient-to-br from-background via-default-50 to-primary-50">
<Navigation />
<div className="flex items-center justify-center py-20">
<Card className="w-full max-w-sm mx-4 sm:mx-0 sm:w-96 shadow-2xl">
<CardBody className="text-center p-8">
<div className="w-16 h-16 mx-auto mb-4 bg-danger-100 rounded-full flex items-center justify-center">
<Package className="text-danger" size={32} />
</div>
<h1 className="text-2xl font-bold mb-4">
{t("Product Not Found")}
</h1>
<p className="text-default-600 mb-6">
{t(
"The product you're looking for doesn't exist or has been removed."
)}
</p>
<Button
onPress={() => router.push("/")}
color="primary"
size="lg"
>
{t("Back to Store")}
</Button>
</CardBody>
</Card>
</div>
</div>
);
};
@@ -0,0 +1,31 @@
"use client";
import React from "react";
import ReactMarkdown from "react-markdown";
import { useTranslation } from "@/shared/lib/useTranslation";
import { Card, CardBody } from "@nextui-org/react";
import { ServiceData } from "@/shared/types/marketplace";
interface ProductOverviewProps {
product: ServiceData;
}
export const ProductOverview: React.FC<ProductOverviewProps> = ({
product,
}) => {
const { t } = useTranslation();
return (
<Card shadow="none">
<CardBody className="space-y-4">
<div className="leading-relaxed prose prose-sm max-w-none">
{product.long_description ? (
<ReactMarkdown>{product.long_description}</ReactMarkdown>
) : (
<p>{t("No description available")}</p>
)}
</div>
</CardBody>
</Card>
);
};
@@ -0,0 +1,39 @@
"use client";
import React from "react";
import { useTranslation } from "@/shared/lib/useTranslation";
import { Button, Avatar, Chip, Card, CardBody } from "@nextui-org/react";
import { ServiceData } from "@/shared/types/marketplace";
interface ProductToolsProps {
product: ServiceData;
}
export const ProductTools: React.FC<ProductToolsProps> = ({ product }) => {
const { t } = useTranslation();
return (
<div className="space-y-4 px-3">
{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-primary">{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>
);
};
@@ -0,0 +1,62 @@
"use client";
import React, { useEffect, useState } from "react";
import { ServiceData } from "@/shared/types/marketplace";
import { Card, Chip } 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";
interface ServerConfigProps {
product: ServiceData;
}
export const ServerConfig: React.FC<ServerConfigProps> = ({ product }) => {
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.origin}/mcp/${product.slug_name}`);
}, [product.slug_name]);
return (
<div className="min-w-[400px] w-[40%] max-w-100 flex-shrink-0 mt-12">
<div className="mb-4 mt-1">
<FlipButton
className="w-full rounded-md"
text={t("Try for free")}
onPress={handleLogin}
/>
</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">
{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">
{`{
"mcpServers": {
"xpack-mcp-market": {
"type": "sse",
"autoApprove"":"all",
"url": "${url}?apikey=`}
<span className="text-success">{`{Your-${platformConfig?.name}-API-Key}`}</span>
{`"
}
}
}`}
</code>
</pre>
</div>
</Card>
</div>
);
};
@@ -0,0 +1,60 @@
"use client";
import React from "react";
import { Card, CardBody, CardFooter, Chip } from "@nextui-org/react";
import { ServiceData } from "@/shared/types/marketplace";
import { useTranslation } from "react-i18next";
import Link from "next/link";
import { ChargeType } from "@/shared/types/marketplace";
import { Price } from "./Price";
interface ServiceCardProps {
service: ServiceData;
}
export const ServiceCard: React.FC<ServiceCardProps> = ({ service }) => {
// generate different icon background color for different services
const { t } = useTranslation();
return (
<Link href={`/marketplace/${service.service_id}`}>
<Card
className="group w-full h-[180px] hover:border-primary-500 transition-all duration-300 border-1"
shadow="none"
radius="sm"
>
<CardBody>
{/* Header with icon and title */}
<div className="flex items-start gap-3 mb-3">
<h3 className="font-semibold text-gray-900 text-sm mb-1 truncate group-hover:text-primary">
{service.name}
</h3>
</div>
{/* Description */}
<p className="text-xs text-gray-600 mb-4 line-clamp-2 leading-relaxed">
{service.short_description || t("No description available")}
</p>
</CardBody>
{/* Footer with tools count */}
<CardFooter>
<div className="flex items-center justify-between w-full">
<Chip
size="sm"
variant="flat"
color="primary"
className="text-[10px] h-5"
>
{t("{{count}} Tools", { count: service.tools.length })}
</Chip>
<div className="flex flex-col gap-1">
<Price price={service.price} charge_type={service.charge_type || ChargeType.Free} />
</div>
</div>
</CardFooter>
</Card>
</Link>
);
};
@@ -0,0 +1,49 @@
"use client";
import React from "react";
import { Pagination } from "@nextui-org/react";
import { ServiceData } from "@/shared/types/marketplace";
import { ServiceCard } from "./ServiceCard";
interface ServiceListSectionProps {
services: ServiceData[];
currentPage: number;
total: number;
pageSize: number;
onPageChange: (page: number) => void;
}
export const ServiceListSection: React.FC<ServiceListSectionProps> = ({
services,
currentPage,
total,
pageSize,
onPageChange,
}) => {
const totalPages = Math.ceil(total / pageSize);
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">
{services.map((service) => (
<ServiceCard key={service.service_id} service={service} />
))}
</div>
{/* Pagination */}
{totalPages > 1 && (
<div className="flex justify-center">
<Pagination
total={totalPages}
page={currentPage}
onChange={onPageChange}
showControls
color="primary"
variant="light"
/>
</div>
)}
</div>
);
};
@@ -0,0 +1,179 @@
import { Modal, ModalContent, ModalBody, Button } from "@nextui-org/react";
import { useState, useRef, useEffect } from "react";
import { CheckIcon, XCircleIcon, ClockIcon } from "lucide-react";
import toast from "react-hot-toast";
import { useSWRConfig } from "swr";
import { useTranslation } from "react-i18next";
import { fetchAPI } from "@/shared/rpc/common-function";
interface ConfirmPurchaseModalProps {
isOpen: boolean;
onClose: () => void;
onConfirm: () => void;
paymentId: string;
}
export const ConfirmPurchaseModal = ({
isOpen,
onClose,
onConfirm,
paymentId,
}: ConfirmPurchaseModalProps) => {
const { t } = useTranslation();
const [countdown, setCountdown] = useState(300); // 5 minutes in seconds
const [isLoading, setIsLoading] = useState(false);
const intervalRef = useRef<NodeJS.Timeout>();
const checkIntervalRef = useRef<NodeJS.Timeout>();
const [paymentStatus, setPaymentStatus] = useState("pending");
const { mutate } = useSWRConfig();
const checkPaymentStatus = () => {
return new Promise(async (resolve) => {
try {
const response = await fetchAPI(
`/api/payment/order_status?payment_id=${paymentId}`,
{
method: "GET",
}
);
if (response.success && response.data.status === 1) {
setPaymentStatus("completed");
clearInterval(intervalRef.current);
clearInterval(checkIntervalRef.current);
mutate("/api/user/info"); // manually trigger user info refresh
resolve(true);
}
resolve(false);
} catch (error) {
console.error("Failed to check payment status:", error);
resolve(false);
}
});
};
const handleManualConfirm = async () => {
setIsLoading(true);
const isCompleted = await checkPaymentStatus();
if (!isCompleted) {
toast.error(
t(
"Payment not completed yet. Please complete the payment before proceeding."
)
);
}
setIsLoading(false);
};
useEffect(() => {
if (isOpen) {
// start countdown
intervalRef.current = setInterval(() => {
setCountdown((prev) => {
if (prev <= 1) {
clearInterval(intervalRef.current);
clearInterval(checkIntervalRef.current);
return 0;
}
return prev - 1;
});
}, 1000);
// Check payment status every 15 seconds
checkIntervalRef.current = setInterval(checkPaymentStatus, 15000);
return () => {
clearInterval(intervalRef.current);
clearInterval(checkIntervalRef.current);
};
}
}, [isOpen]);
const formatTime = (seconds: number) => {
const mins = Math.floor(seconds / 60);
const secs = seconds % 60;
return `${mins}:${secs.toString().padStart(2, "0")}`;
};
// Add status icon components
const StatusIcon = () => {
if (paymentStatus === "completed") {
return <CheckIcon className="w-16 h-16 text-green-500" />;
} else if (countdown <= 0) {
return <XCircleIcon className="w-16 h-16 text-red-500" />;
}
return (
<div className="animate-spin">
<ClockIcon className="w-16 h-16 text-yellow-500" />
</div>
);
};
return (
<Modal isOpen={isOpen} onClose={onClose} size="md" isDismissable={false}>
<ModalContent>
<ModalBody className="p-6">
<h3 className="text-lg font-semibold mb-4">
{t("Confirm Purchase")}
</h3>
<div className="flex flex-col items-center mb-6">
<StatusIcon />
{paymentStatus === "completed" ? (
<div className="mb-6 mt-4 text-center">
<p className="text-green-500 text-sm mb-2">
{t("Payment completed")}
</p>
</div>
) : countdown > 0 ? (
<div className="text-sm text-default-500 text-center mt-4">
{t("Waiting for payment, remaining time: ") +
formatTime(countdown)}
</div>
) : (
<div className="mb-6 mt-4 text-center">
<p className="text-red-500 text-sm mb-2">
{t("Payment timeout")}
</p>
<p className="text-xs text-default-500">
{t("Please restart the payment process")}
</p>
</div>
)}
</div>
<div className="flex justify-center gap-3">
{paymentStatus === "pending" ? (
<>
<Button variant="bordered" onPress={onClose}>
{countdown > 0 ? t("Cancel") : t("Close")}
</Button>
{countdown > 0 && (
<Button
color="primary"
onPress={handleManualConfirm}
isLoading={isLoading}
>
{t("Yes, I've Paid")}
</Button>
)}
</>
) : (
<Button
onPress={onConfirm}
>
{t("Start Now!!")}
</Button>
)}
</div>
{paymentStatus === "pending" && countdown > 0 && (
<p className="text-[10px] text-default-500 mb-4 whitespace-pre-line">
{t(
"After the transaction is completed, the status will be automatically refreshed. If there is no response for a long time, you can manually click the [Yes, I've Paid] button to refresh the status."
)}
</p>
)}
</ModalBody>
</ModalContent>
</Modal>
);
};
@@ -0,0 +1,136 @@
"use client";
import React, { useState, useEffect } from "react";
import {
Modal,
ModalContent,
ModalHeader,
ModalBody,
ModalFooter,
Button,
Input,
Alert,
} from "@nextui-org/react";
import { useTranslation } from "@/shared/lib/useTranslation";
interface DeleteConfirmModalProps {
isOpen: boolean;
onClose: () => void;
onConfirm: () => void | Promise<void>;
title?: string | React.ReactNode;
description?: string | React.ReactNode;
loading?: boolean;
requireNameConfirmation?: boolean;
confirmationName?: string;
confirmationPlaceholder?: string;
}
export const DeleteConfirmModal: React.FC<DeleteConfirmModalProps> = ({
isOpen,
onClose,
onConfirm,
title,
description,
loading = false,
requireNameConfirmation = false,
confirmationName = "",
confirmationPlaceholder,
}) => {
const { t } = useTranslation();
const [inputValue, setInputValue] = useState("");
const [isConfirmDisabled, setIsConfirmDisabled] = useState(false);
// Reset input when modal opens/closes
useEffect(() => {
if (isOpen) {
setInputValue("");
}
}, [isOpen]);
// Check if confirm button should be disabled
useEffect(() => {
if (requireNameConfirmation && confirmationName) {
setIsConfirmDisabled(inputValue.trim() !== confirmationName.trim());
} else {
setIsConfirmDisabled(false);
}
}, [inputValue, requireNameConfirmation, confirmationName]);
const handleConfirm = async () => {
if (isConfirmDisabled) return;
try {
await onConfirm();
} catch (error) {
console.error("Delete confirmation error:", error);
}
};
const defaultTitle = t("Confirm Delete");
const defaultDescription = t("Are you sure you want to delete this item? This action cannot be undone.");
return (
<Modal isOpen={isOpen} onClose={onClose} size="md">
<ModalContent>
{() => (
<>
<ModalHeader className="flex flex-col gap-1">
{title || defaultTitle}
</ModalHeader>
<ModalBody>
<div className="space-y-4">
{/* Description */}
<div className="text-default-600">
{description || defaultDescription}
</div>
{/* Warning message */}
<Alert title={t("This action cannot be undone.")} color="danger" />
{/* Name confirmation input */}
{requireNameConfirmation && confirmationName && (
<div className="space-y-2">
<p className="text-sm text-default-600">
{t('Please type "{{name}}" to confirm deletion:', {
name: confirmationName,
})}
</p>
<Input
value={inputValue}
onChange={(e) => setInputValue(e.target.value)}
placeholder={confirmationPlaceholder || confirmationName}
variant="bordered"
size="sm"
isDisabled={loading}
autoFocus
/>
</div>
)}
</div>
</ModalBody>
<ModalFooter>
<Button
color="default"
variant="light"
onPress={onClose}
isDisabled={loading}
>
{t("Cancel")}
</Button>
<Button
color="danger"
onPress={handleConfirm}
isLoading={loading}
isDisabled={isConfirmDisabled}
>
{t("Delete")}
</Button>
</ModalFooter>
</>
)}
</ModalContent>
</Modal >
);
};
export default DeleteConfirmModal;
@@ -0,0 +1,157 @@
import React, { useState } from "react";
import {
Modal,
ModalContent,
ModalHeader,
ModalBody,
ModalFooter,
Button,
Input,
} 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";
interface RechargeModalProps {
isOpen: boolean;
onClose: () => void;
}
export const RechargeModal: React.FC<RechargeModalProps> = ({
isOpen,
onClose,
}) => {
const { t } = useTranslation();
const [amount, setAmount] = useState<string>("");
const [error, setError] = useState<string>("");
const [paymentId, setPaymentId] = useState("");
const [isConfirmOpen, setIsConfirmOpen] = useState(false);
const handlePurchase = 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;
}
const response = await fetchAPI("/api/payment/create_payment_link", {
method: "POST",
body: {
amount: numAmount,
success_url: window.location.origin + "/pay_success",
} as unknown as BodyInit,
});
if (!response.success) {
toast.error(
t(`Purchase Error:{{error_msg}}`, {
error_msg: response.error_message,
}),
{
duration: 3000,
className: "max-w-fit",
}
);
return;
}
const purchaseWindow = window.open(
response.data.pay_url,
"PurchaseWindow",
"width=600,height=600"
);
setPaymentId(response.data.payment_id);
if (!purchaseWindow) {
alert("The purchase window was blocked by the browser.");
return;
}
setIsConfirmOpen(true);
};
const handleConfirmPurchase = async (confirmed: boolean = false) => {
if (confirmed) {
//auto refresh user info
onClose();
}
setIsConfirmOpen(false);
};
const handleAmountChange = (e: React.ChangeEvent<HTMLInputElement>) => {
const value = e.target.value;
// only allow input numbers and decimal points
if (/^\d*\.?\d*$/.test(value) || value === "") {
setAmount(value);
setError("");
}
};
const handleClose = () => {
setAmount("");
setError("");
onClose();
};
return (
<>
<Modal isOpen={isOpen} onClose={handleClose} size="sm">
<ModalContent>
{() => (
<>
<ModalHeader className="flex flex-col gap-1">
{t("Recharge Account")}
</ModalHeader>
<ModalBody>
<Input
autoFocus
label={t("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>
}
type="text"
variant="bordered"
isInvalid={!!error}
errorMessage={error}
onKeyDown={(e) => {
if (e.key === "Enter") {
handlePurchase();
}
}}
/>
<p className="text-xs text-default-500">
{t("Funds will be added to your account balance")}
</p>
</ModalBody>
<ModalFooter>
<Button variant="light" onPress={handleClose}>
{t("Cancel")}
</Button>
<Button color="primary" onPress={handlePurchase}>
{t("Confirm")}
</Button>
</ModalFooter>
</>
)}
</ModalContent>
</Modal>
{/**Confirm Purchase Modal */}
<ConfirmPurchaseModal
isOpen={isConfirmOpen}
onClose={() => setIsConfirmOpen(false)}
onConfirm={handleConfirmPurchase}
paymentId={paymentId}
/>
</>
);
};