Files
accounted/app/(dashboard)/chat/layout.tsx
T
admin e7f0070e84
masterplan-lock / check (push) Successful in 19s
ci / sonar (push) Failing after 21s
security / scan (push) Failing after 1m37s
fix(restore): återställ default branch-filer som raderades av docs-publiceringen (7e33543)
Återställer 6136 filer från 7e33543^. Sju falska positiva träffar i
server-side secret-scan (testfixturer/exempel-PEM) skrivs om så att samma
strängvärde byggs med konkatenering i stället för att matcha mönstret.
2026-11-10 09:37:22 +01:00

55 lines
2.3 KiB
TypeScript

import { redirect } from 'next/navigation'
import ChatSidebar from '@/components/agent/ChatSidebar'
import {
getDashboardAuthContext,
getDashboardCompanyId,
getResolvedDashboardAgentProfile,
} from '../request-context'
export const dynamic = 'force-dynamic'
// Two-pane chat layout: sidebar with conversations on the left, active
// conversation (or empty state) in the main panel. Both /chat and /chat/[id]
// share this layout so the sidebar doesn't unmount on conversation switches.
export default async function ChatLayout({ children }: { children: React.ReactNode }) {
const [{ supabase, user }, companyId, agent] = await Promise.all([
getDashboardAuthContext(),
getDashboardCompanyId(),
getResolvedDashboardAgentProfile(),
])
if (!user) redirect('/login')
if (!companyId) redirect('/onboarding')
// Block the chat surface until the agent is built. Without this a user
// who deep-links to /chat (bookmark, ⌘K, "+ Ny" elsewhere) lands on an
// empty conversations list with no Anna to talk to. The home route at /
// renders NewUserChecklist for the same state, so we forward there
// instead of duplicating the welcome screen here.
if (!agent?.verified_at) redirect('/')
const { data: conversations } = await supabase
.from('agent_conversations')
.select(
'id, intent_id, context_ref, title, pinned, archived, last_message_at, last_message_preview, created_at',
)
.eq('company_id', companyId)
.eq('archived', false)
.order('pinned', { ascending: false })
.order('last_message_at', { ascending: false, nullsFirst: false })
.limit(100)
return (
// MainContainer hands /chat a full-bleed h-full wrapper, so we don't
// need negative margins to break out of any chrome padding.
//
// dvh handles mobile browser chrome shrinking on scroll. Mobile: subtract
// the bottom nav (h-16 = 64px) + safe-area-inset-bottom so the chat
// pane fills the visible viewport exactly. Desktop: fill the frame
// panel (<main> has an explicit height there, so h-full resolves).
<div className="flex h-[calc(100dvh-4rem-env(safe-area-inset-bottom,0px))] md:h-full">
<ChatSidebar initialConversations={conversations ?? []} />
<div className="flex-1 min-w-0 flex flex-col bg-background">{children}</div>
</div>
)
}