Skip to content

armgit / E2B

Public Imported from GitHub
0

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

requested changes

ErikKaumk3aed83fe4262
diff --git a/apps/docs/src/app/(main)/dashboard/page.tsx b/apps/docs/src/app/(main)/dashboard/page.tsx
index 0b4b08b42..eb309c45c 100644
--- a/apps/docs/src/app/(main)/dashboard/page.tsx
+++ b/apps/docs/src/app/(main)/dashboard/page.tsx
@@ -37,6 +37,8 @@ export default function Dashboard() {
const searchParams = useSearchParams()
const tab = searchParams!.get('tab')
+ const teamParam = searchParams!.get('team')
+
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)
@@ -45,11 +47,19 @@ export default function Dashboard() {
useEffect(() => {
if (user) {
- const defaultTeam = user.teams.find(team => team.is_default)
- setCurrentTeam(defaultTeam || user.teams[0]) // seems like a sensible default
- setTeams(user.teams)
+ if (teamParam) {
+ const team = user.teams.find(team => team.id === teamParam)
+ if (team) {
+ setCurrentTeam(team)
+ setTeams(user.teams)
+ }
+ } else {
+ const defaultTeam = user.teams.find(team => team.is_default)
+ setCurrentTeam(defaultTeam || user.teams[0]) // seems like a sensible default
+ setTeams(user.teams)
+ }
}
- }, [user])
+ }, [user, teamParam])
useEffect(() => {
if (user && currentTeam) {
@@ -67,6 +77,19 @@ export default function Dashboard() {
}
}, [selectedItem, tab, router])
+ useEffect(() => {
+ if (teamParam !== currentTeam?.id) {
+ const params = new URLSearchParams(window.location.search)
+ if (currentTeam) {
+ params.set('team', currentTeam.id)
+ } else {
+ params.delete('team')
+ }
+ const newUrl = `${window.location.pathname}?${params.toString()}`
+ router.push(newUrl)
+ }
+ }, [currentTeam, teamParam, router])
+
if (error) {
return <div>Error: {error.message}</div>
}
@@ -85,7 +108,7 @@ export default function Dashboard() {
<div className="flex-1 md: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} currentApiKey={currentApiKey} />
+ <MainContent selectedItem={selectedItem} user={user} team={currentTeam} currentApiKey={currentApiKey} teams={teams} setTeams={setTeams} setCurrentTeam={setCurrentTeam} />
</div>
</div>
)
@@ -142,7 +165,7 @@ const MenuItem = ({ icon: Icon, label , selected, onClick }: { icon: LucideIcon;
)
-const MainContent = ({ selectedItem, user, team, currentApiKey }: { selectedItem: MenuLabel, user: User, team: Team, currentApiKey: string | null}) => {
+const MainContent = ({ selectedItem, user, team, currentApiKey, teams, setTeams, setCurrentTeam }: { selectedItem: MenuLabel, user: User, team: Team, currentApiKey: string | null, teams: Team[], setTeams: (teams: Team[]) => void, setCurrentTeam: (team: Team) => void}) => {
switch (selectedItem) {
case 'personal':
return <PersonalContent user={user} />
@@ -153,7 +176,7 @@ const MainContent = ({ selectedItem, user, team, currentApiKey }: { selectedItem
case 'billing':
return <BillingContent currentApiKey={currentApiKey} />
case 'team':
- return <TeamContent team={team} user={user} />
+ return <TeamContent team={team} user={user} teams={teams} setTeams={setTeams} setCurrentTeam={setCurrentTeam} />
default:
return <ErrorContent />
}
diff --git a/apps/docs/src/components/Dashboard/AccountSelector.tsx b/apps/docs/src/components/Dashboard/AccountSelector.tsx
index e90ebc4bb..08c10a60f 100644
--- a/apps/docs/src/components/Dashboard/AccountSelector.tsx
+++ b/apps/docs/src/components/Dashboard/AccountSelector.tsx
@@ -7,11 +7,26 @@ import {
} from '@/components/ui/dropdown-menu'
import { ChevronRight, PlusCircle } from 'lucide-react'
import { toast } from '../ui/use-toast'
+import {
+ AlertDialog,
+ AlertDialogAction,
+ AlertDialogCancel,
+ AlertDialogContent,
+ AlertDialogFooter,
+ AlertDialogHeader,
+ AlertDialogTitle,
+ AlertDialogTrigger,
+} from '../ui/alert-dialog'
+import { useState } from 'react'
+import { Button } from '../Button'
const createTeamUrl = `${process.env.NEXT_PUBLIC_BILLING_API_URL}/teams`
export const AccountSelector = ({ teams, user, currentTeam, setCurrentTeam, setTeams }) => {
+ const [isDialogOpen, setIsDialogOpen] = useState(false)
+ const [teamName, setTeamName] = useState('')
+ const closeDialog = () => setIsDialogOpen(false)
const createNewTeam = async() => {
const res = await fetch(createTeamUrl, {
@@ -19,6 +34,9 @@ export const AccountSelector = ({ teams, user, currentTeam, setCurrentTeam, setT
headers: {
'X-User-Access-Token': user.accessToken,
},
+ body: JSON.stringify({
+ name: teamName,
+ }),
})
if (!res.ok) {
// TODO: Add sentry event here
@@ -32,31 +50,50 @@ export const AccountSelector = ({ teams, user, currentTeam, setCurrentTeam, setT
})
setTeams([...teams, team])
+ setCurrentTeam(team)
}
return(
- <DropdownMenu>
- <DropdownMenuTrigger
- className='dropdown-trigger group outline-none flex w-full items-center justify-between rounded-lg p-2 mb-6 hover:bg-zinc-800 hover:cursor-pointer'
- >
- <div className='flex items-start flex-col'>
- <p className='text-sm'>Current team</p>
- <h3 className='font-bold text-left'>{currentTeam.name}</h3>
- </div>
- <ChevronRight className='transform transition-transform duration-300 group-hover:rotate-90' />
- </DropdownMenuTrigger>
- <DropdownMenuContent className='flex flex-col w-48 bg-zinc-900 border border-white/30'>
- {teams?.map((team: any) => (
- <DropdownMenuItem key={team.id} onClick={() => setCurrentTeam(team)}>
- {team.name}
+ <>
+ <DropdownMenu>
+ <DropdownMenuTrigger
+ className='dropdown-trigger group outline-none flex w-full items-center justify-between rounded-lg p-2 mb-6 hover:bg-zinc-800 hover:cursor-pointer'
+ >
+ <div className='flex items-start flex-col'>
+ <p className='text-sm'>Current team</p>
+ <h3 className='font-bold text-left'>{currentTeam.name}</h3>
+ </div>
+ <ChevronRight className='transform transition-transform duration-300 group-hover:rotate-90' />
+ </DropdownMenuTrigger>
+ <DropdownMenuContent className='flex flex-col w-48 bg-zinc-900 border border-white/30'>
+ {teams?.map((team: any) => (
+ <DropdownMenuItem key={team.id} onClick={() => setCurrentTeam(team)}>
+ {team.name}
+ </DropdownMenuItem>
+ ))}
+ <DropdownMenuSeparator />
+ <DropdownMenuItem className='flex items-center space-x-1'>
+ <PlusCircle width={15} height={15} />
+ <p onClick={() => setIsDialogOpen(true)}>Create Team</p>
</DropdownMenuItem>
- ))}
- <DropdownMenuSeparator />
- <DropdownMenuItem className='flex items-center space-x-1'>
- <PlusCircle width={15} height={15} />
- <p onClick={() => createNewTeam()}>Create Team</p>
- </DropdownMenuItem>
- </DropdownMenuContent>
- </DropdownMenu>
+ </DropdownMenuContent>
+ </DropdownMenu>
+
+ <AlertDialog open={isDialogOpen} onOpenChange={setIsDialogOpen}>
+ <AlertDialogTrigger asChild>
+ <Button variant="outline" style={{ display: 'none' }}>Show Dialog</Button>
+ </AlertDialogTrigger>
+ <AlertDialogContent className="bg-inherit text-white border-black">
+ <AlertDialogHeader>
+ <AlertDialogTitle>Give your team a name</AlertDialogTitle>
+ <input className='border border-white/10 text-sm focus:outline-none outline-none rounded-md p-2' value={teamName} onChange={(e) => setTeamName(e.target.value)} />
+ </AlertDialogHeader>
+ <AlertDialogFooter>
+ <AlertDialogCancel className='border-white/10' onClick={closeDialog}>Cancel</AlertDialogCancel>
+ <AlertDialogAction className='bg-[#995100] text-white hover:bg-[#995100]' onClick={() => createNewTeam()}>Create</AlertDialogAction>
+ </AlertDialogFooter>
+ </AlertDialogContent>
+ </AlertDialog>
+ </>
)
}
\ No newline at end of file
diff --git a/apps/docs/src/components/Dashboard/Keys.tsx b/apps/docs/src/components/Dashboard/Keys.tsx
index 6e63abedb..bdd38a5cd 100644
--- a/apps/docs/src/components/Dashboard/Keys.tsx
+++ b/apps/docs/src/components/Dashboard/Keys.tsx
@@ -140,23 +140,23 @@ export const KeysContent = ({ user, currentTeam, currentApiKey }: { user: User,
</div>
<AlertDialog open={isDialogOpen} onOpenChange={setIsDialogOpen}>
- <AlertDialogTrigger asChild>
- <Button variant="outline" style={{ display: 'none' }}>Show Dialog</Button>
- </AlertDialogTrigger>
- <AlertDialogContent className="bg-inherit text-white border-black">
- <AlertDialogHeader>
- <AlertDialogTitle>You are about to delete an API key</AlertDialogTitle>
- <AlertDialogDescription className='text-white/90'>
- This action cannot be undone. This will permanently delete the
- API key with immediate effect.
- </AlertDialogDescription>
- </AlertDialogHeader>
- <AlertDialogFooter>
- <AlertDialogCancel className='border-white/10' onClick={closeDialog}>Cancel</AlertDialogCancel>
- <AlertDialogAction className='bg-red-500 text-white hover:bg-red-600' onClick={deleteApiKey}>Continue</AlertDialogAction>
- </AlertDialogFooter>
- </AlertDialogContent>
- </AlertDialog>
+ <AlertDialogTrigger asChild>
+ <Button variant="outline" style={{ display: 'none' }}>Show Dialog</Button>
+ </AlertDialogTrigger>
+ <AlertDialogContent className="bg-inherit text-white border-black">
+ <AlertDialogHeader>
+ <AlertDialogTitle>You are about to delete an API key</AlertDialogTitle>
+ <AlertDialogDescription className='text-white/90'>
+ This action cannot be undone. This will permanently delete the
+ API key with immediate effect.
+ </AlertDialogDescription>
+ </AlertDialogHeader>
+ <AlertDialogFooter>
+ <AlertDialogCancel className='border-white/10' onClick={closeDialog}>Cancel</AlertDialogCancel>
+ <AlertDialogAction className='bg-red-500 text-white hover:bg-red-600' onClick={deleteApiKey}>Continue</AlertDialogAction>
+ </AlertDialogFooter>
+ </AlertDialogContent>
+ </AlertDialog>
</div>
)
diff --git a/apps/docs/src/components/Dashboard/Personal.tsx b/apps/docs/src/components/Dashboard/Personal.tsx
index b9a64679a..9d44a195b 100644
--- a/apps/docs/src/components/Dashboard/Personal.tsx
+++ b/apps/docs/src/components/Dashboard/Personal.tsx
@@ -47,8 +47,7 @@ export const PersonalContent = ({user}: {user: User}) => {
Reset password
</h1>
<span className='text-neutral-300 pb-4'>
- Resetting the will send an email with a link to reset the password. <br/>
- The action cannot be undone.
+ Resetting will send an email with a link to reset the password. <br/>
</span>
<div className='flex items-center space-x-2 pb-10'>
<Link href={'/sign-in?view=forgotten-password'}>
diff --git a/apps/docs/src/components/Dashboard/Team.tsx b/apps/docs/src/components/Dashboard/Team.tsx
index 6576ac906..83b2d20fa 100644
--- a/apps/docs/src/components/Dashboard/Team.tsx
+++ b/apps/docs/src/components/Dashboard/Team.tsx
@@ -15,7 +15,7 @@ interface TeamMember {
}
-export const TeamContent = ({ team, user }: { team: Team, user: User }) => {
+export const TeamContent = ({ team, user, teams, setTeams, setCurrentTeam }: { team: Team, user: User, teams: Team[] ,setTeams: (teams: Team[]) => void, setCurrentTeam: (team: Team) => void }) => {
const supabase = createPagesBrowserClient()
const [isDialogOpen, setIsDialogOpen] = useState(false)
@@ -23,6 +23,7 @@ export const TeamContent = ({ team, user }: { team: Team, user: User }) => {
const [members, setMembers] = useState<TeamMember[]>([])
const [teamName, setTeamName] = useState(team.name)
const [userToAdd, setUserToAdd] = useState('')
+ const [userAdded, setUserAdded] = useState(false)
useEffect(() => {
const getTeamMembers = async () => {
@@ -50,7 +51,7 @@ export const TeamContent = ({ team, user }: { team: Team, user: User }) => {
}
getTeamMembers()
- }, [supabase, team.id, user.id])
+ }, [supabase, team.id, user.id, userAdded])
const closeDialog = () => setIsDialogOpen(false)
const openDialog = (id: string) => {
@@ -70,7 +71,7 @@ export const TeamContent = ({ team, user }: { team: Team, user: User }) => {
console.log(error)
return
}
-
+ setMembers(members.filter(member => member.id !== currentMemberId))
closeDialog()
}
@@ -90,6 +91,8 @@ export const TeamContent = ({ team, user }: { team: Team, user: User }) => {
title: 'Team name changed',
})
setTeamName(teamName)
+ setTeams(teams.map(t => t.id === team.id ? { ...t, name: teamName } : t))
+ setCurrentTeam({ ...team, name: teamName })
}
const addUserToTeam = async() => {
@@ -104,6 +107,7 @@ export const TeamContent = ({ team, user }: { team: Team, user: User }) => {
}
setUserToAdd('')
+ setUserAdded(!userAdded)
toast({
title: 'User added to team',
})