123 lines
4.3 KiB
JavaScript
123 lines
4.3 KiB
JavaScript
// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
|
|
// See License.txt for license information.
|
|
|
|
import React, {PropTypes, PureComponent} from 'react';
|
|
import {
|
|
Image,
|
|
Keyboard,
|
|
TouchableWithoutFeedback,
|
|
View
|
|
} from 'react-native';
|
|
|
|
import Button from 'react-native-button';
|
|
import ErrorText from 'app/components/error_text';
|
|
import FormattedText from 'app/components/formatted_text';
|
|
import KeyboardLayout from 'app/components/layout/keyboard_layout';
|
|
import TextInputWithLocalizedPlaceholder from 'app/components/text_input_with_localized_placeholder';
|
|
import {GlobalStyles} from 'app/styles';
|
|
|
|
import logo from 'assets/images/logo.png';
|
|
|
|
import Client from 'service/client';
|
|
import RequestStatus from 'service/constants/request_status';
|
|
|
|
import {isValidUrl, stripTrailingSlashes} from 'app/utils/url';
|
|
|
|
export default class SelectServer extends PureComponent {
|
|
static propTypes = {
|
|
serverUrl: PropTypes.string.isRequired,
|
|
server: PropTypes.object.isRequired,
|
|
actions: PropTypes.object.isRequired
|
|
};
|
|
|
|
constructor(props) {
|
|
super(props);
|
|
|
|
this.state = {
|
|
error: null
|
|
};
|
|
}
|
|
|
|
onClick = () => {
|
|
const url = this.props.serverUrl;
|
|
let error = null;
|
|
|
|
if (isValidUrl(url)) {
|
|
Client.setUrl(stripTrailingSlashes(url));
|
|
|
|
this.props.actions.getPing().then(() => {
|
|
if (this.props.server.status === RequestStatus.SUCCESS) {
|
|
Keyboard.dismiss();
|
|
this.props.actions.goToLogin();
|
|
}
|
|
});
|
|
} else {
|
|
error = {
|
|
intl: {
|
|
id: 'mobile.server_url.invalid_format',
|
|
defaultMessage: 'URL must start with http:// or https://'
|
|
}
|
|
};
|
|
}
|
|
|
|
this.setState({error});
|
|
};
|
|
|
|
inputRef = (ref) => {
|
|
this.textInput = ref;
|
|
};
|
|
|
|
blur = () => {
|
|
this.textInput.refs.wrappedInstance.blur();
|
|
};
|
|
|
|
render() {
|
|
return (
|
|
<KeyboardLayout
|
|
behavior='padding'
|
|
style={{flex: 1}}
|
|
keyboardVerticalOffset={0}
|
|
>
|
|
<TouchableWithoutFeedback onPress={this.blur}>
|
|
<View style={[GlobalStyles.container, GlobalStyles.signupContainer]}>
|
|
<Image
|
|
source={logo}
|
|
/>
|
|
<View>
|
|
<FormattedText
|
|
style={[GlobalStyles.header, GlobalStyles.label]}
|
|
id='mobile.components.select_server_view.enterServerUrl'
|
|
defaultMessage='Enter Server URL'
|
|
/>
|
|
</View>
|
|
<TextInputWithLocalizedPlaceholder
|
|
ref={this.inputRef}
|
|
value={this.props.serverUrl}
|
|
onChangeText={this.props.actions.handleServerUrlChanged}
|
|
onSubmitEditing={this.onClick}
|
|
style={GlobalStyles.inputBox}
|
|
autoCapitalize='none'
|
|
autoCorrect={false}
|
|
keyboardType='url'
|
|
placeholder={{id: 'mobile.components.select_server_view.siteUrlPlaceholder', defaultMessage: 'https://mattermost.example.com'}}
|
|
returnKeyType='go'
|
|
underlineColorAndroid='transparent'
|
|
/>
|
|
<Button
|
|
onPress={this.onClick}
|
|
loading={this.props.server.loading}
|
|
containerStyle={GlobalStyles.signupButton}
|
|
>
|
|
<FormattedText
|
|
style={GlobalStyles.signupButtonText}
|
|
id='mobile.components.select_server_view.proceed'
|
|
defaultMessage='Proceed'
|
|
/>
|
|
</Button>
|
|
<ErrorText error={this.state.error || this.props.server.error}/>
|
|
</View>
|
|
</TouchableWithoutFeedback>
|
|
</KeyboardLayout>
|
|
);
|
|
}
|
|
}
|