From a45529f5bd9d63e7cef91f684702fa252aa5ca28 Mon Sep 17 00:00:00 2001 From: Khalim Conn-Kowlessar Date: Tue, 23 Sep 2025 23:33:14 +0000 Subject: [PATCH] update up to allow showing valuation when here isn't one --- .../ValuationImpactComponent.tsx | 114 +++++++++++------- 1 file changed, 71 insertions(+), 43 deletions(-) diff --git a/src/app/components/building-passport/ValuationImpactComponent.tsx b/src/app/components/building-passport/ValuationImpactComponent.tsx index 9a2d5d4..9f902f8 100644 --- a/src/app/components/building-passport/ValuationImpactComponent.tsx +++ b/src/app/components/building-passport/ValuationImpactComponent.tsx @@ -1,30 +1,32 @@ "use client"; import { useState } from "react"; -import React from 'react' +import React from "react"; import { FundingPackageWithMeasures } from "@/app/db/schema/funding"; import { formatNumber } from "@/app/utils"; -import {Card, CardContent} from "@/app/shadcn_components/ui/card"; +import { Card, CardContent } from "@/app/shadcn_components/ui/card"; import { Button } from "@/app/shadcn_components/ui/button"; -import { PiggyBank } from 'lucide-react' -import { Dialog, Transition } from '@headlessui/react' -import { Fragment } from 'react' +import { PiggyBank } from "lucide-react"; +import { Dialog, Transition } from "@headlessui/react"; +import { Fragment } from "react"; import { FundingPackageMeasure } from "@/app/db/schema/funding"; import { set } from "cypress/types/lodash"; - type FundingSummaryProps = { scheme: string | null; - onSeeMore: () => void -} + onSeeMore: () => void; +}; -export const FundingSummary: React.FC = ({ scheme, onSeeMore }) => { - let message: string | null = null +export const FundingSummary: React.FC = ({ + scheme, + onSeeMore, +}) => { + let message: string | null = null; if (!scheme) { - message = 'Funding not assessed for this measure package' - } else if (scheme.toLowerCase() === 'none') { - message = 'Funding not eligible for this measure package' + message = "Funding not assessed for this measure package"; + } else if (scheme.toLowerCase() === "none") { + message = "Funding not eligible for this measure package"; } return ( @@ -55,8 +57,8 @@ export const FundingSummary: React.FC = ({ scheme, onSeeMor )} - ) -} + ); +}; export default function ValuationImpactComponent({ currentValuation, @@ -70,44 +72,65 @@ export default function ValuationImpactComponent({ funding: FundingPackageWithMeasures; }) { const [fundingModalIsOpen, setFundingModalIsOpen] = useState(false); - // If we have no current valuation, we return no component - if (!currentValuation) { - return <>; - } const lowerBoundValuation = - currentValuation + (valuationIncreaseLowerBound ?? 0); + currentValuation && valuationIncreaseLowerBound + ? currentValuation + valuationIncreaseLowerBound + : null; + const upperBoundValuation = - currentValuation + (valuationIncreaseUpperBound ?? 0); + currentValuation && valuationIncreaseUpperBound + ? currentValuation + valuationIncreaseUpperBound + : null; function openFundingModal() { setFundingModalIsOpen(true); } + function renderCurrency(value: number | null) { + return value ? ( + `£${formatNumber(value)}` + ) : ( + Not available + ); + } + return (
+ {/* Current Valuation */}
Current Property Value - £{formatNumber(currentValuation)} + {currentValuation + ? `£${formatNumber(currentValuation)}` + : "Not available"}
+ {/* After Retrofit Valuation */}
After Retrofit Valuation -
- £{formatNumber(lowerBoundValuation)} - £{formatNumber(upperBoundValuation)} -
- Estimated improvement: - - £{formatNumber(valuationIncreaseLowerBound || 0)} - £{formatNumber(valuationIncreaseUpperBound || 0)} - + {lowerBoundValuation && upperBoundValuation ? ( + <> +
+ £{formatNumber(lowerBoundValuation)} - £ + {formatNumber(upperBoundValuation)} +
+ + Estimated improvement: + + + £{formatNumber(valuationIncreaseLowerBound || 0)} - £ + {formatNumber(valuationIncreaseUpperBound || 0)} + + + ) : ( + Not available + )}
- + {/* Funding summary always shown */} + setFundingModalIsOpen(false)} @@ -118,13 +141,12 @@ export default function ValuationImpactComponent({ ); } - type FundingSummaryModalProps = { - isOpen: boolean - closeModal: () => void + isOpen: boolean; + closeModal: () => void; scheme?: string | null; - fundingPackageMeasures: FundingPackageMeasure[] -} + fundingPackageMeasures: FundingPackageMeasure[]; +}; export function FundingSummaryModal({ isOpen, @@ -161,19 +183,25 @@ export function FundingSummaryModal({ - {scheme?.toUpperCase() || 'Funding Details'} + {scheme?.toUpperCase() || "Funding Details"}

- This package has been optimised to meet the eligibility criteria of the {scheme?.toUpperCase()} funding scheme. Measures have been selected to maximise the property’s improvement while minimising cost and ensuring compliance. + This package has been optimised to meet the eligibility + criteria of the {scheme?.toUpperCase()}{" "} + funding scheme. Measures have been selected to maximise the + property’s improvement while minimising cost and ensuring + compliance.

-

Included Measures

+

+ Included Measures +

    {fundingPackageMeasures.map((measure) => (
  • - {measure.measure.replace(/_/g, ' ')} + {measure.measure.replace(/_/g, " ")}
  • ))}
@@ -194,5 +222,5 @@ export function FundingSummaryModal({
- ) + ); }