perf(forms): supplier-invoice form, register forms and review dialogs read the session cache (#1938)
The supplier-invoice editor issued four requests on every mount (suppliers, accounts, settings, fiscal periods) and defaulted vatRegistered=true, entity type and rounding until /api/settings landed, so the moms controls visibly flipped. The register forms fetched the whole chart of accounts to fill one konto combobox, and each transaction review dialog refetched accounts, cash accounts or settings per open. - use-supplier-invoice-data: thin composition of useSuppliers, useAccounts, useCompanySettings and useFiscalPeriods; the settings-driven gates come from a pure deriveSupplierInvoiceDefaults() (tested) instead of state that flips when the fetch returns; the per-invoice öresavrundning toggle is the one local override. Inline supplier create invalidates the shared list instead of patching local state. - SupplierForm, ArticleForm (posting accounts), QuickReviewDialog, InvoiceMatchDialog, supplier-invoices/[id] (payment dialog chart): useAccounts; ArticleForm's inline account create invalidates the chart. - BulkBookDialog, MatchVoucherDialog, DuplicateBookingDialog: cash accounts from useCashAccounts (resolveAccount over the cached list; an empty list still resolves to 1930 with the fallback note). - QuickReviewDialog, BulkBookDialog, NewEmployeeDialog, customers list (default payment terms), salary run page (payment format, bank, IBAN, dimensions): derived from useCompanySettings; the salary page's post-settings-modal refetch becomes a cache invalidation. raw-reference-fetch ratchet: 45 -> 35 files. Co-authored-by: Jakob Wennberg <311770904+jakobwennberg-oss@users.noreply.github.com> Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Jakob Wennberg
Claude Fable 5
parent
40e773548c
commit
4560ccbfc9
@@ -1,6 +1,7 @@
|
||||
'use client'
|
||||
|
||||
import { useState } from 'react'
|
||||
import { useCashAccounts } from '@/lib/reference-data/hooks'
|
||||
import { useTranslations, useLocale } from 'next-intl'
|
||||
import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@/components/ui/dialog'
|
||||
import { Button } from '@/components/ui/button'
|
||||
@@ -9,7 +10,6 @@ import { AlertTriangle, Loader2 } from 'lucide-react'
|
||||
import { formatCurrency, formatDate } from '@/lib/utils'
|
||||
import { getErrorMessage, type ErrorLocale } from '@/lib/errors/get-error-message'
|
||||
import { resolveAccount } from '@/lib/cash-accounts/resolve-account'
|
||||
import type { CashAccount } from '@/types'
|
||||
import type { BookedDuplicateCandidate } from '@/lib/transactions/booking-duplicate-detection'
|
||||
|
||||
/** The bank transaction being booked, as much as the caller knows about it.
|
||||
@@ -99,6 +99,10 @@ export default function DuplicateBookingDialog({
|
||||
const canMatch = candidate !== null && !!matchTransaction && !!onMatched
|
||||
const canIgnore = isSiblingCandidate && !!matchTransaction && !!onIgnored
|
||||
|
||||
// Session-cached (lib/reference-data); an empty list resolves to 1930 and
|
||||
// the link route re-validates the account either way.
|
||||
const { cashAccounts } = useCashAccounts()
|
||||
|
||||
async function handleMatch() {
|
||||
if (!candidate || !matchTransaction || !onMatched || matching) return
|
||||
setMatching(true)
|
||||
@@ -112,20 +116,11 @@ export default function DuplicateBookingDialog({
|
||||
// this account and that the transaction belongs to it.
|
||||
let account = candidate.account_number ?? '1930'
|
||||
if (!candidate.account_number) {
|
||||
try {
|
||||
const caRes = await fetch('/api/cash-accounts')
|
||||
if (caRes.ok) {
|
||||
const caJson = await caRes.json()
|
||||
const accounts = (caJson.data ?? []) as CashAccount[]
|
||||
account = resolveAccount(
|
||||
accounts,
|
||||
matchTransaction.cash_account_id ?? null,
|
||||
matchTransaction.currency ?? 'SEK',
|
||||
).account
|
||||
}
|
||||
} catch {
|
||||
// Network hiccup: fall back to 1930; the link route re-validates.
|
||||
}
|
||||
account = resolveAccount(
|
||||
cashAccounts,
|
||||
matchTransaction.cash_account_id ?? null,
|
||||
matchTransaction.currency ?? 'SEK',
|
||||
).account
|
||||
}
|
||||
|
||||
const res = await fetch('/api/reconciliation/bank/link', {
|
||||
|
||||
Reference in New Issue
Block a user