badguardhome/client/src/components/Settings/Dhcp/index.js

108 lines
4.1 KiB
JavaScript
Raw Normal View History

import React, { Component, Fragment } from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
import { Trans, withNamespaces } from 'react-i18next';
import Form from './Form';
import Leases from './Leases';
import Card from '../../ui/Card';
class Dhcp extends Component {
handleFormSubmit = (values) => {
this.props.setDhcpConfig(values);
};
handleRefresh = () => {
this.props.findActiveDhcp();
}
getToggleDhcpButton = () => {
2018-12-13 11:38:00 +00:00
const { config } = this.props.dhcp;
const buttonText = config.enabled ? 'dhcp_disable' : 'dhcp_enable';
const buttonClass = config.enabled ? 'btn-gray' : 'btn-success';
return (
2018-12-28 16:48:02 +00:00
<button
type="button"
className={`btn btn-standart mr-2 ${buttonClass}`}
onClick={() => this.props.toggleDhcp(config)}
disabled={!config.interface_name}
>
<Trans>{buttonText}</Trans>
</button>
);
}
render() {
const { t, dhcp } = this.props;
const statusButtonClass = classnames({
'btn btn-primary btn-standart': true,
'btn btn-primary btn-standart btn-loading': dhcp.processingStatus,
});
return (
<Fragment>
{!dhcp.processing &&
<Card title={ t('dhcp_title') } subtitle={ t('dhcp_description') } bodyType="card-body box-body--settings">
<div className="row">
<div className="col">
2018-12-28 16:48:02 +00:00
<Form
onSubmit={this.handleFormSubmit}
initialValues={dhcp.config}
enabled={dhcp.config.enabled}
interfaces={dhcp.interfaces}
processing={dhcp.processingInterfaces}
/>
<hr/>
<div className="card-actions mb-3">
{this.getToggleDhcpButton()}
<button
className={statusButtonClass}
type="button"
onClick={this.handleRefresh}
2018-12-28 16:48:02 +00:00
disabled={!dhcp.config.interface_name}
>
<Trans>refresh_status</Trans>
</button>
</div>
2018-12-28 16:48:02 +00:00
{dhcp.active &&
<div className="text-secondary">
2018-12-28 16:48:02 +00:00
{dhcp.active.found ? (
<span className="text-danger">
<Trans>dhcp_found</Trans>
</span>
) : (
<Trans>dhcp_not_found</Trans>
)}
</div>
}
</div>
</div>
</Card>
}
{!dhcp.processing && dhcp.config.enabled &&
<Card title={ t('dhcp_leases') } bodyType="card-body box-body--settings">
<div className="row">
<div className="col">
<Leases leases={dhcp.leases} />
</div>
</div>
</Card>
}
</Fragment>
);
}
}
Dhcp.propTypes = {
dhcp: PropTypes.object,
toggleDhcp: PropTypes.func,
getDhcpStatus: PropTypes.func,
setDhcpConfig: PropTypes.func,
findActiveDhcp: PropTypes.func,
handleSubmit: PropTypes.func,
t: PropTypes.func,
};
export default withNamespaces()(Dhcp);