Files
accounted/app/(dashboard)/chat/layout.tsx
T
Mattsson e11f70b347 Bug/gh issues fiz (#1103)
* refactor: optimize page loading and data fetching

* fix: resolve recurring production runtime errors

* feat: add MCP company and customer updates

* fix: handle year-end tax adjustments

* feat: harden annual report compliance

* fix: expand invoice logo and font support

* fix: sanitize API route error responses

* fix: sanitize user-facing error messages

* feat: persist onboarding and tax assessment notices

* fix: reduce cloud backup audit churn

* feat: refine invoice editor layout

* fix: show saved tax adjustments in INK2

* fix: complete annual report API mappings

* docs: record operational safeguards and decisions

* fix: harden annual report review findings

* fix: adjust column span for description based on VAT registration

* New css class name
2026-07-21 23:00:15 +02:00

54 lines
2.2 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: full viewport.
<div className="flex h-[calc(100dvh-4rem-env(safe-area-inset-bottom,0px))] md:h-screen">
<ChatSidebar initialConversations={conversations ?? []} />
<div className="flex-1 min-w-0 flex flex-col bg-background">{children}</div>
</div>
)
}