ec27228a8e
Em dashes (—) and en dashes (–) had spread across comments, docs, tests, and a few UI strings, reading as AI-generated boilerplate rather than house style. Replaced each with punctuation matching its context: colon for explanatory clauses, comma for asides, plain hyphen for numeric/legal ranges (e.g. "21-23§"), "to"/"till" for date ranges, parentheses for paired-dash asides. messages/en.json and messages/sv.json were fixed by hand together to keep sv/en in sync. Left untouched where the dash is the functional subject rather than decorative punctuation: date-range-parser.ts's separator regex, charset-repair.ts's CP1252 byte-mapping table (and its test), the SIE encoding mojibake docs, generic-csv.ts's minus-sign normalizer, the agent system-prompt files that already instruct against em dashes, and a golden iXBRL test fixture compared byte-for-byte. Also fixes two bugs surfaced along the way: an off-by-one in ApiKeysPanel's scope-label split (a leftover from an earlier partial pass), and a charset-repair test that had lost the literal en-dash it exists to verify. Regenerated the agent atom seed migration (skills:generate) since 27 SKILL.md files changed. Added a CLAUDE.md rule against em/en dashes, with an explicit carve-out for the functional-dash cases above. Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
109 lines
3.8 KiB
TypeScript
109 lines
3.8 KiB
TypeScript
'use client'
|
|
|
|
import { useCallback, useSyncExternalStore } from 'react'
|
|
import Link from 'next/link'
|
|
import { ExternalLink } from 'lucide-react'
|
|
import { Switch } from '@/components/ui/switch'
|
|
import { Label } from '@/components/ui/label'
|
|
|
|
/**
|
|
* Per-user toggle for the periodisering wizard's auto-detection step.
|
|
*
|
|
* Backed by localStorage (key: `periodisering_autodetect_enabled`) because
|
|
* the company_settings table does not yet have a dedicated column for this
|
|
* preference, and the task description explicitly allows the persistence to
|
|
* be UI-local. A future migration can promote this to a real
|
|
* `company_settings.periodisering_autodetect_enabled boolean` column and
|
|
* the wizard's auto-detect step will read either source.
|
|
*
|
|
* Default: enabled. The wizard's auto-detect step renders regardless: the
|
|
* toggle merely controls whether the GET response includes `autoDetected`
|
|
* on subsequent fetches. (Today the API always returns it; the wizard step
|
|
* can early-out based on this setting locally.)
|
|
*/
|
|
const STORAGE_KEY = 'periodisering_autodetect_enabled'
|
|
|
|
function readStored(): boolean {
|
|
if (typeof window === 'undefined') return true
|
|
try {
|
|
const stored = window.localStorage.getItem(STORAGE_KEY)
|
|
return stored === null ? true : stored !== 'false'
|
|
} catch {
|
|
return true
|
|
}
|
|
}
|
|
|
|
/** Subscribe to localStorage changes from OTHER tabs. Same-tab updates are
|
|
* picked up via the explicit re-render after `setItem`: see
|
|
* `notifyChange` below. */
|
|
function subscribe(callback: () => void): () => void {
|
|
if (typeof window === 'undefined') return () => {}
|
|
const handler = (e: StorageEvent) => {
|
|
if (e.key === STORAGE_KEY || e.key === null) callback()
|
|
}
|
|
const customHandler = () => callback()
|
|
window.addEventListener('storage', handler)
|
|
window.addEventListener('gnubok-periodisering-toggle', customHandler)
|
|
return () => {
|
|
window.removeEventListener('storage', handler)
|
|
window.removeEventListener('gnubok-periodisering-toggle', customHandler)
|
|
}
|
|
}
|
|
|
|
/** Fire a same-tab notification so useSyncExternalStore re-subscribers
|
|
* see the change without a manual setState. */
|
|
function notifyChange() {
|
|
if (typeof window === 'undefined') return
|
|
window.dispatchEvent(new Event('gnubok-periodisering-toggle'))
|
|
}
|
|
|
|
export function PeriodiseringAutoDetectToggle() {
|
|
const enabled = useSyncExternalStore(
|
|
subscribe,
|
|
readStored,
|
|
// Server snapshot: default to enabled. Matches the client default so
|
|
// hydration is identical.
|
|
() => true,
|
|
)
|
|
|
|
const handleChange = useCallback((value: boolean) => {
|
|
try {
|
|
window.localStorage.setItem(STORAGE_KEY, String(value))
|
|
} catch {
|
|
// No-op; if storage is blocked the toggle simply won't persist.
|
|
}
|
|
notifyChange()
|
|
}, [])
|
|
|
|
return (
|
|
<section className="space-y-4">
|
|
<h2 className="text-sm font-medium uppercase tracking-wider text-muted-foreground">
|
|
Periodisering
|
|
</h2>
|
|
<div className="flex items-start justify-between gap-4">
|
|
<div className="space-y-1">
|
|
<Label htmlFor="periodisering-autodetect" className="text-sm">
|
|
Aktivera automatisk periodiseringsdetektering
|
|
</Label>
|
|
<p className="text-xs text-muted-foreground max-w-md">
|
|
Skannar fakturor i bokslutet efter datumintervall som sträcker sig
|
|
in i nästa räkenskapsår och föreslår periodiseringar i bokslut-wizarden.
|
|
</p>
|
|
</div>
|
|
<Switch
|
|
id="periodisering-autodetect"
|
|
checked={enabled}
|
|
onCheckedChange={handleChange}
|
|
/>
|
|
</div>
|
|
<Link
|
|
href="/bookkeeping/year-end/periodisering"
|
|
className="inline-flex items-center gap-1.5 text-sm text-muted-foreground hover:text-foreground transition-colors"
|
|
>
|
|
<ExternalLink className="h-3.5 w-3.5" />
|
|
Öppna periodiserings-wizarden
|
|
</Link>
|
|
</section>
|
|
)
|
|
}
|