diff --git a/src/components/ProfileType/ProfileTypeFormDateSelection.tsx b/src/components/ProfileType/ProfileTypeFormDateSelection.tsx index 025d2993252d4288bc18949b496b082a6db77016..59186b342d46dc8799d83fab1540030926596843 100644 --- a/src/components/ProfileType/ProfileTypeFormDateSelection.tsx +++ b/src/components/ProfileType/ProfileTypeFormDateSelection.tsx @@ -141,8 +141,7 @@ const ProfileTypeFormDateSelection: React.FC< }, [profileType, setPreviousStep]) const handleNext = useCallback(() => { - profileType[answerType.attribute] = answer - setNextStep(profileType) + setNextStep({ ...profileType, [answerType.attribute]: answer }) }, [profileType, setNextStep, answer, answerType.attribute]) function handleSelectMonth(event: any) { diff --git a/src/components/ProfileType/ProfileTypeFormMultiChoice.tsx b/src/components/ProfileType/ProfileTypeFormMultiChoice.tsx index f1210185c28b2880619f23c54be80c1ef5617264..46cec7784e22ae7d7284917d0bc49088137e3914 100644 --- a/src/components/ProfileType/ProfileTypeFormMultiChoice.tsx +++ b/src/components/ProfileType/ProfileTypeFormMultiChoice.tsx @@ -67,8 +67,10 @@ const ProfileTypeFormMultiChoice: React.FC<ProfileTypeFormMultiChoiceProps> = ({ }, [profileType, setPreviousStep]) const handleNext = useCallback(() => { - profileType[answerType.attribute] = answer as IndividualInsulationWork[] - setNextStep(profileType) + setNextStep({ + ...profileType, + [answerType.attribute]: answer as IndividualInsulationWork[], + }) }, [profileType, setNextStep, answer, answerType.attribute]) useEffect(() => { diff --git a/src/components/ProfileType/ProfileTypeFormNumber.tsx b/src/components/ProfileType/ProfileTypeFormNumber.tsx index 66e36f2bbe30b49ace38ddbafbedf5e20b75e2c4..c46ac1924aa835385cdc270112a35c7b8305b79d 100644 --- a/src/components/ProfileType/ProfileTypeFormNumber.tsx +++ b/src/components/ProfileType/ProfileTypeFormNumber.tsx @@ -37,8 +37,7 @@ const ProfileTypeFormNumber: React.FC<ProfileTypeFormNumberProps> = ({ }, [profileType, setPreviousStep]) const handleNext = useCallback(() => { - profileType[answerType.attribute] = answer - setNextStep(profileType) + setNextStep({ ...profileType, [answerType.attribute]: answer }) }, [profileType, setNextStep, answer, answerType.attribute]) useEffect(() => { diff --git a/src/components/ProfileType/ProfileTypeFormNumberSelection.tsx b/src/components/ProfileType/ProfileTypeFormNumberSelection.tsx index 944a82388a0830a1ffb40ae00c6255544e3455e9..d40309fa13cd78ab5b95cb5a6b94498a3b323cb7 100644 --- a/src/components/ProfileType/ProfileTypeFormNumberSelection.tsx +++ b/src/components/ProfileType/ProfileTypeFormNumberSelection.tsx @@ -51,8 +51,7 @@ const ProfileTypeFormNumberSelection: React.FC< }, [profileType, setPreviousStep]) const handleNext = useCallback(() => { - profileType[answerType.attribute] = answer - setNextStep(profileType) + setNextStep({ ...profileType, [answerType.attribute]: answer }) }, [profileType, setNextStep, answer, answerType.attribute]) useEffect(() => { diff --git a/src/components/ProfileType/ProfileTypeFormSingleChoice.tsx b/src/components/ProfileType/ProfileTypeFormSingleChoice.tsx index a4fc88272aa457a315d9bbdcc5b450affbe58552..f0fd6681cd7edd02886f21381b08addf581599ff 100644 --- a/src/components/ProfileType/ProfileTypeFormSingleChoice.tsx +++ b/src/components/ProfileType/ProfileTypeFormSingleChoice.tsx @@ -40,8 +40,7 @@ const ProfileTypeFormSingleChoice: React.FC< }, [profileType, setPreviousStep]) const handleNext = useCallback(() => { - profileType[answerType.attribute] = answer - setNextStep(profileType) + setNextStep({ ...profileType, [answerType.attribute]: answer }) }, [profileType, setNextStep, answer, answerType.attribute]) useEffect(() => { diff --git a/src/components/ProfileType/ProfileTypeView.tsx b/src/components/ProfileType/ProfileTypeView.tsx index 5fb0f3b2f6cec6fada99365f8df9ecee08d8154d..b138a714737fe5024930c8b44d8b5abf51cf2d64 100644 --- a/src/components/ProfileType/ProfileTypeView.tsx +++ b/src/components/ProfileType/ProfileTypeView.tsx @@ -86,6 +86,7 @@ const ProfileTypeView: React.FC = () => { if (_profileType) { setProfileType(_profileType) profileTypeFormService = new ProfileTypeFormService(_profileType) + console.log(profileTypeFormService) curProfileEcogesture.heating = _profileType.heating curProfileEcogesture.hotWater = _profileType.hotWater curProfileEcogesture.warmingFluid = _profileType.warmingFluid @@ -115,17 +116,14 @@ const ProfileTypeView: React.FC = () => { ] ) - const setPreviousStep = useCallback( - (_profileType: ProfileType) => { - setProfileType(_profileType) - const profileTypeFormService = new ProfileTypeFormService(_profileType) - const previousStep: ProfileTypeStepForm = - profileTypeFormService.getPreviousFormStep(step) - setIsLoading(true) - setStep(previousStep) - }, - [step] - ) + const setPreviousStep = useCallback(() => { + console.log(profileType) + const profileTypeFormService = new ProfileTypeFormService(profileType) + const previousStep: ProfileTypeStepForm = + profileTypeFormService.getPreviousFormStep(step) + setIsLoading(true) + setStep(previousStep) + }, [profileType, step]) const selectForm = () => { if (answerType.type === ProfileTypeFormType.SINGLE_CHOICE) { @@ -201,14 +199,17 @@ const ProfileTypeView: React.FC = () => { } useEffect(() => { - if (profile.isProfileTypeCompleted) { - setProfileType(curProfileType) - } const _answerType: ProfileTypeAnswer = ProfileTypeFormService.getAnswerForStep(step) setAnswerType(_answerType) setIsLoading(false) - }, [step, profile, curProfileType]) + }, [step]) + + useEffect(() => { + if (profile.isProfileTypeCompleted) { + setProfileType({ ...curProfileType }) + } + }, [curProfileType, profile]) return ( <>