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 Interface from './Interface';
import Card from '../../ui/Card';
import Accordion from '../../ui/Accordion';
class Dhcp extends Component {
handleFormSubmit = (values) => {
this.props.setDhcpConfig(values);
};
handleToggle = (config) => {
this.props.toggleDhcp(config);
}
getToggleDhcpButton = () => {
const {
config, active, processingDhcp, processingConfig,
} = this.props.dhcp;
const activeDhcpFound = active && active.found;
const filledConfig = Object.keys(config).every((key) => {
if (key === 'enabled' || key === 'icmp_timeout_msec') {
return true;
}
return config[key];
});
if (config.enabled) {
return (
);
}
return (
);
}
getActiveDhcpMessage = (t, active) => {
if (active) {
if (active.error) {
return (
);
}
return (
{active.found ? (
dhcp_found
) : (
dhcp_not_found
)}
);
}
return '';
}
getDhcpWarning = (active) => {
if (active && active.found === false) {
return '';
}
return (
dhcp_warning
);
}
render() {
const { t, dhcp } = this.props;
const statusButtonClass = classnames({
'btn btn-primary btn-standard': true,
'btn btn-primary btn-standard btn-loading': dhcp.processingStatus,
});
const {
enabled,
interface_name,
...values
} = dhcp.config;
return (
{!dhcp.processing &&
{this.getToggleDhcpButton()}
{this.getActiveDhcpMessage(t, dhcp.active)}
{this.getDhcpWarning(dhcp.active)}
}
{!dhcp.processing && dhcp.config.enabled &&
}
);
}
}
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);