2020-03-30 19:20:50 +00:00
|
|
|
import React from 'react';
|
2021-10-01 18:12:19 +00:00
|
|
|
import { Text, View } from 'react-native';
|
2021-10-28 17:49:08 +00:00
|
|
|
import { StackNavigationProp, StackNavigationOptions } from '@react-navigation/stack';
|
2020-03-30 19:20:50 +00:00
|
|
|
import { connect } from 'react-redux';
|
2021-12-24 13:12:49 +00:00
|
|
|
import { CompositeNavigationProp } from '@react-navigation/core';
|
2020-03-30 19:20:50 +00:00
|
|
|
|
2021-12-24 13:12:49 +00:00
|
|
|
import { OutsideModalParamList, OutsideParamList } from '../../stacks/types';
|
2020-03-30 19:20:50 +00:00
|
|
|
import I18n from '../../i18n';
|
|
|
|
import Button from '../../containers/Button';
|
2022-04-28 18:44:40 +00:00
|
|
|
import { themes } from '../../lib/constants';
|
|
|
|
import { TSupportedThemes, withTheme } from '../../theme';
|
2020-03-30 19:20:50 +00:00
|
|
|
import FormContainer, { FormContainerInner } from '../../containers/FormContainer';
|
2022-05-30 22:01:25 +00:00
|
|
|
import { IApplicationState } from '../../definitions';
|
|
|
|
import { IAssetsFavicon512 } from '../../definitions/IAssetsFavicon512';
|
2020-04-01 15:56:08 +00:00
|
|
|
import { getShowLoginButton } from '../../selectors/login';
|
2021-10-01 18:12:19 +00:00
|
|
|
import ServerAvatar from './ServerAvatar';
|
|
|
|
import styles from './styles';
|
2020-03-30 19:20:50 +00:00
|
|
|
|
2021-10-28 17:49:08 +00:00
|
|
|
interface IWorkSpaceProp {
|
2021-12-24 13:12:49 +00:00
|
|
|
navigation: CompositeNavigationProp<
|
|
|
|
StackNavigationProp<OutsideParamList, 'WorkspaceView'>,
|
|
|
|
StackNavigationProp<OutsideModalParamList>
|
|
|
|
>;
|
2022-04-28 18:44:40 +00:00
|
|
|
theme: TSupportedThemes;
|
2021-10-28 17:49:08 +00:00
|
|
|
Site_Name: string;
|
|
|
|
Site_Url: string;
|
|
|
|
server: string;
|
2022-05-30 22:01:25 +00:00
|
|
|
Assets_favicon_512: IAssetsFavicon512;
|
2021-10-28 17:49:08 +00:00
|
|
|
registrationForm: string;
|
|
|
|
registrationText: string;
|
|
|
|
showLoginButton: boolean;
|
|
|
|
Accounts_iframe_enabled: boolean;
|
|
|
|
inviteLinkToken: string;
|
|
|
|
}
|
2020-03-30 19:20:50 +00:00
|
|
|
|
2021-10-28 17:49:08 +00:00
|
|
|
class WorkspaceView extends React.Component<IWorkSpaceProp, any> {
|
2022-01-24 20:12:25 +00:00
|
|
|
static navigationOptions = (): StackNavigationOptions => ({
|
2021-10-28 17:49:08 +00:00
|
|
|
title: I18n.t('Your_workspace')
|
2022-01-24 20:12:25 +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-10-01 18:12:19 +00:00
|
|
|
return (
|
|
|
|
!Accounts_iframe_enabled &&
|
|
|
|
(registrationForm === 'Public' || (registrationForm === 'Secret URL' && inviteLinkToken?.length))
|
|
|
|
);
|
2020-03-30 19:20:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
login = () => {
|
2021-10-01 18:12:19 +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-10-01 18:12:19 +00:00
|
|
|
};
|
2020-03-30 19:20:50 +00:00
|
|
|
|
|
|
|
register = () => {
|
|
|
|
const { navigation, Site_Name } = this.props;
|
|
|
|
navigation.navigate('RegisterView', { title: Site_Name });
|
2021-10-01 18:12:19 +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-10-01 18:12:19 +00:00
|
|
|
};
|
2020-06-17 20:12:21 +00:00
|
|
|
|
2020-03-30 19:20:50 +00:00
|
|
|
render() {
|
2021-10-01 18:12:19 +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 (
|
2022-03-29 18:53:27 +00:00
|
|
|
<FormContainer 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-10-01 18:12:19 +00:00
|
|
|
{showLoginButton ? (
|
2022-05-30 22:01:25 +00:00
|
|
|
<Button title={I18n.t('Login')} type='primary' onPress={this.login} testID='workspace-view-login' />
|
2021-10-01 18:12:19 +00:00
|
|
|
) : null}
|
|
|
|
{this.showRegistrationButton ? (
|
|
|
|
<Button
|
|
|
|
title={I18n.t('Create_account')}
|
|
|
|
type='secondary'
|
|
|
|
backgroundColor={themes[theme].chatComponentBackground}
|
|
|
|
onPress={this.register}
|
|
|
|
testID='workspace-view-register'
|
|
|
|
/>
|
|
|
|
) : (
|
|
|
|
this.renderRegisterDisabled()
|
|
|
|
)}
|
2020-03-30 19:20:50 +00:00
|
|
|
</FormContainerInner>
|
|
|
|
</FormContainer>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-30 22:01:25 +00:00
|
|
|
const mapStateToProps = (state: IApplicationState) => ({
|
2020-03-30 19:20:50 +00:00
|
|
|
server: state.server.server,
|
2022-05-30 22:01:25 +00:00
|
|
|
Site_Name: state.settings.Site_Name as string,
|
|
|
|
Site_Url: state.settings.Site_Url as string,
|
|
|
|
Assets_favicon_512: state.settings.Assets_favicon_512 as IAssetsFavicon512,
|
|
|
|
registrationForm: state.settings.Accounts_RegistrationForm as string,
|
|
|
|
registrationText: state.settings.Accounts_RegistrationForm_LinkReplacementText as string,
|
|
|
|
Accounts_iframe_enabled: state.settings.Accounts_iframe_enabled as boolean,
|
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));
|