refactoring: changing param list of a fn

This commit is contained in:
2024-02-01 15:07:30 +01:00
parent a1abc450bf
commit 2261e83715
8 changed files with 26 additions and 18 deletions

View File

@@ -109,7 +109,7 @@ const serializeAttachment = async (billAttachment: File | null) => {
* @param formData form data
* @returns
*/
export const updateOrAddBill = withUser(async (user:AuthenticatedUser, locationId: string, billId:string|undefined, billYear:number|undefined, prevState:State, formData: FormData) => {
export const updateOrAddBill = withUser(async (user:AuthenticatedUser, locationId: string, billId:string|undefined, billYear:number|undefined, billMonth:number|undefined, prevState:State, formData: FormData) => {
const { id: userId } = user;
@@ -191,7 +191,9 @@ export const updateOrAddBill = withUser(async (user:AuthenticatedUser, locationI
}
});
}
await gotoHome(billYear ? `/?year=${billYear}` : undefined);
if(billYear && billMonth ) {
await gotoHome({ year: billYear, month: billMonth });
}
})
export const fetchBillById = withUser(async (user:AuthenticatedUser, locationID:string, billID:string) => {
@@ -219,7 +221,7 @@ export const fetchBillById = withUser(async (user:AuthenticatedUser, locationID:
return([billLocation, bill] as [BillingLocation, Bill]);
})
export const deleteBillById = withUser(async (user:AuthenticatedUser, locationID:string, billID:string, year:number) => {
export const deleteBillById = withUser(async (user:AuthenticatedUser, locationID:string, billID:string, year:number, month:number) => {
const { id: userId } = user;
@@ -240,6 +242,6 @@ export const deleteBillById = withUser(async (user:AuthenticatedUser, locationID
}
});
await gotoHome(`/?year=${year}`);
await gotoHome({year, month});
return(post.modifiedCount);
});

View File

@@ -138,5 +138,5 @@ export const deleteLocationById = withUser(async (user:AuthenticatedUser, locati
// find a location with the given locationID
const post = await dbClient.collection<BillingLocation>("lokacije").deleteOne({ _id: locationID, userId });
await gotoHome(`/?year=${yearMonth?.year}`)
await gotoHome(yearMonth)
})

View File

@@ -2,8 +2,15 @@
import { revalidatePath } from "next/cache";
import { redirect } from 'next/navigation';
import { YearMonth } from "../db-types";
export async function gotoHome(path: string = '/') {
export async function gotoHome({year, month}: YearMonth) {
const path = `/?year=${year}&month=${month}`;
await gotoUrl(path);
}
export async function gotoUrl(path: string) {
console.log(path)
revalidatePath(path, "page");
redirect(path);
}