From f966880e550d0bcc6d9ea39ab127ee3c7f6b258c Mon Sep 17 00:00:00 2001 From: Khalim Conn-Kowlessar Date: Tue, 30 May 2023 16:14:27 +0100 Subject: [PATCH] Added property description cards --- src/app/components/property/partCard.tsx | 57 ++++++-- .../[slug]/property/[lmkKey]/page.tsx | 123 ++++++++++-------- 2 files changed, 114 insertions(+), 66 deletions(-) diff --git a/src/app/components/property/partCard.tsx b/src/app/components/property/partCard.tsx index 1ed4da7..d897055 100644 --- a/src/app/components/property/partCard.tsx +++ b/src/app/components/property/partCard.tsx @@ -1,17 +1,48 @@ -export default function PartCard({ title, handleDetailClick }) { +import { Dialog } from "@headlessui/react"; +import { PencilSquareIcon } from "@heroicons/react/24/outline"; +import { useState } from "react"; + +export default function PartCard({ + title, + description, +}: { + title: string; + description: string; +}) { + const [isDetailModalOpen, setIsDetailModalOpen] = useState(false); return ( -
-
-

{title}

- +
+
+
+

{title}

+ +
+

{description}

-

Short description of the card

-
+ setIsDetailModalOpen(false)} + className="fixed inset-0 z-10" + > +
+ + +
+ Card Details + + This is the modal content for the card details. + + + {/* Add your card details and actions here */} +
+
+
+ ); } diff --git a/src/app/portfolio/[slug]/property/[lmkKey]/page.tsx b/src/app/portfolio/[slug]/property/[lmkKey]/page.tsx index ce4c384..92373a0 100644 --- a/src/app/portfolio/[slug]/property/[lmkKey]/page.tsx +++ b/src/app/portfolio/[slug]/property/[lmkKey]/page.tsx @@ -3,11 +3,12 @@ import { useState } from "react"; import { Dialog } from "@headlessui/react"; import Link from "next/link"; -import { ArrowLeftIcon } from "@heroicons/react/24/outline"; +import { ArrowLeftIcon, PencilSquareIcon } from "@heroicons/react/24/outline"; import { SearchData, EpcRating } from "@/types/epc"; import { useRouter } from "next/navigation"; import { useQuery } from "@tanstack/react-query"; import EditEpcTargetModal from "../../../../components/property/EditEpcTargetModal"; +import PartCard from "@/app/components/property/PartCard"; const EpcDefaults: { [key in EpcRating]: EpcRating } = { G: "C", @@ -19,6 +20,50 @@ const EpcDefaults: { [key in EpcRating]: EpcRating } = { A: "A", }; +const partConfig = [ + { + title: "General", + descriptionData: [ + { key: "built-form", prefix: "", suffix: "" }, + { key: "property-type", prefix: "", suffix: "" }, + ], + }, + { + title: "Roof", + descriptionData: [{ key: "roof-description", prefix: "", suffix: "" }], + }, + { + title: "Walls & Floors", + descriptionData: [ + { key: "walls-description", prefix: "Walls: ", suffix: "" }, + { key: "floor-description", prefix: "Floors: ", suffix: "" }, + ], + }, + { + title: "Windows & Doors", + descriptionData: [{ key: "windows-description", prefix: "", suffix: "" }], + }, + { + title: "Heating", + descriptionData: [{ key: "mainheat-description", prefix: "", suffix: "" }], + }, + { + title: "Renewables", + descriptionData: [ + { key: "photo-supply", prefix: "", suffix: "" }, + { key: "solar-water-heating-flag", prefix: "", suffix: "" }, + ], + }, + { + title: "Other", + descriptionData: [ + { key: "lighting-description", prefix: "Lights: ", suffix: "" }, + { key: "number-open-fireplaces", prefix: "", suffix: " open fireplaces" }, + { key: "energy-tariff", prefix: "Energy tariff: ", suffix: "" }, + ], + }, +]; + async function fetchData(postcode: string): Promise { // TODO - add strict typing to the api response @@ -50,7 +95,6 @@ export default function PropertyPage({ } const [isEditModalOpen, setIsEditModalOpen] = useState(false); - const [isDetailModalOpen, setIsDetailModalOpen] = useState(false); const [targetEpcRating, setTargetEpcRating] = useState(""); const { data, error, isLoading } = useQuery({ @@ -78,9 +122,6 @@ export default function PropertyPage({ setIsEditModalOpen(true); }; - const handleDetailClick = () => { - setIsDetailModalOpen(true); - }; // NextJS docs recomment fetching data directly in the component that needs it, // even if requeting the same data in multiple components. rather than passing data between // components as props @@ -112,39 +153,35 @@ export default function PropertyPage({

Target EPC rating

Rating: {targetEpcRating}

- - - +
-
-
-

Card Title

- -
-

Short description of the card

-
+
+ {partConfig.map((part, index) => { + const descriptionList = part.descriptionData + .flatMap((data) => { + const { key, prefix, suffix } = data; + const value = propertyData[key]; - {/* Add more rectangular cards here */} + if (!value) return null; + + return `${prefix}${value}${suffix}`; + }) + .filter((value) => value != null); + + const description = descriptionList.join(", ") || "Not present"; + + return ( + + ); + })} +
- - {/* Detail Modal */} - setIsDetailModalOpen(false)} - className="fixed inset-0 z-10" - > -
- - -
- Card Details - - This is the modal content for the card details. - - - {/* Add your card details and actions here */} -
-
-
);