* feat(pending): queue order toggle, entry date + notes in review, account names everywhere Four review-queue gaps reported by a customer approving bokslut batches: - Oldest-first toggle: /api/pending-operations accepts order=asc|desc (default desc); the queue header gets an Äldst först / Nyast först button, remembered per browser (localStorage pending.sortOrder). - Fiscal year visible: categorize previews now carry the transaction date (preview_data.date) and render a Datum row, so two open years are distinguishable. - The agent's `notes` (audit-trail context) is shown in the detail panel as Anteckning; before, it was stored in params and never rendered. - Account names: VoucherLinesTable and PreviewKonteringTable fall back to the chart name from AccountNamesContext (6110 Kontorsmateriel · AMAZON PRIME instead of the bank text alone); useAccountNamesSource moves to a shared hook so the chat ApprovalCard provides the same names. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * fix(agent): call useAccountNamesSource in ApprovalCard The provider referenced accountNames without the hook call; the core build (tsc) caught it. Local tsc had not, so this also re-runs the full check. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> --------- Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
40 lines
1.3 KiB
TypeScript
40 lines
1.3 KiB
TypeScript
'use client'
|
|
|
|
import { useEffect, useState } from 'react'
|
|
|
|
/**
|
|
* Account number -> account name for the proposal previews, fetched once per
|
|
* mount for the active company. Provide the result through
|
|
* AccountNamesContext (OperationPreview) so every preview surface (the
|
|
* /pending queue, the chat ApprovalCard) shows "6110 Kontorsmateriel" and
|
|
* not just the number or the bank's raw text. Display-only: a failed fetch
|
|
* leaves the map empty and previews fall back to the number.
|
|
*/
|
|
export function useAccountNamesSource(): Record<string, string> {
|
|
const [names, setNames] = useState<Record<string, string>>({})
|
|
useEffect(() => {
|
|
let alive = true
|
|
void fetch('/api/bookkeeping/accounts')
|
|
.then((r) => r.json())
|
|
.then(({ data }) => {
|
|
if (!alive) return
|
|
setNames(
|
|
Object.fromEntries(
|
|
((data ?? []) as Array<{ account_number: string; account_name: string }>).map((a) => [
|
|
a.account_number,
|
|
a.account_name,
|
|
]),
|
|
),
|
|
)
|
|
})
|
|
.catch(() => {
|
|
// Display-only: the number still shows, so a failure is not worth
|
|
// surfacing as an error the user cannot act on.
|
|
})
|
|
return () => {
|
|
alive = false
|
|
}
|
|
}, [])
|
|
return names
|
|
}
|