Added suspense to LocationAddPage and LocationDetelePage
This commit is contained in:
9
app/location/[id]/add/LocationAddPage.tsx
Normal file
9
app/location/[id]/add/LocationAddPage.tsx
Normal 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} />);
|
||||||
|
}
|
||||||
@@ -1,6 +1,15 @@
|
|||||||
import { parseYearMonth } from '@/app/lib/format';
|
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 } }) {
|
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>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
14
app/location/[id]/delete/LocationDeletePage.tsx
Normal file
14
app/location/[id]/delete/LocationDeletePage.tsx
Normal 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} />);
|
||||||
|
}
|
||||||
@@ -1,14 +1,17 @@
|
|||||||
import { notFound } from 'next/navigation';
|
import { notFound } from 'next/navigation';
|
||||||
import { fetchLocationById } from '@/app/lib/actions/locationActions';
|
import { fetchLocationById } from '@/app/lib/actions/locationActions';
|
||||||
import { LocationDeleteForm } from '@/app/ui/LocationDeleteForm';
|
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 } }) {
|
export default async function Page({ params:{ id } }: { params: { id:string } }) {
|
||||||
|
|
||||||
const location = await fetchLocationById(id);
|
return (
|
||||||
|
<Main>
|
||||||
if (!location) {
|
<Suspense fallback={<div>Loading...</div>}>
|
||||||
return(notFound());
|
<LocationDeletePage locationId={id} />
|
||||||
}
|
</Suspense>
|
||||||
|
</Main>
|
||||||
return (<LocationDeleteForm location={location} />);
|
);
|
||||||
}
|
}
|
||||||
@@ -10,7 +10,7 @@ export default async function LocationEditPage({ locationId }: { locationId:stri
|
|||||||
return(notFound());
|
return(notFound());
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = <LocationEditForm location={location} yearMonth={location.yearMonth} />;
|
const result = <LocationEditForm location={location} />;
|
||||||
|
|
||||||
return (result);
|
return (result);
|
||||||
}
|
}
|
||||||
@@ -4,7 +4,6 @@ import { FC } from "react";
|
|||||||
import { BillingLocation } from "../lib/db-types";
|
import { BillingLocation } from "../lib/db-types";
|
||||||
import { deleteLocationById } from "../lib/actions/locationActions";
|
import { deleteLocationById } from "../lib/actions/locationActions";
|
||||||
import { useFormState } from "react-dom";
|
import { useFormState } from "react-dom";
|
||||||
import { Main } from "./Main";
|
|
||||||
import { gotoUrl } from "../lib/actions/navigationActions";
|
import { gotoUrl } from "../lib/actions/navigationActions";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
|
|
||||||
@@ -23,7 +22,6 @@ export const LocationDeleteForm:FC<LocationDeleteFormProps> = ({ location }) =>
|
|||||||
};
|
};
|
||||||
|
|
||||||
return(
|
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 card-compact card-bordered min-w-[20em] max-w-[90em] bg-base-100 shadow-s my-1">
|
||||||
<div className="card-body">
|
<div className="card-body">
|
||||||
<form action={dispatch}>
|
<form action={dispatch}>
|
||||||
@@ -37,6 +35,5 @@ export const LocationDeleteForm:FC<LocationDeleteFormProps> = ({ location }) =>
|
|||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</Main>
|
);
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,10 +12,10 @@ export type LocationEditFormProps = {
|
|||||||
/** location which should be edited */
|
/** location which should be edited */
|
||||||
location: BillingLocation,
|
location: BillingLocation,
|
||||||
/** year adn month at a new billing location should be assigned */
|
/** year adn month at a new billing location should be assigned */
|
||||||
yearMonth: undefined
|
yearMonth?: undefined
|
||||||
} | {
|
} | {
|
||||||
/** location which should be edited */
|
/** location which should be edited */
|
||||||
location: undefined,
|
location?: undefined,
|
||||||
/** year adn month at a new billing location should be assigned */
|
/** year adn month at a new billing location should be assigned */
|
||||||
yearMonth: YearMonth
|
yearMonth: YearMonth
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user