badguardhome/client/src/install/Setup/Controls.js

127 lines
3.5 KiB
JavaScript
Raw Normal View History

2019-01-18 17:17:48 +00:00
import React, { Component } from 'react';
import { connect } from 'react-redux';
import PropTypes from 'prop-types';
import { Trans } from 'react-i18next';
import * as actionCreators from '../../actions/install';
class Controls extends Component {
2019-02-01 16:52:42 +00:00
renderPrevButton(step) {
switch (step) {
case 2:
case 3:
return (
<button
type="button"
2019-02-07 13:21:17 +00:00
className="btn btn-secondary btn-lg setup__button"
2019-02-01 16:52:42 +00:00
onClick={this.props.prevStep}
>
<Trans>back</Trans>
</button>
);
default:
return false;
}
}
renderNextButton(step) {
const {
nextStep,
invalid,
pristine,
install,
ip,
port,
} = this.props;
2019-01-18 17:17:48 +00:00
switch (step) {
case 1:
return (
<button
type="button"
2019-02-07 13:21:17 +00:00
className="btn btn-success btn-lg setup__button"
onClick={nextStep}
2019-01-18 17:17:48 +00:00
>
<Trans>get_started</Trans>
</button>
);
case 2:
case 3:
return (
2019-02-01 16:52:42 +00:00
<button
type="submit"
2019-02-07 13:21:17 +00:00
className="btn btn-success btn-lg setup__button"
2019-02-07 13:09:12 +00:00
disabled={
invalid
|| pristine
|| install.processingSubmit
|| install.dns.status
|| install.web.status
2019-02-07 13:09:12 +00:00
}
2019-02-01 16:52:42 +00:00
>
<Trans>next</Trans>
</button>
2019-01-18 17:17:48 +00:00
);
case 4:
return (
2019-02-01 16:52:42 +00:00
<button
type="button"
2019-02-07 13:21:17 +00:00
className="btn btn-success btn-lg setup__button"
onClick={nextStep}
2019-02-01 16:52:42 +00:00
>
<Trans>next</Trans>
</button>
2019-01-18 17:17:48 +00:00
);
case 5:
return (
<button
2019-02-01 16:52:42 +00:00
type="button"
2019-02-07 13:21:17 +00:00
className="btn btn-success btn-lg setup__button"
onClick={() =>
this.props.openDashboard(ip, port)}
2019-01-18 17:17:48 +00:00
>
<Trans>open_dashboard</Trans>
</button>
);
default:
return false;
}
}
render() {
2019-02-07 13:09:12 +00:00
const { install } = this.props;
2019-01-18 17:17:48 +00:00
return (
<div className="setup__nav">
2019-02-01 16:52:42 +00:00
<div className="btn-list">
2019-02-07 13:09:12 +00:00
{this.renderPrevButton(install.step)}
{this.renderNextButton(install.step)}
2019-02-01 16:52:42 +00:00
</div>
2019-01-18 17:17:48 +00:00
</div>
);
}
}
Controls.propTypes = {
2019-02-07 13:09:12 +00:00
install: PropTypes.object.isRequired,
2019-01-18 17:17:48 +00:00
nextStep: PropTypes.func,
prevStep: PropTypes.func,
2019-02-01 16:52:42 +00:00
openDashboard: PropTypes.func,
2019-01-18 17:17:48 +00:00
submitting: PropTypes.bool,
2019-01-21 08:55:39 +00:00
invalid: PropTypes.bool,
2019-02-01 16:52:42 +00:00
pristine: PropTypes.bool,
ip: PropTypes.string,
port: PropTypes.number,
2019-01-18 17:17:48 +00:00
};
const mapStateToProps = (state) => {
2019-02-07 13:09:12 +00:00
const { install } = state;
const props = { install };
2019-01-18 17:17:48 +00:00
return props;
};
export default connect(
mapStateToProps,
actionCreators,
)(Controls);