mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 04:46:40 +07:00
made saga open register dialog
This commit is contained in:
parent
837b4ee6f3
commit
f1463ed5ea
6 changed files with 19 additions and 13 deletions
|
@ -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 mapStateToProps> & typeof mapDispatchToProps & IDialogProps & {};
|
||||
|
@ -39,9 +39,8 @@ const LoginDialogUnconnected: FC<IProps> = ({
|
|||
onRequestClose,
|
||||
userSendLoginRequest,
|
||||
userSetLoginError,
|
||||
authLoginWithSocial,
|
||||
modalShowDialog,
|
||||
authGotOauthEvent,
|
||||
authGotOauthLoginEvent,
|
||||
}) => {
|
||||
const [username, setUserName] = useState('');
|
||||
const [password, setPassword] = useState('');
|
||||
|
@ -76,9 +75,9 @@ const LoginDialogUnconnected: FC<IProps> = ({
|
|||
return;
|
||||
}
|
||||
|
||||
authGotOauthEvent(event.data);
|
||||
authGotOauthLoginEvent(event.data);
|
||||
},
|
||||
[authGotOauthEvent]
|
||||
[authGotOauthLoginEvent]
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
|
|
|
@ -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 mapStateToProps> & typeof mapDispatchToProps & IDialogProps & {};
|
||||
|
||||
const LoginSocialRegisterDialogUnconnected: FC<Props> = ({ onRequestClose }) => {
|
||||
const LoginSocialRegisterDialogUnconnected: FC<Props> = ({ onRequestClose, token }) => {
|
||||
const [username, setUsername] = useState('');
|
||||
|
||||
return (
|
||||
|
@ -22,6 +23,7 @@ const LoginSocialRegisterDialogUnconnected: FC<Props> = ({ onRequestClose }) =>
|
|||
<div className={styles.wrap}>
|
||||
<Group>
|
||||
<DialogTitle>Добро пожаловать в семью!</DialogTitle>
|
||||
<InputText handler={setUsername} value={token} title="Token" />
|
||||
<InputText handler={setUsername} value={username} title="Юзернэйм" />
|
||||
<InputText handler={setUsername} value={username} title="Пароль" type="password" />
|
||||
</Group>
|
||||
|
|
|
@ -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,
|
||||
});
|
||||
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -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<typeof authLoginWithSocial>) {
|
|||
error,
|
||||
}: Unwrap<ReturnType<typeof apiLoginWithSocial>> = 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<typeof authLoginWithSocial>) {
|
|||
}
|
||||
}
|
||||
|
||||
function* gotOauthEvent({ event }: ReturnType<typeof authGotOauthEvent>) {
|
||||
function* gotOauthLoginEvent({ event }: ReturnType<typeof authGotOauthLoginEvent>) {
|
||||
if (!event?.type) return;
|
||||
|
||||
switch (event.type) {
|
||||
|
@ -493,6 +496,7 @@ function* gotOauthEvent({ event }: ReturnType<typeof authGotOauthEvent>) {
|
|||
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;
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue