From cf97b3d4b57da42dd9be77f1144b2e21776dfc25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikola=20Dere=C5=BEi=C4=87?= Date: Tue, 6 Feb 2024 14:16:31 +0100 Subject: [PATCH] added to LocationEditPage --- app/location/[id]/edit/LocationEditPage.tsx | 16 ++++ app/location/[id]/edit/page.tsx | 20 ++-- app/ui/LocationEditForm.tsx | 101 +++++++++++--------- 3 files changed, 84 insertions(+), 53 deletions(-) create mode 100644 app/location/[id]/edit/LocationEditPage.tsx diff --git a/app/location/[id]/edit/LocationEditPage.tsx b/app/location/[id]/edit/LocationEditPage.tsx new file mode 100644 index 0000000..50d0b31 --- /dev/null +++ b/app/location/[id]/edit/LocationEditPage.tsx @@ -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 = ; + + return (result); +} \ No newline at end of file diff --git a/app/location/[id]/edit/page.tsx b/app/location/[id]/edit/page.tsx index b28cd30..251f944 100644 --- a/app/location/[id]/edit/page.tsx +++ b/app/location/[id]/edit/page.tsx @@ -1,13 +1,15 @@ -import { notFound } from 'next/navigation'; -import { LocationEditForm } from '@/app/ui/LocationEditForm'; -import { fetchLocationById } from '@/app/lib/actions/locationActions'; +import { Suspense } from 'react'; +import LocationEditPage from './LocationEditPage'; +import { Main } from '@/app/ui/Main'; +import { LocationEditFormSkeleton } from '@/app/ui/LocationEditForm'; export default async function Page({ params:{ id } }: { params: { id:string } }) { - const location = await fetchLocationById(id); - - if (!location) { - return(notFound()); - } - return (); + return ( +
+ }> + + +
+ ); } \ No newline at end of file diff --git a/app/ui/LocationEditForm.tsx b/app/ui/LocationEditForm.tsx index 97b5c49..387dca0 100644 --- a/app/ui/LocationEditForm.tsx +++ b/app/ui/LocationEditForm.tsx @@ -5,7 +5,6 @@ import { FC } from "react"; import { BillingLocation, YearMonth } from "../lib/db-types"; import { updateOrAddLocation } from "../lib/actions/locationActions"; import { useFormState } from "react-dom"; -import { Main } from "./Main"; import Link from "next/link"; import { gotoHome } from "../lib/actions/navigationActions"; @@ -32,52 +31,66 @@ export const LocationEditForm:FC = ({ location, yearMonth }; return( -
-
-
-
+
+
+ + { + location && + + + + } + +
+ {state.errors?.locationName && + state.errors.locationName.map((error: string) => ( +

+ {error} +

+ ))} +
+ + +
+ {state.errors?.locationNotes && + state.errors.locationNotes.map((error: string) => ( +

+ {error} +

+ ))} +
+ +
{ - location && - - - + state.message && +

+ {state.message} +

} - -
- {state.errors?.locationName && - state.errors.locationName.map((error: string) => ( -

- {error} -

- ))} -
+
- -
- {state.errors?.locationNotes && - state.errors.locationNotes.map((error: string) => ( -

- {error} -

- ))} -
- -
- { - state.message && -

- {state.message} -

- } -
- -
- - -
- -
+
+ + +
+
-
+ + ) +} + +export const LocationEditFormSkeleton:FC = () => +{ + return( +
+
+ + +
+ + +
+
+
) }