0521c385d2
* feat(transactions): per-row underlag status + attach-document dialog
- New "Matcha mot underlag" dialog on /transactions (inbox pick or fresh
upload), the tx→doc mirror of the Documents view's matcher
- Per-row Underlag/Underlag saknas badges on booked history rows, driven
by computeJeUnderlagStatus — same posted-only, exemption-aware scope as
the worklist count so badge and count never disagree
- attach-document route + commit dispatcher now propagate the doc onto
the verifikation when the tx is already booked (BFL 5 kap 6 §), with a
409 guard for docs consumed by a different verifikation, idempotent
re-attach (no same-value rewrite under period lock), and an honest 409
when the period-lock trigger blocks the propagation
- Booking-dialog doc links also pin the doc to the transaction row
(first linked doc wins) via the link route's new transaction_id param
messages/{sv,en}.json also carries the strings for the pending-ops
expiry UI that lands in the next commit.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* feat(pending-operations): auto-expire stale staged operations after 30 days
- New daily cron (02:30 UTC, vercel.json + both docker crontabs) flips
>30-day-old pending ops to rejected with the dispatcher's
{ auto_rejected: true, reason: 'expired' } result_data shape — rows are
never deleted, the table is the audit trail
- /pending renders an "Utgick automatiskt" badge + detail line for these,
orders terminal tabs by resolved_at so a fresh expiry sweep isn't
buried, and adds a first-time-reviewer explainer
- Origin labels spell out where a proposal came from (AI chat, MCP key,
API, cron) instead of the raw actor_label
- agent_chat actor type added to PendingOperationActorType/AuditLogEntry
(DB CHECK already widened in 20260519090000) and to the agent filter
- ApprovalCard notes that ignoring a proposal is safe
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* docs(mcp): surface the client telemetry marker in connect instructions
Tag the connector URLs shown in ApiKeysPanel, the connect-claude doc and
the gnubok-mcp README with ?client=<surface> (claude-connector /
claude-code) and GNUBOK_CLIENT=claude-desktop for the npm bridge.
Telemetry-only — the server already reads the param/header; this just
lets us measure which Claude surface connected.
The claude mcp add copy blocks quote the URL: an unquoted ? in the query
string trips zsh globbing ("no matches found").
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* review: fix stale-closure badge flip + zod-validate link route body (PR #712)
- handleDocumentAttached read journal_entry_id off the render-time
transactions snapshot; if the list changed while the attach dialog was
open the optimistic badge flip was silently skipped. Read it off the
dialog's own subject (attachDocTx) instead.
- POST /api/documents/[id]/link now validates the body against the new
LinkDocumentSchema (uuid-strict, all four fields) instead of a bare
presence check on journal_entry_id — same canonical VALIDATION_ERROR
envelope. Test fixtures switched to real UUIDs accordingly.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
138 lines
4.0 KiB
TypeScript
138 lines
4.0 KiB
TypeScript
'use client'
|
|
|
|
import { useState } from 'react'
|
|
import { useTranslations } from 'next-intl'
|
|
import Link from 'next/link'
|
|
import { Paperclip, Loader2 } from 'lucide-react'
|
|
import { Badge } from '@/components/ui/badge'
|
|
import { cn } from '@/lib/utils'
|
|
import { useToast } from '@/components/ui/use-toast'
|
|
|
|
interface Props {
|
|
documentId: string | null | undefined
|
|
/** The booked tx's journal entry — link target when the underlag lives only
|
|
* at verifikat level (multi-doc entries, booking-dialog uploads). */
|
|
journalEntryId?: string | null
|
|
/** Underlag exists on the journal entry even though no doc is pinned to the
|
|
* transaction row (computeJeUnderlagStatus === 'has'). */
|
|
hasJeDoc?: boolean
|
|
/** Booked, requires underlag, has none (computeJeUnderlagStatus === 'missing'). */
|
|
missing?: boolean
|
|
/** Opens the attach dialog from the negative state. Omit for viewers —
|
|
* the badge then renders non-interactive. */
|
|
onAttach?: () => void
|
|
className?: string
|
|
}
|
|
|
|
const badgeClass = 'h-4 gap-1 px-1.5 py-0 text-[10px] font-normal'
|
|
// Enlarges the hit area beyond the 16px badge without shifting layout.
|
|
const hitAreaClass = 'shrink-0 p-1 -m-1'
|
|
|
|
/**
|
|
* Per-row underlag status for the /transactions lists.
|
|
*
|
|
* - Pinned doc (transactions.document_id): clickable badge that fetches a
|
|
* signed URL and opens the document in a new tab.
|
|
* - Verifikat-level doc only: same badge, links to the verifikat page (which
|
|
* lists all attachments — handles multi-doc without a per-row fetch).
|
|
* - Missing on a booked row: discreet outline badge that doubles as the
|
|
* attach affordance when onAttach is provided.
|
|
*/
|
|
export function TransactionAttachmentIndicator({
|
|
documentId,
|
|
journalEntryId,
|
|
hasJeDoc,
|
|
missing,
|
|
onAttach,
|
|
className,
|
|
}: Props) {
|
|
const t = useTranslations('tx_underlag')
|
|
const { toast } = useToast()
|
|
const [isLoading, setIsLoading] = useState(false)
|
|
|
|
const handleOpen = async (e: React.MouseEvent) => {
|
|
e.stopPropagation()
|
|
e.preventDefault()
|
|
if (isLoading || !documentId) return
|
|
setIsLoading(true)
|
|
try {
|
|
const res = await fetch(`/api/documents/${documentId}`)
|
|
if (!res.ok) {
|
|
toast({ title: t('open_failed'), variant: 'destructive' })
|
|
return
|
|
}
|
|
const { data } = await res.json()
|
|
if (data?.download_url) {
|
|
window.open(data.download_url, '_blank', 'noopener,noreferrer')
|
|
}
|
|
} finally {
|
|
setIsLoading(false)
|
|
}
|
|
}
|
|
|
|
if (documentId) {
|
|
return (
|
|
<button
|
|
type="button"
|
|
onClick={handleOpen}
|
|
title={t('attached_title')}
|
|
aria-label={t('attached_aria')}
|
|
className={cn(hitAreaClass, className)}
|
|
>
|
|
<Badge variant="secondary" className={badgeClass}>
|
|
{isLoading ? (
|
|
<Loader2 className="h-3 w-3 animate-spin" />
|
|
) : (
|
|
<Paperclip className="h-3 w-3" />
|
|
)}
|
|
{t('attached_label')}
|
|
</Badge>
|
|
</button>
|
|
)
|
|
}
|
|
|
|
if (hasJeDoc && journalEntryId) {
|
|
return (
|
|
<Link
|
|
href={`/bookkeeping/${journalEntryId}`}
|
|
title={t('attached_title')}
|
|
aria-label={t('attached_aria')}
|
|
onClick={(e) => e.stopPropagation()}
|
|
className={cn(hitAreaClass, className)}
|
|
>
|
|
<Badge variant="secondary" className={badgeClass}>
|
|
<Paperclip className="h-3 w-3" />
|
|
{t('attached_label')}
|
|
</Badge>
|
|
</Link>
|
|
)
|
|
}
|
|
|
|
if (missing) {
|
|
const badge = (
|
|
<Badge variant="outline" className={cn(badgeClass, 'text-muted-foreground')}>
|
|
<Paperclip className="h-3 w-3" />
|
|
{t('missing_label')}
|
|
</Badge>
|
|
)
|
|
if (!onAttach) return <span className={cn('shrink-0', className)}>{badge}</span>
|
|
return (
|
|
<button
|
|
type="button"
|
|
onClick={(e) => {
|
|
e.stopPropagation()
|
|
e.preventDefault()
|
|
onAttach()
|
|
}}
|
|
title={t('missing_title')}
|
|
aria-label={t('missing_title')}
|
|
className={cn(hitAreaClass, className)}
|
|
>
|
|
{badge}
|
|
</button>
|
|
)
|
|
}
|
|
|
|
return null
|
|
}
|