za actions dodan "noStore"

This commit is contained in:
2024-02-06 14:17:12 +01:00
parent cf97b3d4b5
commit f0581eb533
2 changed files with 14 additions and 1 deletions

View File

@@ -7,7 +7,7 @@ import { ObjectId } from 'mongodb';
import { withUser } from '@/app/lib/auth'; import { withUser } from '@/app/lib/auth';
import { AuthenticatedUser } from '../types/next-auth'; import { AuthenticatedUser } from '../types/next-auth';
import { gotoHome } from './navigationActions'; import { gotoHome } from './navigationActions';
import { Noto_Sans_Tamil_Supplement } from 'next/font/google'; import { unstable_noStore as noStore } from 'next/cache';
import { asyncTimeout } from '../asyncTimeout'; import { asyncTimeout } from '../asyncTimeout';
export type State = { export type State = {
@@ -35,6 +35,8 @@ const UpdateLocation = FormSchema.omit({ _id: true });
*/ */
export const updateOrAddLocation = withUser(async (user:AuthenticatedUser, locationId: string | undefined, yearMonth: YearMonth | undefined, prevState:State, formData: FormData) => { export const updateOrAddLocation = withUser(async (user:AuthenticatedUser, locationId: string | undefined, yearMonth: YearMonth | undefined, prevState:State, formData: FormData) => {
noStore();
const validatedFields = UpdateLocation.safeParse({ const validatedFields = UpdateLocation.safeParse({
locationName: formData.get('locationName'), locationName: formData.get('locationName'),
locationNotes: formData.get('locationNotes'), locationNotes: formData.get('locationNotes'),
@@ -95,6 +97,8 @@ export const updateOrAddLocation = withUser(async (user:AuthenticatedUser, locat
export const fetchAllLocations = withUser(async (user:AuthenticatedUser, year:number) => { export const fetchAllLocations = withUser(async (user:AuthenticatedUser, year:number) => {
noStore();
const dbClient = await getDbClient(); const dbClient = await getDbClient();
const { id: userId } = user; const { id: userId } = user;
@@ -119,6 +123,8 @@ export const fetchAllLocations = withUser(async (user:AuthenticatedUser, year:nu
export const fetchLocationById = withUser(async (user:AuthenticatedUser, locationID:string) => { export const fetchLocationById = withUser(async (user:AuthenticatedUser, locationID:string) => {
noStore();
const dbClient = await getDbClient(); const dbClient = await getDbClient();
const { id: userId } = user; const { id: userId } = user;
@@ -138,6 +144,8 @@ export const fetchLocationById = withUser(async (user:AuthenticatedUser, locatio
export const deleteLocationById = withUser(async (user:AuthenticatedUser, locationID:string, yearMonth:YearMonth) => { export const deleteLocationById = withUser(async (user:AuthenticatedUser, locationID:string, yearMonth:YearMonth) => {
noStore();
const dbClient = await getDbClient(); const dbClient = await getDbClient();
const { id: userId } = user; const { id: userId } = user;

View File

@@ -5,6 +5,7 @@ import { ObjectId } from 'mongodb';
import { Bill, BillingLocation, YearMonth } from '../db-types'; import { Bill, BillingLocation, YearMonth } from '../db-types';
import { AuthenticatedUser } from '../types/next-auth'; import { AuthenticatedUser } from '../types/next-auth';
import { withUser } from '../auth'; import { withUser } from '../auth';
import { unstable_noStore as noStore } from 'next/cache';
/** /**
* Server-side action which adds a new month to the database * Server-side action which adds a new month to the database
@@ -15,6 +16,8 @@ import { withUser } from '../auth';
* @returns * @returns
*/ */
export const addMonth = withUser(async (user:AuthenticatedUser, { year, month }: YearMonth) => { export const addMonth = withUser(async (user:AuthenticatedUser, { year, month }: YearMonth) => {
noStore();
const { id: userId } = user; const { id: userId } = user;
// update the bill in the mongodb // update the bill in the mongodb
@@ -60,6 +63,8 @@ export const addMonth = withUser(async (user:AuthenticatedUser, { year, month }:
}); });
export const fetchAvailableYears = withUser(async (user:AuthenticatedUser) => { export const fetchAvailableYears = withUser(async (user:AuthenticatedUser) => {
noStore();
const { id: userId } = user; const { id: userId } = user;
const dbClient = await getDbClient(); const dbClient = await getDbClient();