From bb1eff91d0cf716f19ca5e097b7a7f04033bc2ee Mon Sep 17 00:00:00 2001 From: Khalim Conn-Kowlessar Date: Wed, 31 May 2023 09:15:29 +0100 Subject: [PATCH] Added core layout for the plan table --- src/app/components/plan/PartDropdown.tsx | 58 +++++++++++ src/app/components/plan/PartModal.tsx | 96 +++++++++++++++++++ src/app/components/plan/PlanPart.tsx | 58 +++++++++++ .../[slug]/property/[lmkKey]/plan/page.tsx | 90 +++++++++-------- 4 files changed, 256 insertions(+), 46 deletions(-) create mode 100644 src/app/components/plan/PartDropdown.tsx create mode 100644 src/app/components/plan/PartModal.tsx create mode 100644 src/app/components/plan/PlanPart.tsx diff --git a/src/app/components/plan/PartDropdown.tsx b/src/app/components/plan/PartDropdown.tsx new file mode 100644 index 0000000..7cf8947 --- /dev/null +++ b/src/app/components/plan/PartDropdown.tsx @@ -0,0 +1,58 @@ +import { Fragment } from "react"; +import { Menu, Transition } from "@headlessui/react"; +import { ChevronDownIcon } from "@heroicons/react/20/solid"; + +type Option = { + label: string; + value: string; +}; + +type DropdownProps = { + options: Option[]; + onSelectOption: (option: Option) => void; + selectedOption: string; +}; + +export default function PartDropdown({ + options, + onSelectOption, + selectedOption, +}: DropdownProps) { + return ( + + + Selected option: {selectedOption ?? ""}{" "} + + + + {options.map((option) => ( + + {({ active }) => ( + + )} + + ))} + + + + ); +} diff --git a/src/app/components/plan/PartModal.tsx b/src/app/components/plan/PartModal.tsx new file mode 100644 index 0000000..ef940dc --- /dev/null +++ b/src/app/components/plan/PartModal.tsx @@ -0,0 +1,96 @@ +import { Dialog, Transition } from "@headlessui/react"; +import { Dispatch, Fragment, SetStateAction, useState } from "react"; +import { TanButton } from "../Button"; +import PartDropdown from "./PartDropdown"; + +export default function PartModal({ + title, + isOpen, + setIsOpen, + options, + selectedOption, + setSelectedOption, +}: { + title: string; + isOpen: boolean; + setIsOpen: Dispatch>; + options: { label: string; value: string }[]; + selectedOption: string; + setSelectedOption: Dispatch>; +}) { + function handleModalSubmit() { + // setTargetEpcRating(modalEpcTarget); + setIsOpen(false); + } + + return ( + <> + + setIsOpen(false)} + > + +
+ + +
+
+ + + + {title} + +
+
+ You can select different options for this part - this is + example functionality for demo +
+ + setSelectedOption(option.value) + } + selectedOption={selectedOption} + /> +
+ +
+ + +
+
+
+
+
+
+
+ + ); +} diff --git a/src/app/components/plan/PlanPart.tsx b/src/app/components/plan/PlanPart.tsx new file mode 100644 index 0000000..4890e42 --- /dev/null +++ b/src/app/components/plan/PlanPart.tsx @@ -0,0 +1,58 @@ +import { useState } from "react"; +import PartModal from "./PartModal"; + +type PlanPartProps = { + title: string; + cost: number; + co2Emissions: number; + workHours: number; +}; + +export default function PlanPart({ + title, + cost, + co2Emissions, + workHours, +}: PlanPartProps) { + const [isOpen, setIsOpen] = useState(false); + + // These are temporary options for the demo + const options = [ + { label: "option 1", value: "option 1" }, + { label: "option 2", value: "option 2" }, + { label: "option 3", value: "option 3" }, + { label: "option 4", value: "option 4" }, + { label: "option 5", value: "option 5" }, + ]; + + const [selectedOption, setSelectedOption] = useState(options[0].value); + + return ( +
{ + setIsOpen(true); + }} + className="active:bg-blue-700 focus:outline-none transition-colors duration-200 flex bg-white p-4 rounded-lg shadow mb-4 items-center border-l-4 border-l-brandmidblue hover:bg-brandmidblue hover:text-white hover:border-l-brandtan cursor-pointer" + > +

