2018-08-10 17:26:36 +00:00
|
|
|
import React from 'react';
|
2018-09-25 19:28:42 +00:00
|
|
|
import {
|
2018-10-23 21:39:48 +00:00
|
|
|
View, Text, Image, TouchableOpacity
|
2018-09-25 19:28:42 +00:00
|
|
|
} from 'react-native';
|
2018-08-10 17:26:36 +00:00
|
|
|
import PropTypes from 'prop-types';
|
2018-09-19 14:18:32 +00:00
|
|
|
import Icon from 'react-native-vector-icons/MaterialIcons';
|
2018-09-26 13:56:36 +00:00
|
|
|
import { connect, Provider } from 'react-redux';
|
|
|
|
import { Navigation } from 'react-native-navigation';
|
2018-10-23 21:39:48 +00:00
|
|
|
import SafeAreaView from 'react-native-safe-area-view';
|
2018-08-10 17:26:36 +00:00
|
|
|
|
2018-09-19 14:18:32 +00:00
|
|
|
import { selectServerRequest, serverInitAdd, serverFinishAdd } from '../../actions/server';
|
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';
|
|
|
|
import LoggedView from '../View';
|
2018-09-19 14:18:32 +00:00
|
|
|
import DeviceInfo from '../../utils/deviceInfo';
|
2018-09-26 13:56:36 +00:00
|
|
|
import store from '../../lib/createStore';
|
2018-10-23 21:39:48 +00:00
|
|
|
import EventEmitter from '../../utils/events';
|
2018-09-26 13:56:36 +00:00
|
|
|
|
|
|
|
let NewServerView = null;
|
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()),
|
|
|
|
selectServer: server => dispatch(selectServerRequest(server))
|
|
|
|
}))
|
2018-08-10 17:26:36 +00:00
|
|
|
/** @extends React.Component */
|
|
|
|
export default class OnboardingView extends LoggedView {
|
2018-10-23 21:39:48 +00:00
|
|
|
static options() {
|
|
|
|
return {
|
|
|
|
topBar: {
|
|
|
|
visible: false,
|
|
|
|
drawBehind: true
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-08-10 17:26:36 +00:00
|
|
|
static propTypes = {
|
2018-10-23 21:39:48 +00:00
|
|
|
componentId: PropTypes.string,
|
2018-09-19 14:18:32 +00:00
|
|
|
previousServer: PropTypes.string,
|
|
|
|
adding: PropTypes.bool,
|
|
|
|
selectServer: PropTypes.func.isRequired,
|
|
|
|
currentServer: PropTypes.string,
|
|
|
|
initAdd: PropTypes.func,
|
|
|
|
finishAdd: PropTypes.func
|
2018-08-10 17:26:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
constructor(props) {
|
2018-10-23 21:39:48 +00:00
|
|
|
super('OnboardingView', props);
|
2018-08-10 17:26:36 +00:00
|
|
|
}
|
|
|
|
|
2018-09-19 14:18:32 +00:00
|
|
|
componentDidMount() {
|
|
|
|
const { previousServer, initAdd } = this.props;
|
|
|
|
if (previousServer) {
|
|
|
|
initAdd();
|
|
|
|
}
|
2018-10-23 21:39:48 +00:00
|
|
|
EventEmitter.addEventListener('NewServer', this.handleNewServerEvent);
|
2018-09-19 14:18:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
const {
|
|
|
|
selectServer, previousServer, currentServer, adding, finishAdd
|
|
|
|
} = this.props;
|
|
|
|
if (adding) {
|
|
|
|
if (previousServer !== currentServer) {
|
|
|
|
selectServer(previousServer);
|
|
|
|
}
|
|
|
|
finishAdd();
|
|
|
|
}
|
2018-10-23 21:39:48 +00:00
|
|
|
EventEmitter.removeListener('NewServer', this.handleNewServerEvent);
|
2018-09-19 14:18:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
close = () => {
|
2018-10-23 21:39:48 +00:00
|
|
|
const { componentId } = this.props;
|
|
|
|
Navigation.dismissModal(componentId);
|
2018-09-19 14:18:32 +00:00
|
|
|
}
|
|
|
|
|
2018-10-23 21:39:48 +00:00
|
|
|
newServer = (server) => {
|
2018-09-26 13:56:36 +00:00
|
|
|
if (NewServerView == null) {
|
|
|
|
NewServerView = require('../NewServerView').default;
|
2018-10-23 21:39:48 +00:00
|
|
|
Navigation.registerComponentWithRedux('NewServerView', () => NewServerView, Provider, store);
|
2018-09-26 13:56:36 +00:00
|
|
|
}
|
|
|
|
|
2018-10-23 21:39:48 +00:00
|
|
|
const { componentId } = this.props;
|
|
|
|
Navigation.push(componentId, {
|
|
|
|
component: {
|
|
|
|
id: 'NewServerView',
|
|
|
|
name: 'NewServerView',
|
|
|
|
passProps: {
|
|
|
|
server
|
|
|
|
},
|
|
|
|
options: {
|
|
|
|
topBar: {
|
|
|
|
visible: false
|
|
|
|
}
|
|
|
|
}
|
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 = () => {
|
2018-09-25 19:28:42 +00:00
|
|
|
const { previousServer } = this.props;
|
|
|
|
|
|
|
|
if (previousServer) {
|
2018-09-19 14:18:32 +00:00
|
|
|
let top = 15;
|
|
|
|
if (DeviceInfo.getBrand() === 'Apple') {
|
|
|
|
top = DeviceInfo.isNotch() ? 45 : 30;
|
|
|
|
}
|
|
|
|
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
|
|
|
>
|
|
|
|
<Icon
|
|
|
|
name='close'
|
|
|
|
size={30}
|
|
|
|
color='#1D74F5'
|
|
|
|
/>
|
|
|
|
</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' }}>
|
2018-09-19 14:18:32 +00:00
|
|
|
<Image style={styles.onboarding} source={{ uri: 'onboarding' }} />
|
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')}
|
2018-09-19 14:18:32 +00:00
|
|
|
icon={<Image source={{ uri: 'connect_server' }} style={{ width: 30, height: 30 }} />}
|
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-09-19 14:18:32 +00:00
|
|
|
icon={<Image source={{ uri: 'logo_onboarding' }} style={{ width: 32, height: 27 }} />}
|
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')}
|
2018-09-19 14:18:32 +00:00
|
|
|
icon={<Image source={{ uri: 'plus_onboarding' }} style={{ width: 24, height: 24 }} />}
|
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>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|