import { revalidatePath } from "next/cache"; import { INVOICE_PATHS } from "./invoice-routes"; // SERVER-SIDE ONLY — imports `next/cache`, so nothing client-side may pull this in. Route // paths live in ./invoice-routes.ts for exactly that reason. // // Every mutation path must refresh BOTH halves of the register. Booking a line, importing // a PDF and retrying an intake can all land on either page depending on the debtor, so // revalidating only one leaves the other showing stale rows. // // Revalidating a page that did not change costs a re-render, not correctness — so the // asymmetry is free to fix and expensive to miss. Use `revalidateInvoicePages` instead of a // bare `revalidatePath` for anything that writes to `invoices` or `invoice_lines`. // Invoice amounts and bookings feed every one of these readers. Keep them here so // upload, retry, clear and reassignment cannot each invalidate a different subset. // Dynamic detail patterns require the "page" type in Next's revalidation API. const READERS = [...INVOICE_PATHS, "/income", "/sites", "/charts", "/", "/sites/[id]"]; export function revalidateInvoicePages(...extra: string[]) { for (const path of new Set([...READERS, ...extra])) { if (path.includes("[")) revalidatePath(path, "page"); else revalidatePath(path); } }