implemented property discrete typing to recommendation cards

This commit is contained in:
Khalim Conn-Kowlessar 2023-11-30 18:04:52 +00:00
parent b5efb56dc9
commit 35d6a5641b
3 changed files with 41 additions and 27 deletions

View file

@ -14,16 +14,25 @@ const noSelectionStyling =
"shadow active:shadow active:bg-brandmidblue w-full border rounded p-4 cursor-pointer text-gray-300 bg-white hover:bg-hoverblue hover:text-gray-100 transition-colors rounded-md flex flex-col justify-start";
const TitleMap = {
wall_insulation: "Wall Insulation",
floor_insulation: "Floor Insulation",
roof_insulation: "Roof Insulation",
mechanical_ventilation: "Mechanical Ventilation",
sealing_open_fireplace: "Sealing Open Fireplace",
low_energy_lighting: "Low Energy Lighting",
iwi: "Internal Wall Insulation",
ewi: "External Wall Insulation",
cwi: "Cavity Wall Insulation",
// Walls
internal_wall_insulation: "Internal Wall Insulation",
external_wall_insulation: "External Wall Insulation",
cavity_wall_insulation: "Cavity Wall Insulation",
// Roof
loft_insulation: "Loft Insulation",
room_roof_insulation: "Room Roof Insulation",
flat_roof_insulation: "Flat Roof Insulation",
// Floor
solid_floor_insulation: "Solid Floor Insulation",
suspended_floor_insulation: "Suspended Floor Insulation",
exposed_floor_insulation: "Exposed Floor Insulation",
// Default options when no recommendation is selected
wall_insulation: "Wall Insulation",
floor_insulation: "Floor Insulation",
roof_insulation: "Roof Insulation",
};
export default function RecommendationCard({
@ -59,26 +68,13 @@ export default function RecommendationCard({
const [modalIsOpen, setModalIsOpen] = useState(false);
const getTitle = () => {
if (componentType === "wall_insulation" && cardComponent) {
const description = cardComponent.description.toLowerCase();
if (description.includes("internal")) {
return TitleMap.iwi;
} else if (description.includes("external")) {
return TitleMap.ewi;
} else if (description.includes("cavity")) {
return TitleMap.cwi;
}
if (!cardComponent) {
return TitleMap[componentType];
}
if (componentType === "roof_insulation" && cardComponent) {
const description = cardComponent.description.toLowerCase();
if (description.includes("loft")) {
return TitleMap.loft_insulation;
}
}
const recommendationType = cardComponent.type as RecommendationType;
// Logic for other componentTypes can be added here
return TitleMap[componentType];
return TitleMap[recommendationType];
};
return (

View file

@ -19,20 +19,37 @@ interface RecommendationContainerProps {
propertyMeta: PropertyMeta;
}
const typeToCategoryMap: { [key in RecommendationType]?: RecommendationType } =
{
internal_wall_insulation: "wall_insulation",
external_wall_insulation: "wall_insulation",
cavity_wall_insulation: "wall_insulation",
loft_insulation: "roof_insulation",
room_roof_insulation: "roof_insulation",
flat_roof_insulation: "roof_insulation",
suspended_floor_insulation: "floor_insulation",
solid_floor_insulation: "floor_insulation",
exposed_floor_insulation: "floor_insulation",
};
export default function RecommendationContainer({
recommendations,
propertyMeta,
}: RecommendationContainerProps) {
const categorizedRecommendations = recommendations.reduce((acc, curr) => {
const typeKey = curr.type as RecommendationType;
const category = typeToCategoryMap[typeKey] ?? typeKey;
if (!acc[typeKey]) {
acc[typeKey] = [];
if (!acc[category]) {
acc[category] = [];
}
acc[typeKey].push(curr);
acc[category].push(curr);
return acc;
}, {} as Record<RecommendationType, (typeof recommendations)[0][]>);
console.log(categorizedRecommendations);
const defaultWallsRecommendations =
categorizedRecommendations.wall_insulation?.find(
(rec: Recommendation) => rec.default

View file

@ -96,7 +96,8 @@ export type RecommendationMaterial = InferModel<
// We allow recommendation types to be a string however we'll set up a typing for it here to control
// the types we expect
// Note: roof_insulation, wall_insulation and floor_insulation aren't used in the app anymore and
// have been superseded by the more specific types. The backend will no longer return these types
// have been superseded by the more specific types. The backend will no longer return these types and
// we will depracate these in the future
export type RecommendationType =
| "internal_wall_insulation"
| "external_wall_insulation"