[FIX] Redirect user to SetUsernameView (#1728)

Co-authored-by: Diego Mello <diegolmello@gmail.com>
This commit is contained in:
Djorkaeff Alexandre 2020-02-21 12:53:07 -03:00 committed by GitHub
parent c36a0363fc
commit 9220f9e9e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 13 deletions

View File

@ -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') {

View File

@ -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)

View File

@ -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 });
}

View File

@ -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 });
}