Skip to content

Commit

Permalink
Query correct team for templates
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubno committed Nov 20, 2024
1 parent dbf9f60 commit b493a57
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
2 changes: 1 addition & 1 deletion apps/web/src/app/(dashboard)/dashboard/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ function MainContent({
case 'sandboxes':
return <SandboxesContent team={team} />
case 'templates':
return <TemplatesContent user={user} />
return <TemplatesContent user={user} teamId={team.id} />
case 'usage':
return <UsageContent team={team} />
case 'billing':
Expand Down
25 changes: 17 additions & 8 deletions apps/web/src/components/Dashboard/Templates.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,20 @@ interface Template {
templateID: string
}

export function TemplatesContent({ user }: { user: E2BUser }) {
export function TemplatesContent({
user,
teamId,
}: {
user: E2BUser
teamId: string
}) {
const [templates, setTemplates] = useState<Template[]>([])

useEffect(() => {
function f() {
const apiKey = user.accessToken
if (apiKey) {
fetchTemplates(apiKey).then((newTemplates) => {
const accessToken = user.accessToken
if (accessToken) {
fetchTemplates(accessToken, teamId).then((newTemplates) => {
if (newTemplates) {
setTemplates(newTemplates)
}
Expand All @@ -42,7 +48,7 @@ export function TemplatesContent({ user }: { user: E2BUser }) {
f()
// Cleanup interval on component unmount
return () => clearInterval(interval)
}, [user])
}, [user, teamId])

return (
<div className="flex flex-col justify-center">
Expand Down Expand Up @@ -81,11 +87,14 @@ export function TemplatesContent({ user }: { user: E2BUser }) {
)
}

async function fetchTemplates(apiKey: string): Promise<Template[]> {
const res = await fetch('https://api.e2b.dev/templates', {
async function fetchTemplates(
accessToken: string,
teamId: string
): Promise<Template[]> {
const res = await fetch(`https://api.e2b.dev/templates?teamID=${teamId}`, {
method: 'GET',
headers: {
Authorization: `Bearer ${apiKey}`,
Authorization: `Bearer ${accessToken}`,
},
})
try {
Expand Down

0 comments on commit b493a57

Please sign in to comment.