import assert from 'assert';
import moment from 'moment';
import React, { Component, PropTypes } from 'react';
import { If, Then, Else } from 'react-if';
import ReactMapboxGl, { Marker } from 'react-mapbox-gl';
import cheapRuler from 'cheap-ruler';
import { Layout, Container, Header } from './Layout';
import { mapbox as mapboxConfig } from '../config';
import Backend from '../lib/backend';
import { ConnectionState } from '../enums';
import ExternalLinkSVG from '../assets/images/icon-extLink.svg';
export default class Connect extends Component {
static propTypes = {
settings: PropTypes.object.isRequired,
onSettings: PropTypes.func.isRequired,
onConnect: PropTypes.func.isRequired,
onCopyIP: PropTypes.func.isRequired,
onDisconnect: PropTypes.func.isRequired,
onExternalLink: PropTypes.func.isRequired,
getServerInfo: PropTypes.func.isRequired
};
constructor() {
super();
// timer used along with `state.showCopyIPMessage`
this._copyTimer = null;
this.state = {
isFirstPass: true,
// this flag is used together with timer to display
// a message that IP address has been copied to clipboard
showCopyIPMessage: false
};
}
// Component Lifecycle
componentDidMount() {
this.setState({ isFirstPass: false });
}
componentWillUnmount() {
this.setState({ isFirstPass: true });
}
render() {
let error = null;
// check if user out of time
// this is by far the simplest implementation
// later on backend will notify us and disconnect VPN etc..
if(moment(this.props.user.paidUntil).isSameOrBefore(moment())) {
error = new Backend.Error(Backend.ErrorType.noCredit);
}
// Offline?
if(this.props.connect.isOnline === false) {
error = new Backend.Error(Backend.ErrorType.noInternetConnection);
}
return (