From 984d2053a18a0a708223ba3dfda2748120f94966 Mon Sep 17 00:00:00 2001 From: Khalim Conn-Kowlessar Date: Tue, 30 May 2023 14:11:20 +0100 Subject: [PATCH] Added epc target modal --- src/app/components/button.tsx | 19 ++++ .../property/EditEpcTargetModal.tsx | 96 +++++++++++++++++++ .../components/property/EpcDropDownMenu.tsx | 48 ++++++++++ .../[slug]/property/[lmkKey]/page.tsx | 43 ++++----- src/types/epc.ts | 4 +- 5 files changed, 184 insertions(+), 26 deletions(-) create mode 100644 src/app/components/button.tsx create mode 100644 src/app/components/property/EditEpcTargetModal.tsx create mode 100644 src/app/components/property/EpcDropDownMenu.tsx diff --git a/src/app/components/button.tsx b/src/app/components/button.tsx new file mode 100644 index 00000000..59bd3e4c --- /dev/null +++ b/src/app/components/button.tsx @@ -0,0 +1,19 @@ +import { Dispatch, SetStateAction } from "react"; + +export function TanButton({ + label, + onClick, +}: { + label: string; + onClick: Dispatch>; +}) { + return ( + + ); +} diff --git a/src/app/components/property/EditEpcTargetModal.tsx b/src/app/components/property/EditEpcTargetModal.tsx new file mode 100644 index 00000000..0eb72bd9 --- /dev/null +++ b/src/app/components/property/EditEpcTargetModal.tsx @@ -0,0 +1,96 @@ +import { Dialog, Transition } from "@headlessui/react"; +import { Dispatch, Fragment, SetStateAction, useState } from "react"; +import { TanButton } from "../button"; +import EpcDropdownMenu from "../../components/property/EpcDropDownMenu"; +import { EpcRating } from "@/types/epc"; + +export default function EditEpctargetModal({ + isEditModalOpen, + setIsEditModalOpen, + setTargetEpcRating, + targetEpcRating, +}: { + isEditModalOpen: boolean; + setIsEditModalOpen: Dispatch>; + setTargetEpcRating: Dispatch>; + targetEpcRating: EpcRating; +}) { + function handleEditModalClose() { + setIsEditModalOpen(false); + } + + const [modalEpcTarget, setModalEpcTarget] = + useState(targetEpcRating); + + function handleModalSubmit() { + setTargetEpcRating(modalEpcTarget); + setIsEditModalOpen(false); + } + + return ( + <> + + setIsEditModalOpen(false)} + > + +
+ + +
+
+ + + + Set a target EPC rating + + setModalEpcTarget(option.value)} + modalEpcTarget={modalEpcTarget} + /> + +
+ + +
+
+
+
+
+
+
+ + ); +} diff --git a/src/app/components/property/EpcDropDownMenu.tsx b/src/app/components/property/EpcDropDownMenu.tsx new file mode 100644 index 00000000..f82afce3 --- /dev/null +++ b/src/app/components/property/EpcDropDownMenu.tsx @@ -0,0 +1,48 @@ +import { Fragment } from "react"; +import { Menu, Transition } from "@headlessui/react"; +import { SearchData, SearchResult } from "@/types/epc"; + +type Option = { + label: SearchResult["current-energy-rating"]; + value: SearchResult["current-energy-rating"]; +}; + +type DropdownProps = { + options: Option[]; + selectedOption: Option | null; + onSelectOption: (option: Option) => void; + modalEpcTarget: SearchResult["current-energy-rating"]; +}; + +export default function EpcDropdownMenu({ + options, + selectedOption, + onSelectOption, + modalEpcTarget, +}: DropdownProps) { + return ( + + + {"Selected option: " + modalEpcTarget ?? ""} + + + + {options.map((option) => ( + + {({ active }) => ( + + )} + + ))} + + + + ); +} diff --git a/src/app/portfolio/[slug]/property/[lmkKey]/page.tsx b/src/app/portfolio/[slug]/property/[lmkKey]/page.tsx index b92c1343..983c11ce 100644 --- a/src/app/portfolio/[slug]/property/[lmkKey]/page.tsx +++ b/src/app/portfolio/[slug]/property/[lmkKey]/page.tsx @@ -4,11 +4,12 @@ import { useState } from "react"; import { Dialog } from "@headlessui/react"; import Link from "next/link"; import { ArrowLeftIcon } from "@heroicons/react/24/outline"; -import { SearchData } from "@/types/epc"; +import { SearchData, EpcRating } from "@/types/epc"; import { useRouter } from "next/navigation"; import { useQuery } from "@tanstack/react-query"; +import EditEpcTargetModal from "../../../../components/property/EditEpctargetModal"; -const EpcDefaults = { +const EpcDefaults: { [key in EpcRating]: EpcRating } = { G: "C", F: "C", E: "C", @@ -50,6 +51,7 @@ export default function PropertyPage({ const [isEditModalOpen, setIsEditModalOpen] = useState(false); const [isDetailModalOpen, setIsDetailModalOpen] = useState(false); + const [targetEpcRating, setTargetEpcRating] = useState("C"); const { data, error, isLoading } = useQuery({ queryKey: ["search", postcode], @@ -68,6 +70,10 @@ export default function PropertyPage({ const propertyData = data.rows.filter((row) => row["lmk-key"] === lmkKey)[0]; const currentEpcRating = propertyData["current-energy-rating"]; + if (!targetEpcRating) { + setTargetEpcRating(EpcDefaults[currentEpcRating]); + } + const handleEditClick = () => { setIsEditModalOpen(true); }; @@ -83,7 +89,7 @@ export default function PropertyPage({
-
+
Back to portfolio
@@ -94,17 +100,17 @@ export default function PropertyPage({

{propertyData.address}

-
+

Current EPC rating

Rating: {currentEpcRating}

Target EPC rating

-

Rating: {EpcDefaults[currentEpcRating]}

+

Rating: {targetEpcRating}

@@ -124,25 +130,12 @@ export default function PropertyPage({ {/* Add more rectangular cards here */} - {/* Edit Modal */} - setIsEditModalOpen(false)} - className="fixed inset-0 z-10" - > -
- - -
- Edit Target EPC Rating - - This is the modal content for editing the target EPC rating. - - - {/* Add your form inputs and actions here */} -
-
-
+ {/* Detail Modal */}