diff --git a/src/components/Ecogesture/EcogestureEmptyList.tsx b/src/components/Ecogesture/EcogestureEmptyList.tsx index 2aad11c27ec0d0b558ecac1c6782d24d4a216a71..a4f36b70788bd2860cc103f146d24a7a4bd92d6c 100644 --- a/src/components/Ecogesture/EcogestureEmptyList.tsx +++ b/src/components/Ecogesture/EcogestureEmptyList.tsx @@ -69,7 +69,7 @@ const EcogestureEmptyList: React.FC<EcogestureEmptyListProps> = ({ navigate('/ecogesture-form') }} classes={{ - root: 'btn-highlight btn2', + root: 'btn-highlight', label: 'text-16-bold', }} > diff --git a/src/components/Ecogesture/__snapshots__/EcogestureEmptyList.spec.tsx.snap b/src/components/Ecogesture/__snapshots__/EcogestureEmptyList.spec.tsx.snap index 80b817f03803af8c47a20a7687266d4f6432ecd9..a97c14eaea5675b7f44b101a8f1dc6b701e1a8e6 100644 --- a/src/components/Ecogesture/__snapshots__/EcogestureEmptyList.spec.tsx.snap +++ b/src/components/Ecogesture/__snapshots__/EcogestureEmptyList.spec.tsx.snap @@ -207,7 +207,7 @@ exports[`EcogestureEmptyList component should be rendered correctly 1`] = ` classes={ Object { "label": "text-16-bold", - "root": "btn-highlight btn2", + "root": "btn-highlight", } } onClick={[Function]} @@ -236,7 +236,7 @@ exports[`EcogestureEmptyList component should be rendered correctly 1`] = ` "outlinedSecondary": "MuiButton-outlinedSecondary", "outlinedSizeLarge": "MuiButton-outlinedSizeLarge", "outlinedSizeSmall": "MuiButton-outlinedSizeSmall", - "root": "MuiButton-root btn-highlight btn2", + "root": "MuiButton-root btn-highlight", "sizeLarge": "MuiButton-sizeLarge", "sizeSmall": "MuiButton-sizeSmall", "startIcon": "MuiButton-startIcon", @@ -251,7 +251,7 @@ exports[`EcogestureEmptyList component should be rendered correctly 1`] = ` > <WithStyles(ForwardRef(ButtonBase)) aria-label="ecogesture.emptyList.btn2" - className="MuiButton-root btn-highlight btn2 MuiButton-text" + className="MuiButton-root btn-highlight MuiButton-text" component="button" disabled={false} focusRipple={true} @@ -261,7 +261,7 @@ exports[`EcogestureEmptyList component should be rendered correctly 1`] = ` > <ForwardRef(ButtonBase) aria-label="ecogesture.emptyList.btn2" - className="MuiButton-root btn-highlight btn2 MuiButton-text" + className="MuiButton-root btn-highlight MuiButton-text" classes={ Object { "disabled": "Mui-disabled", @@ -278,7 +278,7 @@ exports[`EcogestureEmptyList component should be rendered correctly 1`] = ` > <button aria-label="ecogesture.emptyList.btn2" - className="MuiButtonBase-root MuiButton-root btn-highlight btn2 MuiButton-text" + className="MuiButtonBase-root MuiButton-root btn-highlight MuiButton-text" disabled={false} onBlur={[Function]} onClick={[Function]} diff --git a/src/components/Ecogesture/__snapshots__/EcogestureView.spec.tsx.snap b/src/components/Ecogesture/__snapshots__/EcogestureView.spec.tsx.snap index caf3bc141149ed26b0b6c7e13653819fed1febac..50965b8272031fe0d5d756ebda4d77811f41f39c 100644 --- a/src/components/Ecogesture/__snapshots__/EcogestureView.spec.tsx.snap +++ b/src/components/Ecogesture/__snapshots__/EcogestureView.spec.tsx.snap @@ -765,7 +765,7 @@ exports[`EcogestureView component should be rendered correctly 1`] = ` classes={ Object { "label": "text-16-bold", - "root": "btn-highlight btn2", + "root": "btn-highlight", } } onClick={[Function]} @@ -794,7 +794,7 @@ exports[`EcogestureView component should be rendered correctly 1`] = ` "outlinedSecondary": "MuiButton-outlinedSecondary", "outlinedSizeLarge": "MuiButton-outlinedSizeLarge", "outlinedSizeSmall": "MuiButton-outlinedSizeSmall", - "root": "MuiButton-root btn-highlight btn2", + "root": "MuiButton-root btn-highlight", "sizeLarge": "MuiButton-sizeLarge", "sizeSmall": "MuiButton-sizeSmall", "startIcon": "MuiButton-startIcon", @@ -809,7 +809,7 @@ exports[`EcogestureView component should be rendered correctly 1`] = ` > <WithStyles(ForwardRef(ButtonBase)) aria-label="ecogesture.emptyList.btn2" - className="MuiButton-root btn-highlight btn2 MuiButton-text" + className="MuiButton-root btn-highlight MuiButton-text" component="button" disabled={false} focusRipple={true} @@ -819,7 +819,7 @@ exports[`EcogestureView component should be rendered correctly 1`] = ` > <ForwardRef(ButtonBase) aria-label="ecogesture.emptyList.btn2" - className="MuiButton-root btn-highlight btn2 MuiButton-text" + className="MuiButton-root btn-highlight MuiButton-text" classes={ Object { "disabled": "Mui-disabled", @@ -836,7 +836,7 @@ exports[`EcogestureView component should be rendered correctly 1`] = ` > <button aria-label="ecogesture.emptyList.btn2" - className="MuiButtonBase-root MuiButton-root btn-highlight btn2 MuiButton-text" + className="MuiButtonBase-root MuiButton-root btn-highlight MuiButton-text" disabled={false} onBlur={[Function]} onClick={[Function]} @@ -1101,7 +1101,7 @@ exports[`EcogestureView component should be rendered correctly 1`] = ` classes={ Object { "label": "text-16-bold", - "root": "btn-highlight btn2", + "root": "btn-highlight", } } onClick={[Function]} @@ -1130,7 +1130,7 @@ exports[`EcogestureView component should be rendered correctly 1`] = ` "outlinedSecondary": "MuiButton-outlinedSecondary", "outlinedSizeLarge": "MuiButton-outlinedSizeLarge", "outlinedSizeSmall": "MuiButton-outlinedSizeSmall", - "root": "MuiButton-root btn-highlight btn2", + "root": "MuiButton-root btn-highlight", "sizeLarge": "MuiButton-sizeLarge", "sizeSmall": "MuiButton-sizeSmall", "startIcon": "MuiButton-startIcon", @@ -1145,7 +1145,7 @@ exports[`EcogestureView component should be rendered correctly 1`] = ` > <WithStyles(ForwardRef(ButtonBase)) aria-label="ecogesture.emptyList.btn2" - className="MuiButton-root btn-highlight btn2 MuiButton-text" + className="MuiButton-root btn-highlight MuiButton-text" component="button" disabled={false} focusRipple={true} @@ -1155,7 +1155,7 @@ exports[`EcogestureView component should be rendered correctly 1`] = ` > <ForwardRef(ButtonBase) aria-label="ecogesture.emptyList.btn2" - className="MuiButton-root btn-highlight btn2 MuiButton-text" + className="MuiButton-root btn-highlight MuiButton-text" classes={ Object { "disabled": "Mui-disabled", @@ -1172,7 +1172,7 @@ exports[`EcogestureView component should be rendered correctly 1`] = ` > <button aria-label="ecogesture.emptyList.btn2" - className="MuiButtonBase-root MuiButton-root btn-highlight btn2 MuiButton-text" + className="MuiButtonBase-root MuiButton-root btn-highlight MuiButton-text" disabled={false} onBlur={[Function]} onClick={[Function]} diff --git a/src/components/Ecogesture/ecogestureEmptyList.scss b/src/components/Ecogesture/ecogestureEmptyList.scss index 49974c072391ef74e2f70d34753e48d9ea40ea66..a072890654d9629babe8c4a94abbf687ef71efda 100644 --- a/src/components/Ecogesture/ecogestureEmptyList.scss +++ b/src/components/Ecogesture/ecogestureEmptyList.scss @@ -28,9 +28,6 @@ button { margin: 0; } - button.btn2 { - margin-left: 1rem; - } } .reinit-button { margin-left: 15px; diff --git a/src/components/EcogestureForm/EcogestureFormEquipment.tsx b/src/components/EcogestureForm/EcogestureFormEquipment.tsx index 323d4969e2a99263ef24a72a8ef2928c4c372622..841883c608e0404344e2d41346e8206715a02d29 100644 --- a/src/components/EcogestureForm/EcogestureFormEquipment.tsx +++ b/src/components/EcogestureForm/EcogestureFormEquipment.tsx @@ -4,7 +4,7 @@ import { useI18n } from 'cozy-ui/transpiled/react/I18n' import { EquipmentType } from 'enum/ecogesture.enum' import { EcogestureStepForm } from 'enum/ecogestureForm.enum' import { ProfileTypeStepForm } from 'enum/profileType.enum' -import { ProfileEcogesture } from 'models/profileEcogesture.model' +import { ProfileEcogesture, ProfileType } from 'models' import React, { Dispatch, useCallback, useState } from 'react' import { useDispatch, useSelector } from 'react-redux' import { useNavigate } from 'react-router-dom' @@ -20,7 +20,7 @@ import './ecogestureFormEquipment.scss' interface EcogestureFormEquipmentProps { profileEcogesture: ProfileEcogesture setPreviousStep: (_profileEcogesture: ProfileEcogesture) => void - setNextStep?: (_profileEcogesture: ProfileEcogesture) => void + setNextStep?: (_profileType?: ProfileType) => void step: ProfileTypeStepForm | EcogestureStepForm } diff --git a/src/components/ProfileType/ProfileTypeFormSingleChoice.tsx b/src/components/ProfileType/ProfileTypeFormSingleChoice.tsx index f0fd6681cd7edd02886f21381b08addf581599ff..b8ec1909a60440312be59cf795e14a5f8a9d1ec6 100644 --- a/src/components/ProfileType/ProfileTypeFormSingleChoice.tsx +++ b/src/components/ProfileType/ProfileTypeFormSingleChoice.tsx @@ -10,6 +10,8 @@ import { ProfileTypeAnswerChoices, } from 'models/profileType.model' import React, { useCallback, useEffect, useState } from 'react' +import { useSelector } from 'react-redux' +import { AppStore } from 'store' interface ProfileTypeFormSingleChoiceProps { step: ProfileTypeStepForm @@ -35,6 +37,10 @@ const ProfileTypeFormSingleChoice: React.FC< const { t } = useI18n() const [answer, setAnswer] = useState<ProfileTypeAnswerChoices>('') + const { + profile: { isProfileEcogestureCompleted }, + profileEcogesture, + } = useSelector((state: AppStore) => state.ecolyo) const handlePrevious = useCallback(() => { setPreviousStep(profileType) }, [profileType, setPreviousStep]) @@ -44,8 +50,15 @@ const ProfileTypeFormSingleChoice: React.FC< }, [profileType, setNextStep, answer, answerType.attribute]) useEffect(() => { + // Set answer if profileType is completed if (step < viewedStep || isProfileTypeComplete) { setAnswer(profileType[answerType.attribute]) + return + } + // Set answer if ecogestureProfile is completed + if (isProfileEcogestureCompleted) { + setAnswer(profileEcogesture[answerType.attribute]) + return } }, [step, viewedStep, profileType, answerType, isProfileTypeComplete]) @@ -71,7 +84,7 @@ const ProfileTypeFormSingleChoice: React.FC< > <input type={'radio'} - value={value} + value={value.toString()} name={value.toString()} onChange={() => setAnswer(value)} checked={answer === value ? true : false} @@ -90,7 +103,7 @@ const ProfileTypeFormSingleChoice: React.FC< step={step} handlePrevious={handlePrevious} handleNext={handleNext} - disableNextButton={answer === ''} + disableNextButton={answer === '' || answer === undefined} /> </> ) diff --git a/src/components/ProfileType/ProfileTypeView.tsx b/src/components/ProfileType/ProfileTypeView.tsx index 27c43500d59ef43272afc818a1b48828a8237d6b..aedfcb8ad9d2b8a1674513323c90c022a9ee4c68 100644 --- a/src/components/ProfileType/ProfileTypeView.tsx +++ b/src/components/ProfileType/ProfileTypeView.tsx @@ -80,15 +80,25 @@ const ProfileTypeView: React.FC = () => { setHeaderHeight(height) }, []) + // if ecogesture profile is completed, update default profileType + useEffect(() => { + if (profile.isProfileEcogestureCompleted) { + setProfileType({ + ...profileType, + hotWater: curProfileEcogesture.hotWater, + heating: curProfileEcogesture.heating, + warmingFluid: curProfileEcogesture.warmingFluid, + equipments: curProfileEcogesture.equipments, + }) + } + }, [profile.isProfileEcogestureCompleted]) + const setNextStep = useCallback( (_profileType?: ProfileType) => { let profileTypeFormService: ProfileTypeFormService if (_profileType) { setProfileType(_profileType) profileTypeFormService = new ProfileTypeFormService(_profileType) - curProfileEcogesture.heating = _profileType.heating - curProfileEcogesture.hotWater = _profileType.hotWater - curProfileEcogesture.warmingFluid = _profileType.warmingFluid } else { // if equipments are updated, keep profileType as it is profileTypeFormService = new ProfileTypeFormService({ diff --git a/src/models/index.ts b/src/models/index.ts index 69e5f3bc14850f2b389b87537395b6042eb90aa9..09b065bde0cefccc575de8795af3273f8519c7d9 100644 --- a/src/models/index.ts +++ b/src/models/index.ts @@ -19,6 +19,7 @@ export * from './konnector.model' export * from './modal.model' export * from './partnersInfo.model' export * from './profile.model' +export * from './profileEcogesture.model' export * from './profileType.model' export * from './quiz.model' export * from './relation.model' diff --git a/src/models/profileType.model.ts b/src/models/profileType.model.ts index f1f0b97959607348f2dd977fe8994fe65ad8ce91..adf82054779dd32507d2199170ee09b769a817a0 100644 --- a/src/models/profileType.model.ts +++ b/src/models/profileType.model.ts @@ -14,6 +14,7 @@ import { WarmingType, } from 'enum/profileType.enum' import { DateTime } from 'luxon' +import { ProfileEcogesture } from './profileEcogesture.model' interface ProfileTypeIndexableTypes { [key: string]: @@ -75,6 +76,7 @@ export interface DetailsMonthlyForecast { export type ProfileTypeAnswerChoices = | string + | string[] | number | HousingType | ConstructionYear @@ -86,6 +88,8 @@ export type ProfileTypeAnswerChoices = | HotWaterEquipment | FluidType | DateTime + | EquipmentType[] + | ProfileEcogesture | null export interface ProfileTypeAnswer { type: ProfileTypeFormType