This commit is contained in:
Daniil Chemerkin 2025-05-07 08:20:25 +00:00
parent 8e5f3edcac
commit cb147393ad
7 changed files with 30 additions and 14 deletions

View File

@ -6,7 +6,7 @@ export interface AuthContextValue {
user: User.User | null user: User.User | null
token: AuthToken token: AuthToken
logout: () => void 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<AuthContextValue>({} as AuthContextValue) export const AuthContext = createContext<AuthContextValue>({} as AuthContextValue)

View File

@ -11,8 +11,10 @@ export function AuthProvider({
const dispatch = useDispatch(); const dispatch = useDispatch();
const token = useSelector(selectors.selectToken); const token = useSelector(selectors.selectToken);
const user = useSelector(selectors.selectUser); const user = useSelector(selectors.selectUser);
const { gender, partnerGender, birthdate, partnerBirthdate, birthPlace, partnerBirthPlace } = useSelector(selectors.selectQuestionnaire);
const signUp = useCallback( 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.token.update(token));
dispatch(actions.user.update(user)); dispatch(actions.user.update(user));
dispatch(actions.form.addEmail(user.email)); dispatch(actions.form.addEmail(user.email));
@ -24,23 +26,23 @@ export function AuthProvider({
) )
); );
} }
if (newUser) { if (newUser && !isAnonymous) {
dispatch(actions.questionnaire.update({ dispatch(actions.questionnaire.update({
gender: newUser.profile.gender ?? undefined, gender: newUser.profile?.gender || gender || undefined,
birthPlace: newUser.profile.birthplace?.address ?? undefined, birthPlace: newUser.profile?.birthplace?.address || birthPlace || undefined,
birthdate: newUser.profile.birthdate ?? undefined, birthdate: newUser.profile?.birthdate || birthdate || undefined,
partnerBirthPlace: newUser.partner?.birthplace?.address ?? undefined, partnerBirthPlace: newUser.partner?.birthplace?.address || partnerBirthPlace || undefined,
partnerBirthdate: newUser.partner?.birthdate ?? undefined, partnerBirthdate: newUser.partner?.birthdate || partnerBirthdate || undefined,
partnerGender: newUser.partner?.gender ?? undefined, partnerGender: newUser.partner?.gender || partnerGender || undefined,
})) }))
dispatch(actions.user.update({ dispatch(actions.user.update({
username: newUser.profile.name ?? undefined, username: newUser.profile?.name ?? undefined,
})); }));
} }
return token; return token;
}, },
[dispatch] [dispatch, gender, partnerGender, birthdate, partnerBirthdate, birthPlace, partnerBirthPlace]
); );
const logout = useCallback(() => dispatch(actions.reset()), [dispatch]); const logout = useCallback(() => dispatch(actions.reset()), [dispatch]);
const auth = useMemo( const auth = useMemo(

View File

@ -31,6 +31,7 @@ function Birthplace() {
birthplace, birthplace,
}) })
); );
dispatch(actions.questionnaire.update({ birthPlace: birthplace }));
} }
setIsValidBirthplace(true); setIsValidBirthplace(true);
}; };

View File

@ -33,6 +33,7 @@ function BirthplacePartner() {
birthplacePartner, birthplacePartner,
}) })
); );
dispatch(actions.questionnaire.update({ partnerBirthPlace: birthplace }));
} }
setIsValidBirthplace(true); setIsValidBirthplace(true);
}; };

View File

@ -22,6 +22,7 @@ function Birthtime() {
const handleClick = () => { const handleClick = () => {
dispatch(actions.compatibilityV4Answers.update({ birthtime })); dispatch(actions.compatibilityV4Answers.update({ birthtime }));
dispatch(actions.questionnaire.update({ birthtime }));
navigate(routes.client.compatibilityV4YourAnalysis()); navigate(routes.client.compatibilityV4YourAnalysis());
} }

View File

@ -4,7 +4,7 @@ import { useTranslations } from "@/hooks/translations";
import { ELocalesPlacement } from "@/locales"; import { ELocalesPlacement } from "@/locales";
import Answer from "../../components/Answer"; import Answer from "../../components/Answer";
import { IAnswersSessionCompatibilityV4 } from "@/api/resources/Session"; import { IAnswersSessionCompatibilityV4 } from "@/api/resources/Session";
import { useMemo } from "react"; import { useEffect, useMemo } from "react";
import { actions, selectors } from "@/store"; import { actions, selectors } from "@/store";
import { useDispatch, useSelector } from "react-redux"; import { useDispatch, useSelector } from "react-redux";
import { useSession } from "@/hooks/session/useSession"; import { useSession } from "@/hooks/session/useSession";
@ -132,6 +132,17 @@ function WhatAddToAnalysis() {
[translate, isSingle] [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"]) => { const handleClick = async (id: IAnswersSessionCompatibilityV4["what_add_to_analysis"]) => {
if (!whatAddToAnalysis) { if (!whatAddToAnalysis) {
dispatch(actions.compatibilityV4Answers.update({ dispatch(actions.compatibilityV4Answers.update({

View File

@ -185,7 +185,7 @@ export const useAuthentication = () => {
}) })
metricService.setUserID(userId); metricService.setUserID(userId);
} }
signUp(token, user, userMe); signUp(token, user, userMe, isAnonymous);
setToken(token); setToken(token);
dispatch(actions.userConfig.setAuthCode(authCode || "")); dispatch(actions.userConfig.setAuthCode(authCode || ""));
dispatch(actions.personalVideo.updateStatus({ generatingVideo: generatingVideo || false, videoId: videoId || "" })); dispatch(actions.personalVideo.updateStatus({ generatingVideo: generatingVideo || false, videoId: videoId || "" }));
@ -222,7 +222,7 @@ export const useAuthentication = () => {
}) })
metricService.setUserID(userId); metricService.setUserID(userId);
} }
signUp(token, user, userMe); signUp(token, user, userMe, true);
setToken(token); setToken(token);
dispatch(actions.userConfig.setAuthCode(authCode || "")); dispatch(actions.userConfig.setAuthCode(authCode || ""));
dispatch(actions.personalVideo.updateStatus({ generatingVideo: generatingVideo || false, videoId: videoId || "" })); dispatch(actions.personalVideo.updateStatus({ generatingVideo: generatingVideo || false, videoId: videoId || "" }));