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'; class Dhcp extends Component { handleFormSubmit = (values) => { this.props.setDhcpConfig(values); }; handleFormChange = (value) => { this.props.setDhcpConfig(value); } handleToggle = (config) => { this.props.toggleDhcp(config); this.props.findActiveDhcp(config.interface_name); } getToggleDhcpButton = () => { const { config, active, processingDhcp } = this.props.dhcp; const activeDhcpFound = active && active.found; const filledConfig = Object.keys(config).every((key) => { if (key === 'enabled') { return true; } return config[key]; }); if (config.enabled) { return ( ); } return ( ); } getActiveDhcpMessage = () => { const { active } = this.props.dhcp; if (active) { if (active.error) { return (
{active.error}
); } return ( {active.found ? (
dhcp_found
) : (
dhcp_not_found
)}
); } return ''; } 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 (
{!dhcp.processing &&

{this.getToggleDhcpButton()}
{this.getActiveDhcpMessage()} }
{!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);