|
| 1 | +'use client' |
| 2 | + |
| 3 | +import { Button } from '@repo/ui/components/button' |
| 4 | +import { SidebarInset, SidebarProvider, SidebarTrigger } from '@repo/ui/components/sidebar' |
| 5 | +import { Toaster } from '@repo/ui/components/sonner' |
| 6 | +import { useQueryClient } from '@tanstack/react-query' |
| 7 | +import { AssistantSidebar } from 'components/assistant' |
| 8 | +import { ApiHealthBadge } from 'components/shared/api-health-badge' |
| 9 | +import { AuthBadge } from 'components/shared/auth-badge' |
| 10 | +import { LogOut } from 'lucide-react' |
| 11 | +import { toast } from 'sonner' |
| 12 | +import { authSessionJwtQueryKey, authSessionUserQueryKey } from '@/lib/query-keys' |
| 13 | + |
| 14 | +import { PageTitle } from './page-title' |
| 15 | +import { DashboardSidebar } from './sidebar' |
| 16 | + |
| 17 | +export function DashboardShell({ |
| 18 | + children, |
| 19 | +}: Readonly<{ children: React.ReactNode }>): React.JSX.Element { |
| 20 | + const queryClient = useQueryClient() |
| 21 | + |
| 22 | + async function handleSignOut() { |
| 23 | + const response = await fetch('/auth/logout', { redirect: 'manual' }) |
| 24 | + const isSuccess = response.status >= 200 && response.status < 400 |
| 25 | + if (!isSuccess) { |
| 26 | + toast.error('Sign out failed. Please try again.') |
| 27 | + return |
| 28 | + } |
| 29 | + queryClient.invalidateQueries({ queryKey: authSessionUserQueryKey }) |
| 30 | + queryClient.invalidateQueries({ queryKey: authSessionJwtQueryKey }) |
| 31 | + window.location.href = '/' |
| 32 | + } |
| 33 | + |
| 34 | + return ( |
| 35 | + <SidebarProvider> |
| 36 | + <DashboardSidebar /> |
| 37 | + <div className="flex min-w-0 flex-1"> |
| 38 | + <SidebarInset className="flex min-w-0 flex-1 flex-col"> |
| 39 | + <header className="flex h-14 shrink-0 items-center justify-between gap-3 border-b px-4 md:gap-4 md:px-6"> |
| 40 | + <div className="flex min-h-11 items-center md:hidden"> |
| 41 | + <SidebarTrigger className="size-11 shrink-0" /> |
| 42 | + </div> |
| 43 | + <div className="flex min-w-0 flex-1 items-center"> |
| 44 | + <PageTitle /> |
| 45 | + </div> |
| 46 | + <div className="flex min-h-11 items-center gap-3 md:gap-4"> |
| 47 | + <ApiHealthBadge /> |
| 48 | + <AuthBadge /> |
| 49 | + <Button |
| 50 | + variant="ghost" |
| 51 | + size="icon" |
| 52 | + className="size-11 sm:size-9" |
| 53 | + aria-label="Sign out" |
| 54 | + type="button" |
| 55 | + onClick={handleSignOut} |
| 56 | + > |
| 57 | + <LogOut /> |
| 58 | + </Button> |
| 59 | + </div> |
| 60 | + </header> |
| 61 | + <div className="flex min-h-0 flex-1" style={{ height: 'calc(100dvh - 3.5rem)' }}> |
| 62 | + <main className="min-w-0 w-0 flex-1 overflow-auto p-4 md:p-6">{children}</main> |
| 63 | + <AssistantSidebar /> |
| 64 | + </div> |
| 65 | + </SidebarInset> |
| 66 | + </div> |
| 67 | + <Toaster richColors position="top-right" /> |
| 68 | + </SidebarProvider> |
| 69 | + ) |
| 70 | +} |
0 commit comments