2020-09-11 17:10:16 +00:00
|
|
|
import { Q } from '@nozbe/watermelondb';
|
2022-01-17 21:27:28 +00:00
|
|
|
import { Base64 } from 'js-base64';
|
|
|
|
import React from 'react';
|
|
|
|
import { BackHandler, Image, Keyboard, StyleSheet, Text, View } from 'react-native';
|
2020-09-11 17:10:16 +00:00
|
|
|
import { TouchableOpacity } from 'react-native-gesture-handler';
|
2021-09-23 14:17:53 +00:00
|
|
|
import Orientation from 'react-native-orientation-locker';
|
2022-01-17 21:27:28 +00:00
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import parse from 'url-parse';
|
2021-09-13 20:41:05 +00:00
|
|
|
|
2022-01-17 21:27:28 +00:00
|
|
|
import { inviteLinksClear } from '../../actions/inviteLinks';
|
|
|
|
import { selectServerRequest, serverFinishAdd, serverRequest } from '../../actions/server';
|
2022-04-28 20:37:25 +00:00
|
|
|
import { CERTIFICATE_KEY, themes } from '../../lib/constants';
|
2020-09-11 17:10:16 +00:00
|
|
|
import Button from '../../containers/Button';
|
|
|
|
import FormContainer, { FormContainerInner } from '../../containers/FormContainer';
|
2020-10-30 16:15:58 +00:00
|
|
|
import * as HeaderButton from '../../containers/HeaderButton';
|
2022-01-17 21:27:28 +00:00
|
|
|
import OrSeparator from '../../containers/OrSeparator';
|
2022-05-03 15:48:02 +00:00
|
|
|
import { IApplicationState, IBaseScreen, TServerHistoryModel } from '../../definitions';
|
2022-01-17 21:27:28 +00:00
|
|
|
import { withDimensions } from '../../dimensions';
|
|
|
|
import I18n from '../../i18n';
|
2020-09-11 17:10:16 +00:00
|
|
|
import database from '../../lib/database';
|
2020-09-15 13:01:43 +00:00
|
|
|
import { sanitizeLikeString } from '../../lib/database/utils';
|
2022-04-07 13:13:19 +00:00
|
|
|
import UserPreferences from '../../lib/methods/userPreferences';
|
2022-01-17 21:27:28 +00:00
|
|
|
import { OutsideParamList } from '../../stacks/types';
|
|
|
|
import { withTheme } from '../../theme';
|
2022-06-06 14:17:51 +00:00
|
|
|
import { isTablet } from '../../lib/methods/helpers';
|
|
|
|
import EventEmitter from '../../lib/methods/helpers/events';
|
|
|
|
import { BASIC_AUTH_KEY, setBasicAuth } from '../../lib/methods/helpers/fetch';
|
|
|
|
import { showConfirmationAlert } from '../../lib/methods/helpers/info';
|
|
|
|
import { events, logEvent } from '../../lib/methods/helpers/log';
|
|
|
|
import { moderateScale, verticalScale } from './scaling';
|
2023-03-15 18:38:45 +00:00
|
|
|
// import SSLPinning from '../../lib/methods/helpers/sslPinning';
|
2022-01-17 21:27:28 +00:00
|
|
|
import sharedStyles from '../Styles';
|
2021-09-13 20:41:05 +00:00
|
|
|
import ServerInput from './ServerInput';
|
2022-07-28 13:36:40 +00:00
|
|
|
import { serializeAsciiUrl } from '../../lib/methods';
|
2018-08-10 17:26:36 +00:00
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
2021-09-23 14:17:53 +00:00
|
|
|
onboardingImage: {
|
|
|
|
alignSelf: 'center',
|
|
|
|
resizeMode: 'contain'
|
|
|
|
},
|
2018-08-10 17:26:36 +00:00
|
|
|
title: {
|
2018-11-14 21:42:03 +00:00
|
|
|
...sharedStyles.textBold,
|
2021-09-23 14:17:53 +00:00
|
|
|
letterSpacing: 0,
|
|
|
|
alignSelf: 'center'
|
|
|
|
},
|
|
|
|
subtitle: {
|
|
|
|
...sharedStyles.textRegular,
|
|
|
|
alignSelf: 'center'
|
2018-08-10 17:26:36 +00:00
|
|
|
},
|
2019-09-02 16:19:05 +00:00
|
|
|
certificatePicker: {
|
|
|
|
alignItems: 'center',
|
2020-03-30 19:20:50 +00:00
|
|
|
justifyContent: 'flex-end'
|
2019-09-02 16:19:05 +00:00
|
|
|
},
|
|
|
|
chooseCertificateTitle: {
|
2019-12-04 16:39:53 +00:00
|
|
|
...sharedStyles.textRegular
|
2019-09-02 16:19:05 +00:00
|
|
|
},
|
|
|
|
chooseCertificate: {
|
2019-12-04 16:39:53 +00:00
|
|
|
...sharedStyles.textSemibold
|
2020-03-30 19:20:50 +00:00
|
|
|
},
|
|
|
|
description: {
|
|
|
|
...sharedStyles.textRegular,
|
2021-09-23 14:17:53 +00:00
|
|
|
textAlign: 'center'
|
2020-03-30 19:20:50 +00:00
|
|
|
},
|
|
|
|
connectButton: {
|
|
|
|
marginBottom: 0
|
2018-08-10 17:26:36 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-01-17 21:27:28 +00:00
|
|
|
interface INewServerViewProps extends IBaseScreen<OutsideParamList, 'NewServerView'> {
|
2021-10-20 18:04:15 +00:00
|
|
|
connecting: boolean;
|
2022-05-03 15:48:02 +00:00
|
|
|
previousServer: string | null;
|
2021-10-20 18:04:15 +00:00
|
|
|
width: number;
|
|
|
|
height: number;
|
|
|
|
}
|
|
|
|
|
2022-01-17 21:27:28 +00:00
|
|
|
interface INewServerViewState {
|
2021-10-20 18:04:15 +00:00
|
|
|
text: string;
|
|
|
|
connectingOpen: boolean;
|
2022-05-03 15:48:02 +00:00
|
|
|
certificate: string | null;
|
2022-02-01 13:39:09 +00:00
|
|
|
serversHistory: TServerHistoryModel[];
|
2021-10-20 18:04:15 +00:00
|
|
|
}
|
2017-08-05 18:16:32 +00:00
|
|
|
|
2021-10-26 13:39:13 +00:00
|
|
|
interface ISubmitParams {
|
|
|
|
fromServerHistory?: boolean;
|
|
|
|
username?: string;
|
|
|
|
}
|
|
|
|
|
2022-01-17 21:27:28 +00:00
|
|
|
class NewServerView extends React.Component<INewServerViewProps, INewServerViewState> {
|
|
|
|
constructor(props: INewServerViewProps) {
|
2019-08-07 19:20:16 +00:00
|
|
|
super(props);
|
2021-09-23 14:17:53 +00:00
|
|
|
if (!isTablet) {
|
|
|
|
Orientation.lockToPortrait();
|
|
|
|
}
|
2020-07-24 15:41:59 +00:00
|
|
|
this.setHeader();
|
2019-09-02 16:19:05 +00:00
|
|
|
|
2019-08-07 19:20:16 +00:00
|
|
|
this.state = {
|
2020-03-30 19:20:50 +00:00
|
|
|
text: '',
|
|
|
|
connectingOpen: false,
|
2020-09-11 17:10:16 +00:00
|
|
|
certificate: null,
|
|
|
|
serversHistory: []
|
2019-08-07 19:20:16 +00:00
|
|
|
};
|
2020-03-30 19:20:50 +00:00
|
|
|
EventEmitter.addEventListener('NewServer', this.handleNewServerEvent);
|
2020-04-30 16:06:58 +00:00
|
|
|
BackHandler.addEventListener('hardwareBackPress', this.handleBackPress);
|
2018-08-10 17:26:36 +00:00
|
|
|
}
|
|
|
|
|
2020-09-11 17:10:16 +00:00
|
|
|
componentDidMount() {
|
|
|
|
this.queryServerHistory();
|
|
|
|
}
|
|
|
|
|
2020-03-30 19:20:50 +00:00
|
|
|
componentWillUnmount() {
|
|
|
|
EventEmitter.removeListener('NewServer', this.handleNewServerEvent);
|
2020-04-30 16:06:58 +00:00
|
|
|
BackHandler.removeEventListener('hardwareBackPress', this.handleBackPress);
|
2022-01-17 21:27:28 +00:00
|
|
|
const { previousServer, dispatch } = this.props;
|
2021-09-23 14:17:53 +00:00
|
|
|
if (previousServer) {
|
2022-01-17 21:27:28 +00:00
|
|
|
dispatch(serverFinishAdd());
|
2021-09-23 14:17:53 +00:00
|
|
|
}
|
2020-04-30 16:06:58 +00:00
|
|
|
}
|
|
|
|
|
2022-11-01 17:09:00 +00:00
|
|
|
componentDidUpdate(prevProps: Readonly<INewServerViewProps>) {
|
|
|
|
if (prevProps.connecting !== this.props.connecting) {
|
|
|
|
this.setHeader();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-24 15:41:59 +00:00
|
|
|
setHeader = () => {
|
2022-11-01 17:09:00 +00:00
|
|
|
const { previousServer, navigation, connecting } = this.props;
|
2021-09-23 14:17:53 +00:00
|
|
|
if (previousServer) {
|
|
|
|
return navigation.setOptions({
|
|
|
|
headerTitle: I18n.t('Workspaces'),
|
2022-11-01 17:09:00 +00:00
|
|
|
headerLeft: () =>
|
|
|
|
!connecting ? (
|
|
|
|
<HeaderButton.CloseModal navigation={navigation} onPress={this.close} testID='new-server-view-close' />
|
|
|
|
) : null
|
2020-07-24 15:41:59 +00:00
|
|
|
});
|
|
|
|
}
|
2021-09-23 14:17:53 +00:00
|
|
|
|
|
|
|
return navigation.setOptions({
|
|
|
|
headerShown: false
|
|
|
|
});
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2020-07-24 15:41:59 +00:00
|
|
|
|
2020-04-30 16:06:58 +00:00
|
|
|
handleBackPress = () => {
|
2020-06-15 14:00:46 +00:00
|
|
|
const { navigation, previousServer } = this.props;
|
|
|
|
if (navigation.isFocused() && previousServer) {
|
2020-04-30 16:06:58 +00:00
|
|
|
this.close();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2018-08-10 17:26:36 +00:00
|
|
|
|
2021-10-20 18:04:15 +00:00
|
|
|
onChangeText = (text: string) => {
|
2017-08-11 15:47:18 +00:00
|
|
|
this.setState({ text });
|
2020-09-11 17:10:16 +00:00
|
|
|
this.queryServerHistory(text);
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2020-09-11 17:10:16 +00:00
|
|
|
|
2021-10-20 18:04:15 +00:00
|
|
|
queryServerHistory = async (text?: string) => {
|
2020-09-11 17:10:16 +00:00
|
|
|
const db = database.servers;
|
|
|
|
try {
|
2021-02-26 16:25:51 +00:00
|
|
|
const serversHistoryCollection = db.get('servers_history');
|
2021-09-13 20:41:05 +00:00
|
|
|
let whereClause = [Q.where('username', Q.notEq(null)), Q.experimentalSortBy('updated_at', Q.desc), Q.experimentalTake(3)];
|
2020-09-11 17:10:16 +00:00
|
|
|
if (text) {
|
2021-10-20 18:04:15 +00:00
|
|
|
const likeString = sanitizeLikeString(text);
|
2021-09-13 20:41:05 +00:00
|
|
|
whereClause = [...whereClause, Q.where('url', Q.like(`%${likeString}%`))];
|
2020-09-11 17:10:16 +00:00
|
|
|
}
|
2022-02-01 13:39:09 +00:00
|
|
|
const serversHistory = await serversHistoryCollection.query(...whereClause).fetch();
|
2020-09-11 17:10:16 +00:00
|
|
|
this.setState({ serversHistory });
|
|
|
|
} catch {
|
|
|
|
// Do nothing
|
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2017-09-21 17:08:00 +00:00
|
|
|
|
2020-03-30 19:20:50 +00:00
|
|
|
close = () => {
|
2022-01-17 21:27:28 +00:00
|
|
|
const { dispatch, previousServer } = this.props;
|
2022-11-01 17:09:00 +00:00
|
|
|
|
2022-01-17 21:27:28 +00:00
|
|
|
dispatch(inviteLinksClear());
|
2022-05-03 15:48:02 +00:00
|
|
|
if (previousServer) {
|
|
|
|
dispatch(selectServerRequest(previousServer));
|
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2020-03-30 19:20:50 +00:00
|
|
|
|
2021-10-20 18:04:15 +00:00
|
|
|
handleNewServerEvent = (event: { server: string }) => {
|
2020-03-30 19:20:50 +00:00
|
|
|
let { server } = event;
|
2020-11-12 17:09:24 +00:00
|
|
|
if (!server) {
|
|
|
|
return;
|
|
|
|
}
|
2022-01-17 21:27:28 +00:00
|
|
|
const { dispatch } = this.props;
|
2020-03-30 19:20:50 +00:00
|
|
|
this.setState({ text: server });
|
|
|
|
server = this.completeUrl(server);
|
2022-01-17 21:27:28 +00:00
|
|
|
dispatch(serverRequest(server));
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2020-03-30 19:20:50 +00:00
|
|
|
|
2022-02-01 13:39:09 +00:00
|
|
|
onPressServerHistory = (serverHistory: TServerHistoryModel) => {
|
2021-10-26 13:39:13 +00:00
|
|
|
this.setState({ text: serverHistory.url }, () => this.submit({ fromServerHistory: true, username: serverHistory?.username }));
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2020-09-11 17:10:16 +00:00
|
|
|
|
2022-03-09 19:41:26 +00:00
|
|
|
submit = ({ fromServerHistory = false, username }: ISubmitParams = {}) => {
|
2021-02-11 21:44:50 +00:00
|
|
|
logEvent(events.NS_CONNECT_TO_WORKSPACE);
|
2019-09-02 16:19:05 +00:00
|
|
|
const { text, certificate } = this.state;
|
2022-01-17 21:27:28 +00:00
|
|
|
const { dispatch } = this.props;
|
2019-09-02 16:19:05 +00:00
|
|
|
|
2020-03-30 19:20:50 +00:00
|
|
|
this.setState({ connectingOpen: false });
|
|
|
|
|
2018-09-25 19:28:42 +00:00
|
|
|
if (text) {
|
2018-05-30 16:51:30 +00:00
|
|
|
Keyboard.dismiss();
|
2020-02-20 12:58:13 +00:00
|
|
|
const server = this.completeUrl(text);
|
2020-11-30 17:00:06 +00:00
|
|
|
|
|
|
|
// Save info - SSL Pinning
|
2022-03-09 19:41:26 +00:00
|
|
|
if (certificate) {
|
2022-04-28 20:37:25 +00:00
|
|
|
UserPreferences.setString(`${CERTIFICATE_KEY}-${server}`, certificate);
|
2022-03-09 19:41:26 +00:00
|
|
|
}
|
2020-11-30 17:00:06 +00:00
|
|
|
|
|
|
|
// Save info - HTTP Basic Authentication
|
2022-03-09 19:41:26 +00:00
|
|
|
this.basicAuth(server, text);
|
2020-11-30 17:00:06 +00:00
|
|
|
|
2020-09-11 17:10:16 +00:00
|
|
|
if (fromServerHistory) {
|
2022-01-17 21:27:28 +00:00
|
|
|
dispatch(serverRequest(server, username, true));
|
2020-09-11 17:10:16 +00:00
|
|
|
} else {
|
2022-01-17 21:27:28 +00:00
|
|
|
dispatch(serverRequest(server));
|
2020-09-11 17:10:16 +00:00
|
|
|
}
|
2020-02-20 12:58:13 +00:00
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2020-02-20 12:58:13 +00:00
|
|
|
|
2020-03-30 19:20:50 +00:00
|
|
|
connectOpen = () => {
|
2021-02-11 21:44:50 +00:00
|
|
|
logEvent(events.NS_JOIN_OPEN_WORKSPACE);
|
2020-03-30 19:20:50 +00:00
|
|
|
this.setState({ connectingOpen: true });
|
2022-01-17 21:27:28 +00:00
|
|
|
const { dispatch } = this.props;
|
|
|
|
dispatch(serverRequest('https://open.rocket.chat'));
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2020-03-30 19:20:50 +00:00
|
|
|
|
2022-03-09 19:41:26 +00:00
|
|
|
basicAuth = (server: string, text: string) => {
|
2020-02-20 12:58:13 +00:00
|
|
|
try {
|
|
|
|
const parsedUrl = parse(text, true);
|
|
|
|
if (parsedUrl.auth.length) {
|
2020-07-20 16:35:17 +00:00
|
|
|
const credentials = Base64.encode(parsedUrl.auth);
|
2022-03-09 19:41:26 +00:00
|
|
|
UserPreferences.setString(`${BASIC_AUTH_KEY}-${server}`, credentials);
|
2020-02-20 12:58:13 +00:00
|
|
|
setBasicAuth(credentials);
|
|
|
|
}
|
|
|
|
} catch {
|
|
|
|
// do nothing
|
2019-09-02 16:19:05 +00:00
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2019-09-02 16:19:05 +00:00
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
chooseCertificate = async () => {
|
2019-09-02 16:19:05 +00:00
|
|
|
try {
|
2023-03-15 18:38:45 +00:00
|
|
|
// const certificate = await SSLPinning?.pickCertificate();
|
|
|
|
// this.setState({ certificate });
|
2020-11-30 17:00:06 +00:00
|
|
|
} catch {
|
|
|
|
// Do nothing
|
2018-05-30 16:51:30 +00:00
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2017-09-21 17:08:00 +00:00
|
|
|
|
2021-10-20 18:04:15 +00:00
|
|
|
completeUrl = (url: string) => {
|
2020-02-20 12:58:13 +00:00
|
|
|
const parsedUrl = parse(url, true);
|
|
|
|
if (parsedUrl.auth.length) {
|
2020-03-26 13:20:41 +00:00
|
|
|
url = parsedUrl.origin;
|
2020-02-20 12:58:13 +00:00
|
|
|
}
|
|
|
|
|
2019-11-19 19:58:24 +00:00
|
|
|
url = url && url.replace(/\s/g, '');
|
2018-04-24 19:34:03 +00:00
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
if (/^(\w|[0-9-_]){3,}$/.test(url) && /^(htt(ps?)?)|(loca((l)?|(lh)?|(lho)?|(lhos)?|(lhost:?\d*)?)$)/.test(url) === false) {
|
|
|
|
url = `${url}.rocket.chat`;
|
2017-08-11 15:47:18 +00:00
|
|
|
}
|
|
|
|
|
2019-09-16 21:04:20 +00:00
|
|
|
if (/^(https?:\/\/)?(((\w|[0-9-_])+(\.(\w|[0-9-_])+)+)|localhost)(:\d+)?$/.test(url)) {
|
2017-08-11 15:47:18 +00:00
|
|
|
if (/^localhost(:\d+)?/.test(url)) {
|
2021-09-13 20:41:05 +00:00
|
|
|
url = `http://${url}`;
|
2017-08-11 15:47:18 +00:00
|
|
|
} else if (/^https?:\/\//.test(url) === false) {
|
2021-09-13 20:41:05 +00:00
|
|
|
url = `https://${url}`;
|
2017-08-07 00:34:35 +00:00
|
|
|
}
|
2017-08-11 15:47:18 +00:00
|
|
|
}
|
2022-07-28 13:36:40 +00:00
|
|
|
return serializeAsciiUrl(url.replace(/\/+$/, '').replace(/\\/g, '/'));
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2017-08-11 15:47:18 +00:00
|
|
|
|
2021-10-20 18:04:15 +00:00
|
|
|
uriToPath = (uri: string) => uri.replace('file://', '');
|
2019-09-02 16:19:05 +00:00
|
|
|
|
2020-06-15 19:35:45 +00:00
|
|
|
handleRemove = () => {
|
|
|
|
showConfirmationAlert({
|
|
|
|
message: I18n.t('You_will_unset_a_certificate_for_this_server'),
|
2020-08-25 20:04:18 +00:00
|
|
|
confirmationText: I18n.t('Remove'),
|
2022-05-03 15:48:02 +00:00
|
|
|
onPress: () => this.setState({ certificate: null }) // We not need delete file from DocumentPicker because it is a temp file
|
2019-09-02 16:19:05 +00:00
|
|
|
});
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2019-09-02 16:19:05 +00:00
|
|
|
|
2022-02-01 13:39:09 +00:00
|
|
|
deleteServerHistory = async (item: TServerHistoryModel) => {
|
2020-09-11 17:10:16 +00:00
|
|
|
const db = database.servers;
|
|
|
|
try {
|
2021-10-20 18:04:15 +00:00
|
|
|
await db.write(async () => {
|
2020-09-11 17:10:16 +00:00
|
|
|
await item.destroyPermanently();
|
|
|
|
});
|
2022-01-17 21:27:28 +00:00
|
|
|
this.setState((prevstate: INewServerViewState) => ({
|
2022-02-01 13:39:09 +00:00
|
|
|
serversHistory: prevstate.serversHistory.filter(server => server.id !== item.id)
|
2021-10-20 18:04:15 +00:00
|
|
|
}));
|
2020-09-11 17:10:16 +00:00
|
|
|
} catch {
|
|
|
|
// Nothing
|
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2020-09-11 17:10:16 +00:00
|
|
|
|
2019-09-02 16:19:05 +00:00
|
|
|
renderCertificatePicker = () => {
|
|
|
|
const { certificate } = this.state;
|
2021-09-23 14:17:53 +00:00
|
|
|
const { theme, width, height, previousServer } = this.props;
|
2019-09-02 16:19:05 +00:00
|
|
|
return (
|
2021-09-23 14:17:53 +00:00
|
|
|
<View
|
|
|
|
style={[
|
|
|
|
styles.certificatePicker,
|
|
|
|
{
|
2021-10-20 18:04:15 +00:00
|
|
|
marginBottom: verticalScale({ size: previousServer && !isTablet ? 10 : 30, height })
|
2021-09-23 14:17:53 +00:00
|
|
|
}
|
2022-08-08 21:02:08 +00:00
|
|
|
]}
|
|
|
|
>
|
2021-09-23 14:17:53 +00:00
|
|
|
<Text
|
|
|
|
style={[
|
|
|
|
styles.chooseCertificateTitle,
|
2021-10-20 18:04:15 +00:00
|
|
|
{ color: themes[theme].auxiliaryText, fontSize: moderateScale({ size: 13, width }) }
|
2022-08-08 21:02:08 +00:00
|
|
|
]}
|
|
|
|
>
|
2019-12-04 16:39:53 +00:00
|
|
|
{certificate ? I18n.t('Your_certificate') : I18n.t('Do_you_have_a_certificate')}
|
|
|
|
</Text>
|
|
|
|
<TouchableOpacity
|
2020-06-15 19:35:45 +00:00
|
|
|
onPress={certificate ? this.handleRemove : this.chooseCertificate}
|
2022-08-08 21:02:08 +00:00
|
|
|
testID='new-server-choose-certificate'
|
|
|
|
>
|
2021-10-20 18:04:15 +00:00
|
|
|
<Text
|
2022-08-08 21:02:08 +00:00
|
|
|
style={[styles.chooseCertificate, { color: themes[theme].tintColor, fontSize: moderateScale({ size: 13, width }) }]}
|
|
|
|
>
|
2020-11-30 17:00:06 +00:00
|
|
|
{certificate ?? I18n.t('Apply_Your_Certificate')}
|
2019-12-04 16:39:53 +00:00
|
|
|
</Text>
|
2019-09-02 16:19:05 +00:00
|
|
|
</TouchableOpacity>
|
|
|
|
</View>
|
|
|
|
);
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2019-09-02 16:19:05 +00:00
|
|
|
|
2017-08-03 18:23:43 +00:00
|
|
|
render() {
|
2021-09-23 14:17:53 +00:00
|
|
|
const { connecting, theme, previousServer, width, height } = this.props;
|
2021-09-13 20:41:05 +00:00
|
|
|
const { text, connectingOpen, serversHistory } = this.state;
|
2021-09-23 14:17:53 +00:00
|
|
|
const marginTop = previousServer ? 0 : 35;
|
|
|
|
|
2017-08-03 18:23:43 +00:00
|
|
|
return (
|
2022-03-25 17:55:20 +00:00
|
|
|
<FormContainer testID='new-server-view' keyboardShouldPersistTaps='never'>
|
2020-03-30 19:20:50 +00:00
|
|
|
<FormContainerInner>
|
2021-09-23 14:17:53 +00:00
|
|
|
<Image
|
|
|
|
style={[
|
|
|
|
styles.onboardingImage,
|
|
|
|
{
|
2021-10-20 18:04:15 +00:00
|
|
|
marginBottom: verticalScale({ size: 10, height }),
|
|
|
|
marginTop: isTablet ? 0 : verticalScale({ size: marginTop, height }),
|
|
|
|
width: verticalScale({ size: 100, height }),
|
|
|
|
height: verticalScale({ size: 100, height })
|
2021-09-23 14:17:53 +00:00
|
|
|
}
|
|
|
|
]}
|
|
|
|
source={require('../../static/images/logo.png')}
|
|
|
|
fadeDuration={0}
|
|
|
|
/>
|
|
|
|
<Text
|
|
|
|
style={[
|
|
|
|
styles.title,
|
|
|
|
{
|
|
|
|
color: themes[theme].titleText,
|
2021-10-20 18:04:15 +00:00
|
|
|
fontSize: moderateScale({ size: 22, width }),
|
|
|
|
marginBottom: verticalScale({ size: 8, height })
|
2021-09-23 14:17:53 +00:00
|
|
|
}
|
2022-08-08 21:02:08 +00:00
|
|
|
]}
|
|
|
|
>
|
2021-09-23 14:17:53 +00:00
|
|
|
Rocket.Chat
|
|
|
|
</Text>
|
|
|
|
<Text
|
|
|
|
style={[
|
|
|
|
styles.subtitle,
|
|
|
|
{
|
|
|
|
color: themes[theme].controlText,
|
2021-10-20 18:04:15 +00:00
|
|
|
fontSize: moderateScale({ size: 16, width }),
|
|
|
|
marginBottom: verticalScale({ size: 30, height })
|
2021-09-23 14:17:53 +00:00
|
|
|
}
|
2022-08-08 21:02:08 +00:00
|
|
|
]}
|
|
|
|
>
|
2021-09-23 14:17:53 +00:00
|
|
|
{I18n.t('Onboarding_subtitle')}
|
|
|
|
</Text>
|
2020-09-11 17:10:16 +00:00
|
|
|
<ServerInput
|
|
|
|
text={text}
|
2020-03-30 19:20:50 +00:00
|
|
|
theme={theme}
|
2020-09-11 17:10:16 +00:00
|
|
|
serversHistory={serversHistory}
|
|
|
|
onChangeText={this.onChangeText}
|
|
|
|
onSubmit={this.submit}
|
|
|
|
onDelete={this.deleteServerHistory}
|
|
|
|
onPressServerHistory={this.onPressServerHistory}
|
2020-03-30 19:20:50 +00:00
|
|
|
/>
|
|
|
|
<Button
|
|
|
|
title={I18n.t('Connect')}
|
|
|
|
type='primary'
|
|
|
|
onPress={this.submit}
|
|
|
|
disabled={!text || connecting}
|
|
|
|
loading={!connectingOpen && connecting}
|
2021-10-20 18:04:15 +00:00
|
|
|
style={[styles.connectButton, { marginTop: verticalScale({ size: 16, height }) }]}
|
2020-05-20 16:33:40 +00:00
|
|
|
testID='new-server-view-button'
|
2020-03-30 19:20:50 +00:00
|
|
|
/>
|
2020-05-08 17:36:10 +00:00
|
|
|
<OrSeparator theme={theme} />
|
2021-09-23 14:17:53 +00:00
|
|
|
<Text
|
|
|
|
style={[
|
|
|
|
styles.description,
|
|
|
|
{
|
|
|
|
color: themes[theme].auxiliaryText,
|
2021-10-20 18:04:15 +00:00
|
|
|
fontSize: moderateScale({ size: 14, width }),
|
|
|
|
marginBottom: verticalScale({ size: 16, height })
|
2021-09-23 14:17:53 +00:00
|
|
|
}
|
2022-08-08 21:02:08 +00:00
|
|
|
]}
|
|
|
|
>
|
2021-09-13 20:41:05 +00:00
|
|
|
{I18n.t('Onboarding_join_open_description')}
|
|
|
|
</Text>
|
2020-03-30 19:20:50 +00:00
|
|
|
<Button
|
|
|
|
title={I18n.t('Join_our_open_workspace')}
|
|
|
|
type='secondary'
|
|
|
|
backgroundColor={themes[theme].chatComponentBackground}
|
|
|
|
onPress={this.connectOpen}
|
|
|
|
disabled={connecting}
|
|
|
|
loading={connectingOpen && connecting}
|
2020-05-20 16:33:40 +00:00
|
|
|
testID='new-server-view-open'
|
2020-03-30 19:20:50 +00:00
|
|
|
/>
|
|
|
|
</FormContainerInner>
|
2020-11-30 17:00:06 +00:00
|
|
|
{this.renderCertificatePicker()}
|
2020-03-30 19:20:50 +00:00
|
|
|
</FormContainer>
|
2017-08-03 18:23:43 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2019-08-07 13:51:34 +00:00
|
|
|
|
2022-05-03 15:48:02 +00:00
|
|
|
const mapStateToProps = (state: IApplicationState) => ({
|
2020-06-15 14:00:46 +00:00
|
|
|
connecting: state.server.connecting,
|
|
|
|
previousServer: state.server.previousServer
|
2019-08-07 13:51:34 +00:00
|
|
|
});
|
|
|
|
|
2022-01-17 21:27:28 +00:00
|
|
|
export default connect(mapStateToProps)(withDimensions(withTheme(NewServerView)));
|