29 files changed
+1391
-90
No files matched your search
@@ -937,5 +937,17 @@
|
||||
"Failed to load resource group detail": "获取资源组详情失败",
|
||||
"Resource Group Detail": "资源组详情",
|
||||
"Current display time is UTC time": "当前显示时间为UTC时间",
|
||||
"View Resource Group Detail": "查看资源组详情"
|
||||
"View Resource Group Detail": "查看资源组详情",
|
||||
"Configure tags bar display": "配置标签栏显示",
|
||||
"Failed to load orders": "加载订单失败",
|
||||
"Transaction Time": "交易时间",
|
||||
"All": "全部",
|
||||
"Purchase": "消费",
|
||||
"No orders found": "无订单",
|
||||
"Account Balance": "账户余额",
|
||||
"View your balance and transaction history": "查看您的余额和交易历史",
|
||||
"Display tags bar": "显示标签栏",
|
||||
"Front end displays tags bar and allows users to filter products based on tags.": "前端显示标签栏,允许用户根据标签过滤产品。",
|
||||
"Tags Bar": "标签栏",
|
||||
"Auth Key Name": "认证密钥名称"
|
||||
}
|
||||
@@ -34,6 +34,7 @@ import {
|
||||
Palette,
|
||||
SquareMenu,
|
||||
TableOfContents,
|
||||
Tags,
|
||||
Trello,
|
||||
XIcon,
|
||||
} from "lucide-react";
|
||||
@@ -161,6 +162,12 @@ const SystemSettingsModal: React.FC<SystemSettingsModalProps> = ({
|
||||
icon: <SquareMenu size={16} />,
|
||||
description: "Configure site navigation and menus",
|
||||
},
|
||||
{
|
||||
key: SettingModalTab.TAGS_BAR,
|
||||
label: "Tags Bar",
|
||||
icon: <Tags size={16} />,
|
||||
description: "Configure tags bar display",
|
||||
},
|
||||
{
|
||||
key: SettingModalTab.FAQ,
|
||||
label: "FAQ",
|
||||
@@ -240,6 +247,7 @@ const SystemSettingsModal: React.FC<SystemSettingsModalProps> = ({
|
||||
items: groupItems([
|
||||
SettingModalTab.THEME,
|
||||
SettingModalTab.NAVIGATION,
|
||||
SettingModalTab.TAGS_BAR,
|
||||
SettingModalTab.FAQ,
|
||||
]),
|
||||
},
|
||||
|
||||
@@ -31,6 +31,7 @@ import { AdminConfig, EmailConfig } from "@/types/system";
|
||||
import { LoginSettingsContent } from "./LoginSettingsContent";
|
||||
import { EmailConfigForm } from "@/components/system-setting/EmailConfigForm";
|
||||
import { LanguageSetting } from "@/components/system-setting/LanguageSetting";
|
||||
import { TagsBarSetting } from "../system-setting/TagsBarSetting";
|
||||
|
||||
interface SystemSettingsRightContentProps {
|
||||
filteredKeys: string[];
|
||||
@@ -201,6 +202,13 @@ const SystemSettingsRightContent: React.FC<SystemSettingsRightContentProps> = ({
|
||||
/>
|
||||
)}
|
||||
|
||||
{section.key === "tagsBar" && (
|
||||
<TagsBarSetting
|
||||
isEnabled={!!platformConfig.tag_bar_display}
|
||||
onSave={onSavePlatformConfig}
|
||||
/>
|
||||
)}
|
||||
|
||||
{section.key === "faq" && (
|
||||
<FaqSettings
|
||||
onSave={saveFaqConfig}
|
||||
|
||||
@@ -8,6 +8,7 @@ export enum SettingModalTab {
|
||||
CODE_INJECTION = "code-injection",
|
||||
XPACK_EXPLORE = "xpack-explore",
|
||||
NAVIGATION = "navigation",
|
||||
TAGS_BAR = "tagsBar",
|
||||
FAQ = "faq",
|
||||
CHANGE_PASSWORD = "change-password",
|
||||
EMAIL_LOGIN_SETTINGS = "email-login-settings",
|
||||
|
||||
@@ -0,0 +1,388 @@
|
||||
"use client";
|
||||
|
||||
import React, { useState, useCallback, useRef, useEffect } from "react";
|
||||
import {
|
||||
Table,
|
||||
TableHeader,
|
||||
TableColumn,
|
||||
TableBody,
|
||||
TableRow,
|
||||
TableCell,
|
||||
Button,
|
||||
Pagination,
|
||||
Tooltip,
|
||||
Spinner,
|
||||
Chip,
|
||||
Dropdown,
|
||||
DropdownTrigger,
|
||||
DropdownMenu,
|
||||
DropdownItem,
|
||||
} from "@nextui-org/react";
|
||||
import { useTranslation } from "@/shared/lib/useTranslation";
|
||||
import { Calendar, HelpCircle, Filter } from "lucide-react";
|
||||
import { fetchAPI } from "@/shared/rpc/common-function";
|
||||
import i18n from "@/shared/lib/i18n";
|
||||
import { toast } from "react-hot-toast";
|
||||
import { fetchAdminAPI } from "@/rpc/admin-api";
|
||||
|
||||
export interface OrderItem {
|
||||
id: string;
|
||||
amount: string;
|
||||
balance: string;
|
||||
order_id: string;
|
||||
// 支付类型,stripe默认值
|
||||
payment_type: string;
|
||||
// 支付状态,0=未支付,1=已支付,2=支付失败
|
||||
payment_state: number;
|
||||
description: string;
|
||||
// 充值时间
|
||||
create_at: string;
|
||||
// 交易时间,确认订单时间,只有充值完成后才有
|
||||
confirm_at: string;
|
||||
// 订单类型,充值(recharge),消费(purchase),退款(refund),冲正(reversal)
|
||||
order_type: string;
|
||||
}
|
||||
|
||||
interface AccountBalanceTableProps {
|
||||
userId?: string;
|
||||
source?: "client" | "admin";
|
||||
}
|
||||
|
||||
const AccountBalanceTable: React.FC<AccountBalanceTableProps> = ({ userId, source }) => {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const [items, setItems] = useState<OrderItem[]>([]);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [pagination, setPagination] = useState({
|
||||
page: 1,
|
||||
pageSize: 10,
|
||||
total: 0,
|
||||
});
|
||||
const [selectedType, setSelectedType] = useState<string>("all");
|
||||
const [selectedStatus, setSelectedStatus] = useState<string>("all");
|
||||
const resourceGroupsParams = useRef({
|
||||
page: 1,
|
||||
pageSize: 10,
|
||||
keyword: "",
|
||||
orderType: "",
|
||||
status: "",
|
||||
});
|
||||
|
||||
const pages = Math.ceil(pagination.total / pagination.pageSize);
|
||||
const currentPage = Number(pagination.page);
|
||||
|
||||
const fetchOrders = useCallback(
|
||||
async (
|
||||
page: number,
|
||||
page_size: number,
|
||||
order_type?: string,
|
||||
status?: string
|
||||
): Promise<{ data: OrderItem[]; total: number; page: number; page_size: number }> => {
|
||||
try {
|
||||
const params = new URLSearchParams({
|
||||
page: page.toString(),
|
||||
page_size: page_size.toString(),
|
||||
});
|
||||
if (order_type) params.append("order_type", order_type);
|
||||
if (status) params.append("status", status);
|
||||
if (userId) params.append("user_id", userId);
|
||||
|
||||
// 根据是否有 userId 来决定使用哪个 API
|
||||
const apiUrl = userId
|
||||
? `/api/order/list/by_user?${params.toString()}`
|
||||
: `/api/user/order/list?${params.toString()}`;
|
||||
|
||||
const response = source === "client" ? await fetchAPI<OrderItem[]>(apiUrl) : await fetchAdminAPI<OrderItem[]>(apiUrl);
|
||||
if (!response.success) {
|
||||
toast.error(response.error_message || i18n.t("Failed to load orders"));
|
||||
return {
|
||||
data: [],
|
||||
total: 0,
|
||||
page,
|
||||
page_size,
|
||||
};
|
||||
}
|
||||
return {
|
||||
data: response.data || [],
|
||||
total: response.page?.total || 0,
|
||||
page: response.page?.page || page,
|
||||
page_size: response.page?.page_size || page_size,
|
||||
};
|
||||
} catch (error) {
|
||||
console.error("Error fetching orders:", error);
|
||||
return {
|
||||
data: [],
|
||||
total: 0,
|
||||
page,
|
||||
page_size,
|
||||
};
|
||||
}
|
||||
},
|
||||
[userId]
|
||||
);
|
||||
|
||||
const loadOrders = useCallback(
|
||||
async (
|
||||
page: number = 1,
|
||||
pageSize: number = 10,
|
||||
keyword: string = "",
|
||||
orderType: string = "",
|
||||
status: string = ""
|
||||
) => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const response = await fetchOrders(
|
||||
page,
|
||||
pageSize,
|
||||
orderType || undefined,
|
||||
status || undefined
|
||||
);
|
||||
setItems(response.data);
|
||||
setPagination({
|
||||
page: response.page,
|
||||
pageSize: response.page_size,
|
||||
total: response.total,
|
||||
});
|
||||
resourceGroupsParams.current = {
|
||||
page: response.page,
|
||||
pageSize: response.page_size,
|
||||
keyword,
|
||||
orderType,
|
||||
status,
|
||||
};
|
||||
} catch (error) {
|
||||
console.error(t("Failed to load orders"), error);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
},
|
||||
[fetchOrders]
|
||||
);
|
||||
|
||||
const formatDate = (dateString: string) => {
|
||||
return (
|
||||
<div className="flex items-center gap-1">
|
||||
<Calendar className="w-3 h-3 text-gray-500" />
|
||||
<span className="text-sm text-gray-600">
|
||||
{new Date(dateString).toLocaleString()}
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
// 格式化金额,带正负号和美元符号
|
||||
const formatAmount = (amount: string | number): string => {
|
||||
const numAmount = typeof amount === 'string' ? parseFloat(amount) : amount;
|
||||
if (isNaN(numAmount)) return '$0.00';
|
||||
const absAmount = Math.abs(numAmount).toFixed(2);
|
||||
if (numAmount > 0) {
|
||||
return `+$${absAmount}`;
|
||||
} else if (numAmount < 0) {
|
||||
return `-$${absAmount}`;
|
||||
}
|
||||
return `$${absAmount}`;
|
||||
};
|
||||
|
||||
// 格式化余额,只显示美元符号,不带正负号
|
||||
const formatBalance = (balance: string | number): string => {
|
||||
const numBalance = typeof balance === 'string' ? parseFloat(balance) : balance;
|
||||
if (isNaN(numBalance)) return '$0.00';
|
||||
|
||||
return `$${Math.abs(numBalance).toFixed(2)}`;
|
||||
};
|
||||
|
||||
const getStatusColor = (status: number) => {
|
||||
switch (status) {
|
||||
case 1:
|
||||
return "success";
|
||||
case 2:
|
||||
return "danger";
|
||||
default:
|
||||
return "warning";
|
||||
}
|
||||
};
|
||||
|
||||
const onPageChange = (page: number) => {
|
||||
const { pageSize, orderType, status } = resourceGroupsParams.current;
|
||||
loadOrders(page, pageSize, "", orderType, status);
|
||||
};
|
||||
|
||||
const handleTypeChange = (value: string) => {
|
||||
setSelectedType(value);
|
||||
const orderType = value === "all" ? "" : value;
|
||||
const { status } = resourceGroupsParams.current;
|
||||
loadOrders(1, pagination.pageSize, "", orderType, status);
|
||||
};
|
||||
|
||||
const handleStatusChange = (value: string) => {
|
||||
setSelectedStatus(value);
|
||||
const status = value === "all" ? "" : value;
|
||||
const { orderType } = resourceGroupsParams.current;
|
||||
loadOrders(1, pagination.pageSize, "", orderType, status);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
loadOrders(1, 10, "");
|
||||
}, [loadOrders]);
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<Table
|
||||
aria-label="Orders table"
|
||||
classNames={{
|
||||
wrapper: "min-h-[400px]",
|
||||
}}
|
||||
removeWrapper
|
||||
>
|
||||
<TableHeader>
|
||||
<TableColumn>
|
||||
<div className="flex items-center gap-1">
|
||||
<span>{t("Transaction Time")}</span>
|
||||
</div>
|
||||
</TableColumn>
|
||||
<TableColumn>
|
||||
<div className="flex items-center gap-2">
|
||||
<span>{t("Type")}</span>
|
||||
<Dropdown>
|
||||
<DropdownTrigger>
|
||||
<Button
|
||||
isIconOnly
|
||||
size="sm"
|
||||
variant="light"
|
||||
aria-label="Filter by type"
|
||||
>
|
||||
<Filter
|
||||
className={`w-4 h-4 ${
|
||||
selectedType !== "all" ? "text-primary" : ""
|
||||
}`}
|
||||
/>
|
||||
</Button>
|
||||
</DropdownTrigger>
|
||||
<DropdownMenu
|
||||
aria-label="Type filter"
|
||||
selectionMode="single"
|
||||
selectedKeys={[selectedType]}
|
||||
onSelectionChange={(keys) => {
|
||||
const selected = Array.from(keys)[0] as string;
|
||||
handleTypeChange(selected);
|
||||
}}
|
||||
>
|
||||
<DropdownItem key="all">{t("All")}</DropdownItem>
|
||||
<DropdownItem key="recharge">{t("Recharge")}</DropdownItem>
|
||||
<DropdownItem key="purchase">{t("Purchase")}</DropdownItem>
|
||||
</DropdownMenu>
|
||||
</Dropdown>
|
||||
</div>
|
||||
</TableColumn>
|
||||
<TableColumn>{t("Description")}</TableColumn>
|
||||
<TableColumn>{t("Amount")}</TableColumn>
|
||||
<TableColumn>{t("Balance")}</TableColumn>
|
||||
<TableColumn>
|
||||
<div className="flex items-center gap-2">
|
||||
<span>{t("Status")}</span>
|
||||
<Dropdown>
|
||||
<DropdownTrigger>
|
||||
<Button
|
||||
isIconOnly
|
||||
size="sm"
|
||||
variant="light"
|
||||
aria-label="Filter by status"
|
||||
>
|
||||
<Filter
|
||||
className={`w-4 h-4 ${
|
||||
selectedStatus !== "all" ? "text-primary" : ""
|
||||
}`}
|
||||
/>
|
||||
</Button>
|
||||
</DropdownTrigger>
|
||||
<DropdownMenu
|
||||
aria-label="Status filter"
|
||||
selectionMode="single"
|
||||
selectedKeys={[selectedStatus]}
|
||||
onSelectionChange={(keys) => {
|
||||
const selected = Array.from(keys)[0] as string;
|
||||
handleStatusChange(selected);
|
||||
}}
|
||||
>
|
||||
<DropdownItem key="all">{t("All")}</DropdownItem>
|
||||
<DropdownItem key="0">{t("Pending")}</DropdownItem>
|
||||
<DropdownItem key="1">{t("Completed")}</DropdownItem>
|
||||
<DropdownItem key="2">{t("Failed")}</DropdownItem>
|
||||
</DropdownMenu>
|
||||
</Dropdown>
|
||||
</div>
|
||||
</TableColumn>
|
||||
</TableHeader>
|
||||
<TableBody
|
||||
items={items}
|
||||
isLoading={loading}
|
||||
loadingContent={<Spinner />}
|
||||
emptyContent={t("No orders found")}
|
||||
>
|
||||
{(order) => (
|
||||
<TableRow key={order.id}>
|
||||
<TableCell>{formatDate(order.payment_state === 0 ? order.create_at : order.confirm_at)}</TableCell>
|
||||
<TableCell>
|
||||
<span
|
||||
className={
|
||||
order.order_type === "recharge"
|
||||
? "text-green-500"
|
||||
: "text-red-500"
|
||||
}
|
||||
>
|
||||
{
|
||||
order.order_type === "recharge" ? t("Recharge") : t("Purchase")
|
||||
}
|
||||
</span>
|
||||
</TableCell>
|
||||
<TableCell>{order.description}</TableCell>
|
||||
<TableCell>
|
||||
<span
|
||||
className={
|
||||
order.order_type === "recharge"
|
||||
? "text-green-500"
|
||||
: "text-red-500"
|
||||
}
|
||||
>
|
||||
{formatAmount(order.amount)}
|
||||
</span>
|
||||
</TableCell>
|
||||
<TableCell>{formatBalance(order.balance)}</TableCell>
|
||||
<TableCell>
|
||||
<Chip
|
||||
className="capitalize"
|
||||
color={getStatusColor(order.payment_state)}
|
||||
size="sm"
|
||||
variant="flat"
|
||||
>
|
||||
{t(
|
||||
order.payment_state === 1
|
||||
? "Completed"
|
||||
: order.payment_state === 2
|
||||
? "Failed"
|
||||
: "Pending"
|
||||
)}
|
||||
</Chip>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
)}
|
||||
</TableBody>
|
||||
</Table>
|
||||
|
||||
{pages > 1 && (
|
||||
<div className="flex w-full justify-center">
|
||||
<Pagination
|
||||
showControls
|
||||
color="primary"
|
||||
variant="light"
|
||||
page={currentPage}
|
||||
total={pages}
|
||||
onChange={onPageChange}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default AccountBalanceTable;
|
||||
@@ -53,6 +53,10 @@ const OverviewPage: React.FC = () => {
|
||||
|
||||
useEffect(() => {
|
||||
fetchApiKeys();
|
||||
if (sessionStorage.getItem('create_new_authorization')) {
|
||||
handleNewKey();
|
||||
sessionStorage.removeItem('create_new_authorization');
|
||||
}
|
||||
}, []);
|
||||
|
||||
// create new auth key
|
||||
|
||||
@@ -11,8 +11,9 @@ import { formatCurrency } from "@/shared/utils/currency";
|
||||
// Import dashboard content components
|
||||
import DashboardOverview from "@/components/dashboard/DashboardOverview";
|
||||
import WalletManagement from "@/components/wallet/WalletManagement";
|
||||
import UserAccountBalance from "@/components/dashboard/UserAccountBalance";
|
||||
import { Home, Key, Wallet } from "lucide-react";
|
||||
import { Avatar, Card, CardBody, Button, Divider } from "@nextui-org/react";
|
||||
import { Avatar, Card, CardBody, Button, Divider, Link } from "@nextui-org/react";
|
||||
import { RechargeModal } from "@/shared/components/modal/RechargeModal";
|
||||
import { useTranslation } from "@/shared/lib/useTranslation";
|
||||
import { ChangePasswordModal } from "@/components/common/ChangePasswordModal";
|
||||
@@ -41,7 +42,7 @@ const DashboardContent: React.FC = () => {
|
||||
const [isRechargeModalOpen, setIsRechargeModalOpen] = useState(false);
|
||||
const getInitialTab = (): TabKey => {
|
||||
const tabFromUrl = searchParams.get("tab") as TabKey;
|
||||
if (tabFromUrl && [TabKey.OVERVIEW, TabKey.WALLET].includes(tabFromUrl)) {
|
||||
if (tabFromUrl && [TabKey.OVERVIEW, TabKey.WALLET, TabKey.USER_ACCOUNT].includes(tabFromUrl)) {
|
||||
return tabFromUrl;
|
||||
}
|
||||
return TabKey.OVERVIEW;
|
||||
@@ -158,8 +159,15 @@ const DashboardContent: React.FC = () => {
|
||||
<Wallet size={16} />
|
||||
<span>
|
||||
{t("Balance: {{amount}}", {
|
||||
amount: formatCurrency(user?.wallet?.balance || 0),
|
||||
})}
|
||||
amount: "",
|
||||
}).replace("{{amount}}", "")}
|
||||
<Link
|
||||
href="#"
|
||||
className="text-xs cursor-pointer"
|
||||
onPress={() => handleTabNavigate(TabKey.USER_ACCOUNT)}
|
||||
>
|
||||
{formatCurrency(user?.wallet?.balance || 0)}
|
||||
</Link>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
@@ -187,6 +195,7 @@ const DashboardContent: React.FC = () => {
|
||||
{activeTab === TabKey.WALLET && (
|
||||
<WalletManagement onRecharge={() => setIsRechargeModalOpen(true)} />
|
||||
)}
|
||||
{activeTab === TabKey.USER_ACCOUNT && <UserAccountBalance />}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
"use client";
|
||||
|
||||
import React from "react";
|
||||
import { useTranslation } from "@/shared/lib/useTranslation";
|
||||
import DashboardDemoContent from "@/shared/components/DashboardDemoContent";
|
||||
import AccountBalanceTable from "./AccountBalanceTable";
|
||||
|
||||
const UserAccountBalance: React.FC = () => {
|
||||
const { t } = useTranslation();
|
||||
|
||||
return (
|
||||
<DashboardDemoContent
|
||||
title={t("Account Balance")}
|
||||
description={t("View your balance and transaction history")}
|
||||
>
|
||||
<div className="space-y-6 w-full">
|
||||
<AccountBalanceTable source="client" />
|
||||
</div>
|
||||
</DashboardDemoContent>
|
||||
);
|
||||
};
|
||||
|
||||
export default UserAccountBalance;
|
||||
@@ -4,12 +4,19 @@ import React, { useState, useEffect } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { HeroSection } from "../../shared/components/marketplace/HeroSection";
|
||||
import { ServiceListSection } from "@/shared/components/marketplace/ServiceListSection";
|
||||
import { TagFilter } from "@/shared/components/marketplace/TagFilter";
|
||||
import { ServiceData } from "@/shared/types/marketplace";
|
||||
import { fetchServices } from "@/services/marketplaceService";
|
||||
import { Spinner } from "@nextui-org/react";
|
||||
import { ThemeType } from "@/shared/types/system";
|
||||
|
||||
interface MarketplaceMainProps {
|
||||
initialServices: ServiceData[];
|
||||
availableTags: string[];
|
||||
isTagBarDisplay: boolean;
|
||||
selectedTag: string;
|
||||
setSelectedTag: (tag: string) => void;
|
||||
currentTheme: ThemeType;
|
||||
initialTotal: number;
|
||||
initialPage: number;
|
||||
initialSearch: string;
|
||||
@@ -19,6 +26,11 @@ interface MarketplaceMainProps {
|
||||
|
||||
export const MarketplaceMain: React.FC<MarketplaceMainProps> = ({
|
||||
initialServices,
|
||||
availableTags,
|
||||
isTagBarDisplay,
|
||||
selectedTag,
|
||||
setSelectedTag,
|
||||
currentTheme,
|
||||
initialTotal,
|
||||
initialPage,
|
||||
initialSearch,
|
||||
@@ -33,16 +45,18 @@ export const MarketplaceMain: React.FC<MarketplaceMainProps> = ({
|
||||
const [total, setTotal] = useState(initialTotal);
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
|
||||
// load services data
|
||||
const loadServices = async (page: number, search: string) => {
|
||||
const loadServices = async (page: number, search: string, tag: string = "ALL") => {
|
||||
try {
|
||||
setLoading(true);
|
||||
const result = await fetchServices({
|
||||
page,
|
||||
page_size: pageSize,
|
||||
keyword: search,
|
||||
// 如果需要,可以在这里添加tag参数传递给API
|
||||
tag: tag !== "ALL" ? tag : undefined,
|
||||
});
|
||||
|
||||
setServices(result.data.services);
|
||||
setTotal(result.page.total);
|
||||
setCurrentPage(page);
|
||||
@@ -79,13 +93,20 @@ export const MarketplaceMain: React.FC<MarketplaceMainProps> = ({
|
||||
// when page number changes, reload
|
||||
const handlePageChange = (page: number) => {
|
||||
updateURL(page, searchQuery);
|
||||
loadServices(page, searchQuery);
|
||||
loadServices(page, searchQuery, selectedTag);
|
||||
};
|
||||
|
||||
// handle search submit
|
||||
const handleSearch = () => {
|
||||
updateURL(1, searchQuery);
|
||||
loadServices(1, searchQuery);
|
||||
loadServices(1, searchQuery, selectedTag);
|
||||
};
|
||||
|
||||
// handle tag change
|
||||
const handleTagChange = (tag: string) => {
|
||||
setSelectedTag(tag);
|
||||
setCurrentPage(1);
|
||||
loadServices(1, searchQuery, tag);
|
||||
};
|
||||
|
||||
// if there is an error, show error message
|
||||
@@ -102,9 +123,25 @@ export const MarketplaceMain: React.FC<MarketplaceMainProps> = ({
|
||||
{/* Hero Section */}
|
||||
<HeroSection
|
||||
searchQuery={searchQuery}
|
||||
isTagBarDisplay={isTagBarDisplay}
|
||||
onSearchChange={setSearchQuery}
|
||||
onSearch={handleSearch}
|
||||
/>
|
||||
|
||||
{/* filter section */}
|
||||
{
|
||||
isTagBarDisplay && (
|
||||
<>
|
||||
<TagFilter
|
||||
theme={currentTheme}
|
||||
tags={availableTags}
|
||||
selectedTag={selectedTag}
|
||||
onTagChange={handleTagChange}
|
||||
maxWidthPercent={80}
|
||||
/>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
{/* Server List Section */}
|
||||
{loading ? (
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
"use client";
|
||||
|
||||
import React from "react";
|
||||
import { Switch } from "@nextui-org/react";
|
||||
import { useTranslation } from "@/shared/lib/useTranslation";
|
||||
|
||||
export type TagsBarSettingConfig = {
|
||||
tag_bar_display: boolean;
|
||||
};
|
||||
|
||||
interface TagsBarSettingProps {
|
||||
isEnabled: boolean;
|
||||
onSave: (config: TagsBarSettingConfig) => void;
|
||||
}
|
||||
|
||||
export const TagsBarSetting: React.FC<TagsBarSettingProps> = ({
|
||||
isEnabled,
|
||||
onSave,
|
||||
}) => {
|
||||
const { t } = useTranslation();
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<div className="flex flex-col gap-4">
|
||||
{/* 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("Display tags bar")}
|
||||
</span>
|
||||
<span className="text-xs text-gray-500">
|
||||
{t(
|
||||
"Front end displays tags bar and allows users to filter products based on tags."
|
||||
)}
|
||||
</span>
|
||||
</div>
|
||||
<Switch
|
||||
isSelected={isEnabled}
|
||||
onValueChange={(value) => {
|
||||
onSave({
|
||||
tag_bar_display: value
|
||||
});
|
||||
}}
|
||||
color="primary"
|
||||
size="sm"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -9,7 +9,7 @@ import { Home as ClassicHome } from "./classic/Home";
|
||||
import { Home as CreativeHome } from "./creative/Home";
|
||||
import { Home as TemuHome } from "./temu/Home";
|
||||
import { ServiceData } from "@/shared/types/marketplace";
|
||||
import { fetchServices } from "@/services/marketplaceService";
|
||||
import { fetchServices, fetchTagsList } from "@/services/marketplaceService";
|
||||
import { Navigation } from "@/shared/components/Navigation";
|
||||
import { MarketplaceMain } from "../marketplace/Main";
|
||||
import { Footer } from "@/shared/components/Footer";
|
||||
@@ -53,18 +53,36 @@ export const ThemeSelector: React.FC<ThemeSelectorProps> = ({
|
||||
const [currentPage, setCurrentPage] = useState(initialPage);
|
||||
const [total, setTotal] = useState(initialTotal);
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
const isTagBarDisplay = platformConfig.tag_bar_display || false;
|
||||
// 可用的标签列表(这里可以从API获取或配置)
|
||||
const [availableTags, setAvailableTags] = useState<string[]>([]);
|
||||
const [selectedTag, setSelectedTag] = useState("ALL");
|
||||
// search suggestion
|
||||
const searchSuggestions = ["Search MCP servers"];
|
||||
|
||||
useEffect(() => {
|
||||
const loadTagsList = async () => {
|
||||
const tags = await fetchTagsList();
|
||||
setAvailableTags(tags);
|
||||
};
|
||||
loadTagsList();
|
||||
}, []);
|
||||
|
||||
// handle tag change
|
||||
const handleTagChange = (tag: string) => {
|
||||
setSelectedTag(tag);
|
||||
setCurrentPage(1);
|
||||
loadServices(1, searchQuery, tag);
|
||||
};
|
||||
// loading service data
|
||||
const loadServices = async (page: number, search: string) => {
|
||||
const loadServices = async (page: number, search: string, tag: string = "ALL") => {
|
||||
try {
|
||||
setLoading(true);
|
||||
const result = await fetchServices({
|
||||
page,
|
||||
page_size: pageSize,
|
||||
keyword: search,
|
||||
tag: tag !== "ALL" ? tag : undefined,
|
||||
});
|
||||
|
||||
setServices(result.data.services);
|
||||
@@ -103,13 +121,13 @@ export const ThemeSelector: React.FC<ThemeSelectorProps> = ({
|
||||
// page change handler
|
||||
const handlePageChange = (page: number) => {
|
||||
updateURL(page, searchQuery);
|
||||
loadServices(page, searchQuery);
|
||||
loadServices(page, searchQuery, selectedTag);
|
||||
};
|
||||
|
||||
// search submit handler
|
||||
const handleSearch = () => {
|
||||
updateURL(1, searchQuery);
|
||||
loadServices(1, searchQuery);
|
||||
loadServices(1, searchQuery, selectedTag);
|
||||
};
|
||||
|
||||
// search input change handler
|
||||
@@ -122,6 +140,11 @@ export const ThemeSelector: React.FC<ThemeSelectorProps> = ({
|
||||
case Theme.MODERN:
|
||||
return (
|
||||
<ModernHome
|
||||
currentTheme={currentTheme}
|
||||
selectedTag={selectedTag}
|
||||
handleTagChange={handleTagChange}
|
||||
isTagBarDisplay={isTagBarDisplay}
|
||||
availableTags={availableTags}
|
||||
searchQuery={searchQuery}
|
||||
services={services}
|
||||
currentPage={currentPage}
|
||||
@@ -139,6 +162,11 @@ export const ThemeSelector: React.FC<ThemeSelectorProps> = ({
|
||||
case Theme.CLASSIC:
|
||||
return (
|
||||
<ClassicHome
|
||||
currentTheme={currentTheme}
|
||||
selectedTag={selectedTag}
|
||||
handleTagChange={handleTagChange}
|
||||
isTagBarDisplay={isTagBarDisplay}
|
||||
availableTags={availableTags}
|
||||
searchQuery={searchQuery}
|
||||
services={services}
|
||||
currentPage={currentPage}
|
||||
@@ -156,6 +184,11 @@ export const ThemeSelector: React.FC<ThemeSelectorProps> = ({
|
||||
case Theme.CREATIVE:
|
||||
return (
|
||||
<CreativeHome
|
||||
currentTheme={currentTheme}
|
||||
selectedTag={selectedTag}
|
||||
handleTagChange={handleTagChange}
|
||||
isTagBarDisplay={isTagBarDisplay}
|
||||
availableTags={availableTags}
|
||||
searchQuery={searchQuery}
|
||||
services={services}
|
||||
currentPage={currentPage}
|
||||
@@ -173,6 +206,11 @@ export const ThemeSelector: React.FC<ThemeSelectorProps> = ({
|
||||
case Theme.TEMU:
|
||||
return (
|
||||
<TemuHome
|
||||
currentTheme={currentTheme}
|
||||
selectedTag={selectedTag}
|
||||
handleTagChange={handleTagChange}
|
||||
isTagBarDisplay={isTagBarDisplay}
|
||||
availableTags={availableTags}
|
||||
searchQuery={searchQuery}
|
||||
services={services}
|
||||
currentPage={currentPage}
|
||||
@@ -194,6 +232,11 @@ export const ThemeSelector: React.FC<ThemeSelectorProps> = ({
|
||||
<Navigation items={navigationItems} />
|
||||
<main className="flex-1">
|
||||
<MarketplaceMain
|
||||
currentTheme={currentTheme}
|
||||
selectedTag={selectedTag}
|
||||
setSelectedTag={setSelectedTag}
|
||||
isTagBarDisplay={isTagBarDisplay}
|
||||
availableTags={availableTags}
|
||||
initialServices={services}
|
||||
initialTotal={total}
|
||||
initialPage={currentPage}
|
||||
|
||||
@@ -24,11 +24,18 @@ import { Footer } from "./Footer";
|
||||
import { Navigation } from "./Navigation";
|
||||
import { NavigationItem } from "@/shared/components/Navigation";
|
||||
import { Faq } from "@/components/marketplace/Faq";
|
||||
import { TagFilter } from "@/shared/components/marketplace/TagFilter";
|
||||
import { ThemeType } from "@/shared/types/system";
|
||||
|
||||
interface HomeProps {
|
||||
// 状态
|
||||
searchQuery: string;
|
||||
services: ServiceData[];
|
||||
isTagBarDisplay: boolean;
|
||||
availableTags: string[];
|
||||
selectedTag: string;
|
||||
handleTagChange: (tag: string) => void;
|
||||
currentTheme: ThemeType;
|
||||
currentPage: number;
|
||||
total: number;
|
||||
pageSize: number;
|
||||
@@ -50,6 +57,11 @@ interface HomeProps {
|
||||
export const Home: React.FC<HomeProps> = ({
|
||||
searchQuery,
|
||||
services,
|
||||
isTagBarDisplay,
|
||||
availableTags,
|
||||
selectedTag,
|
||||
handleTagChange,
|
||||
currentTheme,
|
||||
currentPage,
|
||||
total,
|
||||
pageSize,
|
||||
@@ -83,9 +95,9 @@ export const Home: React.FC<HomeProps> = ({
|
||||
<h1 className="text-4xl lg:text-5xl font-bold mb-6 text-slate-800">
|
||||
{t(
|
||||
platformConfig.headline ||
|
||||
platformConfig.name ||
|
||||
_DefaultPlatformConfig.headline ||
|
||||
""
|
||||
platformConfig.name ||
|
||||
_DefaultPlatformConfig.headline ||
|
||||
""
|
||||
)}
|
||||
</h1>
|
||||
|
||||
@@ -93,8 +105,8 @@ export const Home: React.FC<HomeProps> = ({
|
||||
<p className="text-xl text-gray-600 max-w-3xl mx-auto leading-relaxed">
|
||||
{t(
|
||||
platformConfig.subheadline ||
|
||||
_DefaultPlatformConfig.subheadline ||
|
||||
""
|
||||
_DefaultPlatformConfig.subheadline ||
|
||||
""
|
||||
)}
|
||||
</p>
|
||||
</div>
|
||||
@@ -140,6 +152,21 @@ export const Home: React.FC<HomeProps> = ({
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* filter section */}
|
||||
{
|
||||
isTagBarDisplay && (
|
||||
<div className="pt-10">
|
||||
<TagFilter
|
||||
theme={currentTheme}
|
||||
tags={availableTags}
|
||||
selectedTag={selectedTag}
|
||||
onTagChange={handleTagChange}
|
||||
maxWidthPercent={80}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
{/* Server List Section */}
|
||||
{loading ? (
|
||||
<div className="mx-auto h-[200px] flex items-center justify-center">
|
||||
@@ -148,7 +175,7 @@ export const Home: React.FC<HomeProps> = ({
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<div className="bg-gray-50 py-16">
|
||||
<div className={`bg-gray-50 ${isTagBarDisplay ? 'py-10' : 'py-16'}`}>
|
||||
<div className="mx-auto px-6 max-w-7xl">
|
||||
{/* Server Grid */}
|
||||
<div className="flex flex-wrap justify-center gap-4 mb-12">
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import React from "react";
|
||||
import React, { useState, useEffect } from "react";
|
||||
import { Button } from "@nextui-org/react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
@@ -8,6 +8,7 @@ import { DynamicLogo } from "@/shared/components/DynamicLogo";
|
||||
import { useAuth } from "@/shared/lib/useAuth";
|
||||
import { NavigationItem } from "@/shared/components/Navigation";
|
||||
import Link from "next/link";
|
||||
import { useSharedStore } from "@/shared/store/share";
|
||||
|
||||
interface NavigationProps {
|
||||
items?: NavigationItem[];
|
||||
@@ -17,6 +18,13 @@ export const Navigation: React.FC<NavigationProps> = ({ items }) => {
|
||||
const { t } = useTranslation();
|
||||
const { handleLogin } = useAuth();
|
||||
|
||||
const [userToken, setUserToken] = useState<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
const userToken = useSharedStore?.getState?.().user_token
|
||||
setUserToken(userToken);
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div className="fixed top-0 left-0 right-0 z-50">
|
||||
{/* Classic Header */}
|
||||
@@ -26,21 +34,27 @@ export const Navigation: React.FC<NavigationProps> = ({ items }) => {
|
||||
<DynamicLogo alt="Platform Logo" className="h-[32px] text-white" />
|
||||
</div>
|
||||
<div className="flex space-x-2">
|
||||
<Button
|
||||
onPress={handleLogin}
|
||||
variant="light"
|
||||
className="hidden sm:block text-white text-sm px-4 py-1 rounded-sm font-medium"
|
||||
size="sm"
|
||||
>
|
||||
<b className="text-md"> {t("Sign In")}</b>
|
||||
</Button>
|
||||
{
|
||||
!userToken && (
|
||||
<>
|
||||
<Button
|
||||
onPress={handleLogin}
|
||||
variant="light"
|
||||
className="hidden sm:block text-white text-sm px-4 py-1 rounded-sm font-medium"
|
||||
size="sm"
|
||||
>
|
||||
<b className="text-md"> {t("Sign In")}</b>
|
||||
</Button>
|
||||
</>
|
||||
)
|
||||
}
|
||||
<Button
|
||||
color="primary"
|
||||
className="bg-red-600 hover:bg-red-700 text-white text-sm px-4 py-1 rounded-sm font-medium"
|
||||
size="sm"
|
||||
onPress={handleLogin}
|
||||
>
|
||||
{t("Get Started")}
|
||||
{userToken ? t("Dashboard") : t("Get Started")}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -24,11 +24,18 @@ import { Footer } from "./Footer";
|
||||
import { Navigation } from "./Navigation";
|
||||
import { NavigationItem } from "@/shared/components/Navigation";
|
||||
import { Faq } from "@/components/marketplace/Faq";
|
||||
import { TagFilter } from "@/shared/components/marketplace/TagFilter";
|
||||
import { ThemeType } from "@/shared/types/system";
|
||||
|
||||
interface HomeProps {
|
||||
// 状态
|
||||
searchQuery: string;
|
||||
services: ServiceData[];
|
||||
isTagBarDisplay: boolean;
|
||||
availableTags: string[];
|
||||
selectedTag: string;
|
||||
handleTagChange: (tag: string) => void;
|
||||
currentTheme: ThemeType;
|
||||
currentPage: number;
|
||||
total: number;
|
||||
pageSize: number;
|
||||
@@ -50,6 +57,11 @@ interface HomeProps {
|
||||
export const Home: React.FC<HomeProps> = ({
|
||||
searchQuery,
|
||||
services,
|
||||
isTagBarDisplay,
|
||||
availableTags,
|
||||
selectedTag,
|
||||
handleTagChange,
|
||||
currentTheme,
|
||||
currentPage,
|
||||
total,
|
||||
pageSize,
|
||||
@@ -102,9 +114,9 @@ export const Home: React.FC<HomeProps> = ({
|
||||
<span className="bg-clip-text text-transparent bg-gradient-to-r from-pink-600 via-red-500 to-orange-600">
|
||||
{t(
|
||||
platformConfig.headline ||
|
||||
platformConfig.name ||
|
||||
_DefaultPlatformConfig.headline ||
|
||||
""
|
||||
platformConfig.name ||
|
||||
_DefaultPlatformConfig.headline ||
|
||||
""
|
||||
)}
|
||||
</span>
|
||||
</h1>
|
||||
@@ -113,8 +125,8 @@ export const Home: React.FC<HomeProps> = ({
|
||||
<p className="text-lg font-medium max-w-3xl mx-auto leading-relaxed text-gray-700">
|
||||
{t(
|
||||
platformConfig.subheadline ||
|
||||
_DefaultPlatformConfig.subheadline ||
|
||||
""
|
||||
_DefaultPlatformConfig.subheadline ||
|
||||
""
|
||||
)}
|
||||
</p>
|
||||
</div>
|
||||
@@ -166,6 +178,21 @@ export const Home: React.FC<HomeProps> = ({
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* filter section */}
|
||||
{
|
||||
isTagBarDisplay && (
|
||||
<>
|
||||
<TagFilter
|
||||
theme={currentTheme}
|
||||
tags={availableTags}
|
||||
selectedTag={selectedTag}
|
||||
onTagChange={handleTagChange}
|
||||
maxWidthPercent={80}
|
||||
/>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
{/* Creative Server List Section */}
|
||||
{loading ? (
|
||||
<div className="relative z-10 mx-auto h-[200px] flex items-center justify-center">
|
||||
@@ -177,7 +204,7 @@ export const Home: React.FC<HomeProps> = ({
|
||||
</div>
|
||||
) : (
|
||||
<div className="relative z-10">
|
||||
<div className="relative mx-auto px-6 py-16 max-w-8xl">
|
||||
<div className={`relative mx-auto px-6 ${isTagBarDisplay ? 'py-12' : 'py-16'} max-w-8xl`}>
|
||||
{/* Creative Server Grid */}
|
||||
<div className="flex flex-wrap justify-center gap-4 mb-12">
|
||||
{services.map((service, index) => {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import React from "react";
|
||||
import React, { useEffect } from "react";
|
||||
import { Button } from "@nextui-org/react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import Link from "next/link";
|
||||
@@ -16,6 +16,7 @@ import { ArrowRightIcon } from "lucide-react";
|
||||
import { DynamicLogo } from "@/shared/components/DynamicLogo";
|
||||
import { useAuth } from "@/shared/lib/useAuth";
|
||||
import { NavigationItem } from "@/shared/components/Navigation";
|
||||
import { useSharedStore } from "@/shared/store/share";
|
||||
|
||||
interface NavigationProps {
|
||||
items?: NavigationItem[];
|
||||
@@ -26,6 +27,13 @@ export const Navigation: React.FC<NavigationProps> = ({ items }) => {
|
||||
const { handleLogin } = useAuth();
|
||||
const [isMenuOpen, setIsMenuOpen] = useState(false);
|
||||
|
||||
const [userToken, setUserToken] = useState<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
const userToken = useSharedStore?.getState?.().user_token
|
||||
setUserToken(userToken);
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<>
|
||||
{/* Creative Navigation */}
|
||||
@@ -65,16 +73,22 @@ export const Navigation: React.FC<NavigationProps> = ({ items }) => {
|
||||
</NavbarContent>
|
||||
<NavbarContent justify="end" className="items-center gap-2 sm:gap-4">
|
||||
<div className="hidden sm:flex gap-2">
|
||||
<Button onPress={handleLogin} variant="light">
|
||||
<b className="text-md"> {t("Sign In")}</b>
|
||||
</Button>
|
||||
{
|
||||
!userToken && (
|
||||
<>
|
||||
<Button onPress={handleLogin} variant="light">
|
||||
<b className="text-md"> {t("Sign In")}</b>
|
||||
</Button>
|
||||
</>
|
||||
)
|
||||
}
|
||||
<Button
|
||||
color="primary"
|
||||
className="bg-gradient-to-r from-pink-500 via-red-500 to-orange-500 hover:from-pink-600 hover:via-red-600 hover:to-orange-600 text-white shadow-lg hover:shadow-xl transition-all duration-300 hover:scale-105 flex items-center justify-center gap-4 pr-1 h-[45px]"
|
||||
radius="full"
|
||||
onPress={handleLogin}
|
||||
>
|
||||
<b className="text-md">{t("Get Started")}</b>
|
||||
<b className="text-md">{userToken ? t("Dashboard") : t("Get Started")}</b>
|
||||
<div className="w-8 h-8 bg-white/20 flex items-center justify-center rounded-full">
|
||||
<ArrowRightIcon
|
||||
size={16}
|
||||
@@ -89,7 +103,7 @@ export const Navigation: React.FC<NavigationProps> = ({ items }) => {
|
||||
onPress={handleLogin}
|
||||
size="sm"
|
||||
>
|
||||
<b className="text-md">{t("Get Started")}</b>
|
||||
<b className="text-md">{userToken ? t("Dashboard") : t("Get Started")}</b>
|
||||
</Button>
|
||||
</div>
|
||||
</NavbarContent>
|
||||
@@ -101,7 +115,7 @@ export const Navigation: React.FC<NavigationProps> = ({ items }) => {
|
||||
radius="full"
|
||||
onPress={handleLogin}
|
||||
>
|
||||
<b className="text-md">{t("Get Started")}</b>
|
||||
<b className="text-md">{userToken ? t("Dashboard") : t("Get Started")}</b>
|
||||
<div className="w-8 h-8 bg-white/20 flex items-center justify-center rounded-full">
|
||||
<ArrowRightIcon
|
||||
size={16}
|
||||
|
||||
@@ -26,11 +26,18 @@ import { Navigation } from "./Navigation";
|
||||
import { Footer } from "./Footer";
|
||||
import { NavigationItem } from "@/shared/components/Navigation";
|
||||
import { Faq } from "@/components/marketplace/Faq";
|
||||
import { TagFilter } from "@/shared/components/marketplace/TagFilter";
|
||||
import { ThemeType } from "@/shared/types/system";
|
||||
|
||||
interface HomeProps {
|
||||
// 状态
|
||||
searchQuery: string;
|
||||
services: ServiceData[];
|
||||
isTagBarDisplay: boolean;
|
||||
availableTags: string[];
|
||||
selectedTag: string;
|
||||
handleTagChange: (tag: string) => void;
|
||||
currentTheme: ThemeType;
|
||||
currentPage: number;
|
||||
total: number;
|
||||
pageSize: number;
|
||||
@@ -52,6 +59,11 @@ interface HomeProps {
|
||||
export const Home: React.FC<HomeProps> = ({
|
||||
searchQuery,
|
||||
services,
|
||||
isTagBarDisplay,
|
||||
availableTags,
|
||||
selectedTag,
|
||||
handleTagChange,
|
||||
currentTheme,
|
||||
currentPage,
|
||||
total,
|
||||
pageSize,
|
||||
@@ -78,7 +90,7 @@ export const Home: React.FC<HomeProps> = ({
|
||||
<Navigation items={navItems} />
|
||||
{/* Modern Hero Section */}
|
||||
<div className="pt-32">
|
||||
<div className="mx-auto px-6 py-20 max-w-6xl">
|
||||
<div className={`mx-auto px-6 max-w-6xl ${isTagBarDisplay ? 'py-16' : 'py-20'}`}>
|
||||
<div className="text-center mb-16">
|
||||
{/* Modern Icon */}
|
||||
<div className="flex justify-center mb-8">
|
||||
@@ -91,9 +103,9 @@ export const Home: React.FC<HomeProps> = ({
|
||||
<h1 className="text-4xl lg:text-6xl font-bold mb-6 text-gray-900 leading-tight">
|
||||
{t(
|
||||
platformConfig.headline ||
|
||||
platformConfig.name ||
|
||||
_DefaultPlatformConfig.headline ||
|
||||
""
|
||||
platformConfig.name ||
|
||||
_DefaultPlatformConfig.headline ||
|
||||
""
|
||||
)}
|
||||
</h1>
|
||||
|
||||
@@ -101,8 +113,8 @@ export const Home: React.FC<HomeProps> = ({
|
||||
<p className="text-lg text-gray-600 max-w-2xl mx-auto leading-relaxed">
|
||||
{t(
|
||||
platformConfig.subheadline ||
|
||||
_DefaultPlatformConfig.subheadline ||
|
||||
""
|
||||
_DefaultPlatformConfig.subheadline ||
|
||||
""
|
||||
)}
|
||||
</p>
|
||||
</div>
|
||||
@@ -145,6 +157,21 @@ export const Home: React.FC<HomeProps> = ({
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* filter section */}
|
||||
{
|
||||
isTagBarDisplay && (
|
||||
<>
|
||||
<TagFilter
|
||||
theme={currentTheme}
|
||||
tags={availableTags}
|
||||
selectedTag={selectedTag}
|
||||
onTagChange={handleTagChange}
|
||||
maxWidthPercent={80}
|
||||
/>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
<section>
|
||||
{/* Server List Section */}
|
||||
{loading ? (
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import React from "react";
|
||||
import React, { useEffect } from "react";
|
||||
import { Button } from "@nextui-org/react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import Link from "next/link";
|
||||
@@ -16,6 +16,7 @@ import { ArrowRightIcon } from "lucide-react";
|
||||
import { DynamicLogo } from "@/shared/components/DynamicLogo";
|
||||
import { useAuth } from "@/shared/lib/useAuth";
|
||||
import { NavigationItem } from "@/shared/components/Navigation";
|
||||
import { useSharedStore } from "@/shared/store/share";
|
||||
|
||||
interface NavigationProps {
|
||||
items?: NavigationItem[];
|
||||
@@ -25,7 +26,12 @@ export const Navigation: React.FC<NavigationProps> = ({ items }) => {
|
||||
const { t } = useTranslation();
|
||||
const { handleLogin } = useAuth();
|
||||
const [isMenuOpen, setIsMenuOpen] = useState(false);
|
||||
const [userToken, setUserToken] = useState<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
const userToken = useSharedStore?.getState?.().user_token
|
||||
setUserToken(userToken);
|
||||
}, []);
|
||||
return (
|
||||
<>
|
||||
{/* Modern Navigation */}
|
||||
@@ -61,16 +67,22 @@ export const Navigation: React.FC<NavigationProps> = ({ items }) => {
|
||||
</NavbarContent>
|
||||
<NavbarContent justify="end" className="items-center gap-2 sm:gap-4">
|
||||
<div className="hidden sm:flex gap-2">
|
||||
<Button onPress={handleLogin} variant="light">
|
||||
<b className="text-md"> {t("Sign In")}</b>
|
||||
</Button>
|
||||
{
|
||||
!userToken && (
|
||||
<>
|
||||
<Button onPress={handleLogin} variant="light">
|
||||
<b className="text-md"> {t("Sign In")}</b>
|
||||
</Button>
|
||||
</>
|
||||
)
|
||||
}
|
||||
<Button
|
||||
color="primary"
|
||||
className="bg-gradient-to-r from-blue-500 to-purple-600 text-white hover:from-blue-600 hover:to-purple-700 flex items-center justify-center gap-4 pr-1 h-[45px] shadow-lg"
|
||||
radius="full"
|
||||
onPress={handleLogin}
|
||||
>
|
||||
<b className="text-md">{t("Get Started")}</b>
|
||||
<b className="text-md">{userToken ? t("Dashboard") : t("Get Started")}</b>
|
||||
<div className="w-8 h-8 bg-white/20 flex items-center justify-center rounded-full">
|
||||
<ArrowRightIcon
|
||||
size={16}
|
||||
@@ -85,7 +97,7 @@ export const Navigation: React.FC<NavigationProps> = ({ items }) => {
|
||||
onPress={handleLogin}
|
||||
size="sm"
|
||||
>
|
||||
<b className="text-md">{t("Get Started")}</b>
|
||||
<b className="text-md">{userToken ? t("Dashboard") : t("Get Started")}</b>
|
||||
</Button>
|
||||
</div>
|
||||
</NavbarContent>
|
||||
@@ -97,7 +109,7 @@ export const Navigation: React.FC<NavigationProps> = ({ items }) => {
|
||||
radius="full"
|
||||
onPress={handleLogin}
|
||||
>
|
||||
<b className="text-md">{t("Get Started")}</b>
|
||||
<b className="text-md">{userToken ? t("Dashboard") : t("Get Started")}</b>
|
||||
<div className="w-8 h-8 bg-white/20 flex items-center justify-center rounded-full">
|
||||
<ArrowRightIcon
|
||||
size={16}
|
||||
|
||||
@@ -23,11 +23,18 @@ import { Footer } from "./Footer";
|
||||
import { Navigation } from "./Navigation";
|
||||
import { NavigationItem } from "@/shared/components/Navigation";
|
||||
import { Faq } from "@/components/marketplace/Faq";
|
||||
import { TagFilter } from "@/shared/components/marketplace/TagFilter";
|
||||
import { ThemeType } from "@/shared/types/system";
|
||||
|
||||
interface HomeProps {
|
||||
// 状态
|
||||
searchQuery: string;
|
||||
services: ServiceData[];
|
||||
isTagBarDisplay: boolean;
|
||||
availableTags: string[];
|
||||
selectedTag: string;
|
||||
handleTagChange: (tag: string) => void;
|
||||
currentTheme: ThemeType;
|
||||
currentPage: number;
|
||||
total: number;
|
||||
pageSize: number;
|
||||
@@ -49,6 +56,11 @@ interface HomeProps {
|
||||
export const Home: React.FC<HomeProps> = ({
|
||||
searchQuery,
|
||||
services,
|
||||
isTagBarDisplay,
|
||||
availableTags,
|
||||
selectedTag,
|
||||
handleTagChange,
|
||||
currentTheme,
|
||||
currentPage,
|
||||
total,
|
||||
pageSize,
|
||||
@@ -95,9 +107,9 @@ export const Home: React.FC<HomeProps> = ({
|
||||
<h1 className="text-4xl lg:text-6xl font-bold mb-6 text-white">
|
||||
{t(
|
||||
platformConfig.headline ||
|
||||
platformConfig.name ||
|
||||
_DefaultPlatformConfig.headline ||
|
||||
""
|
||||
platformConfig.name ||
|
||||
_DefaultPlatformConfig.headline ||
|
||||
""
|
||||
)}
|
||||
</h1>
|
||||
|
||||
@@ -105,8 +117,8 @@ export const Home: React.FC<HomeProps> = ({
|
||||
<p className="text-xl text-white/90 mb-8 max-w-2xl mx-auto">
|
||||
{t(
|
||||
platformConfig.subheadline ||
|
||||
_DefaultPlatformConfig.subheadline ||
|
||||
""
|
||||
_DefaultPlatformConfig.subheadline ||
|
||||
""
|
||||
)}
|
||||
</p>
|
||||
|
||||
@@ -139,6 +151,21 @@ export const Home: React.FC<HomeProps> = ({
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* filter section */}
|
||||
{
|
||||
isTagBarDisplay && (
|
||||
<div className="pt-12">
|
||||
<TagFilter
|
||||
theme={currentTheme}
|
||||
tags={availableTags}
|
||||
selectedTag={selectedTag}
|
||||
onTagChange={handleTagChange}
|
||||
maxWidthPercent={80}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
{/* Products Section */}
|
||||
<div className="mx-auto px-6 py-12 max-w-7xl">
|
||||
{/* Section Header */}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import React from "react";
|
||||
import React, { useEffect } from "react";
|
||||
import { Button } from "@nextui-org/react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import Link from "next/link";
|
||||
@@ -16,6 +16,7 @@ import { DynamicLogo } from "@/shared/components/DynamicLogo";
|
||||
import { useAuth } from "@/shared/lib/useAuth";
|
||||
import { NavigationItem } from "@/shared/components/Navigation";
|
||||
import { ArrowRightIcon } from "lucide-react";
|
||||
import { useSharedStore } from "@/shared/store/share";
|
||||
|
||||
interface NavigationProps {
|
||||
items?: NavigationItem[];
|
||||
@@ -26,6 +27,13 @@ export const Navigation: React.FC<NavigationProps> = ({ items }) => {
|
||||
const { handleLogin } = useAuth();
|
||||
const [isMenuOpen, setIsMenuOpen] = useState(false);
|
||||
|
||||
const [userToken, setUserToken] = useState<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
const userToken = useSharedStore?.getState?.().user_token
|
||||
setUserToken(userToken);
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<>
|
||||
{/* Temu Style Navigation */}
|
||||
@@ -64,15 +72,21 @@ export const Navigation: React.FC<NavigationProps> = ({ items }) => {
|
||||
</NavbarContent>
|
||||
<NavbarContent justify="end" className="items-center gap-2 sm:gap-4">
|
||||
<div className="hidden sm:flex items-center gap-2">
|
||||
<Button onPress={handleLogin} variant="light">
|
||||
<b className="text-md"> {t("Sign In")}</b>
|
||||
</Button>
|
||||
{
|
||||
!userToken && (
|
||||
<>
|
||||
<Button onPress={handleLogin} variant="light">
|
||||
<b className="text-md"> {t("Sign In")}</b>
|
||||
</Button>
|
||||
</>
|
||||
)
|
||||
}
|
||||
<Button
|
||||
className="bg-orange-500 hover:bg-orange-600 text-white font-semibold px-6 h-[40px] transition-all duration-200"
|
||||
radius="md"
|
||||
onPress={handleLogin}
|
||||
>
|
||||
{t("Get Started")}
|
||||
{userToken ? t("Dashboard") : t("Get Started")}
|
||||
</Button>
|
||||
</div>
|
||||
<div className="sm:hidden">
|
||||
@@ -81,7 +95,7 @@ export const Navigation: React.FC<NavigationProps> = ({ items }) => {
|
||||
onPress={handleLogin}
|
||||
size="sm"
|
||||
>
|
||||
{t("Sign In")}
|
||||
{userToken ? t("Dashboard") : t("Sign In")}
|
||||
</Button>
|
||||
</div>
|
||||
</NavbarContent>
|
||||
@@ -100,7 +114,7 @@ export const Navigation: React.FC<NavigationProps> = ({ items }) => {
|
||||
radius="md"
|
||||
onPress={handleLogin}
|
||||
>
|
||||
{t("Sign In")}
|
||||
{userToken ? t("Dashboard") : t("Sign In")}
|
||||
</Button>
|
||||
</NavbarMenuItem>
|
||||
</NavbarMenu>
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
"use client";
|
||||
|
||||
import React from "react";
|
||||
import { Button} from "@nextui-org/react";
|
||||
import { ChevronLeftIcon } from "lucide-react";
|
||||
import { useTranslation } from "@/shared/lib/useTranslation";
|
||||
import { withComponentInjection } from "@/shared/hooks/useComponentInjection";
|
||||
import AccountBalanceTable from "../dashboard/AccountBalanceTable";
|
||||
|
||||
interface UserBalanceDetailProps {
|
||||
userId: string;
|
||||
userEmail: string;
|
||||
onCancel: () => void;
|
||||
}
|
||||
|
||||
const BaseUserBalanceDetail: React.FC<UserBalanceDetailProps> = ({
|
||||
userId,
|
||||
userEmail,
|
||||
onCancel,
|
||||
}) => {
|
||||
const { t } = useTranslation();
|
||||
|
||||
return (
|
||||
<div className="w-full py-8 h-full flex flex-col">
|
||||
{/* page title */}
|
||||
<div className="flex items-center justify-between mb-6 px-8">
|
||||
<div className="flex items-center gap-3">
|
||||
<Button isIconOnly onPress={onCancel} variant="flat" size="sm">
|
||||
<ChevronLeftIcon className="w-5 h-5" />
|
||||
</Button>
|
||||
<h1 className="text-2xl font-bold">
|
||||
{t("Account Balance")}
|
||||
</h1>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<span>{t("Email")}: </span>{userEmail || '-'}
|
||||
</div>
|
||||
</div>
|
||||
<div className="px-8">
|
||||
<AccountBalanceTable userId={userId} source="admin" />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
export const UserBalanceDetail = withComponentInjection(
|
||||
"components/user-management/UserBalanceDetail",
|
||||
BaseUserBalanceDetail
|
||||
);
|
||||
@@ -7,6 +7,9 @@ import { UserTable } from "./UserTable";
|
||||
import { DeleteConfirmModal } from "@/shared/components/modal/DeleteConfirmModal";
|
||||
import DashboardDemoContent from "@/shared/components/DashboardDemoContent";
|
||||
import { useUserManagement } from "@/hooks/useUserManagement";
|
||||
import { UserBalanceDetail } from "./UserBalanceDetail";
|
||||
|
||||
type ViewMode = "list" | "detail";
|
||||
|
||||
const UserManagement: React.FC = () => {
|
||||
const { t } = useTranslation();
|
||||
@@ -28,6 +31,11 @@ const UserManagement: React.FC = () => {
|
||||
user: null as User | null,
|
||||
});
|
||||
|
||||
const [viewMode, setViewMode] = useState<ViewMode>('list');
|
||||
const [selectedUserId, setSelectedUserId] = useState<string | null>(null);
|
||||
const [selectedUserEmail, setSelectedUserEmail] = useState<string | null>(null);
|
||||
|
||||
|
||||
const handleDeleteUserClick = useCallback((user: User) => {
|
||||
setDeleteModal({
|
||||
isOpen: true,
|
||||
@@ -35,6 +43,18 @@ const UserManagement: React.FC = () => {
|
||||
});
|
||||
}, []);
|
||||
|
||||
const handleViewUserBalanceDetail = useCallback((user: User) => {
|
||||
setSelectedUserId(user.id);
|
||||
setSelectedUserEmail(user.email);
|
||||
setViewMode('detail');
|
||||
}, []);
|
||||
|
||||
const handleCloseUserBalanceDetail = useCallback(() => {
|
||||
setSelectedUserId(null);
|
||||
setSelectedUserEmail(null);
|
||||
setViewMode('list');
|
||||
}, []);
|
||||
|
||||
const handleConfirmDelete = useCallback(async () => {
|
||||
if (deleteModal.user) {
|
||||
try {
|
||||
@@ -61,6 +81,16 @@ const UserManagement: React.FC = () => {
|
||||
[handleRechargeUser]
|
||||
);
|
||||
|
||||
if (viewMode === "detail" ) {
|
||||
return (
|
||||
<UserBalanceDetail
|
||||
userId={selectedUserId || ''}
|
||||
userEmail={selectedUserEmail || ''}
|
||||
onCancel={handleCloseUserBalanceDetail}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<DashboardDemoContent
|
||||
title={t("User")}
|
||||
@@ -74,6 +104,7 @@ const UserManagement: React.FC = () => {
|
||||
fetchUsers={fetchUsers}
|
||||
loading={loading}
|
||||
onDelete={handleDeleteUserClick}
|
||||
viewUserBalanceDetail={handleViewUserBalanceDetail}
|
||||
onRecharge={handleRecharge}
|
||||
pagination={pagination}
|
||||
onPageChange={setPage}
|
||||
|
||||
@@ -14,10 +14,12 @@ import {
|
||||
Spinner,
|
||||
Select,
|
||||
SelectItem,
|
||||
Link
|
||||
} from "@nextui-org/react";
|
||||
import { useTranslation } from "@/shared/lib/useTranslation";
|
||||
import { User } from "@/types/user";
|
||||
import { Trash2, CreditCard, Calendar, HelpCircle } from "lucide-react";
|
||||
|
||||
import { AdminRechargeModal } from "@/components/user-management/AdminRechargeModal";
|
||||
import { fetchSimpleResourceGroups, updateUserResourceGroup } from "@/api/resourceGroup.api";
|
||||
import toast from "react-hot-toast";
|
||||
@@ -27,6 +29,7 @@ interface UserTableProps {
|
||||
fetchUsers: () => void;
|
||||
loading?: boolean;
|
||||
onDelete: (user: User) => void;
|
||||
viewUserBalanceDetail: (userId: User) => void;
|
||||
onRecharge: (id: string, amount: number) => Promise<boolean>;
|
||||
pagination: {
|
||||
page: number;
|
||||
@@ -40,6 +43,7 @@ export const UserTable: React.FC<UserTableProps> = ({
|
||||
users,
|
||||
fetchUsers,
|
||||
loading = false,
|
||||
viewUserBalanceDetail,
|
||||
onDelete,
|
||||
onRecharge,
|
||||
pagination,
|
||||
@@ -135,7 +139,7 @@ export const UserTable: React.FC<UserTableProps> = ({
|
||||
<TableHeader>
|
||||
<TableColumn>{t("Email")}</TableColumn>
|
||||
<TableColumn width={250}>{t("Resource Group")}</TableColumn>
|
||||
<TableColumn>
|
||||
<TableColumn width={200}>
|
||||
<div className="flex items-center gap-1">
|
||||
<span>{t("Register Date")}</span>
|
||||
<Tooltip
|
||||
@@ -148,8 +152,8 @@ export const UserTable: React.FC<UserTableProps> = ({
|
||||
</Tooltip>
|
||||
</div>
|
||||
</TableColumn>
|
||||
<TableColumn>{t("Balance")}</TableColumn>
|
||||
<TableColumn>{t("Actions")}</TableColumn>
|
||||
<TableColumn width={120}>{t("Balance")}</TableColumn>
|
||||
<TableColumn width={100}>{t("Actions")}</TableColumn>
|
||||
</TableHeader>
|
||||
<TableBody
|
||||
items={items}
|
||||
@@ -185,7 +189,15 @@ export const UserTable: React.FC<UserTableProps> = ({
|
||||
</Select>
|
||||
</TableCell>
|
||||
<TableCell>{formatDate(user.created_at)}</TableCell>
|
||||
<TableCell>{user.balance.toFixed(2) || "-"}</TableCell>
|
||||
<TableCell>
|
||||
<Link
|
||||
href="#"
|
||||
className="text-xs cursor-pointer"
|
||||
onPress={() => viewUserBalanceDetail(user)}
|
||||
>
|
||||
{user.balance.toFixed(2) || "-"}
|
||||
</Link>
|
||||
</TableCell>
|
||||
|
||||
<TableCell>
|
||||
<div className="relative flex items-center gap-2">
|
||||
|
||||
@@ -17,6 +17,7 @@ interface FetchServicesParams {
|
||||
page?: number;
|
||||
page_size?: number;
|
||||
keyword?: string;
|
||||
tag?: string;
|
||||
}
|
||||
interface ServicesResponseData {
|
||||
services: ServiceData[];
|
||||
@@ -42,6 +43,7 @@ export async function fetchServices(
|
||||
page_size: _BasePageDetail.page_size,
|
||||
page: _BasePageDetail.page,
|
||||
keyword: "",
|
||||
tag: "",
|
||||
}
|
||||
): Promise<ServicesResponse> {
|
||||
// Build query parameters
|
||||
@@ -50,7 +52,7 @@ export async function fetchServices(
|
||||
if (params.page_size)
|
||||
queryParams.append("page_size", params.page_size.toString());
|
||||
if (params.keyword) queryParams.append("keyword", params.keyword);
|
||||
|
||||
if (params.tag) queryParams.append("tag", params.tag);
|
||||
const response = await fetchAPI<BaseMCPService[]>(
|
||||
`/api/web/mcp_services${queryParams.toString() ? "?" + queryParams.toString() : ""}`
|
||||
);
|
||||
@@ -99,3 +101,26 @@ export async function fetchServiceById(
|
||||
|
||||
return convertMcpService([response.data])[0];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Fetch tags list
|
||||
*/
|
||||
export async function fetchTagsList(
|
||||
): Promise<string[] | []> {
|
||||
const response = await fetchAPI<string[]>(
|
||||
`/api/web/mcp_tags`,
|
||||
{
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
if (!response.success) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return response.data || []
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import React, { useState } from "react";
|
||||
import React, { useEffect, useState } from "react";
|
||||
import {
|
||||
Navbar,
|
||||
NavbarContent,
|
||||
@@ -15,6 +15,7 @@ import { useAuth } from "@/shared/lib/useAuth";
|
||||
import { ArrowRightIcon } from "lucide-react";
|
||||
import { DynamicLogo } from "@/shared/components/DynamicLogo";
|
||||
import Link from "next/link";
|
||||
import { useSharedStore } from "../store/share";
|
||||
export type NavigationItem = {
|
||||
label: string;
|
||||
href: string;
|
||||
@@ -45,6 +46,13 @@ function NavigationClient({
|
||||
const { t } = useTranslation();
|
||||
const { handleLogin } = useAuth();
|
||||
|
||||
const [userToken, setUserToken] = useState<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
const userToken = useSharedStore?.getState?.().user_token
|
||||
setUserToken(userToken);
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<>
|
||||
{/* Main Navigation */}
|
||||
@@ -97,9 +105,17 @@ function NavigationClient({
|
||||
{langNode ? (
|
||||
langNode
|
||||
) : (
|
||||
<Button onPress={handleLogin} variant="light">
|
||||
<b className="text-md"> {t("Sign In")}</b>
|
||||
</Button>
|
||||
<>
|
||||
{
|
||||
!userToken && (
|
||||
<>
|
||||
<Button onPress={handleLogin} variant="light">
|
||||
<b className="text-md"> {t("Sign In")}</b>
|
||||
</Button>
|
||||
</>
|
||||
)
|
||||
}
|
||||
</>
|
||||
)}
|
||||
|
||||
{/* Desktop Auth Button */}
|
||||
@@ -110,7 +126,7 @@ function NavigationClient({
|
||||
radius="full"
|
||||
onPress={onLogin || handleLogin}
|
||||
>
|
||||
<b className="text-md"> {t(signinText)}</b>
|
||||
<b className="text-md"> {userToken ? t("Dashboard") : t(signinText) }</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}
|
||||
@@ -128,7 +144,7 @@ function NavigationClient({
|
||||
onPress={onLogin || handleLogin}
|
||||
size="sm"
|
||||
>
|
||||
<b className="text-md"> {t(signinText)}</b>
|
||||
<b className="text-md"> {userToken ? t("Dashboard") : t(signinText) }</b>
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
@@ -156,7 +172,7 @@ function NavigationClient({
|
||||
radius="full"
|
||||
onPress={onLogin || handleLogin}
|
||||
>
|
||||
<b className="text-md"> {t(signinText)}</b>
|
||||
<b className="text-md"> {userToken ? t("Dashboard") : t(signinText) }</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}
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
|
||||
interface HeroSectionProps {
|
||||
searchQuery: string;
|
||||
isTagBarDisplay: boolean;
|
||||
onSearchChange: (value: string) => void;
|
||||
onSearch?: () => void;
|
||||
searchSuggestions?: string[];
|
||||
@@ -16,6 +17,7 @@ interface HeroSectionProps {
|
||||
|
||||
export const HeroSection: React.FC<HeroSectionProps> = ({
|
||||
searchQuery,
|
||||
isTagBarDisplay,
|
||||
onSearchChange,
|
||||
onSearch,
|
||||
searchSuggestions = [],
|
||||
@@ -77,7 +79,7 @@ export const HeroSection: React.FC<HeroSectionProps> = ({
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="relative overflow-hidden mx-auto p-6 py-24 max-w-7xl">
|
||||
<div className={`relative overflow-hidden mx-auto p-6 ${isTagBarDisplay ? 'py-12' : 'py-24'} max-w-7xl`}>
|
||||
<div className="text-center mb-12">
|
||||
<h1 className="text-5xl lg:text-6xl font-bold mb-6 leading-tight">
|
||||
{t(
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import React, { useState } from "react";
|
||||
import React, { useCallback, useEffect, useState } from "react";
|
||||
import { Card, Chip, Button, Select, SelectItem } from "@nextui-org/react";
|
||||
import { FlipButton } from "@/shared/components/FlipButton";
|
||||
import { useAuth } from "@/shared/lib/useAuth";
|
||||
@@ -9,7 +9,16 @@ import { usePlatformConfig } from "@/shared/contexts/PlatformConfigContext";
|
||||
import { Copy } from "lucide-react";
|
||||
import { copyToClipboard } from "@/shared/utils/clipboard";
|
||||
import toast from "react-hot-toast";
|
||||
import { useSharedStore } from "@/shared/store/share";
|
||||
import { fetchAPI } from "@/shared/rpc/common-function";
|
||||
import i18n from "@/shared/lib/i18n";
|
||||
|
||||
type apiKeyList = {
|
||||
name: string;
|
||||
apikey: string;
|
||||
create_time: string;
|
||||
apikey_id: number;
|
||||
}
|
||||
interface ServerConfigProps {
|
||||
mcpName?: string;
|
||||
url?: string;
|
||||
@@ -20,6 +29,18 @@ interface ServerConfigProps {
|
||||
|
||||
type McpType = "sse" | "streamable-http";
|
||||
|
||||
// 辅助函数:将 API Key 掩码显示,只保留前2位和后4位
|
||||
const maskApiKey = (apiKey: string): string => {
|
||||
if (!apiKey || apiKey.length <= 6) {
|
||||
return apiKey; // 如果太短就直接返回
|
||||
}
|
||||
const prefix = apiKey.slice(0, 2);
|
||||
const suffix = apiKey.slice(-4);
|
||||
const maskedLength = apiKey.length - 6;
|
||||
const masked = '*'.repeat(maskedLength);
|
||||
return `${prefix}${masked}${suffix}`;
|
||||
};
|
||||
|
||||
export const ServerConfig: React.FC<ServerConfigProps> = ({
|
||||
mcpName,
|
||||
url = process.env.NEXT_PUBLIC_MCP_URL,
|
||||
@@ -31,6 +52,49 @@ export const ServerConfig: React.FC<ServerConfigProps> = ({
|
||||
const { handleLogin } = useAuth();
|
||||
const { platformConfig } = usePlatformConfig();
|
||||
const [mcpType, setMcpType] = useState<McpType>("sse");
|
||||
// API Key List
|
||||
const [apiKeys, setApiKeys] = useState<{ key: string, label: string }[]>([]);
|
||||
// Selected API Key
|
||||
const [selectedApiKey, setSelectedApiKey] = useState<string | null>(null);
|
||||
// User Token
|
||||
const [userToken, setUserToken] = useState<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
const fetchData = async () => {
|
||||
const userToken = useSharedStore?.getState?.().user_token
|
||||
setUserToken(userToken);
|
||||
if (userToken) {
|
||||
const data = await fetchApiKeys()
|
||||
if (data.length > 0) {
|
||||
setApiKeys(data.map((item) => ({
|
||||
key: item.apikey,
|
||||
label: item.name,
|
||||
})));
|
||||
setSelectedApiKey(data[0].apikey)
|
||||
}
|
||||
}
|
||||
}
|
||||
fetchData();
|
||||
}, []);
|
||||
|
||||
const fetchApiKeys = useCallback(
|
||||
async (
|
||||
): Promise<apiKeyList[]> => {
|
||||
try {
|
||||
|
||||
const response = await fetchAPI<apiKeyList[]>('/api/apikey/list');
|
||||
if (!response.success) {
|
||||
toast.error(response.error_message || i18n.t("Failed to load api keys"));
|
||||
return []
|
||||
}
|
||||
return response.data || []
|
||||
} catch (error) {
|
||||
console.error("Error fetching api keys:", error);
|
||||
return []
|
||||
}
|
||||
},
|
||||
[]
|
||||
);
|
||||
|
||||
const mcpTypeOptions = [
|
||||
{ key: "sse", label: "SSE (Server-Sent Events)" },
|
||||
@@ -40,8 +104,8 @@ export const ServerConfig: React.FC<ServerConfigProps> = ({
|
||||
const getCodeContent = () => {
|
||||
const serverUrl =
|
||||
mcpType === "streamable-http"
|
||||
? `${url}/streamable-http?authkey={Your-${platformConfig?.name}-Auth-Key}`
|
||||
: `${url}?authkey={Your-${platformConfig?.name}-Auth-Key}`;
|
||||
? `${url}/streamable-http?authkey=${selectedApiKey ? selectedApiKey : `{Your-${platformConfig?.name}-Auth-Key}`}`
|
||||
: `${url}?authkey=${selectedApiKey ? selectedApiKey : `{Your-${platformConfig?.name}-Auth-Key}`}`;
|
||||
|
||||
return `{
|
||||
"mcpServers": {
|
||||
@@ -63,16 +127,62 @@ export const ServerConfig: React.FC<ServerConfigProps> = ({
|
||||
}
|
||||
};
|
||||
|
||||
const handleCreateNewAuthorization = () => {
|
||||
sessionStorage.setItem('create_new_authorization', 'true');
|
||||
handleLogin()
|
||||
}
|
||||
|
||||
return (
|
||||
<div className={`min-w-full ${className} flex-shrink-0`}>
|
||||
<div className="mb-2 mt-1">
|
||||
{
|
||||
visitor || can_invoke ? <>
|
||||
<FlipButton
|
||||
className="w-full rounded-md"
|
||||
text={t("Sign up to get the auth key")}
|
||||
onPress={handleLogin}
|
||||
/>
|
||||
{
|
||||
!userToken ? <>
|
||||
<FlipButton
|
||||
className="w-full rounded-md"
|
||||
text={t("Sign up to get the auth key")}
|
||||
onPress={handleLogin}
|
||||
/>
|
||||
</> : <>
|
||||
{
|
||||
apiKeys.length ?
|
||||
<>
|
||||
<Select
|
||||
label={t("Auth Key")}
|
||||
placeholder={t("Auth Key Name")}
|
||||
selectedKeys={selectedApiKey ? [selectedApiKey] : []}
|
||||
onSelectionChange={(keys) => {
|
||||
const selectedKey = Array.from(keys)[0] as string;
|
||||
setSelectedApiKey(selectedKey);
|
||||
}}
|
||||
className="w-full"
|
||||
size="sm"
|
||||
classNames={{
|
||||
trigger: " bg-black text-white data-[hover=true]:bg-dark-200",
|
||||
label: "!text-default-200",
|
||||
value: "!text-white",
|
||||
popoverContent: "bg-black text-white",
|
||||
}}
|
||||
>
|
||||
{apiKeys.map((option) => (
|
||||
<SelectItem key={option.key} value={option.key}>
|
||||
{option.label}
|
||||
</SelectItem>
|
||||
))}
|
||||
</Select>
|
||||
</>
|
||||
:
|
||||
<>
|
||||
<FlipButton
|
||||
className="w-full rounded-md"
|
||||
text={t("Create New Authorization")}
|
||||
onPress={handleCreateNewAuthorization}
|
||||
/>
|
||||
</>
|
||||
}
|
||||
</>
|
||||
}
|
||||
</> : <>
|
||||
<div className="w-full rounded-lg bg-[#F3126033] md:pr-2 h-[40px] md:h-[50px] shadow-lg flex items-center justify-center">
|
||||
<p className="text-[#C20E4D] text-center font-bold text-lg leading-none">
|
||||
@@ -140,7 +250,7 @@ export const ServerConfig: React.FC<ServerConfigProps> = ({
|
||||
{mcpType === "streamable-http"
|
||||
? `${url}/streamable-http?authkey=`
|
||||
: `${url}?authkey=`}
|
||||
<span className="text-success">{`{Your-${platformConfig?.name}-Auth-Key}`}</span>
|
||||
<span className="text-success">{selectedApiKey ? maskApiKey(selectedApiKey) : `{Your-${platformConfig?.name}-Auth-Key}`}</span>
|
||||
{`"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,309 @@
|
||||
"use client";
|
||||
|
||||
import React, { useState, useEffect, useRef } from "react";
|
||||
import {
|
||||
Modal,
|
||||
ModalContent,
|
||||
ModalHeader,
|
||||
ModalBody,
|
||||
ModalFooter,
|
||||
Button,
|
||||
} from "@nextui-org/react";
|
||||
import { Theme, ThemeType } from "@/shared/types/system";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
interface TagFilterProps {
|
||||
tags: string[];
|
||||
theme: ThemeType;
|
||||
selectedTag: string;
|
||||
onTagChange: (tag: string) => void;
|
||||
maxWidthPercent?: number; // 最大宽度百分比,默认80%
|
||||
}
|
||||
|
||||
export const TagFilter: React.FC<TagFilterProps> = ({
|
||||
tags,
|
||||
theme,
|
||||
selectedTag,
|
||||
onTagChange,
|
||||
maxWidthPercent = 80,
|
||||
}) => {
|
||||
const { t } = useTranslation();
|
||||
// 是否打开标签筛选弹窗
|
||||
const [isModalOpen, setIsModalOpen] = useState(false);
|
||||
// 临时选中的标签
|
||||
const [tempSelectedTag, setTempSelectedTag] = useState<string | null>(null);
|
||||
// 可见的标签
|
||||
const [visibleTags, setVisibleTags] = useState<string[]>(["ALL", ...tags]);
|
||||
// 是否显示更多按钮
|
||||
const [showMore, setShowMore] = useState(false);
|
||||
// 从弹窗选择的额外标签
|
||||
const [extraTag, setExtraTag] = useState<string | null>(null);
|
||||
// 容器引用
|
||||
const containerRef = useRef<HTMLDivElement>(null);
|
||||
// 标签容器引用
|
||||
const tagsContainerRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
|
||||
// 根据主题获取颜色配置
|
||||
const getThemeColors = () => {
|
||||
switch (theme) {
|
||||
case Theme.DEFAULT:
|
||||
case Theme.MODERN:
|
||||
return {
|
||||
selected: "bg-[#C8DCFF] text-[#1E40AF]",
|
||||
unselected: "text-gray-700 hover:bg-gray-200",
|
||||
shadow: "shadow-lg shadow-[#C8DCFF]/50",
|
||||
};
|
||||
case Theme.CLASSIC:
|
||||
return {
|
||||
selected: "bg-[#475569] text-white",
|
||||
unselected: "text-gray-700 hover:bg-gray-200",
|
||||
shadow: "shadow-lg shadow-[#475569]/50",
|
||||
};
|
||||
case Theme.TEMU:
|
||||
return {
|
||||
selected: "bg-[#F97316] text-white",
|
||||
unselected: "text-gray-700 hover:bg-gray-200",
|
||||
shadow: "shadow-lg shadow-[#F97316]/50",
|
||||
};
|
||||
case Theme.CREATIVE:
|
||||
return {
|
||||
selected: "to-orange-500 via-red-500 from-pink-500 bg-gradient-to-r text-white",
|
||||
unselected: "text-gray-700 hover:bg-gray-200",
|
||||
shadow: "shadow-lg shadow-[#EF5082]/50",
|
||||
};
|
||||
default:
|
||||
return {
|
||||
selected: "bg-[#C8DCFF] text-[#1E40AF]",
|
||||
unselected: "text-gray-700 hover:bg-gray-200",
|
||||
shadow: "shadow-lg shadow-[#C8DCFF]/50",
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
const themeColors = getThemeColors();
|
||||
|
||||
// 计算哪些标签可以显示
|
||||
useEffect(() => {
|
||||
const calculateVisibleTags = () => {
|
||||
if (!containerRef.current) return;
|
||||
|
||||
const containerWidth = containerRef.current.offsetWidth;
|
||||
const maxWidth = (containerWidth * maxWidthPercent) / 100;
|
||||
|
||||
// More按钮的宽度(估算)
|
||||
const moreButtonWidth = 80;
|
||||
|
||||
// 创建临时元素来测量标签宽度
|
||||
const tempDiv = document.createElement("div");
|
||||
tempDiv.style.position = "absolute";
|
||||
tempDiv.style.visibility = "hidden";
|
||||
tempDiv.style.whiteSpace = "nowrap";
|
||||
tempDiv.className = "px-6 py-2 rounded-full text-sm font-medium";
|
||||
document.body.appendChild(tempDiv);
|
||||
|
||||
let currentWidth = 0;
|
||||
const visible: string[] = ["ALL"];
|
||||
let needsMore = false;
|
||||
|
||||
// 先计算常规标签
|
||||
for (const tag of tags) {
|
||||
if (tag === extraTag) continue; // 跳过额外标签,稍后处理
|
||||
|
||||
tempDiv.textContent = tag;
|
||||
const tagWidth = tempDiv.offsetWidth; // 不加间距
|
||||
|
||||
if (currentWidth + tagWidth + moreButtonWidth > maxWidth) {
|
||||
needsMore = true;
|
||||
break;
|
||||
}
|
||||
|
||||
currentWidth += tagWidth;
|
||||
visible.push(tag);
|
||||
}
|
||||
|
||||
// 处理额外标签或当前选中的标签
|
||||
// 如果当前选中的标签不在可见列表中(除了ALL),需要作为额外标签显示
|
||||
const tagToShow = extraTag || (selectedTag !== "ALL" && !visible.includes(selectedTag) ? selectedTag : null);
|
||||
|
||||
if (tagToShow && tagToShow !== "ALL" && !visible.includes(tagToShow)) {
|
||||
tempDiv.textContent = tagToShow;
|
||||
const tagWidth = tempDiv.offsetWidth; // 不加间距
|
||||
|
||||
// 检查是否还有空间显示额外标签
|
||||
if (currentWidth + tagWidth + moreButtonWidth <= maxWidth) {
|
||||
// 空间足够,直接添加
|
||||
currentWidth += tagWidth;
|
||||
visible.push(tagToShow);
|
||||
} else {
|
||||
// 空间不够,替换掉最后一个常规标签(保留 ALL)
|
||||
if (visible.length > 1) {
|
||||
visible.pop(); // 移除最后一个标签
|
||||
visible.push(tagToShow); // 添加额外标签
|
||||
needsMore = true; // 确保显示 More 按钮
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
document.body.removeChild(tempDiv);
|
||||
|
||||
setVisibleTags(visible);
|
||||
setShowMore(needsMore);
|
||||
};
|
||||
|
||||
// 延迟执行以确保DOM已渲染
|
||||
setTimeout(calculateVisibleTags, 0);
|
||||
|
||||
// 监听窗口大小变化
|
||||
window.addEventListener("resize", calculateVisibleTags);
|
||||
return () => window.removeEventListener("resize", calculateVisibleTags);
|
||||
}, [tags, extraTag, selectedTag, maxWidthPercent]);
|
||||
|
||||
const handleTagClick = (tag: string) => {
|
||||
// 如果点击的是额外标签以外的标签,清除额外标签
|
||||
if (extraTag && tag !== extraTag) {
|
||||
setExtraTag(null);
|
||||
}
|
||||
onTagChange(tag);
|
||||
};
|
||||
|
||||
const handleModalOpen = () => {
|
||||
// 打开弹窗时,初始化临时选中的标签为当前选中的标签
|
||||
setTempSelectedTag(selectedTag);
|
||||
setIsModalOpen(true);
|
||||
};
|
||||
|
||||
const handleModalConfirm = () => {
|
||||
if (tempSelectedTag) {
|
||||
// 如果选择的是 ALL 或者已经在可见标签中的标签,不设置为额外标签
|
||||
if (tempSelectedTag === "ALL" || visibleTags.includes(tempSelectedTag)) {
|
||||
setExtraTag(null);
|
||||
} else {
|
||||
// 否则设置为额外标签
|
||||
setExtraTag(tempSelectedTag);
|
||||
}
|
||||
onTagChange(tempSelectedTag);
|
||||
}
|
||||
setIsModalOpen(false);
|
||||
};
|
||||
|
||||
const handleModalCancel = () => {
|
||||
setTempSelectedTag(null);
|
||||
setIsModalOpen(false);
|
||||
};
|
||||
|
||||
const handleModalTagClick = (tag: string) => {
|
||||
setTempSelectedTag(tag);
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<div ref={containerRef} className="w-full px-6 py-6">
|
||||
<div className="mx-auto max-w-7xl text-center">
|
||||
<div
|
||||
ref={tagsContainerRef}
|
||||
className="inline-flex items-center border-1 bg-[#fff] rounded-full transition-all duration-300"
|
||||
>
|
||||
{visibleTags.map((tag) => {
|
||||
const isSelected = selectedTag === tag;
|
||||
return (
|
||||
<button
|
||||
key={tag}
|
||||
onClick={() => handleTagClick(tag)}
|
||||
className={`
|
||||
px-6 py-2 rounded-full text-sm font-medium transition-all duration-200
|
||||
whitespace-nowrap
|
||||
${
|
||||
isSelected
|
||||
? `${themeColors.selected} ${themeColors.shadow}`
|
||||
: themeColors.unselected
|
||||
}
|
||||
`}
|
||||
>
|
||||
{tag}
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
|
||||
{showMore && (
|
||||
<button
|
||||
onClick={handleModalOpen}
|
||||
className="px-4 py-2 text-sm font-medium text-blue-500 hover:text-blue-600 transition-colors whitespace-nowrap"
|
||||
>
|
||||
More
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* More Modal */}
|
||||
<Modal
|
||||
isOpen={isModalOpen}
|
||||
onClose={handleModalCancel}
|
||||
size="2xl"
|
||||
scrollBehavior="inside"
|
||||
>
|
||||
<ModalContent>
|
||||
<ModalHeader className="flex flex-col gap-1">
|
||||
Tag Filter
|
||||
</ModalHeader>
|
||||
<ModalBody>
|
||||
<div className="flex flex-wrap gap-3 py-4">
|
||||
<button
|
||||
onClick={() => handleModalTagClick("ALL")}
|
||||
className={`
|
||||
px-6 py-2 rounded-full text-sm font-medium transition-all duration-200
|
||||
${
|
||||
tempSelectedTag === "ALL"
|
||||
? "bg-blue-500 text-white shadow-lg shadow-blue-500/50"
|
||||
: "bg-gray-100 text-gray-700 hover:bg-gray-200"
|
||||
}
|
||||
`}
|
||||
>
|
||||
ALL
|
||||
</button>
|
||||
|
||||
{tags.map((tag) => {
|
||||
const isSelected = tempSelectedTag === tag;
|
||||
return (
|
||||
<button
|
||||
key={tag}
|
||||
onClick={() => handleModalTagClick(tag)}
|
||||
className={`
|
||||
px-6 py-2 rounded-full text-sm font-medium transition-all duration-200
|
||||
${
|
||||
isSelected
|
||||
? "bg-blue-500 text-white shadow-lg shadow-blue-500/50"
|
||||
: "bg-gray-100 text-gray-700 hover:bg-gray-200"
|
||||
}
|
||||
`}
|
||||
>
|
||||
{tag}
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</ModalBody>
|
||||
<ModalFooter>
|
||||
<Button
|
||||
color="default"
|
||||
variant="light"
|
||||
onPress={handleModalCancel}
|
||||
>
|
||||
{t("Cancel")}
|
||||
</Button>
|
||||
<Button
|
||||
color="primary"
|
||||
onPress={handleModalConfirm}
|
||||
isDisabled={!tempSelectedTag}
|
||||
>
|
||||
{t("Confirm")}
|
||||
</Button>
|
||||
</ModalFooter>
|
||||
</ModalContent>
|
||||
</Modal>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -10,6 +10,7 @@ export enum TabKey {
|
||||
OVERVIEW = "overview",
|
||||
WALLET = "wallet",
|
||||
ACCOUNT = "account",
|
||||
USER_ACCOUNT = "user-account",
|
||||
}
|
||||
|
||||
export interface SidebarSubItem {
|
||||
|
||||
@@ -31,6 +31,7 @@ export interface PlatformConfig {
|
||||
facebook_description?: string; // facebook description
|
||||
facebook_image_url?: string; // facebook image url
|
||||
meta_description?: string; // meta description
|
||||
tag_bar_display?: boolean; // whether to display tags bar
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user