From e62a7e84c8fa206750231aa6b1193aed0cec7b8b Mon Sep 17 00:00:00 2001 From: Diego Mello Date: Wed, 1 Apr 2020 12:56:08 -0300 Subject: [PATCH] [FIX] Add server and hide login (#1968) * Navigate to new server workspace from ServerDropdown if there's no token * Hide login button based on login services and Accounts_ShowFormLogin setting * [FIX] Lint Co-authored-by: Djorkaeff Alexandre --- app/lib/rocketchat.js | 7 +++--- app/selectors/login.js | 7 ++++++ app/views/RegisterView.js | 28 ++++++++++++++--------- app/views/RoomsListView/ServerDropdown.js | 19 ++++++++------- app/views/WorkspaceView/index.js | 24 +++++++++++-------- 5 files changed, 52 insertions(+), 33 deletions(-) diff --git a/app/lib/rocketchat.js b/app/lib/rocketchat.js index 66b50b489..164d57306 100644 --- a/app/lib/rocketchat.js +++ b/app/lib/rocketchat.js @@ -965,11 +965,12 @@ const RocketChat = { return ret; }, {}); reduxStore.dispatch(setLoginServices(loginServicesReducer)); + } else { + reduxStore.dispatch(setLoginServices({})); } - return Promise.resolve(loginServices.length); } catch (error) { - console.warn(error); - return Promise.reject(); + console.log(error); + reduxStore.dispatch(setLoginServices({})); } }, _determineAuthType(services) { diff --git a/app/selectors/login.js b/app/selectors/login.js index 6bbba8b9f..773056b4b 100644 --- a/app/selectors/login.js +++ b/app/selectors/login.js @@ -1,8 +1,15 @@ import { createSelector } from 'reselect'; const getUser = state => state.login.user || {}; +const getLoginServices = state => state.login.services || {}; +const getShowFormLoginSetting = state => state.settings.Accounts_ShowFormLogin || false; export const getUserSelector = createSelector( [getUser], user => user ); + +export const getShowLoginButton = createSelector( + [getLoginServices, getShowFormLoginSetting], + (loginServices, showFormLogin) => showFormLogin || Object.values(loginServices).length +); diff --git a/app/views/RegisterView.js b/app/views/RegisterView.js index 2c7209c3c..f4a3840f4 100644 --- a/app/views/RegisterView.js +++ b/app/views/RegisterView.js @@ -22,6 +22,7 @@ import RocketChat from '../lib/rocketchat'; import { loginRequest as loginRequestAction } from '../actions/login'; import openLink from '../utils/openLink'; import LoginServices from '../containers/LoginServices'; +import { getShowLoginButton } from '../selectors/login'; const styles = StyleSheet.create({ title: { @@ -68,7 +69,8 @@ class RegisterView extends React.Component { Accounts_EmailVerification: PropTypes.bool, theme: PropTypes.string, Site_Name: PropTypes.string, - loginRequest: PropTypes.func + loginRequest: PropTypes.func, + showLoginButton: PropTypes.bool } constructor(props) { @@ -217,7 +219,7 @@ class RegisterView extends React.Component { render() { const { saving } = this.state; - const { theme } = this.props; + const { theme, showLoginButton } = this.props; return ( @@ -298,14 +300,17 @@ class RegisterView extends React.Component { - - {I18n.t('Do_you_have_an_account')} - {I18n.t('Login')} - - + {showLoginButton + ? ( + + {I18n.t('Do_you_have_an_account')} + {I18n.t('Login')} + + + ) : null} ); @@ -319,7 +324,8 @@ const mapStateToProps = state => ({ CAS_enabled: state.settings.CAS_enabled, CAS_login_url: state.settings.CAS_login_url, Accounts_CustomFields: state.settings.Accounts_CustomFields, - Accounts_EmailVerification: state.settings.Accounts_EmailVerification + Accounts_EmailVerification: state.settings.Accounts_EmailVerification, + showLoginButton: getShowLoginButton(state) }); const mapDispatchToProps = dispatch => ({ diff --git a/app/views/RoomsListView/ServerDropdown.js b/app/views/RoomsListView/ServerDropdown.js index de295e564..f91c20bd8 100644 --- a/app/views/RoomsListView/ServerDropdown.js +++ b/app/views/RoomsListView/ServerDropdown.js @@ -10,7 +10,6 @@ import RNUserDefaults from 'rn-user-defaults'; import { toggleServerDropdown as toggleServerDropdownAction } from '../../actions/rooms'; import { selectServerRequest as selectServerRequestAction } from '../../actions/server'; -import { appStart as appStartAction } from '../../actions'; import styles from './styles'; import Touch from '../../utils/touch'; import RocketChat from '../../lib/rocketchat'; @@ -35,8 +34,7 @@ class ServerDropdown extends Component { server: PropTypes.string, theme: PropTypes.string, toggleServerDropdown: PropTypes.func, - selectServerRequest: PropTypes.func, - appStart: PropTypes.func + selectServerRequest: PropTypes.func } constructor(props) { @@ -132,7 +130,7 @@ class ServerDropdown extends Component { select = async(server) => { const { - server: currentServer, selectServerRequest, appStart, navigation, split + server: currentServer, selectServerRequest, navigation, split } = this.props; this.close(); @@ -142,10 +140,12 @@ class ServerDropdown extends Component { navigation.navigate('RoomView'); } if (!userId) { - appStart(); - this.newServerTimeout = setTimeout(() => { - EventEmitter.emit('NewServer', { server }); - }, 1000); + setTimeout(() => { + navigation.navigate('NewServerView', { previousServer: currentServer }); + this.newServerTimeout = setTimeout(() => { + EventEmitter.emit('NewServer', { server }); + }, ANIMATION_DURATION); + }, ANIMATION_DURATION); } else { selectServerRequest(server); } @@ -267,8 +267,7 @@ const mapStateToProps = state => ({ const mapDispatchToProps = dispatch => ({ toggleServerDropdown: () => dispatch(toggleServerDropdownAction()), - selectServerRequest: server => dispatch(selectServerRequestAction(server)), - appStart: () => dispatch(appStartAction('outside')) + selectServerRequest: server => dispatch(selectServerRequestAction(server)) }); export default withNavigation(connect(mapStateToProps, mapDispatchToProps)(withTheme(withSplit(ServerDropdown)))); diff --git a/app/views/WorkspaceView/index.js b/app/views/WorkspaceView/index.js index 562b446ae..512ff107c 100644 --- a/app/views/WorkspaceView/index.js +++ b/app/views/WorkspaceView/index.js @@ -11,6 +11,7 @@ import { withTheme } from '../../theme'; import FormContainer, { FormContainerInner } from '../../containers/FormContainer'; import { themedHeader } from '../../utils/navigation'; import ServerAvatar from './ServerAvatar'; +import { getShowLoginButton } from '../../selectors/login'; class WorkspaceView extends React.Component { static navigationOptions = ({ screenProps }) => ({ @@ -26,7 +27,8 @@ class WorkspaceView extends React.Component { server: PropTypes.string, Assets_favicon_512: PropTypes.object, registrationEnabled: PropTypes.bool, - registrationText: PropTypes.string + registrationText: PropTypes.string, + showLoginButton: PropTypes.bool } login = () => { @@ -41,7 +43,7 @@ class WorkspaceView extends React.Component { render() { const { - theme, Site_Name, Site_Url, Assets_favicon_512, server, registrationEnabled, registrationText + theme, Site_Name, Site_Url, Assets_favicon_512, server, registrationEnabled, registrationText, showLoginButton } = this.props; return ( @@ -51,12 +53,15 @@ class WorkspaceView extends React.Component { {Site_Name} {Site_Url} -