suna/frontend/src/app/(dashboard)/layout.tsx

79 lines
2.0 KiB
TypeScript
Raw Normal View History

2025-04-16 13:41:55 +08:00
"use client"
2025-04-23 08:25:44 +08:00
import { useEffect, useState } from "react"
2025-04-21 00:08:17 +08:00
import { SidebarLeft } from "@/components/sidebar/sidebar-left"
2025-04-16 02:14:58 +08:00
import {
SidebarInset,
SidebarProvider,
} from "@/components/ui/sidebar"
2025-04-24 12:30:08 +08:00
import { PricingAlert } from "@/components/billing/pricing-alert"
2025-04-23 16:20:10 +08:00
import { MaintenanceAlert } from "@/components/maintenance-alert"
2025-04-24 02:28:31 +08:00
import { useAccounts } from "@/hooks/use-accounts"
import { useAuth } from "@/components/AuthProvider"
import { useRouter } from "next/navigation"
import { Loader2 } from "lucide-react"
2025-04-16 02:37:56 +08:00
2025-04-16 02:14:58 +08:00
interface DashboardLayoutProps {
children: React.ReactNode
2025-04-13 00:37:45 +08:00
}
2025-04-16 13:41:55 +08:00
export default function DashboardLayout({
2025-04-13 00:37:45 +08:00
children,
2025-04-16 02:14:58 +08:00
}: DashboardLayoutProps) {
2025-04-24 12:30:08 +08:00
const [showPricingAlert, setShowPricingAlert] = useState(false)
2025-04-23 08:25:44 +08:00
const [showMaintenanceAlert, setShowMaintenanceAlert] = useState(false)
2025-04-24 02:28:31 +08:00
const { data: accounts } = useAccounts()
const personalAccount = accounts?.find(account => account.personal_account)
const { user, isLoading } = useAuth()
const router = useRouter()
2025-04-23 08:25:44 +08:00
useEffect(() => {
2025-04-26 06:26:53 +08:00
setShowPricingAlert(false)
2025-04-24 12:30:08 +08:00
setShowMaintenanceAlert(false)
2025-04-23 08:25:44 +08:00
}, [])
// Check authentication status
useEffect(() => {
if (!isLoading && !user) {
router.push('/auth')
}
}, [user, isLoading, router])
// Show loading state while checking auth
if (isLoading) {
return (
<div className="flex items-center justify-center min-h-screen">
<Loader2 className="h-8 w-8 animate-spin text-primary" />
</div>
)
}
// Don't render anything if not authenticated
if (!user) {
return null
}
2025-04-12 08:04:40 +08:00
return (
2025-04-16 02:14:58 +08:00
<SidebarProvider>
2025-04-16 15:16:38 +08:00
<SidebarLeft />
2025-04-16 02:14:58 +08:00
<SidebarInset>
2025-04-16 08:04:04 +08:00
<div className="bg-background">
{children}
</div>
2025-04-16 02:14:58 +08:00
</SidebarInset>
2025-04-23 08:25:44 +08:00
2025-04-24 12:30:08 +08:00
<PricingAlert
open={showPricingAlert}
onOpenChange={setShowPricingAlert}
2025-04-24 13:03:24 +08:00
closeable={false}
2025-04-24 02:28:31 +08:00
accountId={personalAccount?.account_id}
2025-04-23 16:20:10 +08:00
/>
2025-04-24 12:30:08 +08:00
<MaintenanceAlert
open={showMaintenanceAlert}
onOpenChange={setShowMaintenanceAlert}
closeable={true}
/>
2025-04-16 02:14:58 +08:00
</SidebarProvider>
)
}