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>
96 lines
3.1 KiB
TypeScript
96 lines
3.1 KiB
TypeScript
'use client'
|
|
|
|
/**
|
|
* Lazy entry point for CorrectionEntryDialog when the user is not on the
|
|
* /bookkeeping/[id] page (e.g. invoice detail, transaction row). Renders a
|
|
* trigger (button or link slot) that, on click, fetches the journal entry
|
|
* with its lines and opens the existing CorrectionEntryDialog.
|
|
*
|
|
* Used by:
|
|
* - /invoices/[id] when invoice.journal_entry_id is set
|
|
* - /transactions row menu when transaction.journal_entry_id is set
|
|
*
|
|
* Surfacing the storno+rättelse flow at the point where users notice the
|
|
* mistake matters: the dialog itself was already correct (it pre-fills
|
|
* lines and emits the storno+correction pair per BFL), but it was hidden
|
|
* behind a deep-link the customer never reached.
|
|
*/
|
|
import { useState } from 'react'
|
|
import CorrectionEntryDialog from '@/components/bookkeeping/CorrectionEntryDialog'
|
|
import { useToast } from '@/components/ui/use-toast'
|
|
import { getErrorMessage } from '@/lib/errors/get-error-message'
|
|
import type { JournalEntry } from '@/types'
|
|
|
|
interface Props {
|
|
journalEntryId: string
|
|
onCorrected?: () => void
|
|
/**
|
|
* Render prop: receives the click handler and current loading state.
|
|
* Letting the caller render its own trigger keeps the affordance visually
|
|
* native to its host page (link on invoice detail, menu item in dropdown).
|
|
*/
|
|
children: (args: { open: () => void; isLoading: boolean }) => React.ReactNode
|
|
}
|
|
|
|
export default function CorrectionAffordance({ journalEntryId, onCorrected, children }: Props) {
|
|
const { toast } = useToast()
|
|
const [entry, setEntry] = useState<JournalEntry | null>(null)
|
|
const [open, setOpen] = useState(false)
|
|
const [isLoading, setIsLoading] = useState(false)
|
|
|
|
async function handleOpen() {
|
|
if (isLoading) return
|
|
setIsLoading(true)
|
|
try {
|
|
const res = await fetch(`/api/bookkeeping/journal-entries/${journalEntryId}`)
|
|
const json = await res.json()
|
|
if (!res.ok) {
|
|
toast({
|
|
title: 'Kunde inte hämta verifikationen',
|
|
description: getErrorMessage(json, { context: 'journal_entry', statusCode: res.status }),
|
|
variant: 'destructive',
|
|
})
|
|
return
|
|
}
|
|
const fetched = json.data as JournalEntry
|
|
if (fetched.status !== 'posted') {
|
|
toast({
|
|
title: 'Verifikationen kan inte ändras',
|
|
description:
|
|
'Endast bokförda verifikationer kan rättas. Utkast hanteras direkt under bokföringen.',
|
|
variant: 'destructive',
|
|
})
|
|
return
|
|
}
|
|
setEntry(fetched)
|
|
setOpen(true)
|
|
} catch (err) {
|
|
toast({
|
|
title: 'Kunde inte hämta verifikationen',
|
|
description: getErrorMessage(err, { context: 'journal_entry' }),
|
|
variant: 'destructive',
|
|
})
|
|
} finally {
|
|
setIsLoading(false)
|
|
}
|
|
}
|
|
|
|
return (
|
|
<>
|
|
{children({ open: handleOpen, isLoading })}
|
|
{entry && (
|
|
<CorrectionEntryDialog
|
|
entry={entry}
|
|
open={open}
|
|
onOpenChange={setOpen}
|
|
onCorrected={() => {
|
|
setOpen(false)
|
|
setEntry(null)
|
|
onCorrected?.()
|
|
}}
|
|
/>
|
|
)}
|
|
</>
|
|
)
|
|
}
|