Files
evidencija-rezija/app/bills/[id]/edit/page.tsx

32 lines
1.0 KiB
TypeScript

import { Location } from '@/app/lib/db-types';
import clientPromise from '@/app/lib/mongodb';
import { BillEditForm } from '@/app/ui/BillEditForm';
import { ObjectId } from 'mongodb';
import { notFound } from 'next/navigation';
const fetchBillById = async (locationID:string, billID:string) => {
const client = await clientPromise;
const db = client.db("rezije");
// find a location with the given locationID
const billLocation = await db.collection<Location>("lokacije").findOne({ _id: locationID })
// find a bill with the given billID
return(billLocation?.bills.find(({ _id }) => _id.toString() === billID))
}
export default async function Page({ params:{ id } }: { params: { id:string } }) {
const [invoiceID, billID] = id.split('-');
const bill = await fetchBillById(invoiceID, billID);
if (!bill) {
console.log('Bill not found');
notFound();
}
return (
<main>
<BillEditForm invoiceID={invoiceID} bill={bill} />
</main>
);
}