completed location deletion
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import { deleteBillById } from '@/app/lib/billActions';
|
import { deleteBillById } from '@/app/lib/billActions';
|
||||||
|
import { revalidatePath } from 'next/cache';
|
||||||
import { notFound, redirect } from 'next/navigation';
|
import { notFound, redirect } from 'next/navigation';
|
||||||
|
|
||||||
export default async function Page({ params:{ id } }: { params: { id:string } }) {
|
export default async function Page({ params:{ id } }: { params: { id:string } }) {
|
||||||
@@ -8,5 +9,6 @@ export default async function Page({ params:{ id } }: { params: { id:string } })
|
|||||||
return(notFound());
|
return(notFound());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
revalidatePath('/');
|
||||||
redirect(`/`);
|
redirect(`/`);
|
||||||
}
|
}
|
||||||
4
app/location/[id]/delete/not-found.tsx
Normal file
4
app/location/[id]/delete/not-found.tsx
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
import { NotFoundPage } from '@/app/ui/NotFoundPage';
|
||||||
|
|
||||||
|
export default () =>
|
||||||
|
<NotFoundPage title="404 Billing Location Not Found" description="Could not find the requested Billing Location." />;
|
||||||
15
app/location/[id]/delete/page.tsx
Normal file
15
app/location/[id]/delete/page.tsx
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
import { deleteBillById } from '@/app/lib/billActions';
|
||||||
|
import { deleteLocationById } from '@/app/lib/locationActions';
|
||||||
|
import { revalidatePath } from 'next/cache';
|
||||||
|
import { notFound, redirect } from 'next/navigation';
|
||||||
|
|
||||||
|
export default async function Page({ params:{ id } }: { params: { id:string } }) {
|
||||||
|
const locationID = id;
|
||||||
|
|
||||||
|
if(await deleteLocationById(locationID) === 0) {
|
||||||
|
return(notFound());
|
||||||
|
}
|
||||||
|
|
||||||
|
revalidatePath('/');
|
||||||
|
redirect(`/`);
|
||||||
|
}
|
||||||
@@ -32,13 +32,11 @@ export const LocationEditForm:FC<LocationEditFormProps> = ({ location, yearMonth
|
|||||||
<div className="card-body">
|
<div className="card-body">
|
||||||
<form action={dispatch}>
|
<form action={dispatch}>
|
||||||
{
|
{
|
||||||
// show delete button only if location is set (otherwise it's a add operation)
|
location &&
|
||||||
location ?
|
<a href={`/location/${location._id}/delete`} className="absolute bottom-5 right-4 tooltip" data-tip="Delete Location">
|
||||||
<a href={`/location/${location._id}/delete`} className="card-subtitle tooltip" data-tip="Delete Location">
|
<TrashIcon className="h-[1em] w-[1em] text-error text-2xl" />
|
||||||
<TrashIcon className="h-[1em] w-[1em] absolute cursor-pointer text-error bottom-5 right-4 text-2xl" />
|
</a>
|
||||||
</a> : null
|
|
||||||
}
|
}
|
||||||
|
|
||||||
<input id="locationName" name="locationName" type="text" placeholder="Naziv lokacije" className="input input-bordered w-full" defaultValue={location?.name ?? ""} />
|
<input id="locationName" name="locationName" type="text" placeholder="Naziv lokacije" className="input input-bordered w-full" defaultValue={location?.name ?? ""} />
|
||||||
<div id="status-error" aria-live="polite" aria-atomic="true">
|
<div id="status-error" aria-live="polite" aria-atomic="true">
|
||||||
{state.errors?.locationName &&
|
{state.errors?.locationName &&
|
||||||
|
|||||||
Reference in New Issue
Block a user