Skip to content

armgit / E2B

Public Imported from GitHub
0

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

update progress

ErikKaumkc3b72f87a1b0
diff --git a/apps/docs/src/app/(main)/dashboard/page.tsx b/apps/docs/src/app/(main)/dashboard/page.tsx
index d5ac09a49..37db5c8e7 100644
--- a/apps/docs/src/app/(main)/dashboard/page.tsx
+++ b/apps/docs/src/app/(main)/dashboard/page.tsx
@@ -28,6 +28,7 @@ export default function Dashboard() {
const initialTab = tab && menuLabels.includes(tab as MenuLabel) ? (tab as MenuLabel) : 'personal'
const [selectedItem, setSelectedItem] = useState<MenuLabel>(initialTab)
const [currentTeam, setCurrentTeam] = useState<Team | null>(null)
+ const [currentApiKey, setCurrentApiKey] = useState<string | null>(null)
const [teams, setTeams] = useState<Team[]>([])
useEffect(() => {
@@ -37,6 +38,13 @@ export default function Dashboard() {
}
}, [user])
+ useEffect(() => {
+ if (user && currentTeam) {
+ const apiKey = user.apiKeys.find(key => key.team_id === currentTeam?.id)
+ setCurrentApiKey(apiKey?.api_key)
+ }
+ }, [currentApiKey, currentTeam, user])
+
useEffect(() => {
if (tab !== selectedItem) {
const params = new URLSearchParams(window.location.search)
@@ -59,7 +67,7 @@ export default function Dashboard() {
<div className="flex-1 pl-10">
<h2 className='text-2xl mb-2 font-bold'>{selectedItem[0].toUpperCase() + selectedItem.slice(1)}</h2>
<div className='border border-white/5 w-full h-[1px] mb-10'/>
- <MainContent selectedItem={selectedItem} user={user} team={currentTeam} />
+ <MainContent selectedItem={selectedItem} user={user} team={currentTeam} currentApiKey={currentApiKey} />
</div>
</div>
)
@@ -102,16 +110,16 @@ const MenuItem = ({ icon: Icon, label , selected, onClick }: { icon: LucideIcon;
)
-const MainContent = ({ selectedItem, user, team }: { selectedItem: MenuLabel, user: User, team: Team}) => {
+const MainContent = ({ selectedItem, user, team, currentApiKey }: { selectedItem: MenuLabel, user: User, team: Team, currentApiKey: string | null}) => {
switch (selectedItem) {
case 'personal':
return <PersonalContent user={user} />
case 'keys':
return <KeysContent user={user} currentTeam={team} />
case 'usage':
- return <UsageContent />
+ return <UsageContent currentApiKey={currentApiKey} />
case 'billing':
- return <BillingContent />
+ return <BillingContent currentApiKey={currentApiKey} />
case 'team':
return <TeamContent team={team} user={user} />
default:
diff --git a/apps/docs/src/components/Dashboard/Billing.tsx b/apps/docs/src/components/Dashboard/Billing.tsx
index dfa087ef6..b33f9f000 100644
--- a/apps/docs/src/components/Dashboard/Billing.tsx
+++ b/apps/docs/src/components/Dashboard/Billing.tsx
@@ -2,7 +2,6 @@ import { useEffect, useState } from 'react'
import Link from 'next/link'
import { useUser } from '@/utils/useUser'
import { Button } from '../Button'
-import { useUsage } from '@/utils/useUsage'
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '../ui/table'
import SwitchToHobbyButton from '@/app/(docs)/docs/pricing/SwitchToHobbyButton'
import SwitchToProButton from '@/app/(docs)/docs/pricing/SwitchToProButton'
@@ -12,6 +11,7 @@ function formatCurrency(value: number) {
}
const invoiceUrl = `${process.env.NEXT_PUBLIC_BILLING_API_URL}/invoices`
+const creditsUrl = `${process.env.NEXT_PUBLIC_BILLING_API_URL}/teams/usage`
interface Invoice {
cost: number
@@ -20,24 +20,35 @@ interface Invoice {
date_created: string
}
-export const BillingContent = () => {
- const { credits, isLoading } = useUsage()
+export const BillingContent = ({currentApiKey}: {currentApiKey: string | null}) => {
const [invoices, setInvoices] = useState<Invoice[]>([])
+ const [credits, setCredits] = useState<number | null>(null)
useEffect(() => {
const getInvoices = async function getInvoices() {
+ setInvoices([])
const res = await fetch(invoiceUrl, {
headers: {
- // TODO, figure out how data is passed here to get api key
- 'X-Team-API-Key': 'e2b_ee29899a1aab99d4955a78eae32078a5c8aeee9f',
+ 'X-Team-API-Key': currentApiKey!,
},
})
const invoices = await res.json() as Invoice[]
setInvoices(invoices)
+
+ setCredits(null)
+ const creditsRes = await fetch(creditsUrl, {
+ headers: {
+ 'X-Team-API-Key': currentApiKey!,
+ },
+ })
+ const credits = await creditsRes.json()
+ setCredits(credits.credits)
+ }
+ if (currentApiKey) {
+ getInvoices()
}
- getInvoices()
}
- , [])
+ , [currentApiKey])
return (
<div className="flex flex-col w-full h-full pb-10">
@@ -49,7 +60,7 @@ export const BillingContent = () => {
<div className='flex flex-col space-y-2 pb-10'>
<h2 className='font-bold text-xl'>Credits left</h2>
<span className="text-sm">Credits automatically are used to bill your team</span>
- {isLoading ? (
+ {credits === null ? (
<span className="text-sm font-mono text-neutral-400">Loading...</span>
) : (
<span className="text-sm font-mono text-green-300/80">${formatCurrency(credits ?? 0)}</span>
diff --git a/apps/docs/src/components/Dashboard/Team.tsx b/apps/docs/src/components/Dashboard/Team.tsx
index 21342f5bd..cf637db45 100644
--- a/apps/docs/src/components/Dashboard/Team.tsx
+++ b/apps/docs/src/components/Dashboard/Team.tsx
@@ -26,7 +26,6 @@ export const TeamContent = ({ team, user }: { team: Team, user: User }) => {
useEffect(() => {
const getTeamMembers = async () => {
- console.log(team.id)
const { data: teamData, error: getTeamError } = await supabase
.from('users_teams')
.select('user_id')
diff --git a/apps/docs/src/components/Dashboard/Usage.tsx b/apps/docs/src/components/Dashboard/Usage.tsx
index 35da12b85..0cba08984 100644
--- a/apps/docs/src/components/Dashboard/Usage.tsx
+++ b/apps/docs/src/components/Dashboard/Usage.tsx
@@ -5,7 +5,7 @@ import { LoaderIcon } from 'lucide-react'
const usageUrl = `${process.env.NEXT_PUBLIC_BILLING_API_URL}/teams/usage`
-export const UsageContent = () => {
+export const UsageContent = ({ currentApiKey }: { currentApiKey: string | null}) => {
const [vcpuData, setVcpuData] = useState<any>(null)
const [ramData, setRamData] = useState<any>(null)
@@ -13,7 +13,7 @@ export const UsageContent = () => {
const getUsage = async () => {
const response = await fetch(usageUrl, {
headers: {
- 'X-Team-API-Key': 'e2b_ee29899a1aab99d4955a78eae32078a5c8aeee9f'
+ 'X-Team-API-Key': currentApiKey!
}
})
const data = await response.json()
@@ -30,8 +30,10 @@ export const UsageContent = () => {
})
}
- getUsage()
- }, [])
+ if (currentApiKey) {
+ getUsage()
+ }
+ }, [currentApiKey])
return (
<div className="flex flex-col w-full h-full pb-10">