diff --git a/src/app/api/due-considerations/route.ts b/src/app/api/due-considerations/route.ts new file mode 100644 index 0000000..71c6b16 --- /dev/null +++ b/src/app/api/due-considerations/route.ts @@ -0,0 +1,57 @@ +import { NextRequest, NextResponse } from "next/server"; +import { z } from "zod"; + +const BodySchema = z.object({ + folderKey: z.string(), + userId: z.string(), + scheme: z.string(), +}); + +export async function POST(request: NextRequest) { + const body = await request.json(); + let validatedBody; + + try { + validatedBody = BodySchema.parse(body); + } catch (error) { + console.error("Invalid input: ", error); + return new NextResponse(JSON.stringify({ msg: "Invalid input" }), { + status: 400, + }); + } + + try { + // We'll trigger the plan build in our fastapi backend and then the user will just have to + // wait for the plan to be ready + + const headers = { + "Content-Type": "application/json", + }; + + console.log("validatedBody", validatedBody); + + const response = await fetch( + `${process.env.DUE_CONSIDERATIONS_API_URL}/due-considerations`, + { + method: "POST", + headers: headers, + body: JSON.stringify(validatedBody), + } + ); + + if (!response.ok) { + throw new Error("API request failed"); + } + + const responseData = await response.json(); + + return new NextResponse(JSON.stringify(responseData), { + status: 200, + }); + } catch (error) { + console.error(error); + return new NextResponse(JSON.stringify({ msg: "Internal server error" }), { + status: 500, + }); + } +} diff --git a/src/app/components/building-passport/RecommendationContainer.tsx b/src/app/components/building-passport/RecommendationContainer.tsx index cccb5bb..b7dc87b 100644 --- a/src/app/components/building-passport/RecommendationContainer.tsx +++ b/src/app/components/building-passport/RecommendationContainer.tsx @@ -48,14 +48,14 @@ export default function RecommendationContainer({ // ) || { estimatedCost: 0, sapPoints: 0 }; const [costMap, setCostMap] = useState({ - Walls: defaultWallsRecommendations?.estimatedCost || 0, - Floor: defaultFloorRecommendations?.estimatedCost || 0, + wall_insulation: defaultWallsRecommendations?.estimatedCost || 0, + floor_insulation: defaultFloorRecommendations?.estimatedCost || 0, // Ventilation: defaultVentiliationRecommendations?.estimatedCost || 0, }); const [sapMap, setSapMap] = useState({ - Walls: defaultWallsRecommendations?.sapPoints || 0, - Floor: defaultFloorRecommendations.sapPoints || 0, + wall_insulation: defaultWallsRecommendations?.sapPoints || 0, + floor_insulation: defaultFloorRecommendations.sapPoints || 0, // Ventilation: defaultVentiliationRecommendations.sapPoints, }); diff --git a/src/app/components/building-passport/RecommendationCostSummaryCard.tsx b/src/app/components/building-passport/RecommendationCostSummaryCard.tsx index 6a798f4..2d98e9b 100644 --- a/src/app/components/building-passport/RecommendationCostSummaryCard.tsx +++ b/src/app/components/building-passport/RecommendationCostSummaryCard.tsx @@ -1,6 +1,5 @@ "use client"; import { formatNumber } from "@/app/utils"; -import { useState } from "react"; export default function RecommendationCostSummaryCard({ totalEstimatedCost, diff --git a/src/app/components/building-passport/RecommendationModal.tsx b/src/app/components/building-passport/RecommendationModal.tsx index 70bcf17..49f2541 100644 --- a/src/app/components/building-passport/RecommendationModal.tsx +++ b/src/app/components/building-passport/RecommendationModal.tsx @@ -77,6 +77,8 @@ export default function RecommendationModal({ // update the cost sum setTotalEstimatedCost(sumRecommendationMetricMap(newCostMap)); + console.log("B4", sapMap); + // Update the sap map const newSapMap = { ...sapMap, @@ -84,12 +86,15 @@ export default function RecommendationModal({ }; setSapMap(newSapMap); + console.log("AFTER", newSapMap); + // update the sap sum - const newSapImporvement = sumRecommendationMetricMap(newSapMap); - setTotalSapPoints(newSapImporvement); + const newSapImprovement = sumRecommendationMetricMap(newSapMap); + console.log("newSapImprovement", newSapImprovement); + setTotalSapPoints(newSapImprovement); // TODO: While we have placeholder SAP points, constrain to 100 - const newSapPoints = Math.min(currentSapPoints + newSapImporvement, 100); + const newSapPoints = Math.min(currentSapPoints + newSapImprovement, 100); // update the expected EPC rating setExpectedEpcRating(sapToEpc(newSapPoints)); diff --git a/src/app/shadcn_components/ui/skeleton.tsx b/src/app/shadcn_components/ui/skeleton.tsx new file mode 100644 index 0000000..01b8b6d --- /dev/null +++ b/src/app/shadcn_components/ui/skeleton.tsx @@ -0,0 +1,15 @@ +import { cn } from "@/lib/utils" + +function Skeleton({ + className, + ...props +}: React.HTMLAttributes) { + return ( +
+ ) +} + +export { Skeleton } diff --git a/src/app/utils.ts b/src/app/utils.ts index 8a099ef..55c10d9 100644 --- a/src/app/utils.ts +++ b/src/app/utils.ts @@ -30,17 +30,17 @@ export function sapToEpc(sapPoints: number): string { throw new Error("SAP points should be between 1 and 100."); } - if (sapPoints > 91) { + if (sapPoints >= 92) { return "A"; - } else if (sapPoints > 80) { + } else if (sapPoints >= 81) { return "B"; - } else if (sapPoints > 69) { + } else if (sapPoints >= 69) { return "C"; - } else if (sapPoints > 55) { + } else if (sapPoints >= 55) { return "D"; - } else if (sapPoints > 39) { + } else if (sapPoints >= 39) { return "E"; - } else if (sapPoints > 21) { + } else if (sapPoints >= 21) { return "F"; } else { return "G"; diff --git a/src/types/recommendations.ts b/src/types/recommendations.ts index 3934a0b..f6db317 100644 --- a/src/types/recommendations.ts +++ b/src/types/recommendations.ts @@ -1,6 +1,6 @@ export interface RecommendationMetricMap { - Walls: number; - Floor: number; + wall_insulation: number; + floor_insulation: number; // TODO: Implement ventilation // Ventilation: number; }