1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-25 12:56:41 +07:00

sending register request

This commit is contained in:
Fedor Katurov 2020-08-20 17:04:56 +07:00
parent 3a11b01c99
commit 9486c5bdf5
5 changed files with 43 additions and 3 deletions

View file

@ -1,12 +1,12 @@
import React, { FC } from 'react'; import React, { FC } from 'react';
import { Button } from '~/components/input/Button'; import { Button } from '~/components/input/Button';
import styles from './styles.module.scss'; import styles from './styles.scss';
interface IProps {} interface IProps {}
const LoginSocialRegisterButtons: FC<IProps> = () => ( const LoginSocialRegisterButtons: FC<IProps> = () => (
<div className={styles.wrap}> <div className={styles.wrap}>
<Button stretchy>Зарегистрироваться</Button> <Button>Впустите меня!</Button>
</div> </div>
); );

View file

@ -10,7 +10,7 @@ import styles from './styles.scss';
import { selectAuthRegisterSocial } from '~/redux/auth/selectors'; import { selectAuthRegisterSocial } from '~/redux/auth/selectors';
import * as AUTH_ACTIONS from '~/redux/auth/actions'; import * as AUTH_ACTIONS from '~/redux/auth/actions';
import { useCloseOnEscape } from '~/utils/hooks'; import { useCloseOnEscape } from '~/utils/hooks';
import { LoginSocialRegisterButtons } from '~/containers/dialogs/LogianSocialRegisterButtons'; import { LoginSocialRegisterButtons } from '~/containers/dialogs/LoginSocialRegisterButtons';
const mapStateToProps = selectAuthRegisterSocial; const mapStateToProps = selectAuthRegisterSocial;
const mapDispatchToProps = { const mapDispatchToProps = {

View file

@ -140,6 +140,8 @@ export const apiLoginWithSocial = ({
password?: string; password?: string;
}): Promise<IResultWithStatus<{ }): Promise<IResultWithStatus<{
token: string; token: string;
error: string;
errors: Record<string, string>;
needs_register: boolean; needs_register: boolean;
}>> => }>> =>
api api

View file

@ -13,9 +13,11 @@ import {
authRequestRestoreCode, authRequestRestoreCode,
authRestorePassword, authRestorePassword,
authSendMessage, authSendMessage,
authSendRegisterSocial,
authSetLastSeenMessages, authSetLastSeenMessages,
authSetProfile, authSetProfile,
authSetRegisterSocial, authSetRegisterSocial,
authSetRegisterSocialErrors,
authSetRestore, authSetRestore,
authSetSocials, authSetSocials,
authSetToken, authSetToken,
@ -46,6 +48,7 @@ import { modalSetShown, modalShowDialog } from '~/redux/modal/actions';
import { import {
selectAuth, selectAuth,
selectAuthProfile, selectAuthProfile,
selectAuthRegisterSocial,
selectAuthRestore, selectAuthRestore,
selectAuthUpdates, selectAuthUpdates,
selectAuthUser, selectAuthUser,
@ -497,6 +500,40 @@ function* gotOauthLoginEvent({ event }: ReturnType<typeof authGotOauthLoginEvent
} }
} }
function* authRegisterSocial({ username, password }: ReturnType<typeof authSendRegisterSocial>) {
try {
yield put(authSetRegisterSocial({ error: '' }));
const { token }: Unwrap<ReturnType<typeof selectAuthRegisterSocial>> = yield select(
selectAuthRegisterSocial
);
const {
data,
error,
}: Unwrap<ReturnType<typeof apiLoginWithSocial>> = yield call(apiLoginWithSocial, {
token,
username,
password,
});
if (data?.errors) {
yield put(authSetRegisterSocialErrors(data.errors));
} else if (data?.error) {
throw new Error(error);
}
if (data.token) {
yield put(authSetToken(data.token));
yield call(refreshUser);
yield put(modalSetShown(false));
return;
}
} catch (e) {
yield put(authSetRegisterSocial({ error: e.message }));
}
}
function* authSaga() { function* authSaga() {
yield takeEvery(REHYDRATE, checkUserSaga); yield takeEvery(REHYDRATE, checkUserSaga);
yield takeLatest([REHYDRATE, AUTH_USER_ACTIONS.LOGGED_IN], startPollingSaga); yield takeLatest([REHYDRATE, AUTH_USER_ACTIONS.LOGGED_IN], startPollingSaga);
@ -518,6 +555,7 @@ function* authSaga() {
yield takeLatest(AUTH_USER_ACTIONS.ATTACH_SOCIAL, attachSocial); yield takeLatest(AUTH_USER_ACTIONS.ATTACH_SOCIAL, attachSocial);
yield takeLatest(AUTH_USER_ACTIONS.LOGIN_WITH_SOCIAL, loginWithSocial); yield takeLatest(AUTH_USER_ACTIONS.LOGIN_WITH_SOCIAL, loginWithSocial);
yield takeEvery(AUTH_USER_ACTIONS.GOT_OAUTH_LOGIN_EVENT, gotOauthLoginEvent); yield takeEvery(AUTH_USER_ACTIONS.GOT_OAUTH_LOGIN_EVENT, gotOauthLoginEvent);
yield takeEvery(AUTH_USER_ACTIONS.SEND_REGISTER_SOCIAL, authRegisterSocial);
} }
export default authSaga; export default authSaga;