Files
accounted/lib/extensions/invoice-inbox-utils.ts
T
Jakob WennbergandClaude Opus 4.6 acb85edf4a feat: wire Zod validation into API routes, improve types and components
- Add 8 new Zod schemas (UpdateCustomer, UpdateSupplier, UpdateSupplierInvoice,
  UpdateAccount, BankUnlink, RunReconciliation, CorrectJournalEntry,
  EvaluateMappingRules) and wire validateBody() into 24 JSON-body API routes
- Remove redundant manual validation checks replaced by Zod
- Add comprehensive schema tests (222 tests)
- Improve type definitions in types/index.ts with expanded interfaces
- Refactor extension types (push-notifications, receipt-ocr) for cleaner imports
- Update transaction components (BatchCategorySelector, SwipeCategorizationView,
  QuickReviewDialog, VatTreatmentSelect) and invoice inbox workspace
- Add invoice-inbox utilities and type decoupling tests
- Fix NE-bilaga, SRU export, and invoice PDF template type usage
- Update CLAUDE.md with expanded architecture documentation

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 16:00:38 +01:00

55 lines
1.5 KiB
TypeScript

import type { InboxItemStatus } from '@/types'
import type { InvoiceExtractionResult } from '@/extensions/general/invoice-inbox/types'
const STATUS_LABELS: Record<InboxItemStatus, string> = {
pending: 'Väntar',
processing: 'Bearbetar',
ready: 'Klar',
confirmed: 'Bekräftad',
rejected: 'Avvisad',
error: 'Fel',
}
export function getStatusLabel(status: InboxItemStatus): string {
return STATUS_LABELS[status] ?? status
}
const STATUS_VARIANTS: Record<InboxItemStatus, string> = {
pending: 'secondary',
processing: 'default',
ready: 'warning',
confirmed: 'success',
rejected: 'destructive',
error: 'destructive',
}
export function getStatusVariant(status: InboxItemStatus): string {
return STATUS_VARIANTS[status] ?? 'outline'
}
export function getConfidenceLabel(confidence: number | null): { label: string; variant: string } {
if (confidence == null) {
return { label: 'Okänd', variant: 'outline' }
}
if (confidence >= 0.9) {
return { label: 'Hög', variant: 'success' }
}
if (confidence >= 0.7) {
return { label: 'Medium', variant: 'warning' }
}
return { label: 'Låg', variant: 'destructive' }
}
export function formatExtractionSummary(
data: InvoiceExtractionResult | null | undefined
): { supplierName: string; total: number; lineCount: number } {
if (!data) {
return { supplierName: '', total: 0, lineCount: 0 }
}
return {
supplierName: data.supplier?.name ?? '',
total: data.totals?.total ?? 0,
lineCount: data.lineItems?.length ?? 0,
}
}