Fix client-side cache staleness after proof of payment upload

Added cache revalidation to ensure ViewLocationCard reflects uploaded
proof of payment when navigating back from ViewBillCard:

- Server-side: Added revalidatePath() to upload actions in billActions
  and locationActions to invalidate Next.js server cache
- Client-side: Added router.refresh() calls in ViewBillCard and
  ViewLocationCard to refresh client router cache after successful upload

This maintains the current UX (no redirect on upload) while ensuring
fresh data is displayed on navigation.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Knee Cola
2025-12-07 16:57:00 +01:00
parent cfa6a4c5b7
commit 0f8b5678f4
4 changed files with 32 additions and 13 deletions

View File

@@ -1,9 +1,10 @@
"use client";
import { DocumentIcon, CheckCircleIcon, XCircleIcon } from "@heroicons/react/24/outline";
import { TicketIcon, CheckCircleIcon, XCircleIcon, DocumentIcon } from "@heroicons/react/24/outline";
import { Bill, BillingLocation } from "../lib/db-types";
import { FC, useState } from "react";
import Link from "next/link";
import { useRouter } from "next/navigation";
import { formatYearMonth } from "../lib/format";
import { useTranslations } from "next-intl";
import { Pdf417Barcode } from "./Pdf417Barcode";
@@ -16,6 +17,7 @@ export interface ViewBillCardProps {
export const ViewBillCard: FC<ViewBillCardProps> = ({ location, bill }) => {
const router = useRouter();
const t = useTranslations("bill-edit-form");
const { _id: billID, name, paid, attachment, notes, payedAmount, hub3aText, proofOfPayment } = bill ?? { _id: undefined, name: "", paid: false, notes: "" };
@@ -49,6 +51,7 @@ export const ViewBillCard: FC<ViewBillCardProps> = ({ location, bill }) => {
if (result.success) {
setProofOfPaymentFilename(file.name);
setProofOfPaymentUploadedAt(new Date());
router.refresh();
} else {
setUploadError(result.error || 'Upload failed');
}
@@ -125,7 +128,7 @@ export const ViewBillCard: FC<ViewBillCardProps> = ({ location, bill }) => {
target="_blank"
className='text-center w-full max-w-[20rem] text-nowrap truncate inline-block'
>
<DocumentIcon className="h-[1em] w-[1em] text-2xl inline-block mr-1" />
<TicketIcon className="h-[1em] w-[1em] text-2xl inline-block mr-1" />
{ decodeURIComponent(proofOfPaymentFilename) }
</Link>
</div>