Skip to content

armgit / E2B

Public Imported from GitHub
0

Open-source, secure environment with real-world tools for enterprise-grade agents.

add cost chart as well

ErikKaumk5bcf5ba778c3
diff --git a/apps/docs/src/components/Dashboard/Usage.tsx b/apps/docs/src/components/Dashboard/Usage.tsx
index 95c448cac..d10ef356f 100644
--- a/apps/docs/src/components/Dashboard/Usage.tsx
+++ b/apps/docs/src/components/Dashboard/Usage.tsx
@@ -2,13 +2,15 @@ import { useEffect, useState } from 'react'
import { Card, CardContent } from '../ui/card'
import { LoaderIcon } from 'lucide-react'
import LineChart from './Chart'
+import { MonthlyCosts, useUsage } from '@/utils/useUsage'
const usageUrl = `${process.env.NEXT_PUBLIC_BILLING_API_URL}/teams/usage`
export const UsageContent = ({ currentApiKey }: { currentApiKey: string | null}) => {
const [vcpuData, setVcpuData] = useState<any>(null)
const [ramData, setRamData] = useState<any>(null)
-
+ const { usage: costUsage } = useUsage()
+
useEffect(() => {
const getUsage = async (apiKey: string) => {
setVcpuData(null)
@@ -37,6 +39,7 @@ export const UsageContent = ({ currentApiKey }: { currentApiKey: string | null})
}
}, [currentApiKey])
+
return (
<div className="flex flex-col w-full h-full pb-10">
<div className='pb-10'>
@@ -46,7 +49,7 @@ export const UsageContent = ({ currentApiKey }: { currentApiKey: string | null})
</p>
</div>
- {vcpuData && ramData ? (
+ {vcpuData && ramData && costUsage ? (
<div className='flex flex-col 2xl:flex-row w-full space-y-4 2xl:space-y-0 2xl:space-x-4'>
<div className='flex flex-col w-full md:w-2/3'>
@@ -67,6 +70,15 @@ export const UsageContent = ({ currentApiKey }: { currentApiKey: string | null})
</Card>
</div>
+ <div className='flex flex-col w-full md:w-2/3'>
+ <h2 className='font-bold pb-4 text-xl'>Cost</h2>
+ <Card className="w-full bg-inherit/10 border border-white/20 mb-10">
+ <CardContent>
+ <LineChart className="aspect-[4/3]" series={transformCostData(costUsage)} type="Cost" />
+ </CardContent>
+ </Card>
+ </div>
+
</div>
) : (
<div className='flex items-center justify-center w-2/3'>
@@ -77,6 +89,23 @@ export const UsageContent = ({ currentApiKey }: { currentApiKey: string | null})
)
}
+const transformCostData = (costUsage: MonthlyCosts[]) => {
+ const costData = costUsage.map((usage: any) => {
+ return {
+ x: `${String(usage.month).padStart(2, '0')}/${usage.year}`,
+ y: usage.template_usage.length > 0
+ ? usage.template_usage.reduce((acc: number, template: any) => acc + template.sandbox_hours, 0)
+ : 0,
+ }
+ })
+
+ return [
+ {
+ id: 'Cost',
+ data: costData,
+ },
+ ]
+}
const transformData = (usages: any) => {
const ramData = usages.map((usage: any) => {