From e90f5ccea3fcda290cb8051c51858f8910eb7af4 Mon Sep 17 00:00:00 2001 From: Jonas Daniels Date: Wed, 4 Jun 2025 02:05:13 -0700 Subject: [PATCH] [Dashboard] Fix peak rate date formatting with error handling --- .../[team_slug]/(team)/~/usage/rpc/page.tsx | 39 +++++++++++++------ 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/apps/dashboard/src/app/(app)/team/[team_slug]/(team)/~/usage/rpc/page.tsx b/apps/dashboard/src/app/(app)/team/[team_slug]/(team)/~/usage/rpc/page.tsx index a62bbb96750..ab0d7032fa8 100644 --- a/apps/dashboard/src/app/(app)/team/[team_slug]/(team)/~/usage/rpc/page.tsx +++ b/apps/dashboard/src/app/(app)/team/[team_slug]/(team)/~/usage/rpc/page.tsx @@ -2,7 +2,7 @@ import { getTeamBySlug } from "@/api/team"; import { getLast24HoursRPCUsage } from "@/api/usage/rpc"; import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; -import { format } from "date-fns"; +import { format, parseISO } from "date-fns"; import { AlertTriangleIcon, CheckCircleIcon, @@ -63,6 +63,23 @@ export default async function RPCUsage(props: { Number(totalCounts.rateLimitedCount) + Number(totalCounts.overageCount); + const peakRateDate = (() => { + if (peakRate.date) { + try { + // treat peakRate.date as UTC + const date = peakRate.date.endsWith("Z") + ? parseISO(peakRate.date) + : // force the timestamp to be in UTC + parseISO(`${peakRate.date}Z`); + return format(date, "MMM d, HH:mm"); + } catch (e) { + console.error("Error parsing peak rate date", peakRate.date, e); + return null; + } + } + return null; + })(); + return (
@@ -113,9 +130,7 @@ export default async function RPCUsage(props: {

- {peakRate.date - ? format(new Date(`${peakRate.date}Z`), "MMM d, HH:mm") - : "No Requests in last 24 hours"} + {peakRateDate ? peakRateDate : "No Requests in last 24 hours"}

@@ -134,12 +149,14 @@ export default async function RPCUsage(props: { {/* we count both included and overage as included */} - {( - ((Number(totalCounts.includedCount) + - Number(totalCounts.overageCount)) / - Number(totalRequests)) * - 100 - ).toFixed(1)} + {totalRequests === 0 + ? "0.0" + : ( + ((Number(totalCounts.includedCount) + + Number(totalCounts.overageCount)) / + Number(totalRequests)) * + 100 + ).toFixed(1)} % successful requests
@@ -159,7 +176,7 @@ export default async function RPCUsage(props: { {/* if there are no requests, we show 100% success rate */} {totalRequests === 0 - ? "100" + ? "0.0" : ( (Number(totalCounts.rateLimitedCount) / Number(totalRequests)) *