2020-03-30 19:20:50 +00:00
|
|
|
import React from 'react';
|
|
|
|
import { View, Text } from 'react-native';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
|
|
|
|
import I18n from '../../i18n';
|
|
|
|
import Button from '../../containers/Button';
|
|
|
|
import styles from './styles';
|
|
|
|
import { themes } from '../../constants/colors';
|
|
|
|
import { withTheme } from '../../theme';
|
|
|
|
import FormContainer, { FormContainerInner } from '../../containers/FormContainer';
|
|
|
|
import ServerAvatar from './ServerAvatar';
|
2020-04-01 15:56:08 +00:00
|
|
|
import { getShowLoginButton } from '../../selectors/login';
|
2020-03-30 19:20:50 +00:00
|
|
|
|
|
|
|
class WorkspaceView extends React.Component {
|
2020-07-31 18:30:36 +00:00
|
|
|
static navigationOptions = () => ({
|
2020-06-15 14:00:46 +00:00
|
|
|
title: I18n.t('Your_workspace')
|
2020-07-31 18:30:36 +00:00
|
|
|
})
|
2020-03-30 19:20:50 +00:00
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
navigation: PropTypes.object,
|
|
|
|
theme: PropTypes.string,
|
|
|
|
Site_Name: PropTypes.string,
|
|
|
|
Site_Url: PropTypes.string,
|
|
|
|
server: PropTypes.string,
|
|
|
|
Assets_favicon_512: PropTypes.object,
|
2020-06-12 19:12:08 +00:00
|
|
|
registrationForm: PropTypes.string,
|
2020-04-01 15:56:08 +00:00
|
|
|
registrationText: PropTypes.string,
|
2020-06-12 19:12:08 +00:00
|
|
|
showLoginButton: PropTypes.bool,
|
2020-06-17 20:12:21 +00:00
|
|
|
Accounts_iframe_enabled: PropTypes.bool,
|
2020-06-12 19:12:08 +00:00
|
|
|
inviteLinkToken: PropTypes.string
|
|
|
|
}
|
|
|
|
|
|
|
|
get showRegistrationButton() {
|
2020-06-17 20:12:21 +00:00
|
|
|
const { registrationForm, inviteLinkToken, Accounts_iframe_enabled } = this.props;
|
|
|
|
return !Accounts_iframe_enabled && (registrationForm === 'Public' || (registrationForm === 'Secret URL' && inviteLinkToken?.length));
|
2020-03-30 19:20:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
login = () => {
|
2020-06-17 20:12:21 +00:00
|
|
|
const {
|
|
|
|
navigation, server, Site_Name, Accounts_iframe_enabled
|
|
|
|
} = this.props;
|
|
|
|
if (Accounts_iframe_enabled) {
|
|
|
|
navigation.navigate('AuthenticationWebView', { url: server, authType: 'iframe' });
|
|
|
|
return;
|
|
|
|
}
|
2020-03-30 19:20:50 +00:00
|
|
|
navigation.navigate('LoginView', { title: Site_Name });
|
|
|
|
}
|
|
|
|
|
|
|
|
register = () => {
|
|
|
|
const { navigation, Site_Name } = this.props;
|
|
|
|
navigation.navigate('RegisterView', { title: Site_Name });
|
|
|
|
}
|
|
|
|
|
2020-06-17 20:12:21 +00:00
|
|
|
renderRegisterDisabled = () => {
|
|
|
|
const { Accounts_iframe_enabled, registrationText, theme } = this.props;
|
|
|
|
if (Accounts_iframe_enabled) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return <Text style={[styles.registrationText, { color: themes[theme].auxiliaryText }]}>{registrationText}</Text>;
|
|
|
|
}
|
|
|
|
|
2020-03-30 19:20:50 +00:00
|
|
|
render() {
|
|
|
|
const {
|
2020-06-17 20:12:21 +00:00
|
|
|
theme, Site_Name, Site_Url, Assets_favicon_512, server, showLoginButton
|
2020-03-30 19:20:50 +00:00
|
|
|
} = this.props;
|
2020-06-17 20:12:21 +00:00
|
|
|
|
2020-03-30 19:20:50 +00:00
|
|
|
return (
|
2020-05-20 16:33:40 +00:00
|
|
|
<FormContainer theme={theme} testID='workspace-view'>
|
2020-03-30 19:20:50 +00:00
|
|
|
<FormContainerInner>
|
|
|
|
<View style={styles.alignItemsCenter}>
|
|
|
|
<ServerAvatar theme={theme} url={server} image={Assets_favicon_512 && Assets_favicon_512.defaultUrl} />
|
|
|
|
<Text style={[styles.serverName, { color: themes[theme].titleText }]}>{Site_Name}</Text>
|
|
|
|
<Text style={[styles.serverUrl, { color: themes[theme].auxiliaryText }]}>{Site_Url}</Text>
|
|
|
|
</View>
|
2020-04-01 15:56:08 +00:00
|
|
|
{showLoginButton
|
|
|
|
? (
|
|
|
|
<Button
|
|
|
|
title={I18n.t('Login')}
|
|
|
|
type='primary'
|
|
|
|
onPress={this.login}
|
|
|
|
theme={theme}
|
2020-05-20 16:33:40 +00:00
|
|
|
testID='workspace-view-login'
|
2020-04-01 15:56:08 +00:00
|
|
|
/>
|
|
|
|
) : null}
|
2020-03-30 19:20:50 +00:00
|
|
|
{
|
2020-06-12 19:12:08 +00:00
|
|
|
this.showRegistrationButton ? (
|
2020-03-30 19:20:50 +00:00
|
|
|
<Button
|
|
|
|
title={I18n.t('Create_account')}
|
|
|
|
type='secondary'
|
|
|
|
backgroundColor={themes[theme].chatComponentBackground}
|
|
|
|
onPress={this.register}
|
|
|
|
theme={theme}
|
2020-05-20 16:33:40 +00:00
|
|
|
testID='workspace-view-register'
|
2020-03-30 19:20:50 +00:00
|
|
|
/>
|
2020-06-17 20:12:21 +00:00
|
|
|
) : this.renderRegisterDisabled()
|
2020-03-30 19:20:50 +00:00
|
|
|
}
|
|
|
|
</FormContainerInner>
|
|
|
|
</FormContainer>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const mapStateToProps = state => ({
|
|
|
|
server: state.server.server,
|
|
|
|
adding: state.server.adding,
|
|
|
|
Site_Name: state.settings.Site_Name,
|
|
|
|
Site_Url: state.settings.Site_Url,
|
|
|
|
Assets_favicon_512: state.settings.Assets_favicon_512,
|
2020-06-12 19:12:08 +00:00
|
|
|
registrationForm: state.settings.Accounts_RegistrationForm,
|
2020-04-01 15:56:08 +00:00
|
|
|
registrationText: state.settings.Accounts_RegistrationForm_LinkReplacementText,
|
2020-06-17 20:12:21 +00:00
|
|
|
Accounts_iframe_enabled: state.settings.Accounts_iframe_enabled,
|
2020-06-12 19:12:08 +00:00
|
|
|
showLoginButton: getShowLoginButton(state),
|
|
|
|
inviteLinkToken: state.inviteLinks.token
|
2020-03-30 19:20:50 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
export default connect(mapStateToProps)(withTheme(WorkspaceView));
|