diff --git a/src/containers/dialogs/LoginDialog/index.tsx b/src/containers/dialogs/LoginDialog/index.tsx index 0707d10f..0ed983c7 100644 --- a/src/containers/dialogs/LoginDialog/index.tsx +++ b/src/containers/dialogs/LoginDialog/index.tsx @@ -28,7 +28,7 @@ const mapDispatchToProps = { userSetLoginError: ACTIONS.userSetLoginError, authLoginWithSocial: ACTIONS.authLoginWithSocial, modalShowDialog: MODAL_ACTIONS.modalShowDialog, - authGotOauthEvent: ACTIONS.authGotOauthEvent, + authGotOauthLoginEvent: ACTIONS.authGotOauthLoginEvent, }; type IProps = ReturnType & typeof mapDispatchToProps & IDialogProps & {}; @@ -39,9 +39,8 @@ const LoginDialogUnconnected: FC = ({ onRequestClose, userSendLoginRequest, userSetLoginError, - authLoginWithSocial, modalShowDialog, - authGotOauthEvent, + authGotOauthLoginEvent, }) => { const [username, setUserName] = useState(''); const [password, setPassword] = useState(''); @@ -76,9 +75,9 @@ const LoginDialogUnconnected: FC = ({ return; } - authGotOauthEvent(event.data); + authGotOauthLoginEvent(event.data); }, - [authGotOauthEvent] + [authGotOauthLoginEvent] ); useEffect(() => { diff --git a/src/containers/dialogs/LoginSocialRegisterDialog/index.tsx b/src/containers/dialogs/LoginSocialRegisterDialog/index.tsx index fec9aaee..d24ef5ba 100644 --- a/src/containers/dialogs/LoginSocialRegisterDialog/index.tsx +++ b/src/containers/dialogs/LoginSocialRegisterDialog/index.tsx @@ -7,13 +7,14 @@ import { DialogTitle } from '~/components/dialogs/DialogTitle'; import { Group } from '~/components/containers/Group'; import { InputText } from '~/components/input/InputText'; import styles from './styles.scss'; +import { selectAuthRegisterSocial } from '~/redux/auth/selectors'; -const mapStateToProps = () => ({}); +const mapStateToProps = selectAuthRegisterSocial; const mapDispatchToProps = {}; type Props = ReturnType & typeof mapDispatchToProps & IDialogProps & {}; -const LoginSocialRegisterDialogUnconnected: FC = ({ onRequestClose }) => { +const LoginSocialRegisterDialogUnconnected: FC = ({ onRequestClose, token }) => { const [username, setUsername] = useState(''); return ( @@ -22,6 +23,7 @@ const LoginSocialRegisterDialogUnconnected: FC = ({ onRequestClose }) =>
Добро пожаловать в семью! + diff --git a/src/redux/auth/actions.ts b/src/redux/auth/actions.ts index 975c7b2d..b5301bdf 100644 --- a/src/redux/auth/actions.ts +++ b/src/redux/auth/actions.ts @@ -134,8 +134,8 @@ export const authLoginWithSocial = (token: string, username?: string, password?: password, }); -export const authGotOauthEvent = (event: IOAuthEvent) => ({ - type: AUTH_USER_ACTIONS.GOT_OAUTH_EVENT, +export const authGotOauthLoginEvent = (event: IOAuthEvent) => ({ + type: AUTH_USER_ACTIONS.GOT_OAUTH_LOGIN_EVENT, event, }); diff --git a/src/redux/auth/constants.ts b/src/redux/auth/constants.ts index 99d400ed..65d67476 100644 --- a/src/redux/auth/constants.ts +++ b/src/redux/auth/constants.ts @@ -31,7 +31,7 @@ export const AUTH_USER_ACTIONS = { SET_SOCIALS: 'SET_SOCIALS', ATTACH_SOCIAL: 'ATTACH_SOCIAL', LOGIN_WITH_SOCIAL: 'LOGIN_WITH_SOCIAL', - GOT_OAUTH_EVENT: 'GOT_OAUTH_EVENT', + GOT_OAUTH_LOGIN_EVENT: 'GOT_OAUTH_EVENT', SET_REGISTER_SOCIAL: 'SET_REGISTER_SOCIAL', SET_REGISTER_SOCIAL_ERRORS: 'SET_REGISTER_SOCIAL_ERRORS', diff --git a/src/redux/auth/sagas.ts b/src/redux/auth/sagas.ts index e089698f..114a1fef 100644 --- a/src/redux/auth/sagas.ts +++ b/src/redux/auth/sagas.ts @@ -4,7 +4,7 @@ import { authAttachSocial, authDropSocial, authGetMessages, - authGotOauthEvent, + authGotOauthLoginEvent, authLoadProfile, authLoggedIn, authLoginWithSocial, @@ -15,6 +15,7 @@ import { authSendMessage, authSetLastSeenMessages, authSetProfile, + authSetRegisterSocial, authSetRestore, authSetSocials, authSetToken, @@ -459,7 +460,9 @@ function* loginWithSocial({ token }: ReturnType) { error, }: Unwrap> = yield call(apiLoginWithSocial, { token }); + // Backend asks us for account registration if (data?.needs_register) { + yield put(authSetRegisterSocial({ token })); yield put(modalShowDialog(DIALOGS.LOGIN_SOCIAL_REGISTER)); return; } @@ -479,7 +482,7 @@ function* loginWithSocial({ token }: ReturnType) { } } -function* gotOauthEvent({ event }: ReturnType) { +function* gotOauthLoginEvent({ event }: ReturnType) { if (!event?.type) return; switch (event.type) { @@ -493,6 +496,7 @@ function* gotOauthEvent({ event }: ReturnType) { return; } } + function* authSaga() { yield takeEvery(REHYDRATE, checkUserSaga); yield takeLatest([REHYDRATE, AUTH_USER_ACTIONS.LOGGED_IN], startPollingSaga); @@ -513,7 +517,7 @@ function* authSaga() { yield takeLatest(AUTH_USER_ACTIONS.DROP_SOCIAL, dropSocial); yield takeLatest(AUTH_USER_ACTIONS.ATTACH_SOCIAL, attachSocial); yield takeLatest(AUTH_USER_ACTIONS.LOGIN_WITH_SOCIAL, loginWithSocial); - yield takeEvery(AUTH_USER_ACTIONS.GOT_OAUTH_EVENT, gotOauthEvent); + yield takeEvery(AUTH_USER_ACTIONS.GOT_OAUTH_LOGIN_EVENT, gotOauthLoginEvent); } export default authSaga; diff --git a/src/redux/auth/selectors.ts b/src/redux/auth/selectors.ts index d92ba7f3..f49a5695 100644 --- a/src/redux/auth/selectors.ts +++ b/src/redux/auth/selectors.ts @@ -8,3 +8,4 @@ export const selectAuthProfile = (state: IState) => state.auth.profile; export const selectAuthUser = (state: IState) => state.auth.user; export const selectAuthUpdates = (state: IState) => state.auth.updates; export const selectAuthRestore = (state: IState) => state.auth.restore; +export const selectAuthRegisterSocial = (state: IState) => state.auth.register_social;