Skip to content
Snippets Groups Projects
Commit 594244db authored by Rémi PAILHAREY's avatar Rémi PAILHAREY :fork_knife_plate:
Browse files

wip: update copy of the state instead of mutating it

parent 13428dff
No related branches found
No related tags found
2 merge requests!911chore(types): fix profileTypes,!906refactor(redux-rtk): profileType
...@@ -141,8 +141,7 @@ const ProfileTypeFormDateSelection: React.FC< ...@@ -141,8 +141,7 @@ const ProfileTypeFormDateSelection: React.FC<
}, [profileType, setPreviousStep]) }, [profileType, setPreviousStep])
const handleNext = useCallback(() => { const handleNext = useCallback(() => {
profileType[answerType.attribute] = answer setNextStep({ ...profileType, [answerType.attribute]: answer })
setNextStep(profileType)
}, [profileType, setNextStep, answer, answerType.attribute]) }, [profileType, setNextStep, answer, answerType.attribute])
function handleSelectMonth(event: any) { function handleSelectMonth(event: any) {
......
...@@ -67,8 +67,10 @@ const ProfileTypeFormMultiChoice: React.FC<ProfileTypeFormMultiChoiceProps> = ({ ...@@ -67,8 +67,10 @@ const ProfileTypeFormMultiChoice: React.FC<ProfileTypeFormMultiChoiceProps> = ({
}, [profileType, setPreviousStep]) }, [profileType, setPreviousStep])
const handleNext = useCallback(() => { const handleNext = useCallback(() => {
profileType[answerType.attribute] = answer as IndividualInsulationWork[] setNextStep({
setNextStep(profileType) ...profileType,
[answerType.attribute]: answer as IndividualInsulationWork[],
})
}, [profileType, setNextStep, answer, answerType.attribute]) }, [profileType, setNextStep, answer, answerType.attribute])
useEffect(() => { useEffect(() => {
......
...@@ -37,8 +37,7 @@ const ProfileTypeFormNumber: React.FC<ProfileTypeFormNumberProps> = ({ ...@@ -37,8 +37,7 @@ const ProfileTypeFormNumber: React.FC<ProfileTypeFormNumberProps> = ({
}, [profileType, setPreviousStep]) }, [profileType, setPreviousStep])
const handleNext = useCallback(() => { const handleNext = useCallback(() => {
profileType[answerType.attribute] = answer setNextStep({ ...profileType, [answerType.attribute]: answer })
setNextStep(profileType)
}, [profileType, setNextStep, answer, answerType.attribute]) }, [profileType, setNextStep, answer, answerType.attribute])
useEffect(() => { useEffect(() => {
......
...@@ -51,8 +51,7 @@ const ProfileTypeFormNumberSelection: React.FC< ...@@ -51,8 +51,7 @@ const ProfileTypeFormNumberSelection: React.FC<
}, [profileType, setPreviousStep]) }, [profileType, setPreviousStep])
const handleNext = useCallback(() => { const handleNext = useCallback(() => {
profileType[answerType.attribute] = answer setNextStep({ ...profileType, [answerType.attribute]: answer })
setNextStep(profileType)
}, [profileType, setNextStep, answer, answerType.attribute]) }, [profileType, setNextStep, answer, answerType.attribute])
useEffect(() => { useEffect(() => {
......
...@@ -40,8 +40,7 @@ const ProfileTypeFormSingleChoice: React.FC< ...@@ -40,8 +40,7 @@ const ProfileTypeFormSingleChoice: React.FC<
}, [profileType, setPreviousStep]) }, [profileType, setPreviousStep])
const handleNext = useCallback(() => { const handleNext = useCallback(() => {
profileType[answerType.attribute] = answer setNextStep({ ...profileType, [answerType.attribute]: answer })
setNextStep(profileType)
}, [profileType, setNextStep, answer, answerType.attribute]) }, [profileType, setNextStep, answer, answerType.attribute])
useEffect(() => { useEffect(() => {
......
...@@ -86,6 +86,7 @@ const ProfileTypeView: React.FC = () => { ...@@ -86,6 +86,7 @@ const ProfileTypeView: React.FC = () => {
if (_profileType) { if (_profileType) {
setProfileType(_profileType) setProfileType(_profileType)
profileTypeFormService = new ProfileTypeFormService(_profileType) profileTypeFormService = new ProfileTypeFormService(_profileType)
console.log(profileTypeFormService)
curProfileEcogesture.heating = _profileType.heating curProfileEcogesture.heating = _profileType.heating
curProfileEcogesture.hotWater = _profileType.hotWater curProfileEcogesture.hotWater = _profileType.hotWater
curProfileEcogesture.warmingFluid = _profileType.warmingFluid curProfileEcogesture.warmingFluid = _profileType.warmingFluid
...@@ -115,17 +116,14 @@ const ProfileTypeView: React.FC = () => { ...@@ -115,17 +116,14 @@ const ProfileTypeView: React.FC = () => {
] ]
) )
const setPreviousStep = useCallback( const setPreviousStep = useCallback(() => {
(_profileType: ProfileType) => { console.log(profileType)
setProfileType(_profileType) const profileTypeFormService = new ProfileTypeFormService(profileType)
const profileTypeFormService = new ProfileTypeFormService(_profileType) const previousStep: ProfileTypeStepForm =
const previousStep: ProfileTypeStepForm = profileTypeFormService.getPreviousFormStep(step)
profileTypeFormService.getPreviousFormStep(step) setIsLoading(true)
setIsLoading(true) setStep(previousStep)
setStep(previousStep) }, [profileType, step])
},
[step]
)
const selectForm = () => { const selectForm = () => {
if (answerType.type === ProfileTypeFormType.SINGLE_CHOICE) { if (answerType.type === ProfileTypeFormType.SINGLE_CHOICE) {
...@@ -201,14 +199,17 @@ const ProfileTypeView: React.FC = () => { ...@@ -201,14 +199,17 @@ const ProfileTypeView: React.FC = () => {
} }
useEffect(() => { useEffect(() => {
if (profile.isProfileTypeCompleted) {
setProfileType(curProfileType)
}
const _answerType: ProfileTypeAnswer = const _answerType: ProfileTypeAnswer =
ProfileTypeFormService.getAnswerForStep(step) ProfileTypeFormService.getAnswerForStep(step)
setAnswerType(_answerType) setAnswerType(_answerType)
setIsLoading(false) setIsLoading(false)
}, [step, profile, curProfileType]) }, [step])
useEffect(() => {
if (profile.isProfileTypeCompleted) {
setProfileType({ ...curProfileType })
}
}, [curProfileType, profile])
return ( return (
<> <>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment