From d85e04dc2d3a0553d3264e1f4f2060596373c98d Mon Sep 17 00:00:00 2001 From: Khalim Conn-Kowlessar Date: Tue, 30 May 2023 14:53:18 +0100 Subject: [PATCH] Finished set EPC rating modal --- .../property/EditEpcTargetModal.tsx | 49 +++++++++++++------ .../components/property/EpcDropDownMenu.tsx | 33 ++++++++----- .../[slug]/property/[lmkKey]/page.tsx | 9 ++-- 3 files changed, 62 insertions(+), 29 deletions(-) diff --git a/src/app/components/property/EditEpcTargetModal.tsx b/src/app/components/property/EditEpcTargetModal.tsx index 0eb72bd..084b43c 100644 --- a/src/app/components/property/EditEpcTargetModal.tsx +++ b/src/app/components/property/EditEpcTargetModal.tsx @@ -9,24 +9,45 @@ export default function EditEpctargetModal({ setIsEditModalOpen, setTargetEpcRating, targetEpcRating, + currentEpcRating, }: { isEditModalOpen: boolean; setIsEditModalOpen: Dispatch>; - setTargetEpcRating: Dispatch>; - targetEpcRating: EpcRating; + setTargetEpcRating: Dispatch>; + targetEpcRating: EpcRating | ""; + currentEpcRating: EpcRating; }) { function handleEditModalClose() { setIsEditModalOpen(false); } - const [modalEpcTarget, setModalEpcTarget] = - useState(targetEpcRating); + const [modalEpcTarget, setModalEpcTarget] = useState( + targetEpcRating + ); function handleModalSubmit() { setTargetEpcRating(modalEpcTarget); setIsEditModalOpen(false); } + function getEpcOptions( + epc: EpcRating + ): { label: EpcRating; value: EpcRating }[] { + const alphabet = "ABCDEFG"; + const index = alphabet.indexOf(epc.toUpperCase()); + + if (index === -1) { + throw new Error("Invalid letter input"); + } + + const epcOptions = alphabet.slice(0, index + 1).split(""); + + return epcOptions.map((opt) => ({ + label: opt as EpcRating, + value: opt as EpcRating, + })); + } + return ( <> @@ -58,22 +79,22 @@ export default function EditEpctargetModal({ leaveFrom="opacity-100 scale-100" leaveTo="opacity-0 scale-95" > - + Set a target EPC rating - setModalEpcTarget(option.value)} - modalEpcTarget={modalEpcTarget} - /> +
+ + setModalEpcTarget(option.value) + } + modalEpcTarget={modalEpcTarget} + /> +