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

made saga open register dialog

This commit is contained in:
Fedor Katurov 2020-08-20 11:18:41 +07:00
parent 837b4ee6f3
commit f1463ed5ea
6 changed files with 19 additions and 13 deletions

View file

@ -28,7 +28,7 @@ const mapDispatchToProps = {
userSetLoginError: ACTIONS.userSetLoginError, userSetLoginError: ACTIONS.userSetLoginError,
authLoginWithSocial: ACTIONS.authLoginWithSocial, authLoginWithSocial: ACTIONS.authLoginWithSocial,
modalShowDialog: MODAL_ACTIONS.modalShowDialog, modalShowDialog: MODAL_ACTIONS.modalShowDialog,
authGotOauthEvent: ACTIONS.authGotOauthEvent, authGotOauthLoginEvent: ACTIONS.authGotOauthLoginEvent,
}; };
type IProps = ReturnType<typeof mapStateToProps> & typeof mapDispatchToProps & IDialogProps & {}; type IProps = ReturnType<typeof mapStateToProps> & typeof mapDispatchToProps & IDialogProps & {};
@ -39,9 +39,8 @@ const LoginDialogUnconnected: FC<IProps> = ({
onRequestClose, onRequestClose,
userSendLoginRequest, userSendLoginRequest,
userSetLoginError, userSetLoginError,
authLoginWithSocial,
modalShowDialog, modalShowDialog,
authGotOauthEvent, authGotOauthLoginEvent,
}) => { }) => {
const [username, setUserName] = useState(''); const [username, setUserName] = useState('');
const [password, setPassword] = useState(''); const [password, setPassword] = useState('');
@ -76,9 +75,9 @@ const LoginDialogUnconnected: FC<IProps> = ({
return; return;
} }
authGotOauthEvent(event.data); authGotOauthLoginEvent(event.data);
}, },
[authGotOauthEvent] [authGotOauthLoginEvent]
); );
useEffect(() => { useEffect(() => {

View file

@ -7,13 +7,14 @@ import { DialogTitle } from '~/components/dialogs/DialogTitle';
import { Group } from '~/components/containers/Group'; import { Group } from '~/components/containers/Group';
import { InputText } from '~/components/input/InputText'; import { InputText } from '~/components/input/InputText';
import styles from './styles.scss'; import styles from './styles.scss';
import { selectAuthRegisterSocial } from '~/redux/auth/selectors';
const mapStateToProps = () => ({}); const mapStateToProps = selectAuthRegisterSocial;
const mapDispatchToProps = {}; const mapDispatchToProps = {};
type Props = ReturnType<typeof mapStateToProps> & typeof mapDispatchToProps & IDialogProps & {}; type Props = ReturnType<typeof mapStateToProps> & typeof mapDispatchToProps & IDialogProps & {};
const LoginSocialRegisterDialogUnconnected: FC<Props> = ({ onRequestClose }) => { const LoginSocialRegisterDialogUnconnected: FC<Props> = ({ onRequestClose, token }) => {
const [username, setUsername] = useState(''); const [username, setUsername] = useState('');
return ( return (
@ -22,6 +23,7 @@ const LoginSocialRegisterDialogUnconnected: FC<Props> = ({ onRequestClose }) =>
<div className={styles.wrap}> <div className={styles.wrap}>
<Group> <Group>
<DialogTitle>Добро пожаловать в семью!</DialogTitle> <DialogTitle>Добро пожаловать в семью!</DialogTitle>
<InputText handler={setUsername} value={token} title="Token" />
<InputText handler={setUsername} value={username} title="Юзернэйм" /> <InputText handler={setUsername} value={username} title="Юзернэйм" />
<InputText handler={setUsername} value={username} title="Пароль" type="password" /> <InputText handler={setUsername} value={username} title="Пароль" type="password" />
</Group> </Group>

View file

@ -134,8 +134,8 @@ export const authLoginWithSocial = (token: string, username?: string, password?:
password, password,
}); });
export const authGotOauthEvent = (event: IOAuthEvent) => ({ export const authGotOauthLoginEvent = (event: IOAuthEvent) => ({
type: AUTH_USER_ACTIONS.GOT_OAUTH_EVENT, type: AUTH_USER_ACTIONS.GOT_OAUTH_LOGIN_EVENT,
event, event,
}); });

View file

@ -31,7 +31,7 @@ export const AUTH_USER_ACTIONS = {
SET_SOCIALS: 'SET_SOCIALS', SET_SOCIALS: 'SET_SOCIALS',
ATTACH_SOCIAL: 'ATTACH_SOCIAL', ATTACH_SOCIAL: 'ATTACH_SOCIAL',
LOGIN_WITH_SOCIAL: 'LOGIN_WITH_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: 'SET_REGISTER_SOCIAL',
SET_REGISTER_SOCIAL_ERRORS: 'SET_REGISTER_SOCIAL_ERRORS', SET_REGISTER_SOCIAL_ERRORS: 'SET_REGISTER_SOCIAL_ERRORS',

View file

@ -4,7 +4,7 @@ import {
authAttachSocial, authAttachSocial,
authDropSocial, authDropSocial,
authGetMessages, authGetMessages,
authGotOauthEvent, authGotOauthLoginEvent,
authLoadProfile, authLoadProfile,
authLoggedIn, authLoggedIn,
authLoginWithSocial, authLoginWithSocial,
@ -15,6 +15,7 @@ import {
authSendMessage, authSendMessage,
authSetLastSeenMessages, authSetLastSeenMessages,
authSetProfile, authSetProfile,
authSetRegisterSocial,
authSetRestore, authSetRestore,
authSetSocials, authSetSocials,
authSetToken, authSetToken,
@ -459,7 +460,9 @@ function* loginWithSocial({ token }: ReturnType<typeof authLoginWithSocial>) {
error, error,
}: Unwrap<ReturnType<typeof apiLoginWithSocial>> = yield call(apiLoginWithSocial, { token }); }: Unwrap<ReturnType<typeof apiLoginWithSocial>> = yield call(apiLoginWithSocial, { token });
// Backend asks us for account registration
if (data?.needs_register) { if (data?.needs_register) {
yield put(authSetRegisterSocial({ token }));
yield put(modalShowDialog(DIALOGS.LOGIN_SOCIAL_REGISTER)); yield put(modalShowDialog(DIALOGS.LOGIN_SOCIAL_REGISTER));
return; return;
} }
@ -479,7 +482,7 @@ function* loginWithSocial({ token }: ReturnType<typeof authLoginWithSocial>) {
} }
} }
function* gotOauthEvent({ event }: ReturnType<typeof authGotOauthEvent>) { function* gotOauthLoginEvent({ event }: ReturnType<typeof authGotOauthLoginEvent>) {
if (!event?.type) return; if (!event?.type) return;
switch (event.type) { switch (event.type) {
@ -493,6 +496,7 @@ function* gotOauthEvent({ event }: ReturnType<typeof authGotOauthEvent>) {
return; return;
} }
} }
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);
@ -513,7 +517,7 @@ function* authSaga() {
yield takeLatest(AUTH_USER_ACTIONS.DROP_SOCIAL, dropSocial); yield takeLatest(AUTH_USER_ACTIONS.DROP_SOCIAL, dropSocial);
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_EVENT, gotOauthEvent); yield takeEvery(AUTH_USER_ACTIONS.GOT_OAUTH_LOGIN_EVENT, gotOauthLoginEvent);
} }
export default authSaga; export default authSaga;

View file

@ -8,3 +8,4 @@ export const selectAuthProfile = (state: IState) => state.auth.profile;
export const selectAuthUser = (state: IState) => state.auth.user; export const selectAuthUser = (state: IState) => state.auth.user;
export const selectAuthUpdates = (state: IState) => state.auth.updates; export const selectAuthUpdates = (state: IState) => state.auth.updates;
export const selectAuthRestore = (state: IState) => state.auth.restore; export const selectAuthRestore = (state: IState) => state.auth.restore;
export const selectAuthRegisterSocial = (state: IState) => state.auth.register_social;