{title}

+
{selectedOption}
+
+

Cost: {cost}

+
+
+

CO2 Emissions: {co2Emissions}

+
+
+

Work Hours: {workHours}

+
+ +
+ ); +} diff --git a/src/app/portfolio/[slug]/property/[lmkKey]/plan/page.tsx b/src/app/portfolio/[slug]/property/[lmkKey]/plan/page.tsx index 1eedb9f..9d1adf9 100644 --- a/src/app/portfolio/[slug]/property/[lmkKey]/plan/page.tsx +++ b/src/app/portfolio/[slug]/property/[lmkKey]/plan/page.tsx @@ -5,40 +5,8 @@ import { useQuery } from "@tanstack/react-query"; import { useRouter } from "next/navigation"; import { fetchData } from "../utils"; import { useState } from "react"; - -import React from "react"; import { PencilSquareIcon } from "@heroicons/react/24/outline"; - -type PlanPartProps = { - title: string; - cost: number; - co2Emissions: number; - workHours: number; -}; - -const PlanPart: React.FC = ({ - title, - cost, - co2Emissions, - workHours, -}) => { - return ( -
-
-

{title}

-
-
-

Cost: {cost}

-
-
-

CO2 Emissions: {co2Emissions}

-
-
-

Work Hours: {workHours}

-
-
- ); -}; +import PlanPart from "@/app/components/plan/PlanPart"; export default function Plan({ params, @@ -58,6 +26,37 @@ export default function Plan({ const [totalCost, setTotalCost] = useState("Not set"); const [installTime, setInstallTime] = useState("Not set"); + const partsConfig = [ + { part: "Roof", cost: 1000, co2Emissions: 50, workHours: 20 }, + { part: "Walls", cost: 1000, co2Emissions: 50, workHours: 20 }, + { part: "Floors", cost: 1000, co2Emissions: 50, workHours: 20 }, + { part: "Window Glazing", cost: 1000, co2Emissions: 50, workHours: 20 }, + { + part: "Window Draughproofing", + cost: 1000, + co2Emissions: 50, + workHours: 20, + }, + { part: "Door Insulation", cost: 1000, co2Emissions: 50, workHours: 20 }, + { + part: "Door Draughproofing", + cost: 1000, + co2Emissions: 50, + workHours: 20, + }, + { part: "Heating", cost: 1000, co2Emissions: 50, workHours: 20 }, + { part: "Hot Water", cost: 1000, co2Emissions: 50, workHours: 20 }, + { part: "Solar Panels", cost: 1000, co2Emissions: 50, workHours: 20 }, + { part: "Solar Hot Water", cost: 1000, co2Emissions: 50, workHours: 20 }, + { part: "Lighting", cost: 1000, co2Emissions: 50, workHours: 20 }, + { + part: "Chimneys/ Open Fire Places", + cost: 1000, + co2Emissions: 50, + workHours: 20, + }, + ]; + if (postcode === undefined) { router.push(`/portfolio/${portfolioId}/error`); } @@ -79,25 +78,24 @@ export default function Plan({ const propertyData = data.rows.filter((row) => row["lmk-key"] === lmkKey)[0]; return (
-
+

Your Retrofit Plan

{propertyData.address}

- {/* Clickable Cards */} - {/* Replace this with your actual clickable cards */} - -
- Clickable Card 2 -
- {/* Add more clickable cards as needed */} + {partsConfig.map((part, index) => { + return ( + + ); + })}