2019-01-18 17:17:48 +00:00
|
|
|
import React, { Component, Fragment } from 'react';
|
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
|
|
|
|
|
|
import * as actionCreators from '../../actions/install';
|
|
|
|
|
import { INSTALL_FIRST_STEP, INSTALL_TOTAL_STEPS } 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';
|
|
|
|
|
|
2019-01-21 08:55:39 +00:00
|
|
|
import Toasts from '../../components/Toasts';
|
2019-01-18 17:17:48 +00:00
|
|
|
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) => {
|
|
|
|
|
this.props.setAllSettings(values);
|
|
|
|
|
};
|
|
|
|
|
|
2019-02-01 16:52:42 +00:00
|
|
|
openDashboard = () => {
|
|
|
|
|
console.log('Open dashboard');
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-18 17:17:48 +00:00
|
|
|
nextStep = () => {
|
|
|
|
|
if (this.props.install.step < INSTALL_TOTAL_STEPS) {
|
|
|
|
|
this.props.nextStep();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
prevStep = () => {
|
|
|
|
|
if (this.props.install.step > INSTALL_FIRST_STEP) {
|
|
|
|
|
this.props.prevStep();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-01 16:52:42 +00:00
|
|
|
renderPage(step, config, interfaces) {
|
2019-01-18 17:17:48 +00:00
|
|
|
switch (step) {
|
|
|
|
|
case 1:
|
|
|
|
|
return <Greeting />;
|
|
|
|
|
case 2:
|
|
|
|
|
return (
|
|
|
|
|
<Settings
|
|
|
|
|
initialValues={config}
|
2019-02-01 16:52:42 +00:00
|
|
|
interfaces={interfaces}
|
|
|
|
|
webWarning={config.web.warning}
|
|
|
|
|
dnsWarning={config.dns.warning}
|
2019-01-18 17:17:48 +00:00
|
|
|
onSubmit={this.nextStep}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
case 3:
|
|
|
|
|
return (
|
2019-02-01 16:52:42 +00:00
|
|
|
<Auth onSubmit={this.handleFormSubmit} />
|
2019-01-18 17:17:48 +00:00
|
|
|
);
|
|
|
|
|
case 4:
|
|
|
|
|
return <Devices />;
|
|
|
|
|
case 5:
|
2019-02-01 16:52:42 +00:00
|
|
|
return <Submit onSubmit={this.openDashboard} />;
|
2019-01-18 17:17:48 +00:00
|
|
|
default:
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
render() {
|
|
|
|
|
const {
|
|
|
|
|
processingDefault,
|
|
|
|
|
step,
|
|
|
|
|
web,
|
|
|
|
|
dns,
|
2019-02-01 16:52:42 +00:00
|
|
|
interfaces,
|
2019-01-18 17:17:48 +00:00
|
|
|
} = this.props.install;
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Fragment>
|
|
|
|
|
{processingDefault && <Loading />}
|
|
|
|
|
{!processingDefault &&
|
|
|
|
|
<Fragment>
|
|
|
|
|
<div className="setup">
|
|
|
|
|
<div className="setup__container">
|
|
|
|
|
<img src={logo} className="setup__logo" alt="logo" />
|
2019-02-01 16:52:42 +00:00
|
|
|
{this.renderPage(step, { web, dns }, interfaces)}
|
2019-01-18 17:17:48 +00:00
|
|
|
<Progress step={step} />
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<Footer />
|
2019-01-21 08:55:39 +00:00
|
|
|
<Toasts />
|
2019-01-18 17:17:48 +00:00
|
|
|
</Fragment>
|
|
|
|
|
}
|
|
|
|
|
</Fragment>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Setup.propTypes = {
|
|
|
|
|
getDefaultAddresses: PropTypes.func.isRequired,
|
|
|
|
|
setAllSettings: 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) => {
|
2019-01-21 08:55:39 +00:00
|
|
|
const { install, toasts } = state;
|
|
|
|
|
const props = { install, toasts };
|
2019-01-18 17:17:48 +00:00
|
|
|
return props;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default connect(
|
|
|
|
|
mapStateToProps,
|
|
|
|
|
actionCreators,
|
|
|
|
|
)(Setup);
|