implented adding year-month
This commit is contained in:
10
app/page.tsx
10
app/page.tsx
@@ -3,14 +3,18 @@ import { MonthTitle } from './ui/MonthTitle';
|
||||
import { AddMonthButton } from './ui/AddMonthButton';
|
||||
import { AddLocationButton } from './ui/AddLocationButton';
|
||||
import clientPromise from './lib/mongodb';
|
||||
import { Location } from './lib/db-types';
|
||||
import { BillingLocation } from './lib/db-types';
|
||||
|
||||
const calcNextYearMonth = (yearMonth: number) => {
|
||||
return(yearMonth % 100 === 12 ? yearMonth + 89 : yearMonth + 1);
|
||||
}
|
||||
|
||||
export const Page = async () => {
|
||||
|
||||
const client = await clientPromise;
|
||||
const db = client.db("rezije");
|
||||
|
||||
const locations = await db.collection<Location>("lokacije")
|
||||
const locations = await db.collection<BillingLocation>("lokacije")
|
||||
.find({})
|
||||
.sort({ yearMonth: -1 }) // sort by yearMonth descending
|
||||
.limit(20)
|
||||
@@ -18,7 +22,7 @@ export const Page = async () => {
|
||||
|
||||
return (
|
||||
<main className="flex min-h-screen flex-col p-6 bg-base-300">
|
||||
<AddMonthButton />
|
||||
<AddMonthButton yearMonth={calcNextYearMonth(locations[0].yearMonth)} />
|
||||
{
|
||||
locations.map((location, ix, array) => {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user