From bfbfbfb823dd96f3f08454081bf06e7e31ae2853 Mon Sep 17 00:00:00 2001 From: Adam Cohen Hillel Date: Tue, 22 Apr 2025 17:15:29 +0100 Subject: [PATCH] fix frontend time calculation --- .../components/basejump/account-billing-status.tsx | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/frontend/src/components/basejump/account-billing-status.tsx b/frontend/src/components/basejump/account-billing-status.tsx index c762908f..19227a74 100644 --- a/frontend/src/components/basejump/account-billing-status.tsx +++ b/frontend/src/components/basejump/account-billing-status.tsx @@ -35,10 +35,19 @@ export default async function AccountBillingStatus({ accountId, returnUrl }: Pro const startOfMonth = new Date(); startOfMonth.setDate(1); startOfMonth.setHours(0, 0, 0, 0); + // First get threads for this account + const { data: threadsData } = await supabaseClient + .from('threads') + .select('thread_id') + .eq('account_id', accountId); + const threadIds = threadsData?.map(t => t.thread_id) || []; + + // Then get agent runs for those threads const { data: agentRunData, error: agentRunError } = await supabaseClient .from('agent_runs') .select('started_at, completed_at') + .in('thread_id', threadIds) .gte('started_at', startOfMonth.toISOString()); let totalSeconds = 0; @@ -52,7 +61,7 @@ export default async function AccountBillingStatus({ accountId, returnUrl }: Pro } const hours = Math.floor(totalSeconds / 3600); - const minutes = Math.floor((totalSeconds % 3600) / 60); + const minutes = Math.floor((totalSeconds % 3600) / 60); const seconds = Math.floor(totalSeconds % 60); const usageDisplay = `${hours}h ${minutes}m ${seconds}s`;