working on building passport condition report

This commit is contained in:
Khalim Conn-Kowlessar 2023-08-02 16:23:01 +01:00
parent 0ab8a34417
commit f1945945ec
4 changed files with 32 additions and 13 deletions

View file

@ -27,6 +27,7 @@ export async function GET(
tenure: true,
currentEpcRating: true,
currentSapPoints: true,
updatedAt: true,
},
where: eq(property.id, BigInt(propertyId)),
});

View file

@ -30,6 +30,7 @@ export interface PropertyMeta {
tenure: string;
currentEpcRating: string;
currentSapPoints: number;
updatedAt: string;
}
export type Rating = "Very good" | "Good" | "Poor" | "Very poor" | "N/A";

View file

@ -1,6 +1,10 @@
import EpcCard from "@/app/components/building-passport/EpcCard";
import FeatureTable from "@/app/components/building-passport/FeatureTable";
import { ConditionReportData, PropertyMeta } from "@/app/db/schema/property";
import {
ConditionReportData,
PropertyDetailsEpc,
PropertyMeta,
} from "@/app/db/schema/property";
import { formatDateTime } from "@/app/utils";
import {
generalColumns,
@ -8,7 +12,7 @@ import {
} from "@/app/components/building-passport/FeatureTableColumns";
import { getConditionReport, getPropertyMeta } from "../utils";
function AddressCard({ address }: { address: string }) {
function AddressCard({ address }: { address: string | null }) {
// In the future, we might want to use react-wrap-balancer for some of this text
return (
<div className="flex flex-col items-center p-8 shadow rounded-md max-w-xl mx-auto justify-start text-gray-100 bg-brandblue">
@ -18,14 +22,22 @@ function AddressCard({ address }: { address: string }) {
}
interface PropertyDetailsCardProps {
conditionReportData: ConditionReportData;
conditionReportData: PropertyDetailsEpc;
propertyMeta: PropertyMeta;
propertyDetailsSpatial: {
inConservationArea: string;
};
}
function PropertyDetailsCard({
conditionReportData,
propertyMeta,
propertyDetailsSpatial,
}: PropertyDetailsCardProps) {
const propertyText = [propertyMeta.builtForm, propertyMeta.propertyType]
.filter(Boolean)
.join(" ");
return (
<div className="w-full flex flex-col items-center p-5 shadow rounded-md justify-start text-gray-100 bg-brandblue">
<div className="grid grid-cols-2 gap-8 text-m w-full h-full">
@ -40,7 +52,9 @@ function PropertyDetailsCard({
</tr>
<tr>
<td className="text-gray-100 ">Property Type:</td>
<td className="text-gray-100 text-end pr-8 py-1">{`${conditionReportData.builtForm} ${conditionReportData.propertyType}`}</td>
<td className="text-gray-100 text-end pr-8 py-1">
{propertyText}
</td>
</tr>
<tr>
<td className="text-gray-100 ">Total floor area:</td>
@ -52,7 +66,7 @@ function PropertyDetailsCard({
<tr>
<td className="text-gray-100 ">In conservation area:</td>
<td className="text-gray-100 text-end pr-8 py-1">
{conditionReportData.inConservationArea}
{propertyDetailsSpatial.inConservationArea}
</td>
</tr>
</tbody>
@ -81,7 +95,7 @@ function PropertyDetailsCard({
<tr>
<td className="text-gray-100 ">Number of rooms:</td>
<td className="text-gray-100 text-end pr-8 py-1">
{propertyMeta.numberOfRooms}
{propertyMeta.numberOfRooms || "unkown"}
</td>
</tr>
</tbody>
@ -99,6 +113,9 @@ export default async function PreAssessmentReport({
// TODO: Add main fuel!
const propertyMeta = await getPropertyMeta(params.propertyId);
const conditionReportData = await getConditionReport(params.propertyId);
const propertyDetailsSpatial = {
inConservationArea: "No",
};
console.log("DATA!!");
console.log(conditionReportData);
@ -242,19 +259,16 @@ export default async function PreAssessmentReport({
// const generalFeatures = conditionReportData.generalFeatures;
// const heatingDemand = conditionReportData.heatingDemand;
console.log("I GOT?");
console.log(conditionReportData);
return (
<div className="leading-loose tracking-wider">
<div className="flex py-8 text-lg">Pre Assessment Report</div>
<div className="text-gray-700 text-sm">
Last updated: {formatDateTime(conditionReportData.lastUpdated)}
Last updated: {formatDateTime(propertyMeta.updatedAt)}
</div>
<div className="flex flex-col items-stretch mb-4">
<div className="flex flex-row justify-start mt-4 space-x-4">
<EpcCard
epcRating={conditionReportData.currentEpcRating}
epcRating={propertyMeta.currentEpcRating}
fullMargin={false}
/>
<AddressCard address={conditionReportData.fullAddress} />
@ -262,12 +276,13 @@ export default async function PreAssessmentReport({
<PropertyDetailsCard
conditionReportData={conditionReportData}
propertyMeta={propertyMeta}
propertyDetailsSpatial={propertyDetailsSpatial}
/>
</div>
</div>
<div className="flex py-8 text-lg">General Features</div>
{/* <FeatureTable data={generalFeatures} columns={generalColumns} />
<div className="flex py-8 text-lg">Retrotfit Property Features</div>
<FeatureTable data={generalFeatures} columns={generalColumns} />
{/* <div className="flex py-8 text-lg">Retrotfit Property Features</div>
<FeatureTable data={retrofitFeatures} columns={retrofitColumns} />
<div className="flex py-8 text-lg">Heating Demand</div>
<FeatureTable data={heatingDemand} columns={generalColumns} /> */}

View file

@ -11,9 +11,11 @@ export async function getPropertyMeta(
): Promise<PropertyMeta> {
const url = process.env.URL + `/api/property-meta/${propertyId}`;
// Note, for the moment, we don't cache the data
const response = await fetch(url, {
method: "GET",
headers: { "Content-Type": "application/json" },
next: { revalidate: 60 },
});
if (!response.ok) {
throw new Error("Network response was not ok");