From 234c9c53a81f208b6f47e5767ff418f6245e4f09 Mon Sep 17 00:00:00 2001 From: Khalim Conn-Kowlessar Date: Wed, 2 Aug 2023 14:05:37 +0100 Subject: [PATCH] Adding data to building passport --- .../components/building-passport/Toolbar.tsx | 1 - .../building-passport/[propertyId]/layout.tsx | 17 +---------- .../building-passport/[propertyId]/page.tsx | 27 ++++++----------- .../pre-assessment-report/page.tsx | 30 +++++++------------ .../building-passport/[propertyId]/utils.ts | 17 +++++++++++ 5 files changed, 38 insertions(+), 54 deletions(-) create mode 100644 src/app/portfolio/[slug]/building-passport/[propertyId]/utils.ts diff --git a/src/app/components/building-passport/Toolbar.tsx b/src/app/components/building-passport/Toolbar.tsx index 150ef974..ced6cf91 100644 --- a/src/app/components/building-passport/Toolbar.tsx +++ b/src/app/components/building-passport/Toolbar.tsx @@ -14,7 +14,6 @@ import { NavigationMenuLink, } from "@/app/shadcn_components/ui/navigation-menu"; import { cva } from "class-variance-authority"; -import type { PropertyMeta } from "@/app/db/schema/property"; interface ToolbarProps { propertyId: string; diff --git a/src/app/portfolio/[slug]/building-passport/[propertyId]/layout.tsx b/src/app/portfolio/[slug]/building-passport/[propertyId]/layout.tsx index 86ecaba5..6be6da2c 100644 --- a/src/app/portfolio/[slug]/building-passport/[propertyId]/layout.tsx +++ b/src/app/portfolio/[slug]/building-passport/[propertyId]/layout.tsx @@ -1,19 +1,5 @@ import { Toolbar } from "@/app/components/building-passport/Toolbar"; -import { PropertyMeta } from "@/app/db/schema/property"; - -async function getPropertyMeta(propertyId: string): Promise { - const url = - process.env.URL + `/api/building-passport/property-meta/${propertyId}`; - - const response = await fetch(url, { - method: "GET", - headers: { "Content-Type": "application/json" }, - }); - if (!response.ok) { - throw new Error("Network response was not ok"); - } - return response.json(); -} +import { getPropertyMeta } from "./utils"; export default async function DashboardLayout({ children, // will be a page or nested layout @@ -26,7 +12,6 @@ export default async function DashboardLayout({ const portfolioId = params.slug ?? ""; // The layout is a server component by default so we can fetch meta data here - // TODO: Implement get api const propertyMeta = await getPropertyMeta(params.propertyId); if (!propertyId && propertyId !== "0") { diff --git a/src/app/portfolio/[slug]/building-passport/[propertyId]/page.tsx b/src/app/portfolio/[slug]/building-passport/[propertyId]/page.tsx index 5e015dea..e8c83d33 100644 --- a/src/app/portfolio/[slug]/building-passport/[propertyId]/page.tsx +++ b/src/app/portfolio/[slug]/building-passport/[propertyId]/page.tsx @@ -9,25 +9,16 @@ import { ClockIcon, UserGroupIcon, } from "@heroicons/react/24/solid"; +import { getPropertyMeta } from "./utils"; -export default async function BuildingPassportHome() { - const propertyMeta: PropertyMeta = { - id: 1, - address: "123 Fake Street", - postcode: "AB1 2CD", - hasPreConditionReport: true, - hasRecommendations: true, - createdAt: "2023-07-12 11:51:31.000 +0100", - propertyType: "House", - builtForm: "Detached", - localAuthority: "Birmingham", - constituency: "Birmingham", - numberOfRooms: 5, - yearBuilt: 1990, - tenure: "Rented (social)", - currentEpcRating: "C", - currentSapPoints: 78, - }; +export default async function BuildingPassportHome({ + params, +}: { + params: { slug: string; propertyId: string }; +}) { + // This is a server component and because we make the exact same request in the layout, + // the response is cached so we just gain access to the data + const propertyMeta = await getPropertyMeta(params.propertyId); return (
diff --git a/src/app/portfolio/[slug]/building-passport/[propertyId]/pre-assessment-report/page.tsx b/src/app/portfolio/[slug]/building-passport/[propertyId]/pre-assessment-report/page.tsx index 698c4b73..2e3a92bc 100644 --- a/src/app/portfolio/[slug]/building-passport/[propertyId]/pre-assessment-report/page.tsx +++ b/src/app/portfolio/[slug]/building-passport/[propertyId]/pre-assessment-report/page.tsx @@ -6,6 +6,7 @@ import { generalColumns, retrofitColumns, } from "@/app/components/building-passport/FeatureTableColumns"; +import { getPropertyMeta } from "../utils"; function AddressCard({ address }: { address: string }) { // In the future, we might want to use react-wrap-balancer for some of this text @@ -43,7 +44,10 @@ function PropertyDetailsCard({ Total floor area: - {`${conditionReportData.totalFloorArea} square meters`} + + {`${conditionReportData.totalFloorArea} m`} + 2 + In conservation area: @@ -90,25 +94,13 @@ function PropertyDetailsCard({ // This type is used to define the shape of our data. // You can use a Zod schema here if you want. -export default async function PreAssessmentReport() { +export default async function PreAssessmentReport({ + params, +}: { + params: { slug: string; propertyId: string }; +}) { // TODO: Add main fuel! - const propertyMeta: PropertyMeta = { - id: 1, - address: "123 Fake Street", - postcode: "AB1 2CD", - hasPreConditionReport: true, - hasRecommendations: true, - createdAt: "2023-07-12 11:51:31.000 +0100", - propertyType: "House", - builtForm: "Detached", - localAuthority: "Birmingham", - constituency: "Birmingham", - numberOfRooms: 5, - yearBuilt: 1990, - tenure: "Rented (social)", - currentEpcRating: "C", - currentSapPoints: 78, - }; + const propertyMeta = await getPropertyMeta(params.propertyId); const conditionReportData: ConditionReportData = { id: 1, diff --git a/src/app/portfolio/[slug]/building-passport/[propertyId]/utils.ts b/src/app/portfolio/[slug]/building-passport/[propertyId]/utils.ts new file mode 100644 index 00000000..f3d64f8c --- /dev/null +++ b/src/app/portfolio/[slug]/building-passport/[propertyId]/utils.ts @@ -0,0 +1,17 @@ +import { PropertyMeta } from "@/app/db/schema/property"; + +export async function getPropertyMeta( + propertyId: string +): Promise { + const url = + process.env.URL + `/api/building-passport/property-meta/${propertyId}`; + + const response = await fetch(url, { + method: "GET", + headers: { "Content-Type": "application/json" }, + }); + if (!response.ok) { + throw new Error("Network response was not ok"); + } + return response.json(); +}