2020-03-30 19:20:50 +00:00
|
|
|
import React from 'react';
|
2021-09-13 20:41:05 +00:00
|
|
|
import { Text, View } from 'react-native';
|
2020-03-30 19:20:50 +00:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
|
|
|
|
import I18n from '../../i18n';
|
|
|
|
import Button from '../../containers/Button';
|
|
|
|
import { themes } from '../../constants/colors';
|
|
|
|
import { withTheme } from '../../theme';
|
|
|
|
import FormContainer, { FormContainerInner } from '../../containers/FormContainer';
|
2020-04-01 15:56:08 +00:00
|
|
|
import { getShowLoginButton } from '../../selectors/login';
|
2021-09-13 20:41:05 +00:00
|
|
|
import ServerAvatar from './ServerAvatar';
|
|
|
|
import styles from './styles';
|
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')
|
2021-09-13 20:41:05 +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
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2020-06-12 19:12:08 +00:00
|
|
|
|
|
|
|
get showRegistrationButton() {
|
2020-06-17 20:12:21 +00:00
|
|
|
const { registrationForm, inviteLinkToken, Accounts_iframe_enabled } = this.props;
|
2021-09-13 20:41:05 +00:00
|
|
|
return (
|
|
|
|
!Accounts_iframe_enabled &&
|
|
|
|
(registrationForm === 'Public' || (registrationForm === 'Secret URL' && inviteLinkToken?.length))
|
|
|
|
);
|
2020-03-30 19:20:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
login = () => {
|
2021-09-13 20:41:05 +00:00
|
|
|
const { navigation, server, Site_Name, Accounts_iframe_enabled } = this.props;
|
2020-06-17 20:12:21 +00:00
|
|
|
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 });
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2020-03-30 19:20:50 +00:00
|
|
|
|
|
|
|
register = () => {
|
|
|
|
const { navigation, Site_Name } = this.props;
|
|
|
|
navigation.navigate('RegisterView', { title: Site_Name });
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2020-03-30 19:20:50 +00:00
|
|
|
|
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>;
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2020-06-17 20:12:21 +00:00
|
|
|
|
2020-03-30 19:20:50 +00:00
|
|
|
render() {
|
2021-09-13 20:41:05 +00:00
|
|
|
const { theme, Site_Name, Site_Url, Assets_favicon_512, server, showLoginButton } = 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}>
|
2020-08-05 16:46:42 +00:00
|
|
|
<ServerAvatar theme={theme} url={server} image={Assets_favicon_512?.url ?? Assets_favicon_512?.defaultUrl} />
|
2020-03-30 19:20:50 +00:00
|
|
|
<Text style={[styles.serverName, { color: themes[theme].titleText }]}>{Site_Name}</Text>
|
|
|
|
<Text style={[styles.serverUrl, { color: themes[theme].auxiliaryText }]}>{Site_Url}</Text>
|
|
|
|
</View>
|
2021-09-13 20:41:05 +00:00
|
|
|
{showLoginButton ? (
|
|
|
|
<Button title={I18n.t('Login')} type='primary' onPress={this.login} theme={theme} testID='workspace-view-login' />
|
|
|
|
) : null}
|
|
|
|
{this.showRegistrationButton ? (
|
|
|
|
<Button
|
|
|
|
title={I18n.t('Create_account')}
|
|
|
|
type='secondary'
|
|
|
|
backgroundColor={themes[theme].chatComponentBackground}
|
|
|
|
onPress={this.register}
|
|
|
|
theme={theme}
|
|
|
|
testID='workspace-view-register'
|
|
|
|
/>
|
|
|
|
) : (
|
|
|
|
this.renderRegisterDisabled()
|
|
|
|
)}
|
2020-03-30 19:20:50 +00:00
|
|
|
</FormContainerInner>
|
|
|
|
</FormContainer>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const mapStateToProps = state => ({
|
|
|
|
server: state.server.server,
|
|
|
|
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));
|