<suspense> added to LocationEditPage
This commit is contained in:
16
app/location/[id]/edit/LocationEditPage.tsx
Normal file
16
app/location/[id]/edit/LocationEditPage.tsx
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
import { notFound } from 'next/navigation';
|
||||||
|
import { LocationEditForm } from '@/app/ui/LocationEditForm';
|
||||||
|
import { fetchLocationById } from '@/app/lib/actions/locationActions';
|
||||||
|
|
||||||
|
export default async function LocationEditPage({ locationId }: { locationId:string }) {
|
||||||
|
|
||||||
|
const location = await fetchLocationById(locationId);
|
||||||
|
|
||||||
|
if (!location) {
|
||||||
|
return(notFound());
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = <LocationEditForm location={location} yearMonth={location.yearMonth} />;
|
||||||
|
|
||||||
|
return (result);
|
||||||
|
}
|
||||||
@@ -1,13 +1,15 @@
|
|||||||
import { notFound } from 'next/navigation';
|
import { Suspense } from 'react';
|
||||||
import { LocationEditForm } from '@/app/ui/LocationEditForm';
|
import LocationEditPage from './LocationEditPage';
|
||||||
import { fetchLocationById } from '@/app/lib/actions/locationActions';
|
import { Main } from '@/app/ui/Main';
|
||||||
|
import { LocationEditFormSkeleton } from '@/app/ui/LocationEditForm';
|
||||||
|
|
||||||
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={<LocationEditFormSkeleton />}>
|
||||||
return(notFound());
|
<LocationEditPage locationId={id} />
|
||||||
}
|
</Suspense>
|
||||||
return (<LocationEditForm location={location} yearMonth={location.yearMonth} />);
|
</Main>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
@@ -5,7 +5,6 @@ import { FC } from "react";
|
|||||||
import { BillingLocation, YearMonth } from "../lib/db-types";
|
import { BillingLocation, YearMonth } from "../lib/db-types";
|
||||||
import { updateOrAddLocation } from "../lib/actions/locationActions";
|
import { updateOrAddLocation } from "../lib/actions/locationActions";
|
||||||
import { useFormState } from "react-dom";
|
import { useFormState } from "react-dom";
|
||||||
import { Main } from "./Main";
|
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { gotoHome } from "../lib/actions/navigationActions";
|
import { gotoHome } from "../lib/actions/navigationActions";
|
||||||
|
|
||||||
@@ -32,52 +31,66 @@ export const LocationEditForm:FC<LocationEditFormProps> = ({ location, yearMonth
|
|||||||
};
|
};
|
||||||
|
|
||||||
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}>
|
{
|
||||||
|
location &&
|
||||||
|
<Link href={`/location/${location._id}/delete`} className="absolute bottom-5 right-4 tooltip" data-tip="Delete Location">
|
||||||
|
<TrashIcon className="h-[1em] w-[1em] text-error text-2xl" />
|
||||||
|
</Link>
|
||||||
|
}
|
||||||
|
<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">
|
||||||
|
{state.errors?.locationName &&
|
||||||
|
state.errors.locationName.map((error: string) => (
|
||||||
|
<p className="mt-2 text-sm text-red-500" key={error}>
|
||||||
|
{error}
|
||||||
|
</p>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<textarea id="locationNotes" name="locationNotes" className="textarea textarea-bordered my-1 w-full block" placeholder="Opis" defaultValue={location?.notes ?? ""}></textarea>
|
||||||
|
<div id="status-error" aria-live="polite" aria-atomic="true">
|
||||||
|
{state.errors?.locationNotes &&
|
||||||
|
state.errors.locationNotes.map((error: string) => (
|
||||||
|
<p className="mt-2 text-sm text-red-500" key={error}>
|
||||||
|
{error}
|
||||||
|
</p>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="status-error" aria-live="polite" aria-atomic="true">
|
||||||
{
|
{
|
||||||
location &&
|
state.message &&
|
||||||
<Link href={`/location/${location._id}/delete`} className="absolute bottom-5 right-4 tooltip" data-tip="Delete Location">
|
<p className="mt-2 text-sm text-red-500">
|
||||||
<TrashIcon className="h-[1em] w-[1em] text-error text-2xl" />
|
{state.message}
|
||||||
</Link>
|
</p>
|
||||||
}
|
}
|
||||||
<input id="locationName" name="locationName" type="text" placeholder="Naziv lokacije" className="input input-bordered w-full" defaultValue={location?.name ?? ""} />
|
</div>
|
||||||
<div id="status-error" aria-live="polite" aria-atomic="true">
|
|
||||||
{state.errors?.locationName &&
|
|
||||||
state.errors.locationName.map((error: string) => (
|
|
||||||
<p className="mt-2 text-sm text-red-500" key={error}>
|
|
||||||
{error}
|
|
||||||
</p>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<textarea id="locationNotes" name="locationNotes" className="textarea textarea-bordered my-1 w-full block" placeholder="Opis" defaultValue={location?.notes ?? ""}></textarea>
|
<div className="pt-4">
|
||||||
<div id="status-error" aria-live="polite" aria-atomic="true">
|
<button className="btn btn-primary">Save</button>
|
||||||
{state.errors?.locationNotes &&
|
<button type="button" className="btn btn-neutral ml-3" onClick={handleCancel}>Cancel</button>
|
||||||
state.errors.locationNotes.map((error: string) => (
|
</div>
|
||||||
<p className="mt-2 text-sm text-red-500" key={error}>
|
</form>
|
||||||
{error}
|
|
||||||
</p>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="status-error" aria-live="polite" aria-atomic="true">
|
|
||||||
{
|
|
||||||
state.message &&
|
|
||||||
<p className="mt-2 text-sm text-red-500">
|
|
||||||
{state.message}
|
|
||||||
</p>
|
|
||||||
}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="pt-4">
|
|
||||||
<button className="btn btn-primary">Save</button>
|
|
||||||
<button type="button" className="btn btn-neutral ml-3" onClick={handleCancel}>Cancel</button>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</Main>
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const LocationEditFormSkeleton:FC = () =>
|
||||||
|
{
|
||||||
|
return(
|
||||||
|
<div className="skeleton card card-compact card-bordered min-w-[20em] max-w-[90em] bg-base-100 shadow-s my-1">
|
||||||
|
<div className="card-body">
|
||||||
|
<input id="locationName" name="locationName" type="text" placeholder="Naziv lokacije" className="input input-bordered w-full" />
|
||||||
|
<textarea id="locationNotes" name="locationNotes" className="textarea textarea-bordered my-1 w-full block" placeholder="Opis"></textarea>
|
||||||
|
<div className="pt-4">
|
||||||
|
<button className="btn btn-primary">Save</button>
|
||||||
|
<button type="button" className="btn btn-neutral ml-3">Cancel</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user