form action redirects user to tjhe appropriate year
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { fetchLocationById } from '@/app/lib/actions/locationActions';
|
||||
import { BillEditForm } from '@/app/ui/BillEditForm';
|
||||
import { Main } from '@/app/ui/Main';
|
||||
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
import { deleteBillById } from '@/app/lib/actions/billActions';
|
||||
import { revalidatePath } from 'next/cache';
|
||||
import { notFound, redirect } from 'next/navigation';
|
||||
import { notFound } from 'next/navigation';
|
||||
import { fetchLocationById } from '@/app/lib/actions/locationActions';
|
||||
import { LocationDeleteForm } from '@/app/ui/LocationDeleteForm';
|
||||
import { BillDeleteForm } from '@/app/ui/BillDeleteForm';
|
||||
import { fetchBillById } from '@/app/lib/actions/billActions';
|
||||
|
||||
export default async function Page({ params:{ id } }: { params: { id:string } }) {
|
||||
const [locationID, billID] = id.split('-');
|
||||
|
||||
if(await deleteBillById(locationID, billID) === 0) {
|
||||
const [location, bill] = await fetchBillById(locationID, billID) ?? [];
|
||||
|
||||
if (!location || !bill) {
|
||||
return(notFound());
|
||||
}
|
||||
|
||||
revalidatePath('/');
|
||||
redirect(`/`);
|
||||
return (<BillDeleteForm location={location} bill={bill} />);
|
||||
}
|
||||
@@ -7,14 +7,14 @@ export default async function Page({ params:{ id } }: { params: { id:string } })
|
||||
|
||||
const [locationID, billID] = id.split('-');
|
||||
|
||||
const bill = await fetchBillById(locationID, billID);
|
||||
const [location, bill] = await fetchBillById(locationID, billID) ?? [];
|
||||
|
||||
if (!bill) {
|
||||
return(notFound());
|
||||
}
|
||||
return (
|
||||
<Main>
|
||||
<BillEditForm locationID={locationID} bill={bill} />
|
||||
<BillEditForm locationID={locationID} bill={bill} billYear={location?.yearMonth.year} />
|
||||
</Main>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user