mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 21:06:42 +07:00
sending register request
This commit is contained in:
parent
3a11b01c99
commit
9486c5bdf5
5 changed files with 43 additions and 3 deletions
|
@ -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>
|
||||||
);
|
);
|
||||||
|
|
|
@ -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 = {
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue