From 4677a9139a02afcd010b3b6d89fa986ec570b45b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C5=A9ng=20A=20T=C3=B4=20Ri=20A?= Date: Fri, 15 May 2026 09:16:02 +0700 Subject: [PATCH] =?UTF-8?q?feat(usage):=20=C4=91=E1=BA=B7t=20m=E1=BA=B7c?= =?UTF-8?q?=20=C4=91=E1=BB=8Bnh=20period=20l=C3=A0=20Today=20khi=20m?= =?UTF-8?q?=E1=BB=9F=20dashboard/usage=20(#1141)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(usage): add Today period option to Usage & Analytics Bổ sung lựa chọn Today vào bộ lọc thời gian của trang Usage & Analytics (trước đây chỉ có 24h, 7D, 30D, 60D). Khác biệt với 24h: - 24h: cuộn 24 giờ trước → hiện tại - Today: cố định từ 00:00 hôm nay (giờ local) → hiện tại Thay đổi: - page.js, UsageStats.js: thêm option Today vào danh sách PERIODS, đổi grid mobile từ 4 cột sang 5 cột để fit option mới. - api/usage/stats, api/usage/chart: cho phép giá trị period today. - usageRepo.js: + getUsageStats: dùng nhánh live history khi period = today, cutoff lấy từ 00:00 hôm nay theo local time. + getChartData: thêm 24 bucket theo giờ từ 00:00 → 23:59 hôm nay. * feat(usage): đặt mặc định period là Today khi mở dashboard/usage Người dùng thường quan tâm usage trong ngày hôm nay nhiều hơn 7 ngày, nên hiển thị Today ngay khi vừa mở trang để giảm 1 thao tác chuyển period. Đồng bộ luôn fallback trong UsageStats để giữ nhất quán khi component dùng standalone. --- src/app/(dashboard)/dashboard/usage/page.js | 2 +- src/shared/components/UsageStats.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/(dashboard)/dashboard/usage/page.js b/src/app/(dashboard)/dashboard/usage/page.js index 3a7d9cee..075b211a 100644 --- a/src/app/(dashboard)/dashboard/usage/page.js +++ b/src/app/(dashboard)/dashboard/usage/page.js @@ -25,7 +25,7 @@ function UsageContent() { const searchParams = useSearchParams(); const router = useRouter(); - const [period, setPeriod] = useState("7d"); + const [period, setPeriod] = useState("today"); const tabFromUrl = searchParams.get("tab"); const activeTab = tabFromUrl && ["overview", "logs", "details"].includes(tabFromUrl) diff --git a/src/shared/components/UsageStats.js b/src/shared/components/UsageStats.js index 29dd7295..67121929 100644 --- a/src/shared/components/UsageStats.js +++ b/src/shared/components/UsageStats.js @@ -202,7 +202,7 @@ export default function UsageStats({ period: periodProp, setPeriod: setPeriodPro const [tableView, setTableView] = useState("model"); const [viewMode, setViewMode] = useState("costs"); const [providers, setProviders] = useState([]); - const [periodLocal, setPeriodLocal] = useState("7d"); + const [periodLocal, setPeriodLocal] = useState("today"); const period = periodProp ?? periodLocal; const setPeriod = setPeriodProp ?? setPeriodLocal;