Added suspense to LocationAddPage and LocationDetelePage

This commit is contained in:
2024-02-06 14:48:19 +01:00
parent 3670b4db9f
commit 4ef2330ad4
7 changed files with 60 additions and 28 deletions

View File

@@ -0,0 +1,9 @@
import { notFound } from 'next/navigation';
import { LocationEditForm } from '@/app/ui/LocationEditForm';
import { fetchLocationById } from '@/app/lib/actions/locationActions';
import { YearMonth } from '@/app/lib/db-types';
import { Main } from '@/app/ui/Main';
export default async function LocationAddPage({ yearMonth }: { yearMonth:YearMonth }) {
return (<LocationEditForm yearMonth={yearMonth} />);
}

View File

@@ -1,6 +1,15 @@
import { parseYearMonth } from '@/app/lib/format';
import { LocationEditForm } from '@/app/ui/LocationEditForm';
import { LocationEditFormSkeleton } from '@/app/ui/LocationEditForm';
import LocationAddPage from './LocationAddPage';
import { Main } from '@/app/ui/Main';
import { Suspense } from 'react';
export default async function Page({ params:{ id } }: { params: { id:string } }) {
return (<LocationEditForm yearMonth={ parseYearMonth(id) } />);
return (
<Main>
<Suspense fallback={<LocationEditFormSkeleton />}>
<LocationAddPage yearMonth={ parseYearMonth(id) } />
</Suspense>
</Main>
);
}

View File

@@ -0,0 +1,14 @@
import { notFound } from 'next/navigation';
import { fetchLocationById } from '@/app/lib/actions/locationActions';
import { LocationDeleteForm } from '@/app/ui/LocationDeleteForm';
export const LocationDeletePage = async ({ locationId }: { locationId:string }) => {
const location = await fetchLocationById(locationId);
if (!location) {
return(notFound());
}
return (<LocationDeleteForm location={location} />);
}

View File

@@ -1,14 +1,17 @@
import { notFound } from 'next/navigation';
import { fetchLocationById } from '@/app/lib/actions/locationActions';
import { LocationDeleteForm } from '@/app/ui/LocationDeleteForm';
import { Main } from '@/app/ui/Main';
import { Suspense } from 'react';
import { LocationDeletePage } from './LocationDeletePage';
export default async function Page({ params:{ id } }: { params: { id:string } }) {
const location = await fetchLocationById(id);
if (!location) {
return(notFound());
}
return (<LocationDeleteForm location={location} />);
return (
<Main>
<Suspense fallback={<div>Loading...</div>}>
<LocationDeletePage locationId={id} />
</Suspense>
</Main>
);
}

View File

@@ -10,7 +10,7 @@ export default async function LocationEditPage({ locationId }: { locationId:stri
return(notFound());
}
const result = <LocationEditForm location={location} yearMonth={location.yearMonth} />;
const result = <LocationEditForm location={location} />;
return (result);
}

View File

@@ -4,7 +4,6 @@ import { FC } from "react";
import { BillingLocation } from "../lib/db-types";
import { deleteLocationById } from "../lib/actions/locationActions";
import { useFormState } from "react-dom";
import { Main } from "./Main";
import { gotoUrl } from "../lib/actions/navigationActions";
import Link from "next/link";
@@ -23,20 +22,18 @@ export const LocationDeleteForm:FC<LocationDeleteFormProps> = ({ location }) =>
};
return(
<Main>
<div className="card card-compact card-bordered min-w-[20em] max-w-[90em] bg-base-100 shadow-s my-1">
<div className="card-body">
<form action={dispatch}>
<p className="py-6 px-6">
Please confirm deletion of location <strong>{location.name}</strong>.
</p>
<div className="pt-4 text-center">
<button className="btn btn-primary">Confim</button>
<Link className="btn btn-neutral ml-3" href={`/location/${location._id}/edit/`}>Cancel</Link>
</div>
</form>
</div>
<div className="card card-compact card-bordered min-w-[20em] max-w-[90em] bg-base-100 shadow-s my-1">
<div className="card-body">
<form action={dispatch}>
<p className="py-6 px-6">
Please confirm deletion of location <strong>{location.name}</strong>.
</p>
<div className="pt-4 text-center">
<button className="btn btn-primary">Confim</button>
<Link className="btn btn-neutral ml-3" href={`/location/${location._id}/edit/`}>Cancel</Link>
</div>
</form>
</div>
</Main>
)
</div>
);
}

View File

@@ -12,10 +12,10 @@ export type LocationEditFormProps = {
/** location which should be edited */
location: BillingLocation,
/** year adn month at a new billing location should be assigned */
yearMonth: undefined
yearMonth?: undefined
} | {
/** location which should be edited */
location: undefined,
location?: undefined,
/** year adn month at a new billing location should be assigned */
yearMonth: YearMonth
}