* client: fix DHCP error message

This commit is contained in:
Ildar Kamalov 2019-03-28 16:30:22 +03:00 committed by Simon Zolin
parent d43290fe31
commit ffd9f1aaa9
4 changed files with 95 additions and 9 deletions

View File

@ -32,7 +32,9 @@
"dhcp_ip_addresses": "IP addresses", "dhcp_ip_addresses": "IP addresses",
"dhcp_table_hostname": "Hostname", "dhcp_table_hostname": "Hostname",
"dhcp_table_expires": "Expires", "dhcp_table_expires": "Expires",
"dhcp_warning": "If you want to enable the built-in DHCP server, make sure that there is no other active DHCP server. Otherwise, it can break the internet for connected devices!", "dhcp_warning": "If you want to enable DHCP server anyway, make sure that there is no other active DHCP server in your network. Otherwise, it can break the Internet for connected devices!",
"dhcp_error": "We couldn't determine whether an another DHCP server exists in the network.",
"error_details": "Error details",
"back": "Back", "back": "Back",
"dashboard": "Dashboard", "dashboard": "Dashboard",
"settings": "Settings", "settings": "Settings",

View File

@ -7,6 +7,7 @@ import Form from './Form';
import Leases from './Leases'; import Leases from './Leases';
import Interface from './Interface'; import Interface from './Interface';
import Card from '../../ui/Card'; import Card from '../../ui/Card';
import Accordion from '../../ui/Accordion';
class Dhcp extends Component { class Dhcp extends Component {
handleFormSubmit = (values) => { handleFormSubmit = (values) => {
@ -60,14 +61,17 @@ class Dhcp extends Component {
); );
} }
getActiveDhcpMessage = () => { getActiveDhcpMessage = (t, active) => {
const { active } = this.props.dhcp;
if (active) { if (active) {
if (active.error) { if (active.error) {
return ( return (
<div className="text-danger mb-2"> <div className="text-danger mb-2">
{active.error} <Trans>dhcp_error</Trans>
<div className="mt-2 mb-2">
<Accordion label={t('error_details')}>
<span>{active.error}</span>
</Accordion>
</div>
</div> </div>
); );
} }
@ -90,6 +94,18 @@ class Dhcp extends Component {
return ''; return '';
} }
getDhcpWarning = (active) => {
if (active && active.found === false) {
return '';
}
return (
<div className="text-danger">
<Trans>dhcp_warning</Trans>
</div>
);
}
render() { render() {
const { t, dhcp } = this.props; const { t, dhcp } = this.props;
const statusButtonClass = classnames({ const statusButtonClass = classnames({
@ -138,10 +154,8 @@ class Dhcp extends Component {
<Trans>check_dhcp_servers</Trans> <Trans>check_dhcp_servers</Trans>
</button> </button>
</div> </div>
{this.getActiveDhcpMessage()} {this.getActiveDhcpMessage(t, dhcp.active)}
<div className="text-danger"> {this.getDhcpWarning(dhcp.active)}
<Trans>dhcp_warning</Trans>
</div>
</Fragment> </Fragment>
} }
</div> </div>

View File

@ -0,0 +1,29 @@
.accordion__label {
position: relative;
display: inline-block;
padding-left: 25px;
color: #495057;
cursor: pointer;
}
.accordion__label:after {
content: "";
position: absolute;
top: 7px;
left: 0;
width: 17px;
height: 10px;
background-image: url("./svg/chevron-down.svg");
background-repeat: no-repeat;
background-position: center;
background-size: 100%;
}
.accordion__label--open:after {
transform: rotate(180deg);
}
.accordion__content {
padding-top: 5px;
color: #495057;
}

View File

@ -0,0 +1,41 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import './Accordion.css';
class Accordion extends Component {
state = {
isOpen: false,
}
handleClick = () => {
this.setState(prevState => ({ isOpen: !prevState.isOpen }));
};
render() {
const accordionClass = this.state.isOpen ? 'accordion__label--open' : '';
return (
<div className="accordion">
<div
className={`accordion__label ${accordionClass}`}
onClick={this.handleClick}
>
{this.props.label}
</div>
{this.state.isOpen && (
<div className="accordion__content">
{this.props.children}
</div>
)}
</div>
);
}
}
Accordion.propTypes = {
children: PropTypes.node.isRequired,
label: PropTypes.string.isRequired,
};
export default Accordion;