Close #1597 Squashed commit of the following: commit 1eb89586dd71260e561420fe669abc8b56a506a1 Author: ArtemBaskal <a.baskal@adguard.com> Date: Wed May 20 14:54:10 2020 +0300 Fix translation in install options commit 1ebdc9ebfe12a609f978e47db6505c7095b10f7e Author: ArtemBaskal <a.baskal@adguard.com> Date: Wed May 20 13:11:34 2020 +0300 Remove commented code commit 2a8302c65a2a3cf7b6b1596115d1153dac32a794 Author: ArtemBaskal <a.baskal@adguard.com> Date: Tue May 19 19:02:49 2020 +0300 Update i18n packages, add development browserlist, downgrade eslint to match peerDepencancies version commit 3fcf73fb14cd9da508522d1a300b66af24da95e5 Author: ArtemBaskal <a.baskal@adguard.com> Date: Tue May 19 17:30:37 2020 +0300 Remove all unused dependencies commit e761810e3e54e188ada41245bdce7414cd0f03e8 Author: ArtemBaskal <a.baskal@adguard.com> Date: Tue May 19 16:35:24 2020 +0300 Remove unused dependencies commit d89d27da6befcaabcdc12bf5e7e94cbb24140010 Author: ArtemBaskal <a.baskal@adguard.com> Date: Tue May 19 16:14:09 2020 +0300 Update regular dependencies commit d2dfd01233d059870d5173ffd748cf61a477936f Author: ArtemBaskal <a.baskal@adguard.com> Date: Tue May 19 15:34:10 2020 +0300 Update all dev dependancies commit 02b6fb480e9d310039fbe9b7aae062a41128f070 Author: ArtemBaskal <a.baskal@adguard.com> Date: Tue May 19 14:14:44 2020 +0300 Update all postcss packages commit 5e1fa5f99ad75f77e5e429b28ee1ca0b5e65a9a0 Author: ArtemBaskal <a.baskal@adguard.com> Date: Tue May 19 12:45:02 2020 +0300 Prevent git from converting linebreaks in .js files commit 0b9b3b0dccd47cfa50c9531fb61729e6b5a04523 Author: ArtemBaskal <a.baskal@adguard.com> Date: Tue May 19 12:43:01 2020 +0300 Prevent git from converting linebreaks in .js files commit 18b7495e9ef7130b1ac4dbba84c54127d16c6350 Author: ArtemBaskal <a.baskal@adguard.com> Date: Tue May 19 12:24:47 2020 +0300 Remove linebreak-style eslint rule commit df893dec53adebb1d662fe805fab508fd4ed5e06 Author: ArtemBaskal <a.baskal@adguard.com> Date: Mon May 18 20:55:47 2020 +0300 Add prop types commit 36178ecfc5c7fa11a6ee08d7705ca8560941af40 Author: ArtemBaskal <a.baskal@adguard.com> Date: Mon May 18 18:52:07 2020 +0300 Update eslint and babel, fix eslint warnings commit f045b4a2e6b9b78f7e88e3b5d1419c29966a8230 Author: ArtemBaskal <a.baskal@adguard.com> Date: Mon May 18 16:45:49 2020 +0300 Update css loading webpack rules commit 247fa1ed548ef0706a03fdada8309c1454d191f8 Author: ArtemBaskal <a.baskal@adguard.com> Date: Sat May 16 16:13:49 2020 +0300 Suppress linebreak-style eslint error for Windows commit d6499aac507100d6918c849c06d739d80f2229f0 Author: ArtemBaskal <a.baskal@adguard.com> Date: Sat May 16 14:55:07 2020 +0300 Suppress eslint exit code commit ae2d6c614ea23a90d515168f8752e959298894ef Author: ArtemBaskal <a.baskal@adguard.com> Date: Sat May 16 14:05:18 2020 +0300 Edit css file warnings commit 60675050f2a5baebc679fc05da7e033e5c740d90 Author: ArtemBaskal <a.baskal@adguard.com> Date: Sat May 16 13:10:26 2020 +0300 Remove uglifyjs plugin commit a27806434dd8672e71a26c7a2e810d77e5e229fa Author: ArtemBaskal <a.baskal@adguard.com> Date: Sat May 16 01:29:17 2020 +0300 Fix DefinePlugin value commit 8f2966ca59195c2f70bca5072d20515d536f42a6 Author: ArtemBaskal <a.baskal@adguard.com> Date: Sat May 16 01:05:03 2020 +0300 Update webpack
155 lines
4.4 KiB
JavaScript
155 lines
4.4 KiB
JavaScript
import React, { Component, Fragment } from 'react';
|
|
import { connect } from 'react-redux';
|
|
import PropTypes from 'prop-types';
|
|
import debounce from 'lodash/debounce';
|
|
|
|
import * as actionCreators from '../../actions/install';
|
|
import { getWebAddress } from '../../helpers/helpers';
|
|
import {
|
|
INSTALL_FIRST_STEP,
|
|
INSTALL_TOTAL_STEPS,
|
|
ALL_INTERFACES_IP,
|
|
DEBOUNCE_TIMEOUT,
|
|
} from '../../helpers/constants';
|
|
|
|
import Loading from '../../components/ui/Loading';
|
|
import Greeting from './Greeting';
|
|
import Settings from './Settings';
|
|
import Auth from './Auth';
|
|
import Devices from './Devices';
|
|
import Submit from './Submit';
|
|
import Progress from './Progress';
|
|
|
|
import Toasts from '../../components/Toasts';
|
|
import Footer from '../../components/ui/Footer';
|
|
import logo from '../../components/ui/svg/logo.svg';
|
|
|
|
import './Setup.css';
|
|
import '../../components/ui/Tabler.css';
|
|
|
|
class Setup extends Component {
|
|
componentDidMount() {
|
|
this.props.getDefaultAddresses();
|
|
}
|
|
|
|
handleFormSubmit = (values) => {
|
|
const { staticIp, ...config } = values;
|
|
this.props.setAllSettings(config);
|
|
};
|
|
|
|
handleFormChange = debounce((values) => {
|
|
const { web, dns } = values;
|
|
if (values && web.port && dns.port) {
|
|
this.props.checkConfig({ web, dns, set_static_ip: false });
|
|
}
|
|
}, DEBOUNCE_TIMEOUT);
|
|
|
|
handleFix = (web, dns, set_static_ip) => {
|
|
this.props.checkConfig({ web, dns, set_static_ip });
|
|
};
|
|
|
|
openDashboard = (ip, port) => {
|
|
let address = getWebAddress(ip, port);
|
|
|
|
if (ip === ALL_INTERFACES_IP) {
|
|
address = getWebAddress(window.location.hostname, port);
|
|
}
|
|
|
|
window.location.replace(address);
|
|
}
|
|
|
|
nextStep = () => {
|
|
if (this.props.install.step < INSTALL_TOTAL_STEPS) {
|
|
this.props.nextStep();
|
|
}
|
|
}
|
|
|
|
prevStep = () => {
|
|
if (this.props.install.step > INSTALL_FIRST_STEP) {
|
|
this.props.prevStep();
|
|
}
|
|
}
|
|
|
|
renderPage(step, config, interfaces) {
|
|
switch (step) {
|
|
case 1:
|
|
return <Greeting />;
|
|
case 2:
|
|
return (
|
|
<Settings
|
|
config={config}
|
|
initialValues={config}
|
|
interfaces={interfaces}
|
|
onSubmit={this.nextStep}
|
|
onChange={this.handleFormChange}
|
|
validateForm={this.handleFormChange}
|
|
handleFix={this.handleFix}
|
|
/>
|
|
);
|
|
case 3:
|
|
return (
|
|
<Auth onSubmit={this.handleFormSubmit} />
|
|
);
|
|
case 4:
|
|
return <Devices interfaces={interfaces} />;
|
|
case 5:
|
|
return <Submit openDashboard={this.openDashboard} />;
|
|
default:
|
|
return false;
|
|
}
|
|
}
|
|
|
|
render() {
|
|
const {
|
|
processingDefault,
|
|
step,
|
|
web,
|
|
dns,
|
|
staticIp,
|
|
interfaces,
|
|
} = this.props.install;
|
|
|
|
return (
|
|
<Fragment>
|
|
{processingDefault && <Loading />}
|
|
{!processingDefault
|
|
&& <Fragment>
|
|
<div className="setup">
|
|
<div className="setup__container">
|
|
<img src={logo} className="setup__logo" alt="logo" />
|
|
{this.renderPage(step, { web, dns, staticIp }, interfaces)}
|
|
<Progress step={step} />
|
|
</div>
|
|
</div>
|
|
<Footer />
|
|
<Toasts />
|
|
</Fragment>
|
|
}
|
|
</Fragment>
|
|
);
|
|
}
|
|
}
|
|
|
|
Setup.propTypes = {
|
|
getDefaultAddresses: PropTypes.func.isRequired,
|
|
setAllSettings: PropTypes.func.isRequired,
|
|
checkConfig: PropTypes.func.isRequired,
|
|
nextStep: PropTypes.func.isRequired,
|
|
prevStep: PropTypes.func.isRequired,
|
|
install: PropTypes.object.isRequired,
|
|
step: PropTypes.number,
|
|
web: PropTypes.object,
|
|
dns: PropTypes.object,
|
|
};
|
|
|
|
const mapStateToProps = (state) => {
|
|
const { install, toasts } = state;
|
|
const props = { install, toasts };
|
|
return props;
|
|
};
|
|
|
|
export default connect(
|
|
mapStateToProps,
|
|
actionCreators,
|
|
)(Setup);
|