* 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_table_hostname": "Hostname",
"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",
"dashboard": "Dashboard",
"settings": "Settings",

View file

@ -7,6 +7,7 @@ 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) => {
@ -60,14 +61,17 @@ class Dhcp extends Component {
);
}
getActiveDhcpMessage = () => {
const { active } = this.props.dhcp;
getActiveDhcpMessage = (t, active) => {
if (active) {
if (active.error) {
return (
<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>
);
}
@ -90,6 +94,18 @@ class Dhcp extends Component {
return '';
}
getDhcpWarning = (active) => {
if (active && active.found === false) {
return '';
}
return (
<div className="text-danger">
<Trans>dhcp_warning</Trans>
</div>
);
}
render() {
const { t, dhcp } = this.props;
const statusButtonClass = classnames({
@ -138,10 +154,8 @@ class Dhcp extends Component {
<Trans>check_dhcp_servers</Trans>
</button>
</div>
{this.getActiveDhcpMessage()}
<div className="text-danger">
<Trans>dhcp_warning</Trans>
</div>
{this.getActiveDhcpMessage(t, dhcp.active)}
{this.getDhcpWarning(dhcp.active)}
</Fragment>
}
</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;