diff --git a/src/components/Options/ProfileTypeOptions.tsx b/src/components/Options/ProfileTypeOptions.tsx index 1583af0f45a672fc6259bbfaf1b96b53e190d7e3..f3fde3a9fa7a89176581c56d5e79d222c4873fb8 100644 --- a/src/components/Options/ProfileTypeOptions.tsx +++ b/src/components/Options/ProfileTypeOptions.tsx @@ -6,7 +6,11 @@ import StyledCard from 'components/CommonKit/Card/StyledCard' import StyledIcon from 'components/CommonKit/Icon/StyledIcon' import profileIcon from 'assets/icons/ico/profile.svg' import './profileTypeOptions.scss' -import { IndividualOrCollective, HousingType } from 'enum/profileType.enum' +import { + IndividualOrCollective, + HousingType, + ThreeChoicesAnswer, +} from 'enum/profileType.enum' import { FluidType } from 'enum/fluid.enum' import { useHistory } from 'react-router-dom' @@ -95,39 +99,39 @@ const ProfileTypeOptions: React.FC = () => { )} </ul> </div> - <div className="fields"> - <div className="label"> - {t('profile_type.title_facilities_installation')} + {profile.profileType.hasInstalledVentilation === + ThreeChoicesAnswer.YES || + profile.profileType.hasReplacedHeater === + ThreeChoicesAnswer.YES ? ( + <div className="fields"> + <div className="label"> + {t('profile_type.title_facilities_installation')} + </div> + <ul className="value"> + <li> + {profile.profileType.hasInstalledVentilation === + ThreeChoicesAnswer.YES && + t(`profile_type.title_ventilation`)} + </li> + <li> + {profile.profileType.hasReplacedHeater === + ThreeChoicesAnswer.YES && + t(`profile_type.title_heater_replacement`)} + </li> + </ul> </div> - <ul className="value"> - {profile.profileType.facilitiesInstallation.map( - (equipment, index) => { - return ( - <li key={index}> - {t( - `profile_type.facilities_installation.${equipment}` - )} - </li> - ) - } - )} - </ul> - </div> + ) : ( + '' + )} <div className="fields"> <div className="label"> {t('profile_type.title_hot_water_equipment')} </div> - <ul className="value"> - {profile.profileType.hotWaterEquipment.map( - (equipment, index) => { - return ( - <li key={index}> - {t(`profile_type.hot_water_equipment.${equipment}`)} - </li> - ) - } + <div className="value"> + {t( + `profile_type.hot_water_equipment.${profile.profileType.hotWaterEquipment}` )} - </ul> + </div> </div> {profile.profileType.warmingFluid !== null && ( <div className="fields"> diff --git a/src/components/ProfileType/ProfileTypeView.tsx b/src/components/ProfileType/ProfileTypeView.tsx index 0f2edca3f157ecf96987cdc8c7474ba657e02d02..0fedddde479a8e4f46bff148be37f3c4413870f3 100644 --- a/src/components/ProfileType/ProfileTypeView.tsx +++ b/src/components/ProfileType/ProfileTypeView.tsx @@ -9,7 +9,6 @@ import ProfileTypeFormEnd from 'components/ProfileType/ProfileTypeFinished' import { ProfileType, ProfileTypeAnswer } from 'models/profileType.model' import { ConstructionYear, - FacilitiesInstallation, Floor, HotWaterEquipment, HousingType, @@ -17,6 +16,7 @@ import { IndividualOrCollective, OutsideFacingWalls, ProfileTypeFormType, + ThreeChoicesAnswer, } from 'enum/profileType.enum' import { FluidType } from 'enum/fluid.enum' import { ProfileTypeStepForm } from 'enum/profileType.enum' @@ -36,9 +36,10 @@ const ProfileTypeView = () => { floor: Floor.NOT_APPLICABLE, heating: IndividualOrCollective.INDIVIDUAL, individualInsulationWork: [IndividualInsulationWork.NONE], - facilitiesInstallation: [FacilitiesInstallation.NONE], + hasInstalledVentilation: ThreeChoicesAnswer.UNKWOWN, + hasReplacedHeater: ThreeChoicesAnswer.UNKWOWN, hotWater: IndividualOrCollective.INDIVIDUAL, - hotWaterEquipment: [HotWaterEquipment.OTHER], + hotWaterEquipment: HotWaterEquipment.OTHER, warmingFluid: FluidType.ELECTRICITY, hotWaterFluid: FluidType.ELECTRICITY, cookingFluid: FluidType.ELECTRICITY, diff --git a/src/enum/profileType.enum.ts b/src/enum/profileType.enum.ts index a60de8e23764bad5355180190bf3c58b6f15e74f..9791d5e7eaa81370ab93d9edc8209be47df7dfbb 100644 --- a/src/enum/profileType.enum.ts +++ b/src/enum/profileType.enum.ts @@ -36,13 +36,19 @@ export enum IndividualInsulationWork { WALL_INSULATION = 'wall_insulation', } -export enum FacilitiesInstallation { - NONE = 'none', - COLLECTIVE_HEATER = 'collective_heater', - INDIVIDUAL_HEATER = 'individual_heater', - INDIVIDUAL_VENTILATION = 'individual_ventilation', +export enum ThreeChoicesAnswer { + YES = 'yes', + NO = 'no', + UNKWOWN = 'unknown', } +// export enum FacilitiesInstallation { +// NONE = 'none', +// COLLECTIVE_HEATER = 'collective_heater', +// INDIVIDUAL_HEATER = 'individual_heater', +// INDIVIDUAL_VENTILATION = 'individual_ventilation', +// } + export enum HotWaterEquipment { SOLAR = 'solar', THERMODYNAMIC = 'thermodynamic', @@ -51,20 +57,21 @@ export enum HotWaterEquipment { export enum ProfileTypeStepForm { HOUSING_TYPE = 0, - CONSTRUCTION_YEAR = 1, - AREA = 2, - OCCUPANTS_NUMBER = 3, + AREA = 1, + OCCUPANTS_NUMBER = 2, + CONSTRUCTION_YEAR = 3, OUTSIDE_FACING_WALLS = 4, FLOOR = 5, HEATING = 6, WARMING_FLUID = 7, INDIVIDUAL_INSULATION_WORK = 8, - FACILITIES_INSTALLATION = 9, - HOT_WATER = 10, - HOT_WATER_FLUID = 11, - HOT_WATER_EQUIPMENT = 12, - COOKING_FLUID = 13, - END = 14, + VENTILATION = 9, + HEATER_REPLACEMENT = 10, + HOT_WATER = 11, + HOT_WATER_FLUID = 12, + HOT_WATER_EQUIPMENT = 13, + COOKING_FLUID = 14, + END = 15, } export enum ProfileTypeFormType { diff --git a/src/locales/fr.json b/src/locales/fr.json index 86df6f301ebfa46d54aabd0e27826f4ac68bb32b..e30f5d7e301ed6ea5854d68ef8c66ee2154d446c 100644 --- a/src/locales/fr.json +++ b/src/locales/fr.json @@ -465,13 +465,19 @@ "built_after_1998": "construit après 1998" }, "title_facilities_installation": "Équipement", - "facilities_installation": { - "question": "Quel équipement a été installé ou remplacé ces 10 dernières années ?", - "none": "Aucun", - "collective_heater": "Chauffage collectif", - "individual_heater": "Chauffage individuel", - "individual_ventilation": "Ventilation double flux individuel", - "individual_heater_and_ventilation": "Chauffage et ventilation individuel" + "title_ventilation": "Ventilation double flux", + "ventilation": { + "question": "Etes-vous équipé d'une ventialtion double flux ?", + "yes": "Oui", + "no": "Non", + "unknown": "Je ne sais pas" + }, + "title_heater_replacement": "Pompe à chaleur ou poêle à bois", + "heater_replacement": { + "question": "Au cours de ces 10 dernières années, avez-vous remplacé votre chaudière ou vous êtes-vous équipé d'une pompe à chaleur ou d'un poêle à bois ?", + "yes": "Oui", + "no": "Non", + "unknown": "Je ne sais pas" }, "title_hotWaterEquipment": "Eau chaude", "hot_water": { @@ -481,9 +487,9 @@ }, "hot_water_equipment": { "question": "Quel équipement utilisez-vous pour produire votre eau chaude ?", - "solar": "Solaire", - "thermodynamic": "Thermodynamique", - "other": "Autre" + "solar": "Chauffe-eau solaire", + "thermodynamic": "Chauffe-eau thermodynamique", + "other": "Ni l'un ni l'autre" }, "title_hot_water_equipment": "Eau chaude", "title_heating_source": "Source chauffage", diff --git a/src/models/profileType.model.ts b/src/models/profileType.model.ts index 9e0cc3240f2cea48c1cf74c77856dff1407f0ed8..50028e8d96e6035a0ae11a5da3be8a08f84e7106 100644 --- a/src/models/profileType.model.ts +++ b/src/models/profileType.model.ts @@ -3,11 +3,11 @@ import { Floor, ConstructionYear, IndividualInsulationWork, - FacilitiesInstallation, HotWaterEquipment, OutsideFacingWalls, IndividualOrCollective, ProfileTypeFormType, + ThreeChoicesAnswer, } from 'enum/profileType.enum' import { FluidType } from 'enum/fluid.enum' @@ -19,8 +19,8 @@ interface ProfileTypeIndexableTypes { | Floor | IndividualOrCollective | IndividualInsulationWork[] - | FacilitiesInstallation[] - | HotWaterEquipment[] + | ThreeChoicesAnswer + | HotWaterEquipment | FluidType | number | string @@ -36,8 +36,9 @@ export interface ProfileType extends ProfileTypeIndexableTypes { heating: IndividualOrCollective hotWater: IndividualOrCollective individualInsulationWork: IndividualInsulationWork[] - facilitiesInstallation: FacilitiesInstallation[] - hotWaterEquipment: HotWaterEquipment[] + hasInstalledVentilation: ThreeChoicesAnswer + hasReplacedHeater: ThreeChoicesAnswer + hotWaterEquipment: HotWaterEquipment warmingFluid: FluidType | null hotWaterFluid: FluidType | null cookingFluid: FluidType @@ -71,8 +72,8 @@ export type ProfileTypeAnswerChoices = | Floor | IndividualOrCollective | IndividualInsulationWork[] - | FacilitiesInstallation[] - | HotWaterEquipment[] + | ThreeChoicesAnswer + | HotWaterEquipment | FluidType | null export interface ProfileTypeAnswer { diff --git a/src/services/profileType.service.ts b/src/services/profileType.service.ts index 572c490e4951dc2acfa40b6489b10cf22c86b847..7a1aeaa6c6502d68416608f121b2fc7e52a00937 100644 --- a/src/services/profileType.service.ts +++ b/src/services/profileType.service.ts @@ -13,7 +13,6 @@ import coldWaterData from 'constants/consumptionConstants/coldWater.json' import EcsData from 'constants/consumptionConstants/ecs.json' import { ConstructionYear, - FacilitiesInstallation, Floor, IndividualOrCollective, HotWaterEquipment, @@ -22,6 +21,7 @@ import { OutsideFacingWalls, ProfileTypeStepForm, ProfileTypeFormType, + ThreeChoicesAnswer, } from 'enum/profileType.enum' import { FluidType } from 'enum/fluid.enum' import ConverterService from './converter.service' @@ -62,8 +62,10 @@ export default class ProfileTypeService { const constructionYear: ConstructionYear = this.profileType.constructionYear const individualInsulationWork: IndividualInsulationWork[] = this .profileType.individualInsulationWork - const facilitiesInstallation: FacilitiesInstallation[] = this.profileType - .facilitiesInstallation + const hasInstalledVentilation: ThreeChoicesAnswer = this.profileType + .hasInstalledVentilation + const hasReplacedHeater: ThreeChoicesAnswer = this.profileType + .hasReplacedHeater const heating = this.profileType.heating //Apply corrections @@ -136,17 +138,21 @@ export default class ProfileTypeService { } else correctionInsulation = 0 if ( - !facilitiesInstallation.includes(FacilitiesInstallation.NONE) && + hasInstalledVentilation === ThreeChoicesAnswer.YES && + hasReplacedHeater === ThreeChoicesAnswer.YES && heating !== IndividualOrCollective.COLLECTIVE ) { - if (facilitiesInstallation.length === 1) { - correctionFacilities = - heatingData.adjustment_facilities[facilitiesInstallation[0]] - } else { - correctionFacilities = - heatingData.adjustment_facilities['individual_heater_and_ventilation'] - } - } else correctionFacilities = 0 + correctionFacilities = + heatingData.adjustment_facilities['individual_heater_and_ventilation'] + } else if (hasReplacedHeater === ThreeChoicesAnswer.YES) { + correctionFacilities = + heatingData.adjustment_facilities['individual_heater'] + } else if (hasInstalledVentilation === ThreeChoicesAnswer.YES) { + correctionFacilities = + heatingData.adjustment_facilities['individual_ventilation'] + } else { + correctionFacilities = 0 + } const correctedConsumption = estimatedConsumption * @@ -464,12 +470,12 @@ export default class ProfileTypeService { public getNextFormStep(step: ProfileTypeStepForm): ProfileTypeStepForm { switch (step) { case ProfileTypeStepForm.HOUSING_TYPE: - return ProfileTypeStepForm.CONSTRUCTION_YEAR - case ProfileTypeStepForm.CONSTRUCTION_YEAR: return ProfileTypeStepForm.AREA case ProfileTypeStepForm.AREA: return ProfileTypeStepForm.OCCUPANTS_NUMBER case ProfileTypeStepForm.OCCUPANTS_NUMBER: + return ProfileTypeStepForm.CONSTRUCTION_YEAR + case ProfileTypeStepForm.CONSTRUCTION_YEAR: return ProfileTypeStepForm.OUTSIDE_FACING_WALLS case ProfileTypeStepForm.OUTSIDE_FACING_WALLS: return this.profileType.housingType === HousingType.INDIVIDUAL_HOUSE @@ -483,11 +489,13 @@ export default class ProfileTypeService { : ProfileTypeStepForm.HOT_WATER case ProfileTypeStepForm.WARMING_FLUID: return this.profileType.constructionYear === ConstructionYear.AFTER_1999 - ? ProfileTypeStepForm.FACILITIES_INSTALLATION + ? ProfileTypeStepForm.VENTILATION : ProfileTypeStepForm.INDIVIDUAL_INSULATION_WORK case ProfileTypeStepForm.INDIVIDUAL_INSULATION_WORK: - return ProfileTypeStepForm.FACILITIES_INSTALLATION - case ProfileTypeStepForm.FACILITIES_INSTALLATION: + return ProfileTypeStepForm.VENTILATION + case ProfileTypeStepForm.VENTILATION: + return ProfileTypeStepForm.HEATER_REPLACEMENT + case ProfileTypeStepForm.HEATER_REPLACEMENT: return this.profileType.housingType === HousingType.INDIVIDUAL_HOUSE ? ProfileTypeStepForm.HOT_WATER_FLUID : ProfileTypeStepForm.HOT_WATER @@ -513,14 +521,14 @@ export default class ProfileTypeService { */ public getPreviousFormStep(step: ProfileTypeStepForm): ProfileTypeStepForm { switch (step) { - case ProfileTypeStepForm.CONSTRUCTION_YEAR: - return ProfileTypeStepForm.HOUSING_TYPE case ProfileTypeStepForm.AREA: - return ProfileTypeStepForm.CONSTRUCTION_YEAR + return ProfileTypeStepForm.HOUSING_TYPE case ProfileTypeStepForm.OCCUPANTS_NUMBER: return ProfileTypeStepForm.AREA - case ProfileTypeStepForm.OUTSIDE_FACING_WALLS: + case ProfileTypeStepForm.CONSTRUCTION_YEAR: return ProfileTypeStepForm.OCCUPANTS_NUMBER + case ProfileTypeStepForm.OUTSIDE_FACING_WALLS: + return ProfileTypeStepForm.CONSTRUCTION_YEAR case ProfileTypeStepForm.FLOOR: return ProfileTypeStepForm.OUTSIDE_FACING_WALLS case ProfileTypeStepForm.HEATING: @@ -531,17 +539,19 @@ export default class ProfileTypeService { : ProfileTypeStepForm.HEATING case ProfileTypeStepForm.INDIVIDUAL_INSULATION_WORK: return ProfileTypeStepForm.WARMING_FLUID - case ProfileTypeStepForm.FACILITIES_INSTALLATION: + case ProfileTypeStepForm.VENTILATION: return this.profileType.constructionYear === ConstructionYear.AFTER_1999 ? ProfileTypeStepForm.WARMING_FLUID : ProfileTypeStepForm.INDIVIDUAL_INSULATION_WORK + case ProfileTypeStepForm.HEATER_REPLACEMENT: + return ProfileTypeStepForm.VENTILATION case ProfileTypeStepForm.HOT_WATER: return this.profileType.heating === IndividualOrCollective.INDIVIDUAL - ? ProfileTypeStepForm.FACILITIES_INSTALLATION + ? ProfileTypeStepForm.HEATER_REPLACEMENT : ProfileTypeStepForm.HEATING case ProfileTypeStepForm.HOT_WATER_FLUID: return this.profileType.housingType === HousingType.INDIVIDUAL_HOUSE - ? ProfileTypeStepForm.FACILITIES_INSTALLATION + ? ProfileTypeStepForm.HEATER_REPLACEMENT : ProfileTypeStepForm.HOT_WATER case ProfileTypeStepForm.HOT_WATER_EQUIPMENT: return ProfileTypeStepForm.HOT_WATER_FLUID @@ -589,7 +599,7 @@ export default class ProfileTypeService { return { type: ProfileTypeFormType.NUMBER_SELECTION, attribute: 'outsideFacingWalls', - choices: [0, 1, 2, 3, 4], + choices: [1, 2, 3, 4], } case ProfileTypeStepForm.FLOOR: return { @@ -609,11 +619,17 @@ export default class ProfileTypeService { attribute: 'individualInsulationWork', choices: Object.values(IndividualInsulationWork), } - case ProfileTypeStepForm.FACILITIES_INSTALLATION: + case ProfileTypeStepForm.VENTILATION: return { - type: ProfileTypeFormType.MULTI_CHOICE, - attribute: 'facilitiesInstallation', - choices: Object.values(FacilitiesInstallation), + type: ProfileTypeFormType.SINGLE_CHOICE, + attribute: 'hasInstalledVentilation', + choices: Object.values(ThreeChoicesAnswer), + } + case ProfileTypeStepForm.HEATER_REPLACEMENT: + return { + type: ProfileTypeFormType.SINGLE_CHOICE, + attribute: 'hasReplacedHeater', + choices: Object.values(ThreeChoicesAnswer), } case ProfileTypeStepForm.HOT_WATER: return { @@ -623,7 +639,7 @@ export default class ProfileTypeService { } case ProfileTypeStepForm.HOT_WATER_EQUIPMENT: return { - type: ProfileTypeFormType.MULTI_CHOICE, + type: ProfileTypeFormType.SINGLE_CHOICE, attribute: 'hotWaterEquipment', choices: Object.values(HotWaterEquipment), } @@ -673,7 +689,7 @@ export default class ProfileTypeService { } if (profileType.hotWater === IndividualOrCollective.COLLECTIVE) { profileType.hotWaterFluid = null - profileType.hotWaterEquipment = [] + profileType.hotWaterEquipment = HotWaterEquipment.OTHER } } return profileType diff --git a/src/store/profile/profile.reducer.ts b/src/store/profile/profile.reducer.ts index 08b99d6f629cb488c7e052e3aaf827f5451e1710..dc50c96752c1c5b1493afeeb6f733663a8174cae 100644 --- a/src/store/profile/profile.reducer.ts +++ b/src/store/profile/profile.reducer.ts @@ -7,13 +7,13 @@ import { Profile } from 'models' import { DateTime } from 'luxon' import { ConstructionYear, - FacilitiesInstallation, Floor, HotWaterEquipment, HousingType, IndividualInsulationWork, IndividualOrCollective, OutsideFacingWalls, + ThreeChoicesAnswer, } from 'enum/profileType.enum' import { FluidType } from 'enum/fluid.enum' @@ -45,8 +45,9 @@ const initialState: Profile = { IndividualInsulationWork.WINDOW_REPLACEMENT, IndividualInsulationWork.WALL_INSULATION, ], - facilitiesInstallation: [FacilitiesInstallation.NONE], - hotWaterEquipment: [HotWaterEquipment.SOLAR], + hasInstalledVentilation: ThreeChoicesAnswer.UNKWOWN, + hasReplacedHeater: ThreeChoicesAnswer.UNKWOWN, + hotWaterEquipment: HotWaterEquipment.SOLAR, warmingFluid: FluidType.ELECTRICITY, hotWaterFluid: FluidType.ELECTRICITY, cookingFluid: FluidType.ELECTRICITY,