diff --git a/src/auth/AuthContext.ts b/src/auth/AuthContext.ts index 35af7a7..0cf0675 100644 --- a/src/auth/AuthContext.ts +++ b/src/auth/AuthContext.ts @@ -6,7 +6,7 @@ export interface AuthContextValue { user: User.User | null token: AuthToken logout: () => void - signUp: (token: AuthToken, user: User.User, newUser?: IUser) => AuthToken + signUp: (token: AuthToken, user: User.User, newUser?: IUser, isAnonymous?: boolean) => AuthToken } export const AuthContext = createContext({} as AuthContextValue) diff --git a/src/auth/AuthProvider.tsx b/src/auth/AuthProvider.tsx index 9d87b99..946a02d 100644 --- a/src/auth/AuthProvider.tsx +++ b/src/auth/AuthProvider.tsx @@ -11,8 +11,10 @@ export function AuthProvider({ const dispatch = useDispatch(); const token = useSelector(selectors.selectToken); const user = useSelector(selectors.selectUser); + const { gender, partnerGender, birthdate, partnerBirthdate, birthPlace, partnerBirthPlace } = useSelector(selectors.selectQuestionnaire); + const signUp = useCallback( - (token: AuthToken, user: User.User, newUser?: IUser): AuthToken => { + (token: AuthToken, user: User.User, newUser?: IUser, isAnonymous?: boolean): AuthToken => { dispatch(actions.token.update(token)); dispatch(actions.user.update(user)); dispatch(actions.form.addEmail(user.email)); @@ -24,23 +26,23 @@ export function AuthProvider({ ) ); } - if (newUser) { + if (newUser && !isAnonymous) { dispatch(actions.questionnaire.update({ - gender: newUser.profile.gender ?? undefined, - birthPlace: newUser.profile.birthplace?.address ?? undefined, - birthdate: newUser.profile.birthdate ?? undefined, - partnerBirthPlace: newUser.partner?.birthplace?.address ?? undefined, - partnerBirthdate: newUser.partner?.birthdate ?? undefined, - partnerGender: newUser.partner?.gender ?? undefined, + gender: newUser.profile?.gender || gender || undefined, + birthPlace: newUser.profile?.birthplace?.address || birthPlace || undefined, + birthdate: newUser.profile?.birthdate || birthdate || undefined, + partnerBirthPlace: newUser.partner?.birthplace?.address || partnerBirthPlace || undefined, + partnerBirthdate: newUser.partner?.birthdate || partnerBirthdate || undefined, + partnerGender: newUser.partner?.gender || partnerGender || undefined, })) dispatch(actions.user.update({ - username: newUser.profile.name ?? undefined, + username: newUser.profile?.name ?? undefined, })); } return token; }, - [dispatch] + [dispatch, gender, partnerGender, birthdate, partnerBirthdate, birthPlace, partnerBirthPlace] ); const logout = useCallback(() => dispatch(actions.reset()), [dispatch]); const auth = useMemo( diff --git a/src/components/CompatibilityV4/pages/Birthplace/index.tsx b/src/components/CompatibilityV4/pages/Birthplace/index.tsx index 194b38c..86867c2 100644 --- a/src/components/CompatibilityV4/pages/Birthplace/index.tsx +++ b/src/components/CompatibilityV4/pages/Birthplace/index.tsx @@ -31,6 +31,7 @@ function Birthplace() { birthplace, }) ); + dispatch(actions.questionnaire.update({ birthPlace: birthplace })); } setIsValidBirthplace(true); }; diff --git a/src/components/CompatibilityV4/pages/BirthplacePartner/index.tsx b/src/components/CompatibilityV4/pages/BirthplacePartner/index.tsx index 940cc97..1ea6f5e 100644 --- a/src/components/CompatibilityV4/pages/BirthplacePartner/index.tsx +++ b/src/components/CompatibilityV4/pages/BirthplacePartner/index.tsx @@ -33,6 +33,7 @@ function BirthplacePartner() { birthplacePartner, }) ); + dispatch(actions.questionnaire.update({ partnerBirthPlace: birthplace })); } setIsValidBirthplace(true); }; diff --git a/src/components/CompatibilityV4/pages/Birthtime/index.tsx b/src/components/CompatibilityV4/pages/Birthtime/index.tsx index 38bd3f2..e651a03 100644 --- a/src/components/CompatibilityV4/pages/Birthtime/index.tsx +++ b/src/components/CompatibilityV4/pages/Birthtime/index.tsx @@ -22,6 +22,7 @@ function Birthtime() { const handleClick = () => { dispatch(actions.compatibilityV4Answers.update({ birthtime })); + dispatch(actions.questionnaire.update({ birthtime })); navigate(routes.client.compatibilityV4YourAnalysis()); } diff --git a/src/components/CompatibilityV4/pages/WhatAddToAnalysis/index.tsx b/src/components/CompatibilityV4/pages/WhatAddToAnalysis/index.tsx index 925ab52..d1686ff 100644 --- a/src/components/CompatibilityV4/pages/WhatAddToAnalysis/index.tsx +++ b/src/components/CompatibilityV4/pages/WhatAddToAnalysis/index.tsx @@ -4,7 +4,7 @@ import { useTranslations } from "@/hooks/translations"; import { ELocalesPlacement } from "@/locales"; import Answer from "../../components/Answer"; import { IAnswersSessionCompatibilityV4 } from "@/api/resources/Session"; -import { useMemo } from "react"; +import { useEffect, useMemo } from "react"; import { actions, selectors } from "@/store"; import { useDispatch, useSelector } from "react-redux"; import { useSession } from "@/hooks/session/useSession"; @@ -132,6 +132,17 @@ function WhatAddToAnalysis() { [translate, isSingle] ); + + useEffect(() => { + if (!whatAddToAnalysis?.length) return; + const currentAnswers = whatAddToAnalysis.split(",") + .filter(item => item) + .filter(item => answers.some(answer => answer.id === item)); + dispatch(actions.compatibilityV4Answers.update({ + whatAddToAnalysis: currentAnswers.join(","), + })); + }, [whatAddToAnalysis, answers]) + const handleClick = async (id: IAnswersSessionCompatibilityV4["what_add_to_analysis"]) => { if (!whatAddToAnalysis) { dispatch(actions.compatibilityV4Answers.update({ diff --git a/src/hooks/authentication/use-authentication.ts b/src/hooks/authentication/use-authentication.ts index b282ed3..61da1c0 100644 --- a/src/hooks/authentication/use-authentication.ts +++ b/src/hooks/authentication/use-authentication.ts @@ -185,7 +185,7 @@ export const useAuthentication = () => { }) metricService.setUserID(userId); } - signUp(token, user, userMe); + signUp(token, user, userMe, isAnonymous); setToken(token); dispatch(actions.userConfig.setAuthCode(authCode || "")); dispatch(actions.personalVideo.updateStatus({ generatingVideo: generatingVideo || false, videoId: videoId || "" })); @@ -222,7 +222,7 @@ export const useAuthentication = () => { }) metricService.setUserID(userId); } - signUp(token, user, userMe); + signUp(token, user, userMe, true); setToken(token); dispatch(actions.userConfig.setAuthCode(authCode || "")); dispatch(actions.personalVideo.updateStatus({ generatingVideo: generatingVideo || false, videoId: videoId || "" }));