form action redirects user to tjhe appropriate year

This commit is contained in:
2024-01-17 15:47:55 +01:00
parent 119d64344f
commit 0eb11e7d02
18 changed files with 158 additions and 86 deletions

View File

@@ -1,10 +1,8 @@
'use server';
import { revalidatePath } from 'next/cache';
import { redirect } from 'next/navigation';
import clientPromise, { getDbClient } from '../dbClient';
import { getDbClient } from '../dbClient';
import { ObjectId } from 'mongodb';
import { BillingLocation, YearMonth } from '../db-types';
import { Bill, BillingLocation, YearMonth } from '../db-types';
import { AuthenticatedUser } from '../types/next-auth';
import { withUser } from '../auth';
@@ -22,7 +20,6 @@ export const addMonth = withUser(async (user:AuthenticatedUser, { year, month }:
// update the bill in the mongodb
const dbClient = await getDbClient();
const prevYear = month === 1 ? year - 1 : year;
const prevMonth = month === 1 ? 12 : month - 1;
@@ -52,24 +49,16 @@ export const addMonth = withUser(async (user:AuthenticatedUser, { year, month }:
paid: false,
attachment: null,
notes: null,
}
payedAmount: null
} as Bill
})
} as BillingLocation);
});
const newMonthLocations = await newMonthLocationsCursor.toArray()
await dbClient.collection<BillingLocation>("lokacije").insertMany(newMonthLocations);
// clear the cache for the path
revalidatePath('/');
// go to the bill list
redirect('/');
});
export async function gotoHome() {
redirect('/');
}
export const fetchAvailableYears = withUser(async (user:AuthenticatedUser) => {
const { id: userId } = user;