Skip to content
Snippets Groups Projects
Commit a370e9ed authored by Bastien DUMONT's avatar Bastien DUMONT :angel:
Browse files

Feat/US769 equipments choice in profile settings

parent ca198d05
No related branches found
No related tags found
2 merge requests!610chore(release): 1.9.3,!600Feat/US769equipements choice big profile
...@@ -11,15 +11,20 @@ import { newProfileEcogestureEntry } from 'store/profileEcogesture/profileEcoges ...@@ -11,15 +11,20 @@ import { newProfileEcogestureEntry } from 'store/profileEcogesture/profileEcoges
import { useDispatch } from 'react-redux' import { useDispatch } from 'react-redux'
import { updateProfile } from 'store/profile/profile.actions' import { updateProfile } from 'store/profile/profile.actions'
import { useHistory } from 'react-router-dom' import { useHistory } from 'react-router-dom'
import { ProfileTypeStepForm } from 'enum/profileType.enum'
interface EcogestureFormEquipmentProps { interface EcogestureFormEquipmentProps {
profileEcogesture: ProfileEcogesture profileEcogesture: ProfileEcogesture
setPreviousStep: Function setPreviousStep: Function
setNextStep?: Function
step: ProfileTypeStepForm | EcogestureStepForm
} }
const EcogestureFormEquipment: React.FC<EcogestureFormEquipmentProps> = ({ const EcogestureFormEquipment: React.FC<EcogestureFormEquipmentProps> = ({
profileEcogesture, profileEcogesture,
setPreviousStep, setPreviousStep,
setNextStep,
step,
}: EcogestureFormEquipmentProps) => { }: EcogestureFormEquipmentProps) => {
const { t } = useI18n() const { t } = useI18n()
const dispatch = useDispatch() const dispatch = useDispatch()
...@@ -30,12 +35,13 @@ const EcogestureFormEquipment: React.FC<EcogestureFormEquipmentProps> = ({ ...@@ -30,12 +35,13 @@ const EcogestureFormEquipment: React.FC<EcogestureFormEquipmentProps> = ({
setPreviousStep(profileEcogesture) setPreviousStep(profileEcogesture)
}, [profileEcogesture, setPreviousStep]) }, [profileEcogesture, setPreviousStep])
const handleFinish = useCallback(() => { const handleNext = useCallback(() => {
profileEcogesture.equipments = answer as EquipmentType[] profileEcogesture.equipments = answer as EquipmentType[]
dispatch(newProfileEcogestureEntry(profileEcogesture)) dispatch(newProfileEcogestureEntry(profileEcogesture))
dispatch(updateProfile({ isProfileEcogestureCompleted: true })) dispatch(updateProfile({ isProfileEcogestureCompleted: true }))
history.push('/ecogesture-selection') // Check if gestureForm is used from Big profile or small profile
}, [profileEcogesture, answer, dispatch, history]) setNextStep ? setNextStep() : history.push('/ecogesture-selection')
}, [profileEcogesture, setNextStep, answer, dispatch, history])
const isChecked = useCallback( const isChecked = useCallback(
(value: string): boolean => { (value: string): boolean => {
...@@ -103,9 +109,9 @@ const EcogestureFormEquipment: React.FC<EcogestureFormEquipmentProps> = ({ ...@@ -103,9 +109,9 @@ const EcogestureFormEquipment: React.FC<EcogestureFormEquipmentProps> = ({
</div> </div>
</div> </div>
<FormNavigation <FormNavigation
step={EcogestureStepForm.EQUIPMENTS} step={step}
handlePrevious={handlePrevious} handlePrevious={handlePrevious}
handleNext={handleFinish} handleNext={handleNext}
disableNextButton={answer === []} disableNextButton={answer === []}
isEcogesture={true} isEcogesture={true}
/> />
......
...@@ -128,6 +128,7 @@ const EcogestureFormView: React.FC = () => { ...@@ -128,6 +128,7 @@ const EcogestureFormView: React.FC = () => {
<Content height={headerHeight}> <Content height={headerHeight}>
{step === EcogestureStepForm.EQUIPMENTS && ( {step === EcogestureStepForm.EQUIPMENTS && (
<EcogestureFormEquipment <EcogestureFormEquipment
step={EcogestureStepForm.EQUIPMENTS}
profileEcogesture={profileEcogesture} profileEcogesture={profileEcogesture}
setPreviousStep={setPreviousStep} setPreviousStep={setPreviousStep}
/> />
......
...@@ -305,7 +305,6 @@ exports[`EcogestureFormEquipment component should be rendered correctly 1`] = ` ...@@ -305,7 +305,6 @@ exports[`EcogestureFormEquipment component should be rendered correctly 1`] = `
handleNext={[Function]} handleNext={[Function]}
handlePrevious={[Function]} handlePrevious={[Function]}
isEcogesture={true} isEcogesture={true}
step={3}
> >
<div <div
className="profile-navigation" className="profile-navigation"
...@@ -448,7 +447,7 @@ exports[`EcogestureFormEquipment component should be rendered correctly 1`] = ` ...@@ -448,7 +447,7 @@ exports[`EcogestureFormEquipment component should be rendered correctly 1`] = `
</ForwardRef(Button)> </ForwardRef(Button)>
</WithStyles(ForwardRef(Button))> </WithStyles(ForwardRef(Button))>
<WithStyles(ForwardRef(Button)) <WithStyles(ForwardRef(Button))
aria-label="profile_type.accessibility.button_end" aria-label="profile_type.accessibility.button_next"
className="profile-navigation-button" className="profile-navigation-button"
classes={ classes={
Object { Object {
...@@ -460,7 +459,7 @@ exports[`EcogestureFormEquipment component should be rendered correctly 1`] = ` ...@@ -460,7 +459,7 @@ exports[`EcogestureFormEquipment component should be rendered correctly 1`] = `
onClick={[Function]} onClick={[Function]}
> >
<ForwardRef(Button) <ForwardRef(Button)
aria-label="profile_type.accessibility.button_end" aria-label="profile_type.accessibility.button_next"
className="profile-navigation-button" className="profile-navigation-button"
classes={ classes={
Object { Object {
...@@ -499,7 +498,7 @@ exports[`EcogestureFormEquipment component should be rendered correctly 1`] = ` ...@@ -499,7 +498,7 @@ exports[`EcogestureFormEquipment component should be rendered correctly 1`] = `
onClick={[Function]} onClick={[Function]}
> >
<WithStyles(ForwardRef(ButtonBase)) <WithStyles(ForwardRef(ButtonBase))
aria-label="profile_type.accessibility.button_end" aria-label="profile_type.accessibility.button_next"
className="MuiButton-root btn-profile-next rounded MuiButton-text profile-navigation-button" className="MuiButton-root btn-profile-next rounded MuiButton-text profile-navigation-button"
component="button" component="button"
disabled={false} disabled={false}
...@@ -509,7 +508,7 @@ exports[`EcogestureFormEquipment component should be rendered correctly 1`] = ` ...@@ -509,7 +508,7 @@ exports[`EcogestureFormEquipment component should be rendered correctly 1`] = `
type="button" type="button"
> >
<ForwardRef(ButtonBase) <ForwardRef(ButtonBase)
aria-label="profile_type.accessibility.button_end" aria-label="profile_type.accessibility.button_next"
className="MuiButton-root btn-profile-next rounded MuiButton-text profile-navigation-button" className="MuiButton-root btn-profile-next rounded MuiButton-text profile-navigation-button"
classes={ classes={
Object { Object {
...@@ -526,7 +525,7 @@ exports[`EcogestureFormEquipment component should be rendered correctly 1`] = ` ...@@ -526,7 +525,7 @@ exports[`EcogestureFormEquipment component should be rendered correctly 1`] = `
type="button" type="button"
> >
<button <button
aria-label="profile_type.accessibility.button_end" aria-label="profile_type.accessibility.button_next"
className="MuiButtonBase-root MuiButton-root btn-profile-next rounded MuiButton-text profile-navigation-button" className="MuiButtonBase-root MuiButton-root btn-profile-next rounded MuiButton-text profile-navigation-button"
disabled={false} disabled={false}
onBlur={[Function]} onBlur={[Function]}
...@@ -547,7 +546,7 @@ exports[`EcogestureFormEquipment component should be rendered correctly 1`] = ` ...@@ -547,7 +546,7 @@ exports[`EcogestureFormEquipment component should be rendered correctly 1`] = `
<span <span
className="MuiButton-label text-16-normal" className="MuiButton-label text-16-normal"
> >
profile_type.form.button_end profile_type.form.button_next &gt;
</span> </span>
<NoSsr> <NoSsr>
<WithStyles(memo) <WithStyles(memo)
......
...@@ -29,12 +29,18 @@ import { AppStore } from 'store' ...@@ -29,12 +29,18 @@ import { AppStore } from 'store'
import { DateTime } from 'luxon' import { DateTime } from 'luxon'
import ProfileTypeFormService from 'services/profileTypeForm.service' import ProfileTypeFormService from 'services/profileTypeForm.service'
import ProfileTypeFormDateSelection from './ProfileTypeFormDateSelection' import ProfileTypeFormDateSelection from './ProfileTypeFormDateSelection'
import EcogestureFormEquipment from 'components/EcogestureForm/EcogestureFormEquipment'
import { ProfileEcogesture } from 'models/profileEcogesture.model'
const ProfileTypeView = () => { const ProfileTypeView = () => {
const profile = useSelector((state: AppStore) => state.ecolyo.profile) const profile = useSelector((state: AppStore) => state.ecolyo.profile)
const curProfileType = useSelector( const curProfileType = useSelector(
(state: AppStore) => state.ecolyo.profileType (state: AppStore) => state.ecolyo.profileType
) )
const curProfileEcogesture: ProfileEcogesture = useSelector(
(state: AppStore) => state.ecolyo.profileEcogesture
)
const [headerHeight, setHeaderHeight] = useState<number>(0) const [headerHeight, setHeaderHeight] = useState<number>(0)
const [profileType, setProfileType] = useState<ProfileType>({ const [profileType, setProfileType] = useState<ProfileType>({
updateDate: DateTime.local() updateDate: DateTime.local()
...@@ -58,6 +64,7 @@ const ProfileTypeView = () => { ...@@ -58,6 +64,7 @@ const ProfileTypeView = () => {
warmingFluid: WarmingType.ELECTRICITY, warmingFluid: WarmingType.ELECTRICITY,
hotWaterFluid: FluidType.ELECTRICITY, hotWaterFluid: FluidType.ELECTRICITY,
cookingFluid: FluidType.ELECTRICITY, cookingFluid: FluidType.ELECTRICITY,
equipments: '',
}) })
const [step, setStep] = useState<ProfileTypeStepForm>( const [step, setStep] = useState<ProfileTypeStepForm>(
ProfileTypeStepForm.HOUSING_TYPE ProfileTypeStepForm.HOUSING_TYPE
...@@ -76,9 +83,17 @@ const ProfileTypeView = () => { ...@@ -76,9 +83,17 @@ const ProfileTypeView = () => {
}, []) }, [])
const setNextStep = useCallback( const setNextStep = useCallback(
(_profileType: ProfileType) => { (_profileType?: ProfileType) => {
setProfileType(_profileType) let profileTypeFormService: ProfileTypeFormService
const profileTypeFormService = new ProfileTypeFormService(_profileType) if (_profileType) {
setProfileType(_profileType)
profileTypeFormService = new ProfileTypeFormService(_profileType)
} else {
// if equipments are updated, keep profileType as it is
profileTypeFormService = new ProfileTypeFormService({
...profileType,
})
}
const nextStep: ProfileTypeStepForm = profileTypeFormService.getNextFormStep( const nextStep: ProfileTypeStepForm = profileTypeFormService.getNextFormStep(
step, step,
!profile.isProfileTypeCompleted !profile.isProfileTypeCompleted
...@@ -89,10 +104,10 @@ const ProfileTypeView = () => { ...@@ -89,10 +104,10 @@ const ProfileTypeView = () => {
} }
setStep(nextStep) setStep(nextStep)
}, },
[profile.isProfileTypeCompleted, step, viewedStep] [profile.isProfileTypeCompleted, profileType, step, viewedStep]
) )
const setPrevioustStep = useCallback( const setPreviousStep = useCallback(
(_profileType: ProfileType) => { (_profileType: ProfileType) => {
setProfileType(_profileType) setProfileType(_profileType)
const profileTypeFormService = new ProfileTypeFormService(_profileType) const profileTypeFormService = new ProfileTypeFormService(_profileType)
...@@ -115,7 +130,7 @@ const ProfileTypeView = () => { ...@@ -115,7 +130,7 @@ const ProfileTypeView = () => {
answerType={answerType} answerType={answerType}
setNextStep={setNextStep} setNextStep={setNextStep}
isProfileTypeComplete={profile.isProfileTypeCompleted} isProfileTypeComplete={profile.isProfileTypeCompleted}
setPrevioustStep={setPrevioustStep} setPrevioustStep={setPreviousStep}
/> />
) )
} else if (answerType.type === ProfileTypeFormType.MULTI_CHOICE) { } else if (answerType.type === ProfileTypeFormType.MULTI_CHOICE) {
...@@ -126,7 +141,7 @@ const ProfileTypeView = () => { ...@@ -126,7 +141,7 @@ const ProfileTypeView = () => {
profileType={profileType} profileType={profileType}
answerType={answerType} answerType={answerType}
setNextStep={setNextStep} setNextStep={setNextStep}
setPrevioustStep={setPrevioustStep} setPrevioustStep={setPreviousStep}
isProfileTypeComplete={profile.isProfileTypeCompleted} isProfileTypeComplete={profile.isProfileTypeCompleted}
/> />
) )
...@@ -139,7 +154,7 @@ const ProfileTypeView = () => { ...@@ -139,7 +154,7 @@ const ProfileTypeView = () => {
answerType={answerType} answerType={answerType}
setNextStep={setNextStep} setNextStep={setNextStep}
isProfileTypeComplete={profile.isProfileTypeCompleted} isProfileTypeComplete={profile.isProfileTypeCompleted}
setPrevioustStep={setPrevioustStep} setPrevioustStep={setPreviousStep}
/> />
) )
} else if (answerType.type === ProfileTypeFormType.NUMBER_SELECTION) { } else if (answerType.type === ProfileTypeFormType.NUMBER_SELECTION) {
...@@ -151,7 +166,7 @@ const ProfileTypeView = () => { ...@@ -151,7 +166,7 @@ const ProfileTypeView = () => {
answerType={answerType} answerType={answerType}
setNextStep={setNextStep} setNextStep={setNextStep}
isProfileTypeComplete={profile.isProfileTypeCompleted} isProfileTypeComplete={profile.isProfileTypeCompleted}
setPrevioustStep={setPrevioustStep} setPrevioustStep={setPreviousStep}
/> />
) )
} else if (answerType.type === ProfileTypeFormType.DATE_SELECTION) { } else if (answerType.type === ProfileTypeFormType.DATE_SELECTION) {
...@@ -163,7 +178,18 @@ const ProfileTypeView = () => { ...@@ -163,7 +178,18 @@ const ProfileTypeView = () => {
answerType={answerType} answerType={answerType}
setNextStep={setNextStep} setNextStep={setNextStep}
isProfileTypeComplete={profile.isProfileTypeCompleted} isProfileTypeComplete={profile.isProfileTypeCompleted}
setPrevioustStep={setPrevioustStep} setPrevioustStep={setPreviousStep}
/>
)
} else if (answerType.type === ProfileTypeFormType.EQUIPMENT_SELECTION) {
return (
<EcogestureFormEquipment
step={step}
// viewedStep={viewedStep}
// answerType={answerType}
profileEcogesture={curProfileEcogesture}
setNextStep={setNextStep}
setPreviousStep={setPreviousStep}
/> />
) )
} }
......
...@@ -73,8 +73,9 @@ export enum ProfileTypeStepForm { ...@@ -73,8 +73,9 @@ export enum ProfileTypeStepForm {
HOT_WATER_FLUID = 13, HOT_WATER_FLUID = 13,
HOT_WATER_EQUIPMENT = 14, HOT_WATER_EQUIPMENT = 14,
COOKING_FLUID = 15, COOKING_FLUID = 15,
UPDATE_DATE = 16, EQUIPMENTS = 16,
END = 17, UPDATE_DATE = 17,
END = 18,
} }
export enum ProfileTypeFormType { export enum ProfileTypeFormType {
...@@ -83,4 +84,5 @@ export enum ProfileTypeFormType { ...@@ -83,4 +84,5 @@ export enum ProfileTypeFormType {
NUMBER_SELECTION = 2, NUMBER_SELECTION = 2,
NUMBER = 3, NUMBER = 3,
DATE_SELECTION = 4, DATE_SELECTION = 4,
EQUIPMENT_SELECTION = 5,
} }
...@@ -48,6 +48,7 @@ export interface ProfileType extends ProfileTypeIndexableTypes { ...@@ -48,6 +48,7 @@ export interface ProfileType extends ProfileTypeIndexableTypes {
hotWaterFluid: FluidType | null hotWaterFluid: FluidType | null
cookingFluid: FluidType cookingFluid: FluidType
updateDate: DateTime updateDate: DateTime
equipments: string
} }
export interface MonthlyForecast { export interface MonthlyForecast {
......
...@@ -331,6 +331,11 @@ describe('ProfileType service', () => { ...@@ -331,6 +331,11 @@ describe('ProfileType service', () => {
ProfileTypeStepForm.COOKING_FLUID, ProfileTypeStepForm.COOKING_FLUID,
false false
) )
expect(nextStep).toEqual(ProfileTypeStepForm.EQUIPMENTS)
nextStep = profileTypeFormService.getNextFormStep(
ProfileTypeStepForm.EQUIPMENTS,
false
)
expect(nextStep).toEqual(ProfileTypeStepForm.UPDATE_DATE) expect(nextStep).toEqual(ProfileTypeStepForm.UPDATE_DATE)
nextStep = profileTypeFormService.getNextFormStep( nextStep = profileTypeFormService.getNextFormStep(
ProfileTypeStepForm.UPDATE_DATE, ProfileTypeStepForm.UPDATE_DATE,
......
import { EquipmentType } from 'enum/ecogesture.enum'
import { FluidType } from 'enum/fluid.enum' import { FluidType } from 'enum/fluid.enum'
import { import {
ConstructionYear, ConstructionYear,
...@@ -72,6 +73,8 @@ export default class ProfileTypeFormService { ...@@ -72,6 +73,8 @@ export default class ProfileTypeFormService {
case ProfileTypeStepForm.HOT_WATER_EQUIPMENT: case ProfileTypeStepForm.HOT_WATER_EQUIPMENT:
return ProfileTypeStepForm.COOKING_FLUID return ProfileTypeStepForm.COOKING_FLUID
case ProfileTypeStepForm.COOKING_FLUID: case ProfileTypeStepForm.COOKING_FLUID:
return ProfileTypeStepForm.EQUIPMENTS
case ProfileTypeStepForm.EQUIPMENTS:
return firstProfileType return firstProfileType
? ProfileTypeStepForm.END ? ProfileTypeStepForm.END
: ProfileTypeStepForm.UPDATE_DATE : ProfileTypeStepForm.UPDATE_DATE
...@@ -129,8 +132,10 @@ export default class ProfileTypeFormService { ...@@ -129,8 +132,10 @@ export default class ProfileTypeFormService {
return this.profileType.hotWater === IndividualOrCollective.INDIVIDUAL return this.profileType.hotWater === IndividualOrCollective.INDIVIDUAL
? ProfileTypeStepForm.HOT_WATER_EQUIPMENT ? ProfileTypeStepForm.HOT_WATER_EQUIPMENT
: ProfileTypeStepForm.HOT_WATER : ProfileTypeStepForm.HOT_WATER
case ProfileTypeStepForm.UPDATE_DATE: case ProfileTypeStepForm.EQUIPMENTS:
return ProfileTypeStepForm.COOKING_FLUID return ProfileTypeStepForm.COOKING_FLUID
case ProfileTypeStepForm.UPDATE_DATE:
return ProfileTypeStepForm.EQUIPMENTS
default: default:
return ProfileTypeStepForm.HOUSING_TYPE return ProfileTypeStepForm.HOUSING_TYPE
} }
...@@ -244,6 +249,12 @@ export default class ProfileTypeFormService { ...@@ -244,6 +249,12 @@ export default class ProfileTypeFormService {
attribute: 'cookingFluid', attribute: 'cookingFluid',
choices: [FluidType.ELECTRICITY, FluidType.GAS], choices: [FluidType.ELECTRICITY, FluidType.GAS],
} }
case ProfileTypeStepForm.EQUIPMENTS:
return {
type: ProfileTypeFormType.EQUIPMENT_SELECTION,
attribute: 'equipments',
choices: Object.keys(EquipmentType),
}
case ProfileTypeStepForm.UPDATE_DATE: case ProfileTypeStepForm.UPDATE_DATE:
return { return {
type: ProfileTypeFormType.DATE_SELECTION, type: ProfileTypeFormType.DATE_SELECTION,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment