- invoice/article posting-account overrides accept active class 1-3 accounts; class 1-2 (balance-sheet) accounts are rejected on VAT-bearing lines so the ruta 05 tax base always books to a 3xxx account - shared posting-account regex across server schemas, pending-operation re-validation, and client forms - share-capital settings (aktiekapital/antal_aktier) feed the annual-report note; kvotvarde derived per ABL 1 kap 6 $; all-or-nothing pair constraint - signed per-rate VAT breakdown on credit-note PDFs; U+2212 to ASCII hyphen Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
88 lines
3.5 KiB
TypeScript
88 lines
3.5 KiB
TypeScript
'use client'
|
|
|
|
import { useRouter } from 'next/navigation'
|
|
import { CompanyDangerZone } from '@/components/settings/CompanyDangerZone'
|
|
import { CompanyInfoForm } from '@/components/settings/CompanyInfoForm'
|
|
import { CompanyMembersSection } from '@/components/settings/CompanyMembersSection'
|
|
import { CompanyProfileSection } from '@/components/settings/CompanyProfileSection'
|
|
import { FiscalPeriodEditor } from '@/components/settings/FiscalPeriodEditor'
|
|
import { LogoUpload } from '@/components/settings/LogoUpload'
|
|
import { SettingsFormWrapper } from '@/components/settings/SettingsFormWrapper'
|
|
import { SettingsLoadError } from '@/components/settings/SettingsLoadError'
|
|
import { SettingsLoadingSkeleton } from '@/components/settings/SettingsLoadingSkeleton'
|
|
import { ShareCapitalForm } from '@/components/settings/ShareCapitalForm'
|
|
import { useSettings } from '@/components/settings/useSettings'
|
|
import type { CompanySettings } from '@/types'
|
|
|
|
export function CompanySettingsContent() {
|
|
const router = useRouter()
|
|
const { settings, isLoading, updateSettings, refetch } = useSettings()
|
|
|
|
if (isLoading) return <SettingsLoadingSkeleton />
|
|
if (!settings) return <SettingsLoadError onRetry={refetch} />
|
|
|
|
function handleSave(formData: FormData) {
|
|
// Empty string clears the value (schema accepts null, not '').
|
|
const numberOrNull = (name: string) => {
|
|
const raw = String(formData.get(name) ?? '').trim()
|
|
if (raw === '') return null
|
|
const parsed = Number(raw)
|
|
// NaN would serialize to null in JSON and silently clear the value.
|
|
return Number.isFinite(parsed) ? parsed : null
|
|
}
|
|
const updates: Record<string, unknown> = {
|
|
...(formData.has('company_name') && { company_name: formData.get('company_name') as string }),
|
|
...(formData.has('org_number') && { org_number: formData.get('org_number') as string }),
|
|
address_line1: formData.get('address_line1') as string,
|
|
postal_code: formData.get('postal_code') as string,
|
|
city: formData.get('city') as string,
|
|
phone: (formData.get('phone') as string) || '',
|
|
email: (formData.get('email') as string) || '',
|
|
website: (formData.get('website') as string) || '',
|
|
...(formData.has('aktiekapital') && { aktiekapital: numberOrNull('aktiekapital') }),
|
|
...(formData.has('antal_aktier') && { antal_aktier: numberOrNull('antal_aktier') }),
|
|
}
|
|
return {
|
|
updates,
|
|
onSuccess: (data: Record<string, unknown>) => {
|
|
updateSettings(data as Partial<CompanySettings>)
|
|
// Refresh server components so the company switcher and DashboardNav
|
|
// pick up the new company_name (rendered from server in the dashboard layout).
|
|
if ('company_name' in updates) {
|
|
router.refresh()
|
|
}
|
|
},
|
|
}
|
|
}
|
|
|
|
return (
|
|
<div className="space-y-8">
|
|
<SettingsFormWrapper onSave={handleSave} className="space-y-8">
|
|
<CompanyInfoForm settings={settings} />
|
|
{settings.entity_type === 'aktiebolag' && (
|
|
<ShareCapitalForm
|
|
settings={{ aktiekapital: settings.aktiekapital, antal_aktier: settings.antal_aktier }}
|
|
/>
|
|
)}
|
|
</SettingsFormWrapper>
|
|
|
|
<div className="border-t border-border pt-8">
|
|
<LogoUpload
|
|
logoUrl={settings.logo_url}
|
|
onUpdate={(url) => updateSettings({ logo_url: url })}
|
|
/>
|
|
</div>
|
|
|
|
<div className="border-t border-border pt-8">
|
|
<CompanyMembersSection />
|
|
</div>
|
|
|
|
<FiscalPeriodEditor />
|
|
|
|
<CompanyProfileSection />
|
|
|
|
<CompanyDangerZone />
|
|
</div>
|
|
)
|
|
}
|