2018-08-10 17:26:36 +00:00
|
|
|
import React from 'react';
|
2018-09-25 19:28:42 +00:00
|
|
|
import {
|
2018-11-27 19:40:53 +00:00
|
|
|
View, Text, Image, TouchableOpacity, BackHandler
|
2018-09-25 19:28:42 +00:00
|
|
|
} from 'react-native';
|
2018-08-10 17:26:36 +00:00
|
|
|
import PropTypes from 'prop-types';
|
2019-01-31 16:08:38 +00:00
|
|
|
import { connect } from 'react-redux';
|
2019-03-12 16:23:06 +00:00
|
|
|
import { SafeAreaView } from 'react-navigation';
|
|
|
|
import Orientation from 'react-native-orientation-locker';
|
2018-08-10 17:26:36 +00:00
|
|
|
|
2018-09-19 14:18:32 +00:00
|
|
|
import { selectServerRequest, serverInitAdd, serverFinishAdd } from '../../actions/server';
|
2018-11-27 19:40:53 +00:00
|
|
|
import { appStart as appStartAction } from '../../actions';
|
2018-08-10 17:26:36 +00:00
|
|
|
import I18n from '../../i18n';
|
|
|
|
import openLink from '../../utils/openLink';
|
|
|
|
import Button from './Button';
|
|
|
|
import styles from './styles';
|
2019-01-29 19:52:56 +00:00
|
|
|
import { isIOS, isNotch } from '../../utils/deviceInfo';
|
2018-10-23 21:39:48 +00:00
|
|
|
import EventEmitter from '../../utils/events';
|
2019-03-01 16:49:11 +00:00
|
|
|
import { CustomIcon } from '../../lib/Icons';
|
2019-03-12 16:23:06 +00:00
|
|
|
import StatusBar from '../../containers/StatusBar';
|
2019-03-29 19:36:07 +00:00
|
|
|
import { COLOR_PRIMARY, COLOR_WHITE } from '../../constants/colors';
|
2018-08-10 17:26:36 +00:00
|
|
|
|
2018-09-19 14:18:32 +00:00
|
|
|
@connect(state => ({
|
|
|
|
currentServer: state.server.server,
|
|
|
|
adding: state.server.adding
|
|
|
|
}), dispatch => ({
|
|
|
|
initAdd: () => dispatch(serverInitAdd()),
|
|
|
|
finishAdd: () => dispatch(serverFinishAdd()),
|
2018-11-27 19:40:53 +00:00
|
|
|
selectServer: server => dispatch(selectServerRequest(server)),
|
2019-03-12 16:23:06 +00:00
|
|
|
appStart: root => dispatch(appStartAction(root))
|
2018-09-19 14:18:32 +00:00
|
|
|
}))
|
2019-05-28 13:03:08 +00:00
|
|
|
export default class OnboardingView extends React.Component {
|
2019-03-12 16:23:06 +00:00
|
|
|
static navigationOptions = () => ({
|
|
|
|
header: null
|
|
|
|
})
|
2018-10-23 21:39:48 +00:00
|
|
|
|
2018-08-10 17:26:36 +00:00
|
|
|
static propTypes = {
|
2019-03-12 16:23:06 +00:00
|
|
|
navigation: PropTypes.object,
|
2018-09-19 14:18:32 +00:00
|
|
|
adding: PropTypes.bool,
|
|
|
|
selectServer: PropTypes.func.isRequired,
|
|
|
|
currentServer: PropTypes.string,
|
|
|
|
initAdd: PropTypes.func,
|
2018-11-27 19:40:53 +00:00
|
|
|
finishAdd: PropTypes.func,
|
|
|
|
appStart: PropTypes.func
|
2018-08-10 17:26:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
constructor(props) {
|
2019-05-28 13:03:08 +00:00
|
|
|
super(props);
|
2018-11-27 19:40:53 +00:00
|
|
|
BackHandler.addEventListener('hardwareBackPress', this.handleBackPress);
|
2019-03-12 16:23:06 +00:00
|
|
|
this.previousServer = props.navigation.getParam('previousServer');
|
|
|
|
Orientation.lockToPortrait();
|
2018-08-10 17:26:36 +00:00
|
|
|
}
|
|
|
|
|
2018-09-19 14:18:32 +00:00
|
|
|
componentDidMount() {
|
2019-03-12 16:23:06 +00:00
|
|
|
const { initAdd } = this.props;
|
|
|
|
if (this.previousServer) {
|
2018-09-19 14:18:32 +00:00
|
|
|
initAdd();
|
|
|
|
}
|
2018-10-23 21:39:48 +00:00
|
|
|
EventEmitter.addEventListener('NewServer', this.handleNewServerEvent);
|
2018-09-19 14:18:32 +00:00
|
|
|
}
|
|
|
|
|
2018-12-21 10:55:35 +00:00
|
|
|
shouldComponentUpdate() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-09-19 14:18:32 +00:00
|
|
|
componentWillUnmount() {
|
|
|
|
const {
|
2019-03-12 16:23:06 +00:00
|
|
|
selectServer, currentServer, adding, finishAdd
|
2018-09-19 14:18:32 +00:00
|
|
|
} = this.props;
|
|
|
|
if (adding) {
|
2019-03-12 16:23:06 +00:00
|
|
|
if (this.previousServer !== currentServer) {
|
|
|
|
selectServer(this.previousServer);
|
2018-09-19 14:18:32 +00:00
|
|
|
}
|
|
|
|
finishAdd();
|
|
|
|
}
|
2018-10-23 21:39:48 +00:00
|
|
|
EventEmitter.removeListener('NewServer', this.handleNewServerEvent);
|
2018-11-27 19:40:53 +00:00
|
|
|
BackHandler.removeEventListener('hardwareBackPress', this.handleBackPress);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleBackPress = () => {
|
|
|
|
const { appStart } = this.props;
|
|
|
|
appStart('background');
|
|
|
|
return false;
|
2018-09-19 14:18:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
close = () => {
|
2019-03-12 16:23:06 +00:00
|
|
|
const { appStart } = this.props;
|
|
|
|
appStart('inside');
|
2018-09-19 14:18:32 +00:00
|
|
|
}
|
|
|
|
|
2018-10-23 21:39:48 +00:00
|
|
|
newServer = (server) => {
|
2019-03-12 16:23:06 +00:00
|
|
|
const { navigation } = this.props;
|
|
|
|
navigation.navigate('NewServerView', { server });
|
2018-08-10 17:26:36 +00:00
|
|
|
}
|
|
|
|
|
2018-10-23 21:39:48 +00:00
|
|
|
handleNewServerEvent = (event) => {
|
|
|
|
const { server } = event;
|
|
|
|
this.newServer(server);
|
|
|
|
}
|
2018-09-26 13:56:36 +00:00
|
|
|
|
2018-10-23 21:39:48 +00:00
|
|
|
connectServer = () => {
|
|
|
|
this.newServer();
|
|
|
|
}
|
|
|
|
|
|
|
|
joinCommunity = () => {
|
|
|
|
this.newServer('https://open.rocket.chat');
|
2018-08-10 17:26:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
createWorkspace = () => {
|
|
|
|
openLink('https://cloud.rocket.chat/trial');
|
|
|
|
}
|
|
|
|
|
2018-09-19 14:18:32 +00:00
|
|
|
renderClose = () => {
|
2019-03-12 16:23:06 +00:00
|
|
|
if (this.previousServer) {
|
2018-09-19 14:18:32 +00:00
|
|
|
let top = 15;
|
2019-01-29 19:52:56 +00:00
|
|
|
if (isIOS) {
|
|
|
|
top = isNotch ? 45 : 30;
|
2018-09-19 14:18:32 +00:00
|
|
|
}
|
|
|
|
return (
|
|
|
|
<TouchableOpacity
|
|
|
|
style={[styles.closeModal, { top }]}
|
|
|
|
onPress={this.close}
|
2018-09-25 19:28:42 +00:00
|
|
|
testID='onboarding-close'
|
2018-09-19 14:18:32 +00:00
|
|
|
>
|
2019-03-01 16:49:11 +00:00
|
|
|
<CustomIcon
|
|
|
|
name='cross'
|
2018-09-19 14:18:32 +00:00
|
|
|
size={30}
|
2019-03-29 19:36:07 +00:00
|
|
|
color={COLOR_PRIMARY}
|
2018-09-19 14:18:32 +00:00
|
|
|
/>
|
|
|
|
</TouchableOpacity>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2018-08-10 17:26:36 +00:00
|
|
|
render() {
|
|
|
|
return (
|
2018-10-23 21:39:48 +00:00
|
|
|
<SafeAreaView style={styles.container} testID='onboarding-view' forceInset={{ bottom: 'never' }}>
|
2019-03-12 16:23:06 +00:00
|
|
|
<StatusBar light />
|
2018-11-14 21:42:03 +00:00
|
|
|
<Image style={styles.onboarding} source={{ uri: 'onboarding' }} fadeDuration={0} />
|
2018-08-10 17:26:36 +00:00
|
|
|
<Text style={styles.title}>{I18n.t('Welcome_to_RocketChat')}</Text>
|
|
|
|
<Text style={styles.subtitle}>{I18n.t('Open_Source_Communication')}</Text>
|
|
|
|
<View style={styles.buttonsContainer}>
|
|
|
|
<Button
|
|
|
|
type='secondary'
|
|
|
|
title={I18n.t('Connect_to_a_server')}
|
2019-03-29 19:36:07 +00:00
|
|
|
icon={<CustomIcon name='permalink' size={30} color={COLOR_PRIMARY} />}
|
2018-08-10 17:26:36 +00:00
|
|
|
onPress={this.connectServer}
|
|
|
|
testID='connect-server-button'
|
|
|
|
/>
|
|
|
|
<Button
|
|
|
|
type='secondary'
|
|
|
|
title={I18n.t('Join_the_community')}
|
|
|
|
subtitle='open.rocket.chat'
|
2018-11-14 21:42:03 +00:00
|
|
|
icon={<Image source={{ uri: 'logo_onboarding' }} style={{ width: 32, height: 27 }} fadeDuration={0} />}
|
2018-08-10 17:26:36 +00:00
|
|
|
onPress={this.joinCommunity}
|
|
|
|
testID='join-community-button'
|
|
|
|
/>
|
|
|
|
<Button
|
|
|
|
type='primary'
|
|
|
|
title={I18n.t('Create_a_new_workspace')}
|
2019-03-29 19:36:07 +00:00
|
|
|
icon={<CustomIcon name='plus' size={30} color={COLOR_WHITE} />}
|
2018-08-10 17:26:36 +00:00
|
|
|
onPress={this.createWorkspace}
|
|
|
|
testID='create-workspace-button'
|
|
|
|
/>
|
|
|
|
</View>
|
2018-09-19 14:18:32 +00:00
|
|
|
{this.renderClose()}
|
2018-08-10 17:26:36 +00:00
|
|
|
</SafeAreaView>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|