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:
@@ -7,7 +7,7 @@ import { ObjectId } from 'mongodb';
|
||||
import { withUser } from '@/app/lib/auth';
|
||||
import { AuthenticatedUser } from '../types/next-auth';
|
||||
import { gotoHomeWithMessage } from './navigationActions';
|
||||
import { unstable_noStore as noStore } from 'next/cache';
|
||||
import { unstable_noStore, revalidatePath } from 'next/cache';
|
||||
import { IntlTemplateFn } from '@/app/i18n';
|
||||
import { getTranslations, getLocale } from "next-intl/server";
|
||||
|
||||
@@ -106,7 +106,7 @@ const FormSchema = (t:IntlTemplateFn) => z.object({
|
||||
*/
|
||||
export const updateOrAddLocation = withUser(async (user:AuthenticatedUser, locationId: string | undefined, yearMonth: YearMonth | undefined, prevState:State, formData: FormData) => {
|
||||
|
||||
noStore();
|
||||
unstable_noStore();
|
||||
|
||||
const t = await getTranslations("location-edit-form.validation");
|
||||
|
||||
@@ -373,7 +373,7 @@ export const updateOrAddLocation = withUser(async (user:AuthenticatedUser, locat
|
||||
|
||||
export const fetchAllLocations = withUser(async (user:AuthenticatedUser, year:number) => {
|
||||
|
||||
noStore();
|
||||
unstable_noStore();
|
||||
|
||||
const dbClient = await getDbClient();
|
||||
|
||||
@@ -470,7 +470,7 @@ ova metoda je zamijenjena sa jednostavnijom `fetchLocationById`, koja brže radi
|
||||
|
||||
export const fetchLocationByUserAndId = withUser(async (user:AuthenticatedUser, locationID:string) => {
|
||||
|
||||
noStore();
|
||||
unstable_noStore();
|
||||
|
||||
const dbClient = await getDbClient();
|
||||
|
||||
@@ -499,7 +499,7 @@ export const fetchLocationByUserAndId = withUser(async (user:AuthenticatedUser,
|
||||
|
||||
export const fetchLocationById = async (locationID:string) => {
|
||||
|
||||
noStore();
|
||||
unstable_noStore();
|
||||
|
||||
const dbClient = await getDbClient();
|
||||
|
||||
@@ -526,7 +526,7 @@ export const fetchLocationById = async (locationID:string) => {
|
||||
|
||||
export const deleteLocationById = withUser(async (user:AuthenticatedUser, locationID:string, yearMonth:YearMonth, _prevState:any, formData: FormData) => {
|
||||
|
||||
noStore();
|
||||
unstable_noStore();
|
||||
|
||||
const dbClient = await getDbClient();
|
||||
|
||||
@@ -642,7 +642,8 @@ const serializeAttachment = async (file: File | null):Promise<FileAttachment | n
|
||||
* @returns Promise with success status
|
||||
*/
|
||||
export const uploadUtilBillsProofOfPayment = async (locationID: string, formData: FormData): Promise<{ success: boolean; error?: string }> => {
|
||||
noStore();
|
||||
|
||||
unstable_noStore();
|
||||
|
||||
try {
|
||||
|
||||
@@ -689,6 +690,9 @@ export const uploadUtilBillsProofOfPayment = async (locationID: string, formData
|
||||
} }
|
||||
);
|
||||
|
||||
// Invalidate the location view cache
|
||||
revalidatePath(`/share/location/${locationID}`, 'page');
|
||||
|
||||
return { success: true };
|
||||
} catch (error: any) {
|
||||
console.error('Error uploading util bills proof of payment:', error);
|
||||
|
||||
Reference in New Issue
Block a user