implemented bill deletion + var rename
This commit is contained in:
4
app/bills/[id]/delete/not-found.tsx
Normal file
4
app/bills/[id]/delete/not-found.tsx
Normal file
@@ -0,0 +1,4 @@
|
||||
import { NotFoundPage } from '@/app/ui/NotFoundPage';
|
||||
|
||||
export default () =>
|
||||
<NotFoundPage title="404 Bill Not Found" description="Could not find the requested Bill." />;
|
||||
12
app/bills/[id]/delete/page.tsx
Normal file
12
app/bills/[id]/delete/page.tsx
Normal file
@@ -0,0 +1,12 @@
|
||||
import { deleteBillById } from '@/app/lib/actions';
|
||||
import { notFound, redirect } from 'next/navigation';
|
||||
|
||||
export default async function Page({ params:{ id } }: { params: { id:string } }) {
|
||||
const [locationID, billID] = id.split('-');
|
||||
|
||||
if(await deleteBillById(locationID, billID) === 0) {
|
||||
return(notFound());
|
||||
}
|
||||
|
||||
redirect(`/`);
|
||||
}
|
||||
@@ -1,18 +1,4 @@
|
||||
import Link from 'next/link';
|
||||
import { FaceFrownIcon } from '@heroicons/react/24/outline';
|
||||
import { NotFoundPage } from '@/app/ui/NotFoundPage';
|
||||
|
||||
export default function NotFound() {
|
||||
return (
|
||||
<main className="flex h-full flex-col items-center justify-center gap-2">
|
||||
<FaceFrownIcon className="w-10 text-gray-400" />
|
||||
<h2 className="text-xl font-semibold">404 Bill Not Found</h2>
|
||||
<p>Could not find the requested Bill.</p>
|
||||
<Link
|
||||
href="/"
|
||||
className="mt-4 rounded-md bg-blue-500 px-4 py-2 text-sm text-white transition-colors hover:bg-blue-400"
|
||||
>
|
||||
Go Back
|
||||
</Link>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
export default () =>
|
||||
<NotFoundPage title="404 Bill Not Found" description="Could not find the requested Bill." />;
|
||||
@@ -1,5 +1,5 @@
|
||||
import { PlainLocation, PlainBill, MongoLocation } from '@/app/lib/db-types';
|
||||
import { fetchBillById } from '@/app/lib/fetchBillById';
|
||||
import { BillingLocation, Bill } from '@/app/lib/db-types';
|
||||
import { fetchBillById } from '@/app/lib/actions';
|
||||
import clientPromise from '@/app/lib/mongodb';
|
||||
import { BillEditForm } from '@/app/ui/BillEditForm';
|
||||
import { ObjectId } from 'mongodb';
|
||||
@@ -7,16 +7,16 @@ import { notFound } from 'next/navigation';
|
||||
|
||||
export default async function Page({ params:{ id } }: { params: { id:string } }) {
|
||||
|
||||
const [invoiceID, billID] = id.split('-');
|
||||
const [locationID, billID] = id.split('-');
|
||||
|
||||
const bill = await fetchBillById(invoiceID, billID);
|
||||
const bill = await fetchBillById(locationID, billID);
|
||||
|
||||
if (!bill) {
|
||||
notFound();
|
||||
return(notFound());
|
||||
}
|
||||
return (
|
||||
<main>
|
||||
<BillEditForm invoiceID={invoiceID} bill={bill} />
|
||||
<BillEditForm locationID={locationID} bill={bill} />
|
||||
</main>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user