Remove AI-dependent extensions (ai-chat, ai-categorization, receipt-ocr, invoice-inbox) and their infrastructure (lib/ai/*, ai-consent, LangChain/ Anthropic/OpenAI deps) to simplify core and reduce bundle size. Restructure monolithic settings page into dedicated sub-pages (company, bookkeeping, invoicing, tax, banking, api, account, team, templates) with shared layout and sidebar navigation. Add atomic commit_journal_entry RPC so voucher number increment and status update happen in a single transaction — prevents burned numbers on constraint failures. Add continuity check report and voucher gap explanation tracking. Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
64 lines
1.8 KiB
TypeScript
64 lines
1.8 KiB
TypeScript
'use client'
|
|
|
|
import { useEffect, useState } from 'react'
|
|
import { useSearchParams, useRouter } from 'next/navigation'
|
|
import { SettingsNav } from '@/components/settings/SettingsSidebar'
|
|
import { useCompany } from '@/contexts/CompanyContext'
|
|
import { createClient } from '@/lib/supabase/client'
|
|
|
|
const TAB_TO_ROUTE: Record<string, string> = {
|
|
company: '/settings/company',
|
|
invoicing: '/settings/invoicing',
|
|
bookkeeping: '/settings/bookkeeping',
|
|
tax: '/settings/tax',
|
|
team: '/settings/team',
|
|
banking: '/settings/banking',
|
|
templates: '/settings/templates',
|
|
account: '/settings/account',
|
|
api: '/settings/api',
|
|
}
|
|
|
|
export default function SettingsLayout({ children }: { children: React.ReactNode }) {
|
|
const searchParams = useSearchParams()
|
|
const router = useRouter()
|
|
const { company } = useCompany()
|
|
const [isSandbox, setIsSandbox] = useState(false)
|
|
|
|
// Fetch sandbox status
|
|
useEffect(() => {
|
|
if (!company?.id) return
|
|
const supabase = createClient()
|
|
supabase
|
|
.from('company_settings')
|
|
.select('is_sandbox')
|
|
.eq('company_id', company.id)
|
|
.single()
|
|
.then(({ data }) => {
|
|
if (data?.is_sandbox) setIsSandbox(true)
|
|
})
|
|
}, [company?.id])
|
|
|
|
// Handle legacy ?tab= URLs
|
|
useEffect(() => {
|
|
const tab = searchParams.get('tab')
|
|
if (tab && TAB_TO_ROUTE[tab]) {
|
|
router.replace(TAB_TO_ROUTE[tab])
|
|
}
|
|
}, [searchParams, router])
|
|
|
|
return (
|
|
<div className="space-y-6">
|
|
<div>
|
|
<h1 className="font-display text-2xl md:text-3xl font-medium tracking-tight">Inställningar</h1>
|
|
<p className="text-muted-foreground text-sm mt-1">
|
|
Hantera ditt företag och konto
|
|
</p>
|
|
</div>
|
|
|
|
<SettingsNav isSandbox={isSandbox} />
|
|
|
|
<div>{children}</div>
|
|
</div>
|
|
)
|
|
}
|