[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 <djorkaeff.unb@gmail.com>
This commit is contained in:
parent
076e5e87c6
commit
e62a7e84c8
|
@ -965,11 +965,12 @@ const RocketChat = {
|
||||||
return ret;
|
return ret;
|
||||||
}, {});
|
}, {});
|
||||||
reduxStore.dispatch(setLoginServices(loginServicesReducer));
|
reduxStore.dispatch(setLoginServices(loginServicesReducer));
|
||||||
|
} else {
|
||||||
|
reduxStore.dispatch(setLoginServices({}));
|
||||||
}
|
}
|
||||||
return Promise.resolve(loginServices.length);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.warn(error);
|
console.log(error);
|
||||||
return Promise.reject();
|
reduxStore.dispatch(setLoginServices({}));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
_determineAuthType(services) {
|
_determineAuthType(services) {
|
||||||
|
|
|
@ -1,8 +1,15 @@
|
||||||
import { createSelector } from 'reselect';
|
import { createSelector } from 'reselect';
|
||||||
|
|
||||||
const getUser = state => state.login.user || {};
|
const getUser = state => state.login.user || {};
|
||||||
|
const getLoginServices = state => state.login.services || {};
|
||||||
|
const getShowFormLoginSetting = state => state.settings.Accounts_ShowFormLogin || false;
|
||||||
|
|
||||||
export const getUserSelector = createSelector(
|
export const getUserSelector = createSelector(
|
||||||
[getUser],
|
[getUser],
|
||||||
user => user
|
user => user
|
||||||
);
|
);
|
||||||
|
|
||||||
|
export const getShowLoginButton = createSelector(
|
||||||
|
[getLoginServices, getShowFormLoginSetting],
|
||||||
|
(loginServices, showFormLogin) => showFormLogin || Object.values(loginServices).length
|
||||||
|
);
|
||||||
|
|
|
@ -22,6 +22,7 @@ import RocketChat from '../lib/rocketchat';
|
||||||
import { loginRequest as loginRequestAction } from '../actions/login';
|
import { loginRequest as loginRequestAction } from '../actions/login';
|
||||||
import openLink from '../utils/openLink';
|
import openLink from '../utils/openLink';
|
||||||
import LoginServices from '../containers/LoginServices';
|
import LoginServices from '../containers/LoginServices';
|
||||||
|
import { getShowLoginButton } from '../selectors/login';
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
title: {
|
title: {
|
||||||
|
@ -68,7 +69,8 @@ class RegisterView extends React.Component {
|
||||||
Accounts_EmailVerification: PropTypes.bool,
|
Accounts_EmailVerification: PropTypes.bool,
|
||||||
theme: PropTypes.string,
|
theme: PropTypes.string,
|
||||||
Site_Name: PropTypes.string,
|
Site_Name: PropTypes.string,
|
||||||
loginRequest: PropTypes.func
|
loginRequest: PropTypes.func,
|
||||||
|
showLoginButton: PropTypes.bool
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
|
@ -217,7 +219,7 @@ class RegisterView extends React.Component {
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { saving } = this.state;
|
const { saving } = this.state;
|
||||||
const { theme } = this.props;
|
const { theme, showLoginButton } = this.props;
|
||||||
return (
|
return (
|
||||||
<FormContainer theme={theme}>
|
<FormContainer theme={theme}>
|
||||||
<FormContainerInner>
|
<FormContainerInner>
|
||||||
|
@ -298,14 +300,17 @@ class RegisterView extends React.Component {
|
||||||
</Text>
|
</Text>
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
<View style={styles.bottomContainer}>
|
{showLoginButton
|
||||||
<Text style={[styles.bottomContainerText, { color: themes[theme].auxiliaryText }]}>{I18n.t('Do_you_have_an_account')}</Text>
|
? (
|
||||||
<Text
|
<View style={styles.bottomContainer}>
|
||||||
style={[styles.bottomContainerTextBold, { color: themes[theme].actionTintColor }]}
|
<Text style={[styles.bottomContainerText, { color: themes[theme].auxiliaryText }]}>{I18n.t('Do_you_have_an_account')}</Text>
|
||||||
onPress={this.login}
|
<Text
|
||||||
>{I18n.t('Login')}
|
style={[styles.bottomContainerTextBold, { color: themes[theme].actionTintColor }]}
|
||||||
</Text>
|
onPress={this.login}
|
||||||
</View>
|
>{I18n.t('Login')}
|
||||||
|
</Text>
|
||||||
|
</View>
|
||||||
|
) : null}
|
||||||
</FormContainerInner>
|
</FormContainerInner>
|
||||||
</FormContainer>
|
</FormContainer>
|
||||||
);
|
);
|
||||||
|
@ -319,7 +324,8 @@ const mapStateToProps = state => ({
|
||||||
CAS_enabled: state.settings.CAS_enabled,
|
CAS_enabled: state.settings.CAS_enabled,
|
||||||
CAS_login_url: state.settings.CAS_login_url,
|
CAS_login_url: state.settings.CAS_login_url,
|
||||||
Accounts_CustomFields: state.settings.Accounts_CustomFields,
|
Accounts_CustomFields: state.settings.Accounts_CustomFields,
|
||||||
Accounts_EmailVerification: state.settings.Accounts_EmailVerification
|
Accounts_EmailVerification: state.settings.Accounts_EmailVerification,
|
||||||
|
showLoginButton: getShowLoginButton(state)
|
||||||
});
|
});
|
||||||
|
|
||||||
const mapDispatchToProps = dispatch => ({
|
const mapDispatchToProps = dispatch => ({
|
||||||
|
|
|
@ -10,7 +10,6 @@ import RNUserDefaults from 'rn-user-defaults';
|
||||||
|
|
||||||
import { toggleServerDropdown as toggleServerDropdownAction } from '../../actions/rooms';
|
import { toggleServerDropdown as toggleServerDropdownAction } from '../../actions/rooms';
|
||||||
import { selectServerRequest as selectServerRequestAction } from '../../actions/server';
|
import { selectServerRequest as selectServerRequestAction } from '../../actions/server';
|
||||||
import { appStart as appStartAction } from '../../actions';
|
|
||||||
import styles from './styles';
|
import styles from './styles';
|
||||||
import Touch from '../../utils/touch';
|
import Touch from '../../utils/touch';
|
||||||
import RocketChat from '../../lib/rocketchat';
|
import RocketChat from '../../lib/rocketchat';
|
||||||
|
@ -35,8 +34,7 @@ class ServerDropdown extends Component {
|
||||||
server: PropTypes.string,
|
server: PropTypes.string,
|
||||||
theme: PropTypes.string,
|
theme: PropTypes.string,
|
||||||
toggleServerDropdown: PropTypes.func,
|
toggleServerDropdown: PropTypes.func,
|
||||||
selectServerRequest: PropTypes.func,
|
selectServerRequest: PropTypes.func
|
||||||
appStart: PropTypes.func
|
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
|
@ -132,7 +130,7 @@ class ServerDropdown extends Component {
|
||||||
|
|
||||||
select = async(server) => {
|
select = async(server) => {
|
||||||
const {
|
const {
|
||||||
server: currentServer, selectServerRequest, appStart, navigation, split
|
server: currentServer, selectServerRequest, navigation, split
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
this.close();
|
this.close();
|
||||||
|
@ -142,10 +140,12 @@ class ServerDropdown extends Component {
|
||||||
navigation.navigate('RoomView');
|
navigation.navigate('RoomView');
|
||||||
}
|
}
|
||||||
if (!userId) {
|
if (!userId) {
|
||||||
appStart();
|
setTimeout(() => {
|
||||||
this.newServerTimeout = setTimeout(() => {
|
navigation.navigate('NewServerView', { previousServer: currentServer });
|
||||||
EventEmitter.emit('NewServer', { server });
|
this.newServerTimeout = setTimeout(() => {
|
||||||
}, 1000);
|
EventEmitter.emit('NewServer', { server });
|
||||||
|
}, ANIMATION_DURATION);
|
||||||
|
}, ANIMATION_DURATION);
|
||||||
} else {
|
} else {
|
||||||
selectServerRequest(server);
|
selectServerRequest(server);
|
||||||
}
|
}
|
||||||
|
@ -267,8 +267,7 @@ const mapStateToProps = state => ({
|
||||||
|
|
||||||
const mapDispatchToProps = dispatch => ({
|
const mapDispatchToProps = dispatch => ({
|
||||||
toggleServerDropdown: () => dispatch(toggleServerDropdownAction()),
|
toggleServerDropdown: () => dispatch(toggleServerDropdownAction()),
|
||||||
selectServerRequest: server => dispatch(selectServerRequestAction(server)),
|
selectServerRequest: server => dispatch(selectServerRequestAction(server))
|
||||||
appStart: () => dispatch(appStartAction('outside'))
|
|
||||||
});
|
});
|
||||||
|
|
||||||
export default withNavigation(connect(mapStateToProps, mapDispatchToProps)(withTheme(withSplit(ServerDropdown))));
|
export default withNavigation(connect(mapStateToProps, mapDispatchToProps)(withTheme(withSplit(ServerDropdown))));
|
||||||
|
|
|
@ -11,6 +11,7 @@ import { withTheme } from '../../theme';
|
||||||
import FormContainer, { FormContainerInner } from '../../containers/FormContainer';
|
import FormContainer, { FormContainerInner } from '../../containers/FormContainer';
|
||||||
import { themedHeader } from '../../utils/navigation';
|
import { themedHeader } from '../../utils/navigation';
|
||||||
import ServerAvatar from './ServerAvatar';
|
import ServerAvatar from './ServerAvatar';
|
||||||
|
import { getShowLoginButton } from '../../selectors/login';
|
||||||
|
|
||||||
class WorkspaceView extends React.Component {
|
class WorkspaceView extends React.Component {
|
||||||
static navigationOptions = ({ screenProps }) => ({
|
static navigationOptions = ({ screenProps }) => ({
|
||||||
|
@ -26,7 +27,8 @@ class WorkspaceView extends React.Component {
|
||||||
server: PropTypes.string,
|
server: PropTypes.string,
|
||||||
Assets_favicon_512: PropTypes.object,
|
Assets_favicon_512: PropTypes.object,
|
||||||
registrationEnabled: PropTypes.bool,
|
registrationEnabled: PropTypes.bool,
|
||||||
registrationText: PropTypes.string
|
registrationText: PropTypes.string,
|
||||||
|
showLoginButton: PropTypes.bool
|
||||||
}
|
}
|
||||||
|
|
||||||
login = () => {
|
login = () => {
|
||||||
|
@ -41,7 +43,7 @@ class WorkspaceView extends React.Component {
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const {
|
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;
|
} = this.props;
|
||||||
return (
|
return (
|
||||||
<FormContainer theme={theme}>
|
<FormContainer theme={theme}>
|
||||||
|
@ -51,12 +53,15 @@ class WorkspaceView extends React.Component {
|
||||||
<Text style={[styles.serverName, { color: themes[theme].titleText }]}>{Site_Name}</Text>
|
<Text style={[styles.serverName, { color: themes[theme].titleText }]}>{Site_Name}</Text>
|
||||||
<Text style={[styles.serverUrl, { color: themes[theme].auxiliaryText }]}>{Site_Url}</Text>
|
<Text style={[styles.serverUrl, { color: themes[theme].auxiliaryText }]}>{Site_Url}</Text>
|
||||||
</View>
|
</View>
|
||||||
<Button
|
{showLoginButton
|
||||||
title={I18n.t('Login')}
|
? (
|
||||||
type='primary'
|
<Button
|
||||||
onPress={this.login}
|
title={I18n.t('Login')}
|
||||||
theme={theme}
|
type='primary'
|
||||||
/>
|
onPress={this.login}
|
||||||
|
theme={theme}
|
||||||
|
/>
|
||||||
|
) : null}
|
||||||
{
|
{
|
||||||
registrationEnabled ? (
|
registrationEnabled ? (
|
||||||
<Button
|
<Button
|
||||||
|
@ -83,7 +88,8 @@ const mapStateToProps = state => ({
|
||||||
Site_Url: state.settings.Site_Url,
|
Site_Url: state.settings.Site_Url,
|
||||||
Assets_favicon_512: state.settings.Assets_favicon_512,
|
Assets_favicon_512: state.settings.Assets_favicon_512,
|
||||||
registrationEnabled: state.settings.Accounts_RegistrationForm === 'Public',
|
registrationEnabled: state.settings.Accounts_RegistrationForm === 'Public',
|
||||||
registrationText: state.settings.Accounts_RegistrationForm_LinkReplacementText
|
registrationText: state.settings.Accounts_RegistrationForm_LinkReplacementText,
|
||||||
|
showLoginButton: getShowLoginButton(state)
|
||||||
});
|
});
|
||||||
|
|
||||||
export default connect(mapStateToProps)(withTheme(WorkspaceView));
|
export default connect(mapStateToProps)(withTheme(WorkspaceView));
|
||||||
|
|
Loading…
Reference in New Issue