Skip to content

armgit / E2B

Public Imported from GitHub
0

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

Add suspense

Jakub Novakc0fd0b7ed27a
diff --git a/apps/web/src/app/(dashboard)/dashboard/sign-in/page.tsx b/apps/web/src/app/(auth)/auth/reset-password/page.tsx
similarity index 50%
rename from apps/web/src/app/(dashboard)/dashboard/sign-in/page.tsx
rename to apps/web/src/app/(auth)/auth/reset-password/page.tsx
index f49757670..e8b16739c 100644
--- a/apps/web/src/app/(dashboard)/dashboard/sign-in/page.tsx
+++ b/apps/web/src/app/(auth)/auth/reset-password/page.tsx
@@ -1,9 +1,12 @@
'use client'
import AuthForm from '@/components/AuthForm'
+import { Suspense } from 'react'
export default function Sign() {
return (
- <AuthForm view="sign_in" />
+ <Suspense>
+ <AuthForm view="forgotten_password" />
+ </Suspense>
)
}
diff --git a/apps/web/src/app/(dashboard)/dashboard/reset-password/page.tsx b/apps/web/src/app/(auth)/auth/sign-in/page.tsx
similarity index 52%
rename from apps/web/src/app/(dashboard)/dashboard/reset-password/page.tsx
rename to apps/web/src/app/(auth)/auth/sign-in/page.tsx
index e0a356624..5b27fe7c8 100644
--- a/apps/web/src/app/(dashboard)/dashboard/reset-password/page.tsx
+++ b/apps/web/src/app/(auth)/auth/sign-in/page.tsx
@@ -1,9 +1,12 @@
'use client'
import AuthForm from '@/components/AuthForm'
+import { Suspense } from 'react'
export default function Sign() {
return (
- <AuthForm view="forgotten_password" />
+ <Suspense>
+ <AuthForm view="sign_in" />
+ </Suspense>
)
}
diff --git a/apps/web/src/app/(auth)/auth/sign-up/page.tsx b/apps/web/src/app/(auth)/auth/sign-up/page.tsx
new file mode 100644
index 000000000..2030bd754
--- /dev/null
+++ b/apps/web/src/app/(auth)/auth/sign-up/page.tsx
@@ -0,0 +1,12 @@
+'use client'
+
+import AuthForm from '@/components/AuthForm'
+import { Suspense } from 'react'
+
+export default function SignUp() {
+ return (
+ <Suspense>
+ <AuthForm view="sign_up" />
+ </Suspense>
+ )
+}
diff --git a/apps/web/src/app/(dashboard)/dashboard/page.tsx b/apps/web/src/app/(dashboard)/dashboard/page.tsx
index dd6d949c7..80db92f24 100644
--- a/apps/web/src/app/(dashboard)/dashboard/page.tsx
+++ b/apps/web/src/app/(dashboard)/dashboard/page.tsx
@@ -1,6 +1,6 @@
'use client'
-import { useEffect, useState } from 'react'
+import { Suspense, useEffect, useState } from 'react'
import { BarChart, CreditCard, Key, LucideIcon, Settings, Users } from 'lucide-react'
import { BillingContent } from '@/components/Dashboard/Billing'
@@ -28,49 +28,81 @@ function redirectToCurrentURL() {
const menuLabels = ['personal', 'keys', 'usage', 'billing', 'team',] as const
type MenuLabel = typeof menuLabels[number]
-export default function Dashboard() {
+export default function Page() {
const { user, isLoading, error } = useUser()
const router = useRouter()
+
+ const [accessToken, setAccessToken] = useState<string | null>(null)
+
+ useEffect(() => {
+ if (user) {
+ setAccessToken(user.accessToken)
+ }
+ }, [accessToken, user])
+
+
+ useEffect(() => {
+ if (isLoading) { return }
+ if (!user) {
+ router.push(`/auth/sign-in?${redirectToCurrentURL()}`)
+ }
+ }, [isLoading, user, router])
+
+
+ if (error) {
+ return <div>Error: {error.message}</div>
+ }
+
+ if (user) {
+ return (
+ <div className="flex min-h-screen flex-col md:flex-row pt-16 md:pt-32 px-2 md:px-32">
+ <Suspense>
+ <Dashboard user={user} />
+ </Suspense>
+ </div>
+ )
+ }
+}
+
+const Dashboard = ({ user }) => {
const searchParams = useSearchParams()
const tab = searchParams!.get('tab')
const teamParam = searchParams!.get('team')
+ const [teams, setTeams] = useState<Team[]>([])
+ const [currentTeam, setCurrentTeam] = useState<Team | null>(null)
+ const [currentApiKey, setCurrentApiKey] = useState<string | null>(null)
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 [accessToken, setAccessToken] = useState<string | null>(null)
- const [teams, setTeams] = useState<Team[]>([])
+
+ const router = useRouter()
+
+
+ useEffect(() => {
+ if (user && currentTeam) {
+ const apiKey = currentTeam.apiKeys[0]
+ setCurrentApiKey(apiKey)
+ }
+ }, [currentApiKey, currentTeam, user])
+
useEffect(() => {
if (user) {
if (teamParam) {
- const team = user.teams.find(team => team.id === teamParam)
+ const team = user.teams.find((team: Team) => team.id === teamParam)
if (team) {
setCurrentTeam(team)
setTeams(user.teams)
}
} else {
- const defaultTeam = user.teams.find(team => team.is_default)
+ const defaultTeam = user.teams.find((team: Team) => team.is_default)
setCurrentTeam(defaultTeam || user.teams[0]) // seems like a sensible default
setTeams(user.teams)
}
}
- }, [user, teamParam])
+ }, [user, teamParam, setCurrentTeam, setTeams])
- useEffect(() => {
- if (user && currentTeam) {
- const apiKey = currentTeam.apiKeys[0]
- setCurrentApiKey(apiKey)
- }
- }, [currentApiKey, currentTeam, user])
-
- useEffect(() => {
- if (user) {
- setAccessToken(user.accessToken)
- }
- }, [accessToken, user])
useEffect(() => {
if (tab !== selectedItem) {
@@ -94,33 +126,21 @@ export default function Dashboard() {
}
}, [currentTeam, teamParam, router])
-
- useEffect(() => {
- if (isLoading) { return }
- if (!user) {
- router.push(`/dashboard/sign-in?${redirectToCurrentURL()}`)
- }
- }, [isLoading, user, router])
-
-
- if (error) {
- return <div>Error: {error.message}</div>
- }
-
- if (user && currentTeam) {
+ if (currentTeam) {
return (
- <div className="flex min-h-screen flex-col md:flex-row pt-16 md:pt-32 px-2 md:px-32">
+ <>
<Sidebar selectedItem={selectedItem} setSelectedItem={setSelectedItem} teams={teams} user={user} currentTeam={currentTeam} setCurrentTeam={setCurrentTeam} setTeams={setTeams} />
<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} accessToken={user.accessToken} teams={teams} setTeams={setTeams} setCurrentTeam={setCurrentTeam} />
</div>
- </div>
+ </>
)
}
}
+
const Sidebar = ({ selectedItem, setSelectedItem, teams, user, currentTeam, setCurrentTeam, setTeams }) => (
<div className="md:h-full md:w-48 space-y-2 pb-10 md:pb-0">
@@ -190,4 +210,3 @@ function MainContent({ selectedItem, user, team, accessToken, currentApiKey, tea
// TODO send sentry error from this
const ErrorContent = () => <div>Error Content</div>
-
diff --git a/apps/web/src/app/(dashboard)/dashboard/sign-up/page.tsx b/apps/web/src/app/(dashboard)/dashboard/sign-up/page.tsx
deleted file mode 100644
index 1834e9795..000000000
--- a/apps/web/src/app/(dashboard)/dashboard/sign-up/page.tsx
+++ /dev/null
@@ -1,7 +0,0 @@
-'use client'
-
-import AuthForm from '@/components/AuthForm'
-
-export default function SignUp() {
- return <AuthForm view="sign_up" />
-}
diff --git a/apps/web/src/app/(docs)/docs/api/cli/page.tsx b/apps/web/src/app/(docs)/docs/api/cli/page.tsx
index 35bb8cbfc..3b497e0b3 100644
--- a/apps/web/src/app/(docs)/docs/api/cli/page.tsx
+++ b/apps/web/src/app/(docs)/docs/api/cli/page.tsx
@@ -7,19 +7,75 @@ import { DialogAnimated } from '@/components/DialogAnimated'
import { CloudIcon, LaptopIcon, Link2Icon } from 'lucide-react'
import { Button } from '@/components/Button'
import { usePostHog } from 'posthog-js/react'
-import { useEffect } from 'react'
+import { Suspense, useEffect } from 'react'
type UserConfig = {
- email: string
- accessToken: string
- defaultTeamApiKey: string
- defaultTeamId: string
+ email: string;
+ accessToken: string;
+ defaultTeamApiKey: string;
+ defaultTeamId: string;
}
export default function Page() {
const posthog = usePostHog()
const { user, isLoading: userIsLoading } = useUser()
const apiKey = useApiKey()
+
+ useEffect(
+ function sendAuthorizationStartAnalytics() {
+ posthog?.capture('opened CLI authorization page')
+ },
+ [posthog]
+ )
+
+ return (
+ <div>
+ {/* It's not easy to override RootLayout without grouping everything into `(root)` dir */}
+ {/* So I'm hacking a custom layout with full modal overlay */}
+ {/* https://github.com/vercel/next.js/issues/50591 */}
+ <DialogAnimated
+ open={true}
+ setOpen={() => {}} // intentionally prevent closing
+ >
+ <div className="py-6 sm:py-12">
+ <div className="mx-auto px-6 lg:px-8">
+ <div className="mx-auto sm:text-center">
+ <p
+ className="
+ flex items-center justify-center gap-4
+ text-3xl font-bold tracking-tight sm:text-4xl
+ "
+ >
+ <span className="text-gray-200">
+ <LaptopIcon size={60} />
+ </span>
+ <span className="text-gray-400">
+ <Link2Icon size={30} />
+ </span>
+ <span className="text-gray-200">
+ <CloudIcon size={60} />
+ </span>
+ </p>
+ <h2 className="mt-6 text-base font-semibold leading-7">
+ Linking CLI with your account
+ </h2>
+ <Suspense>
+ <AuthState
+ user={user}
+ apiKey={apiKey}
+ posthog={posthog}
+ userIsLoading={userIsLoading}
+ />
+ </Suspense>
+ </div>
+ </div>
+ </div>
+ </DialogAnimated>
+ </div>
+ )
+}
+
+function AuthState({ user, apiKey, posthog, userIsLoading }) {
const searchParams = useSearchParams()
const searchParamsObj = searchParams ? Object.fromEntries(searchParams) : {}
const { next, state } = searchParamsObj
@@ -43,13 +99,6 @@ export default function Page() {
window.location.href = newUrl.toString()
}
- useEffect(
- function sendAuthorizationStartAnalytics() {
- posthog?.capture('opened CLI authorization page')
- },
- [posthog],
- )
-
useEffect(
function sendAuthorizationAnalytics() {
if (state === 'success') {
@@ -60,7 +109,7 @@ export default function Page() {
})
}
},
- [state, posthog, searchParamsObj.error],
+ [state, posthog, searchParamsObj.error]
)
let content
@@ -93,7 +142,7 @@ export default function Page() {
content = <span className="text-gray-300">Loading, please wait</span>
} else if (!user) {
content = (
- <Link href="/dashboard/sign-in">
+ <Link href="/auth/sign-in">
<Button>Sign In to continue</Button>
</Link>
)
@@ -108,43 +157,5 @@ export default function Page() {
}
}
- return (
- <div>
- {/* It's not easy to override RootLayout without grouping everything into `(root)` dir */}
- {/* So I'm hacking a custom layout with full modal overlay */}
- {/* https://github.com/vercel/next.js/issues/50591 */}
- <DialogAnimated
- open={true}
- setOpen={() => {
- }} // intentionally prevent closing
- >
- <div className="py-6 sm:py-12">
- <div className="mx-auto px-6 lg:px-8">
- <div className="mx-auto sm:text-center">
- <p
- className="
- flex items-center justify-center gap-4
- text-3xl font-bold tracking-tight sm:text-4xl
- "
- >
- <span className="text-gray-200">
- <LaptopIcon size={60} />
- </span>
- <span className="text-gray-400">
- <Link2Icon size={30} />
- </span>
- <span className="text-gray-200">
- <CloudIcon size={60} />
- </span>
- </p>
- <h2 className="mt-6 text-base font-semibold leading-7">
- Linking CLI with your account
- </h2>
- <p className="mt-12 leading-8">{content}</p>
- </div>
- </div>
- </div>
- </DialogAnimated>
- </div>
- )
+ return <p className="mt-12 leading-8">{content}</p>
}