From 9220f9e9e42933f30237ce227622dfdfaa37fb09 Mon Sep 17 00:00:00 2001 From: Djorkaeff Alexandre Date: Fri, 21 Feb 2020 12:53:07 -0300 Subject: [PATCH] [FIX] Redirect user to SetUsernameView (#1728) Co-authored-by: Diego Mello --- app/sagas/init.js | 2 +- app/sagas/login.js | 13 ++++++++----- app/views/RegisterView.js | 12 +++++++----- app/views/SetUsernameView.js | 4 ++-- 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/app/sagas/init.js b/app/sagas/init.js index 80aff1ee2..db31b764c 100644 --- a/app/sagas/init.js +++ b/app/sagas/init.js @@ -118,7 +118,7 @@ const start = function* start({ root }) { if (root === 'inside') { yield Navigation.navigate('InsideStack'); } else if (root === 'setUsername') { - yield Navigation.navigate('SetUsernameView'); + yield Navigation.navigate('SetUsernameStack'); } else if (root === 'outside') { yield Navigation.navigate('OutsideStack'); } else if (root === 'loading') { diff --git a/app/sagas/login.js b/app/sagas/login.js index dff0eed7d..52b413a15 100644 --- a/app/sagas/login.js +++ b/app/sagas/login.js @@ -35,7 +35,13 @@ const handleLoginRequest = function* handleLoginRequest({ credentials, logoutOnE } else { result = yield call(loginWithPasswordCall, credentials); } - return yield put(loginSuccess(result)); + if (!result.username) { + yield put(serverFinishAdd()); + yield put(setUser(result)); + yield put(appStart('setUsername')); + } else { + yield put(loginSuccess(result)); + } } catch (e) { if (logoutOnError && (e.data && e.data.message && /you've been logged out by the server/i.test(e.data.message))) { yield put(logout(true)); @@ -117,9 +123,7 @@ const handleLoginSuccess = function* handleLoginSuccess({ user }) { EventEmitter.emit('connected'); let currentRoot; - if (!user.username) { - yield put(appStart('setUsername')); - } else if (adding) { + if (adding) { yield put(serverFinishAdd()); yield put(appStart('inside')); } else { @@ -193,7 +197,6 @@ const root = function* root() { while (true) { const params = yield take(types.LOGIN.SUCCESS); const loginSuccessTask = yield fork(handleLoginSuccess, params); - // yield take(types.SERVER.SELECT_REQUEST); yield race({ selectRequest: take(types.SERVER.SELECT_REQUEST), timeout: delay(2000) diff --git a/app/views/RegisterView.js b/app/views/RegisterView.js index 964b2e785..b694c600e 100644 --- a/app/views/RegisterView.js +++ b/app/views/RegisterView.js @@ -1,8 +1,6 @@ import React from 'react'; import PropTypes from 'prop-types'; -import { - Keyboard, Text, ScrollView, Alert -} from 'react-native'; +import { Keyboard, Text, ScrollView } from 'react-native'; import { connect } from 'react-redux'; import { SafeAreaView } from 'react-navigation'; import RNPickerSelect from 'react-native-picker-select'; @@ -24,6 +22,7 @@ import { withTheme } from '../theme'; import { themes } from '../constants/colors'; import { themedHeader } from '../utils/navigation'; import { isTablet } from '../utils/deviceInfo'; +import { showErrorAlert } from '../utils/info'; const shouldUpdateState = ['name', 'email', 'password', 'username', 'saving']; @@ -129,12 +128,15 @@ class RegisterView extends React.Component { if (Accounts_EmailVerification) { await navigation.goBack(); - Alert.alert(I18n.t('Verify_email_title'), I18n.t('Verify_email_desc')); + showErrorAlert(I18n.t('Verify_email_desc'), I18n.t('Verify_email_title')); } else { await loginRequest({ user: email, password }); } } catch (e) { - Alert.alert(I18n.t('Oops'), e.data.error); + if (e.data && e.data.errorType === 'username-invalid') { + return loginRequest({ user: email, password }); + } + showErrorAlert(e.data.error, I18n.t('Oops')); } this.setState({ saving: false }); } diff --git a/app/views/SetUsernameView.js b/app/views/SetUsernameView.js index 93d31829f..3881308a7 100644 --- a/app/views/SetUsernameView.js +++ b/app/views/SetUsernameView.js @@ -16,12 +16,12 @@ import scrollPersistTaps from '../utils/scrollPersistTaps'; import I18n from '../i18n'; import RocketChat from '../lib/rocketchat'; import StatusBar from '../containers/StatusBar'; -import log from '../utils/log'; import { themedHeader } from '../utils/navigation'; import { withTheme } from '../theme'; import { themes } from '../constants/colors'; import { isTablet } from '../utils/deviceInfo'; import { getUserSelector } from '../selectors/login'; +import { showErrorAlert } from '../utils/info'; const styles = StyleSheet.create({ loginTitle: { @@ -96,7 +96,7 @@ class SetUsernameView extends React.Component { await RocketChat.setUsername(username); await loginRequest({ resume: token }); } catch (e) { - log(e); + showErrorAlert(e.message, I18n.t('Oops')); } this.setState({ saving: false }); }