fix: invalidate Next.js router cache on payment actions (unpay/create/replace-pop)
This commit is contained in:
parent
146d31df87
commit
ca1c6cfedd
3 changed files with 20 additions and 0 deletions
|
|
@ -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 });
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Reference in a new issue