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';
|
2021-10-05 20:48:04 +00:00
|
|
|
import { StackNavigationProp, StackNavigationOptions } from '@react-navigation/stack';
|
2020-03-30 19:20:50 +00:00
|
|
|
import { connect } from 'react-redux';
|
2021-12-03 19:27:57 +00:00
|
|
|
import { CompositeNavigationProp } from '@react-navigation/core';
|
2020-03-30 19:20:50 +00:00
|
|
|
|
2021-12-03 19:27:57 +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-07 14:10:03 +00:00
|
|
|
import { themes } from '../../lib/constants';
|
2022-04-12 16:27:05 +00:00
|
|
|
import { TSupportedThemes, withTheme } from '../../theme';
|
2020-03-30 19:20:50 +00:00
|
|
|
import FormContainer, { FormContainerInner } from '../../containers/FormContainer';
|
2022-05-03 01:27:33 +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-09-13 20:41:05 +00:00
|
|
|
import ServerAvatar from './ServerAvatar';
|
|
|
|
import styles from './styles';
|
2020-03-30 19:20:50 +00:00
|
|
|
|
2021-10-05 20:48:04 +00:00
|
|
|
interface IWorkSpaceProp {
|
2021-12-03 19:27:57 +00:00
|
|
|
navigation: CompositeNavigationProp<
|
|
|
|
StackNavigationProp<OutsideParamList, 'WorkspaceView'>,
|
|
|
|
StackNavigationProp<OutsideModalParamList>
|
|
|
|
>;
|
2023-05-18 21:09:33 +00:00
|
|
|
theme?: TSupportedThemes;
|
2021-10-05 20:48:04 +00:00
|
|
|
Site_Name: string;
|
|
|
|
Site_Url: string;
|
|
|
|
server: string;
|
2022-05-03 01:27:33 +00:00
|
|
|
Assets_favicon_512: IAssetsFavicon512;
|
2021-10-05 20:48:04 +00:00
|
|
|
registrationForm: string;
|
|
|
|
registrationText: string;
|
|
|
|
showLoginButton: boolean;
|
|
|
|
Accounts_iframe_enabled: boolean;
|
|
|
|
inviteLinkToken: string;
|
|
|
|
}
|
2020-03-30 19:20:50 +00:00
|
|
|
|
2021-10-05 20:48:04 +00:00
|
|
|
class WorkspaceView extends React.Component<IWorkSpaceProp, any> {
|
2022-01-17 16:10:39 +00:00
|
|
|
static navigationOptions = (): StackNavigationOptions => ({
|
2021-10-05 20:48:04 +00:00
|
|
|
title: I18n.t('Your_workspace')
|
2022-01-17 16:10:39 +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;
|
|
|
|
}
|
|
|
|
|
2023-05-18 21:09:33 +00:00
|
|
|
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 (
|
2022-03-25 17:55:20 +00:00
|
|
|
<FormContainer testID='workspace-view'>
|
2020-03-30 19:20:50 +00:00
|
|
|
<FormContainerInner>
|
|
|
|
<View style={styles.alignItemsCenter}>
|
2023-05-18 21:09:33 +00:00
|
|
|
<ServerAvatar theme={theme!} url={server} image={Assets_favicon_512?.url ?? 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>
|
2020-03-30 19:20:50 +00:00
|
|
|
</View>
|
2021-09-13 20:41:05 +00:00
|
|
|
{showLoginButton ? (
|
2022-05-20 16:37:57 +00:00
|
|
|
<Button title={I18n.t('Login')} type='primary' onPress={this.login} testID='workspace-view-login' />
|
2021-09-13 20:41:05 +00:00
|
|
|
) : null}
|
|
|
|
{this.showRegistrationButton ? (
|
|
|
|
<Button
|
|
|
|
title={I18n.t('Create_account')}
|
|
|
|
type='secondary'
|
2023-05-18 21:09:33 +00:00
|
|
|
backgroundColor={themes[theme!].chatComponentBackground}
|
2021-09-13 20:41:05 +00:00
|
|
|
onPress={this.register}
|
|
|
|
testID='workspace-view-register'
|
|
|
|
/>
|
|
|
|
) : (
|
|
|
|
this.renderRegisterDisabled()
|
|
|
|
)}
|
2020-03-30 19:20:50 +00:00
|
|
|
</FormContainerInner>
|
|
|
|
</FormContainer>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-03 01:27:33 +00:00
|
|
|
const mapStateToProps = (state: IApplicationState) => ({
|
2020-03-30 19:20:50 +00:00
|
|
|
server: state.server.server,
|
2022-05-03 01:27:33 +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));
|