* fix(arsredovisning): make the aktiekapital note completable via company settings The annual report warned every AB that the aktiekapital note was missing and pointed at Installningar -> Foretag, but the referenced columns (aktiekapital, antal_aktier, kvotvarde) never existed and no settings UI was ever built, so the warning was a dead end and no AB could produce a complete note before Bolagsverket filing. - migration 20260723103000: company_settings.aktiekapital (numeric) and antal_aktier (integer) with positive CHECKs; kvotvarde is intentionally not stored since ABL 1 kap 6 defines it as aktiekapital / antal aktier - build-data.ts (K2 and K3 note paths): select only the two stored columns and derive kvotvarde with roundOre - UpdateSettingsSchema: aktiekapital (positive), antal_aktier (positive integer), both nullable to allow clearing - new ShareCapitalForm section on Installningar -> Foretag, rendered for aktiebolag only, with live derived kvotvarde display; wired through the existing CompanySettingsContent save path (empty string clears to null) - sv/en strings; settings route tests (round-trip, clear, 400 on invalid); builder tests for derived kvotvarde and the empty-settings warning Staging (metjnjrhvujscngnpzdv) already has the columns applied and the note verified end-to-end against a rehearsal company. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * fix(arsredovisning): address PR review findings on the share-capital note - enforce aktiekapital/antal_aktier as an all-or-nothing pair (DB CHECK, K2/K3 note guard now requires both, partial pair warns instead) - numeric(15,2) column, .int() Zod constraint, maxFractionDigits 0 render - guard numberOrNull against NaN; align kvotvarde preview with schema - strengthen clearing test, add fractional and partial-pair tests Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> --------- Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
84 lines
3.4 KiB
TypeScript
84 lines
3.4 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={settings} />}
|
|
</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>
|
|
)
|
|
}
|