diff --git a/app/api/payments/[id]/replace-pop/route.ts b/app/api/payments/[id]/replace-pop/route.ts index 4df3752..87838d2 100644 --- a/app/api/payments/[id]/replace-pop/route.ts +++ b/app/api/payments/[id]/replace-pop/route.ts @@ -1,4 +1,5 @@ import { NextRequest, NextResponse } from "next/server"; +import { revalidatePath } from "next/cache"; import { getPb } from "../../../../lib/pb"; const BATCHES = "JEI_payment_batches"; @@ -54,5 +55,7 @@ export async function POST( ); } + revalidatePath("/remittance"); + return NextResponse.json({ ok: true }); } diff --git a/app/api/payments/[id]/unpay/route.ts b/app/api/payments/[id]/unpay/route.ts index 20d0fd8..be0a940 100644 --- a/app/api/payments/[id]/unpay/route.ts +++ b/app/api/payments/[id]/unpay/route.ts @@ -1,4 +1,5 @@ import { NextRequest, NextResponse } from "next/server"; +import { revalidatePath } from "next/cache"; import { getPb } from "../../../../lib/pb"; const BATCHES = "JEI_payment_batches"; @@ -63,6 +64,14 @@ export async function POST( ); } + // Invalidate Next.js router caches for the affected pages so subsequent + // navigations to /unpaid, /remittance, and /invoices re-fetch fresh data + // (otherwise the client may show a stale page that hides the just-unpayed + // invoices). + revalidatePath("/unpaid"); + revalidatePath("/remittance"); + revalidatePath("/invoices"); + return NextResponse.json({ ok: true, unpayedCount: invoiceIds.length, diff --git a/app/api/payments/create/route.ts b/app/api/payments/create/route.ts index 7dd354e..91f1b39 100644 --- a/app/api/payments/create/route.ts +++ b/app/api/payments/create/route.ts @@ -1,4 +1,5 @@ import { NextRequest, NextResponse } from "next/server"; +import { revalidatePath } from "next/cache"; import { getPb } from "../../../lib/pb"; const BATCHES = "JEI_payment_batches"; @@ -135,6 +136,13 @@ export async function POST(req: NextRequest) { }), ); + // Invalidate Next.js router caches for the affected pages so the + // just-paid invoices disappear from /unpaid and the new paid rows + + // batch appear on /remittance and /invoices. + revalidatePath("/unpaid"); + revalidatePath("/remittance"); + revalidatePath("/invoices"); + return NextResponse.json({ ok: true, batchId,