feat: 1.4 - List supports search
This commit is contained in:
1 parent
f592178d83
commit
14e6b5c23b
16 files changed
+551
-49
No files matched your search
@@ -10,7 +10,9 @@ import {
|
||||
Listbox,
|
||||
ListboxItem,
|
||||
Skeleton,
|
||||
DateRangePicker
|
||||
} from "@nextui-org/react";
|
||||
import { parseDate } from "@internationalized/date";
|
||||
import { useTranslation } from "@/shared/lib/useTranslation";
|
||||
import {
|
||||
LineChart,
|
||||
@@ -60,9 +62,9 @@ const transformToChartData = (
|
||||
userRegDay?.stats_day || payDay?.stats_day || callDay?.stats_day;
|
||||
const formattedDate = rawDate
|
||||
? new Date(rawDate).toLocaleDateString("en-US", {
|
||||
month: "short",
|
||||
day: "numeric",
|
||||
})
|
||||
month: "short",
|
||||
day: "numeric",
|
||||
})
|
||||
: `Day ${i + 1}`;
|
||||
|
||||
chartData.push({
|
||||
@@ -99,12 +101,114 @@ const ConsoleStats: React.FC = () => {
|
||||
);
|
||||
const [loading, setLoading] = useState(true);
|
||||
|
||||
// Fetch analytics data on component mount
|
||||
// 日期范围状态 - 默认最近30天
|
||||
const [dateRange, setDateRange] = useState<any>(() => {
|
||||
const today = new Date();
|
||||
const thirtyDaysAgo = new Date();
|
||||
thirtyDaysAgo.setDate(today.getDate() - 29);
|
||||
|
||||
// 格式化为 YYYY-MM-DD
|
||||
const formatDate = (date: Date) => {
|
||||
const year = date.getFullYear();
|
||||
const month = String(date.getMonth() + 1).padStart(2, '0');
|
||||
const day = String(date.getDate()).padStart(2, '0');
|
||||
return `${year}-${month}-${day}`;
|
||||
};
|
||||
|
||||
return {
|
||||
start: parseDate(formatDate(thirtyDaysAgo)),
|
||||
end: parseDate(formatDate(today)),
|
||||
};
|
||||
});
|
||||
|
||||
// 计算最早可选日期(30天前)
|
||||
const minValue = useMemo(() => {
|
||||
const date = new Date();
|
||||
date.setDate(date.getDate() - 30);
|
||||
const year = date.getFullYear();
|
||||
const month = String(date.getMonth() + 1).padStart(2, '0');
|
||||
const day = String(date.getDate()).padStart(2, '0');
|
||||
return parseDate(`${year}-${month}-${day}`);
|
||||
}, []);
|
||||
|
||||
// 计算最大可选日期(今天)
|
||||
const maxValue = useMemo(() => {
|
||||
const date = new Date();
|
||||
const year = date.getFullYear();
|
||||
const month = String(date.getMonth() + 1).padStart(2, '0');
|
||||
const day = String(date.getDate()).padStart(2, '0');
|
||||
return parseDate(`${year}-${month}-${day}`);
|
||||
}, []);
|
||||
|
||||
// 校验:开始日期必须早于结束日期,且不能早于30天前
|
||||
const dateValidation = useMemo(() => {
|
||||
if (!dateRange?.start || !dateRange?.end) {
|
||||
return { isInvalid: false, error: "" };
|
||||
}
|
||||
|
||||
const start = dateRange.start;
|
||||
const end = dateRange.end;
|
||||
const minDate = minValue;
|
||||
|
||||
// 检查开始日期是否早于30天前
|
||||
const isStartTooEarly =
|
||||
start.year < minDate.year ||
|
||||
(start.year === minDate.year && start.month < minDate.month) ||
|
||||
(start.year === minDate.year && start.month === minDate.month && start.day < minDate.day);
|
||||
|
||||
if (isStartTooEarly) {
|
||||
return {
|
||||
isInvalid: true,
|
||||
error: t("Start date cannot be earlier than 30 days ago")
|
||||
};
|
||||
}
|
||||
|
||||
// 检查开始日期是否晚于结束日期
|
||||
const isEndBeforeStart =
|
||||
start.year > end.year ||
|
||||
(start.year === end.year && start.month > end.month) ||
|
||||
(start.year === end.year && start.month === end.month && start.day >= end.day);
|
||||
|
||||
if (isEndBeforeStart) {
|
||||
return {
|
||||
isInvalid: true,
|
||||
error: t("Start date must be before end date")
|
||||
};
|
||||
}
|
||||
|
||||
return { isInvalid: false, error: "" };
|
||||
}, [dateRange, minValue, t]);
|
||||
|
||||
// 错误消息
|
||||
const errorMessage = dateValidation.error;
|
||||
const isInvalidDateRange = dateValidation.isInvalid;
|
||||
|
||||
// Fetch analytics data on component mount and when date range changes
|
||||
useEffect(() => {
|
||||
const fetchData = async () => {
|
||||
if (!dateRange?.start || !dateRange?.end) return;
|
||||
|
||||
// 如果日期范围无效,不发送请求
|
||||
if (isInvalidDateRange) {
|
||||
setLoading(false);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
setLoading(true);
|
||||
const response = await getAdminAnalytics();
|
||||
|
||||
// parseDate 返回的对象有 year, month, day 属性
|
||||
const start = dateRange.start;
|
||||
const end = dateRange.end;
|
||||
|
||||
// 转换日期为时间戳(秒)
|
||||
const startDateTime = new Date(start.year, start.month - 1, start.day, 0, 0, 0);
|
||||
const startTime = Math.floor(startDateTime.getTime() / 1000);
|
||||
|
||||
const endDateTime = new Date(end.year, end.month - 1, end.day, 23, 59, 59);
|
||||
const endTime = Math.floor(endDateTime.getTime() / 1000);
|
||||
|
||||
const response = await getAdminAnalytics(startTime, endTime);
|
||||
|
||||
if (response.success) {
|
||||
setAnalyticsData(response.data);
|
||||
@@ -113,14 +217,15 @@ const ConsoleStats: React.FC = () => {
|
||||
response.error_message || "Failed to load analytics data"
|
||||
);
|
||||
}
|
||||
} catch (err) {
|
||||
} catch {
|
||||
toast.error("Failed to load analytics data");
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
fetchData();
|
||||
}, []);
|
||||
}, [dateRange, isInvalidDateRange]);
|
||||
|
||||
// Transform API data to chart format
|
||||
const chartData = useMemo<ChartDataItem[]>(() => {
|
||||
@@ -156,6 +261,24 @@ const ConsoleStats: React.FC = () => {
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
{/* 日期范围选择器 */}
|
||||
<div className="flex justify-end">
|
||||
<DateRangePicker
|
||||
label={t("Select Date Range")}
|
||||
value={dateRange}
|
||||
onChange={setDateRange}
|
||||
minValue={minValue}
|
||||
maxValue={maxValue}
|
||||
isInvalid={isInvalidDateRange}
|
||||
errorMessage={errorMessage}
|
||||
onKeyDown={(e) => e.preventDefault()}
|
||||
onKeyUp={(e) => e.preventDefault()}
|
||||
className="w-[250px]"
|
||||
visibleMonths={2}
|
||||
granularity="day"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Charts with Tabs */}
|
||||
<Card shadow="none" className="border-1">
|
||||
<CardHeader className="p-0 flex items-center justify-between">
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import React, { useState, useCallback, useEffect } from "react";
|
||||
import React, { useState, useCallback, useEffect, useRef } from "react";
|
||||
import { useSearchParams } from "next/navigation";
|
||||
import { useMCPServicesList } from "@/hooks/useMCPServicesList";
|
||||
import { MCPService, MCPServiceFormData } from "@/shared/types/mcp-service";
|
||||
@@ -12,6 +12,8 @@ import { DeleteConfirmModal } from "@/shared/components/modal/DeleteConfirmModal
|
||||
import DashboardDemoContent from "@/shared/components/DashboardDemoContent";
|
||||
import { ServiceTable } from "@/shared/components/mcp-services/ServiceTable";
|
||||
import { OpenAPIGeneratorModal } from "@/shared/components/mcp-services/OpenAPIGeneratorModal";
|
||||
import { Input } from "@nextui-org/react";
|
||||
import { Search } from "lucide-react";
|
||||
|
||||
type ViewMode = "list" | "edit" | "create";
|
||||
|
||||
@@ -30,9 +32,24 @@ export const MCPServicesManagement: React.FC = () => {
|
||||
toggleServiceStatus,
|
||||
parseOpenAPIDocument,
|
||||
loadServices,
|
||||
setSearchTerm,
|
||||
setStatusFilter,
|
||||
} = useMCPServicesList();
|
||||
const [addServiceType, setAddServiceType] = useState<string | null>(null);
|
||||
|
||||
// 搜索相关状态
|
||||
const [searchValue, setSearchValue] = useState('');
|
||||
const searchTimerRef = useRef<NodeJS.Timeout | null>(null);
|
||||
|
||||
// 清理定时器
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
if (searchTimerRef.current) {
|
||||
clearTimeout(searchTimerRef.current);
|
||||
}
|
||||
};
|
||||
}, []);
|
||||
|
||||
// Get initial state from URL
|
||||
const getInitialViewMode = (): ViewMode => {
|
||||
const mode = searchParams.get("mode") as ViewMode;
|
||||
@@ -190,6 +207,26 @@ export const MCPServicesManagement: React.FC = () => {
|
||||
setServiceToDelete(null);
|
||||
}, []);
|
||||
|
||||
// 处理搜索 - 使用防抖
|
||||
const handleSearchChange = useCallback((value: string) => {
|
||||
setSearchValue(value);
|
||||
|
||||
// 清除之前的定时器
|
||||
if (searchTimerRef.current) {
|
||||
clearTimeout(searchTimerRef.current);
|
||||
}
|
||||
|
||||
// 设置新的定时器,500ms 后触发搜索
|
||||
searchTimerRef.current = setTimeout(() => {
|
||||
setSearchTerm(value);
|
||||
}, 500);
|
||||
}, [setSearchTerm]);
|
||||
|
||||
// 处理状态筛选
|
||||
const handleStatusFilterChange = useCallback((status: string) => {
|
||||
setStatusFilter(status);
|
||||
}, [setStatusFilter]);
|
||||
|
||||
// Render edit page if in edit/create mode
|
||||
if (viewMode === "edit" || viewMode === "create") {
|
||||
return (
|
||||
@@ -214,8 +251,27 @@ export const MCPServicesManagement: React.FC = () => {
|
||||
)}
|
||||
>
|
||||
<div className="space-y-6 w-full">
|
||||
{/* comming soon:Filters and Actions */}
|
||||
<ServiceFiltersBar onAddService={handleCreateService} />
|
||||
{/* Filters and Actions */}
|
||||
<div className="flex justify-between items-center gap-4">
|
||||
<ServiceFiltersBar onAddService={handleCreateService} />
|
||||
|
||||
{/* 搜索框 - 右侧 */}
|
||||
<Input
|
||||
isClearable
|
||||
className="w-full sm:max-w-[400px]"
|
||||
placeholder={t('Search by service name')}
|
||||
startContent={<Search className="w-4 h-4" />}
|
||||
value={searchValue}
|
||||
onClear={() => {
|
||||
setSearchValue('');
|
||||
if (searchTimerRef.current) {
|
||||
clearTimeout(searchTimerRef.current);
|
||||
}
|
||||
setSearchTerm('');
|
||||
}}
|
||||
onValueChange={handleSearchChange}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Servers Table */}
|
||||
<ServiceTable
|
||||
@@ -226,6 +282,7 @@ export const MCPServicesManagement: React.FC = () => {
|
||||
onDelete={handleDeleteService}
|
||||
onToggleStatus={handleToggleStatus}
|
||||
onPageChange={onPageChange}
|
||||
onStatusFilterChange={handleStatusFilterChange}
|
||||
/>
|
||||
|
||||
{/* Modals */}
|
||||
|
||||
@@ -10,6 +10,7 @@ import { DeleteServerModal } from "./DeleteServerModal";
|
||||
import { Divider, Select, SelectItem } from "@nextui-org/react";
|
||||
import { useResourceGroups } from "@/hooks/useResourceGroups";
|
||||
import { AddMcpServerModal } from "./AddMcpServerModal";
|
||||
import toast from "react-hot-toast";
|
||||
|
||||
const ResourceGroupManagement: React.FC = () => {
|
||||
const { t } = useTranslation();
|
||||
@@ -99,19 +100,43 @@ const ResourceGroupManagement: React.FC = () => {
|
||||
|
||||
// 保存组(创建或编辑)
|
||||
const handleSaveGroup = async (name: string, isDefault: boolean) => {
|
||||
// 去除首尾空格
|
||||
const trimmedName = name.trim();
|
||||
|
||||
// 验证保留名称(不区分大小写)
|
||||
const reservedNames = ['allow all', 'deny all'];
|
||||
if (reservedNames.some(reserved => reserved.toLowerCase() === trimmedName.toLowerCase())) {
|
||||
toast.error(t('Resource group name "{{name}}" is reserved and cannot be used', { name: trimmedName }));
|
||||
return;
|
||||
}
|
||||
|
||||
// 验证名称是否重复
|
||||
const isDuplicate = groups.some(group => {
|
||||
// 编辑时排除当前组
|
||||
if (editingGroup && group.id === editingGroup.id) {
|
||||
return false;
|
||||
}
|
||||
return group.name.toLowerCase() === trimmedName.toLowerCase();
|
||||
});
|
||||
|
||||
if (isDuplicate) {
|
||||
toast.error(t('Resource group name "{{name}}" already exists', { name: trimmedName }));
|
||||
return;
|
||||
}
|
||||
|
||||
let success = false;
|
||||
|
||||
if (editingGroup) {
|
||||
// 编辑现有组
|
||||
success = await updateGroup(editingGroup.id, name, isDefault);
|
||||
success = await updateGroup(editingGroup.id, trimmedName, isDefault);
|
||||
if (success && selectedGroup?.id === editingGroup.id) {
|
||||
setSelectedGroup({ ...selectedGroup, name, isDefault });
|
||||
setSelectedGroup({ ...selectedGroup, name: trimmedName, isDefault });
|
||||
// 触发 GroupServiceTable 刷新
|
||||
setRefreshTrigger(prev => prev + 1);
|
||||
}
|
||||
} else {
|
||||
// 创建新组
|
||||
const newGroupId = await createGroup(name, isDefault);
|
||||
const newGroupId = await createGroup(trimmedName, isDefault);
|
||||
success = !!newGroupId;
|
||||
if (newGroupId) {
|
||||
setNewGroupId(newGroupId);
|
||||
|
||||
@@ -1,13 +1,52 @@
|
||||
"use client";
|
||||
|
||||
import React from "react";
|
||||
import React, { useState, useRef, useEffect } from "react";
|
||||
import { RevenueTable } from "./RevenueTable";
|
||||
import DashboardDemoContent from "@/shared/components/DashboardDemoContent";
|
||||
import { useRevenueManagement } from "@/hooks/useRevenueManagement";
|
||||
import { Input } from "@nextui-org/react";
|
||||
import { Search } from "lucide-react";
|
||||
import { useTranslation } from "@/shared/lib/useTranslation";
|
||||
|
||||
const RevenueManagement: React.FC = () => {
|
||||
const { t } = useTranslation();
|
||||
// use custom hook to manage revenue data
|
||||
const { records, loading, pagination, setPage } = useRevenueManagement();
|
||||
const {
|
||||
records,
|
||||
loading,
|
||||
pagination,
|
||||
setPage,
|
||||
setSearch,
|
||||
setPaymentType,
|
||||
setSort
|
||||
} = useRevenueManagement();
|
||||
|
||||
const [searchValue, setSearchValue] = useState('');
|
||||
const searchTimerRef = useRef<NodeJS.Timeout | null>(null);
|
||||
|
||||
// 清理定时器
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
if (searchTimerRef.current) {
|
||||
clearTimeout(searchTimerRef.current);
|
||||
}
|
||||
};
|
||||
}, []);
|
||||
|
||||
// 处理搜索 - 使用防抖
|
||||
const handleSearchChange = (value: string) => {
|
||||
setSearchValue(value);
|
||||
|
||||
// 清除之前的定时器
|
||||
if (searchTimerRef.current) {
|
||||
clearTimeout(searchTimerRef.current);
|
||||
}
|
||||
|
||||
// 设置新的定时器,500ms 后触发搜索
|
||||
searchTimerRef.current = setTimeout(() => {
|
||||
setSearch(value);
|
||||
}, 500);
|
||||
};
|
||||
|
||||
return (
|
||||
<DashboardDemoContent
|
||||
@@ -15,13 +54,24 @@ const RevenueManagement: React.FC = () => {
|
||||
description="Monitor platform revenue and view user recharge history"
|
||||
>
|
||||
<div className="space-y-6 w-full">
|
||||
{/* comming soon:Filters */}
|
||||
{/* <RevenueFiltersBar
|
||||
searchQuery={searchQuery}
|
||||
onSearchChange={setSearch}
|
||||
statusFilter={statusFilter}
|
||||
onStatusChange={setStatus}
|
||||
/> */}
|
||||
{/* 搜索框 - 右上角 */}
|
||||
<div className="flex justify-end items-center gap-4">
|
||||
<Input
|
||||
isClearable
|
||||
className="w-full sm:max-w-[400px]"
|
||||
placeholder={t('Search by email')}
|
||||
startContent={<Search className="w-4 h-4" />}
|
||||
value={searchValue}
|
||||
onClear={() => {
|
||||
setSearchValue('');
|
||||
if (searchTimerRef.current) {
|
||||
clearTimeout(searchTimerRef.current);
|
||||
}
|
||||
setSearch('');
|
||||
}}
|
||||
onValueChange={handleSearchChange}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Revenue Table */}
|
||||
<RevenueTable
|
||||
@@ -29,6 +79,8 @@ const RevenueManagement: React.FC = () => {
|
||||
loading={loading}
|
||||
pagination={pagination}
|
||||
onPageChange={setPage}
|
||||
onPaymentTypeChange={setPaymentType}
|
||||
onSortChange={setSort}
|
||||
/>
|
||||
</div>
|
||||
</DashboardDemoContent>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import React from 'react';
|
||||
import React, { useState } from 'react';
|
||||
import {
|
||||
Table,
|
||||
TableHeader,
|
||||
@@ -11,11 +11,16 @@ import {
|
||||
Pagination,
|
||||
Chip,
|
||||
Spinner,
|
||||
Tooltip
|
||||
Tooltip,
|
||||
Dropdown,
|
||||
DropdownTrigger,
|
||||
DropdownMenu,
|
||||
DropdownItem,
|
||||
Button
|
||||
} from '@nextui-org/react';
|
||||
import { useTranslation } from '@/shared/lib/useTranslation';
|
||||
import { PaymentState, RevenueRecord } from '@/types/revenue';
|
||||
import { Calendar, CreditCard, HelpCircle } from 'lucide-react';
|
||||
import { Calendar, CreditCard, HelpCircle, Filter, ArrowUpDown, ArrowUp, ArrowDown } from 'lucide-react';
|
||||
import { formatCurrency } from '@/shared/utils/currency';
|
||||
|
||||
interface RevenueTableProps {
|
||||
@@ -27,6 +32,8 @@ interface RevenueTableProps {
|
||||
total: number;
|
||||
};
|
||||
onPageChange: (page: number) => void;
|
||||
onPaymentTypeChange?: (paymentType: string) => void;
|
||||
onSortChange?: (field: string | undefined, order: 'asc' | 'desc' | undefined) => void;
|
||||
}
|
||||
|
||||
export const RevenueTable: React.FC<RevenueTableProps> = ({
|
||||
@@ -34,8 +41,12 @@ export const RevenueTable: React.FC<RevenueTableProps> = ({
|
||||
loading = false,
|
||||
pagination,
|
||||
onPageChange,
|
||||
onPaymentTypeChange,
|
||||
onSortChange,
|
||||
}) => {
|
||||
const { t } = useTranslation();
|
||||
const [selectedPaymentType, setSelectedPaymentType] = useState('all');
|
||||
const [sortState, setSortState] = useState<'none' | 'desc' | 'asc'>('none');
|
||||
|
||||
const pages = Math.ceil(pagination.total / pagination.pageSize);
|
||||
const currentPage = pagination.page;
|
||||
@@ -92,6 +103,35 @@ export const RevenueTable: React.FC<RevenueTableProps> = ({
|
||||
);
|
||||
};
|
||||
|
||||
// 处理付款方式筛选
|
||||
const handlePaymentTypeChange = (type: string) => {
|
||||
setSelectedPaymentType(type);
|
||||
onPaymentTypeChange?.(type);
|
||||
};
|
||||
|
||||
// 处理排序
|
||||
const handleSortClick = () => {
|
||||
let newSortState: 'none' | 'desc' | 'asc';
|
||||
if (sortState === 'none') {
|
||||
newSortState = 'desc';
|
||||
onSortChange?.('amount', 'desc');
|
||||
} else if (sortState === 'desc') {
|
||||
newSortState = 'asc';
|
||||
onSortChange?.('amount', 'asc');
|
||||
} else {
|
||||
newSortState = 'none';
|
||||
onSortChange?.(undefined, undefined);
|
||||
}
|
||||
setSortState(newSortState);
|
||||
};
|
||||
|
||||
// 获取排序图标
|
||||
const getSortIcon = () => {
|
||||
if (sortState === 'desc') return <ArrowDown className="w-4 h-4" />;
|
||||
if (sortState === 'asc') return <ArrowUp className="w-4 h-4" />;
|
||||
return <ArrowUpDown className="w-4 h-4" />;
|
||||
};
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
<div className="flex justify-center items-center h-64">
|
||||
@@ -122,7 +162,20 @@ export const RevenueTable: React.FC<RevenueTableProps> = ({
|
||||
>
|
||||
<TableHeader>
|
||||
<TableColumn>{t('Account (Email)')}</TableColumn>
|
||||
<TableColumn>{t('Recharge Amount')}</TableColumn>
|
||||
<TableColumn>
|
||||
<div className="flex items-center gap-2">
|
||||
<span>{t('Recharge Amount')}</span>
|
||||
<Button
|
||||
isIconOnly
|
||||
size="sm"
|
||||
variant="light"
|
||||
onPress={handleSortClick}
|
||||
className="min-w-unit-6 w-6 h-6"
|
||||
>
|
||||
{getSortIcon()}
|
||||
</Button>
|
||||
</div>
|
||||
</TableColumn>
|
||||
<TableColumn>
|
||||
<div className="flex items-center gap-1">
|
||||
<span>{t('Recharge Time')}</span>
|
||||
@@ -136,7 +189,41 @@ export const RevenueTable: React.FC<RevenueTableProps> = ({
|
||||
</Tooltip>
|
||||
</div>
|
||||
</TableColumn>
|
||||
<TableColumn>{t('Payment Method')}</TableColumn>
|
||||
<TableColumn>
|
||||
<div className="flex items-center gap-2">
|
||||
<span>{t('Payment Method')}</span>
|
||||
<Dropdown>
|
||||
<DropdownTrigger>
|
||||
<Button
|
||||
isIconOnly
|
||||
size="sm"
|
||||
variant="light"
|
||||
aria-label="Filter by payment method"
|
||||
className="min-w-unit-6 w-6 h-6"
|
||||
>
|
||||
<Filter
|
||||
className={`w-4 h-4 ${
|
||||
selectedPaymentType !== 'all' ? 'text-primary' : ''
|
||||
}`}
|
||||
/>
|
||||
</Button>
|
||||
</DropdownTrigger>
|
||||
<DropdownMenu
|
||||
aria-label="Payment method filter"
|
||||
selectionMode="single"
|
||||
selectedKeys={[selectedPaymentType]}
|
||||
onSelectionChange={(keys) => {
|
||||
const selected = Array.from(keys)[0] as string;
|
||||
handlePaymentTypeChange(selected);
|
||||
}}
|
||||
>
|
||||
<DropdownItem key="all">{t('All')}</DropdownItem>
|
||||
<DropdownItem key="stripe">Stripe</DropdownItem>
|
||||
<DropdownItem key="platform">Platform</DropdownItem>
|
||||
</DropdownMenu>
|
||||
</Dropdown>
|
||||
</div>
|
||||
</TableColumn>
|
||||
<TableColumn>{t('Transaction ID')}</TableColumn>
|
||||
<TableColumn>{t('Status')}</TableColumn>
|
||||
</TableHeader>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import React, { useState, useCallback } from "react";
|
||||
import React, { useState, useCallback, useRef, useEffect } from "react";
|
||||
import { useTranslation } from "@/shared/lib/useTranslation";
|
||||
import { User } from "@/types/user";
|
||||
import { UserTable } from "./UserTable";
|
||||
@@ -8,6 +8,8 @@ import { DeleteConfirmModal } from "@/shared/components/modal/DeleteConfirmModal
|
||||
import DashboardDemoContent from "@/shared/components/DashboardDemoContent";
|
||||
import { useUserManagement } from "@/hooks/useUserManagement";
|
||||
import { UserBalanceDetail } from "./UserBalanceDetail";
|
||||
import { Input } from "@nextui-org/react";
|
||||
import { Search } from "lucide-react";
|
||||
|
||||
type ViewMode = "list" | "detail";
|
||||
|
||||
@@ -23,6 +25,7 @@ const UserManagement: React.FC = () => {
|
||||
handleDeleteUser,
|
||||
setPage,
|
||||
handleRechargeUser,
|
||||
setSearch,
|
||||
} = useUserManagement();
|
||||
|
||||
// Modal states
|
||||
@@ -35,6 +38,19 @@ const UserManagement: React.FC = () => {
|
||||
const [selectedUserId, setSelectedUserId] = useState<string | null>(null);
|
||||
const [selectedUserEmail, setSelectedUserEmail] = useState<string | null>(null);
|
||||
|
||||
// 搜索相关状态
|
||||
const [searchValue, setSearchValue] = useState('');
|
||||
const searchTimerRef = useRef<NodeJS.Timeout | null>(null);
|
||||
|
||||
// 清理定时器
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
if (searchTimerRef.current) {
|
||||
clearTimeout(searchTimerRef.current);
|
||||
}
|
||||
};
|
||||
}, []);
|
||||
|
||||
|
||||
const handleDeleteUserClick = useCallback((user: User) => {
|
||||
setDeleteModal({
|
||||
@@ -81,6 +97,21 @@ const UserManagement: React.FC = () => {
|
||||
[handleRechargeUser]
|
||||
);
|
||||
|
||||
// 处理搜索 - 使用防抖
|
||||
const handleSearchChange = useCallback((value: string) => {
|
||||
setSearchValue(value);
|
||||
|
||||
// 清除之前的定时器
|
||||
if (searchTimerRef.current) {
|
||||
clearTimeout(searchTimerRef.current);
|
||||
}
|
||||
|
||||
// 设置新的定时器,500ms 后触发搜索
|
||||
searchTimerRef.current = setTimeout(() => {
|
||||
setSearch(value);
|
||||
}, 500);
|
||||
}, [setSearch]);
|
||||
|
||||
if (viewMode === "detail" ) {
|
||||
return (
|
||||
<UserBalanceDetail
|
||||
@@ -99,6 +130,25 @@ const UserManagement: React.FC = () => {
|
||||
)}
|
||||
>
|
||||
<div className="space-y-6 w-full">
|
||||
{/* 搜索框 - 右上角 */}
|
||||
<div className="flex justify-end items-center gap-4">
|
||||
<Input
|
||||
isClearable
|
||||
className="w-full sm:max-w-[400px]"
|
||||
placeholder={t('Search by email')}
|
||||
startContent={<Search className="w-4 h-4" />}
|
||||
value={searchValue}
|
||||
onClear={() => {
|
||||
setSearchValue('');
|
||||
if (searchTimerRef.current) {
|
||||
clearTimeout(searchTimerRef.current);
|
||||
}
|
||||
setSearch('');
|
||||
}}
|
||||
onValueChange={handleSearchChange}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<UserTable
|
||||
users={users}
|
||||
fetchUsers={fetchUsers}
|
||||
|
||||
Reference in new issue
Block a user