diff --git a/src/components/settings/DHCPInfo.js b/src/components/settings/DHCPInfo.js index ddc9d4e..b178b36 100644 --- a/src/components/settings/DHCPInfo.js +++ b/src/components/settings/DHCPInfo.js @@ -11,16 +11,27 @@ import React, { Component } from "react"; import { translate } from "react-i18next"; import { api, ignoreCancel, makeCancelable } from "../../utils"; +import { + Button, + Col, + Form, + FormGroup, + Input, + InputGroup, + InputGroupAddon, + Label +} from "reactstrap"; +import { isPositiveNumber, isValidHostname, isValidIpv4 } from "../../validate"; class DHCPInfo extends Component { state = { - active: "---", - ip_start: "---", - ip_end: "---", - router_ip: "---", - lease_time: "---", - domain: "---", - ipv6_support: "---" + active: false, + ip_start: "", + ip_end: "", + router_ip: "", + lease_time: 24, + domain: "", + ipv6_support: false }; constructor(props) { @@ -45,18 +56,7 @@ class DHCPInfo extends Component { ipv6_support: res.ipv6_support }); }) - .catch(ignoreCancel) - .catch(() => { - this.setState({ - active: "-!-", - ip_start: "-!-", - ip_end: "-!-", - router_ip: "-!-", - lease_time: "-!-", - domain: "-!-", - ipv6_support: "-!-" - }); - }); + .catch(ignoreCancel); } componentDidMount() { @@ -67,25 +67,151 @@ class DHCPInfo extends Component { this.updateHandler.cancel(); } + /** + * Create a function which will update the key in the state with the value + * of the event attribute. + * + * @param key {string} the state to update + * @param attr {string} the event target attribute to use + * @returns {function(Event)} + */ + onChange = (key, attr) => { + return e => + this.setState({ + [key]: e.target[attr] + }); + }; + + /** + * Save changes to DHCP settings + * + * @param e the submit event + */ + saveSettings = e => { + e.preventDefault(); + + // TODO: send settings to API + }; + render() { const { t } = this.props; + const isIpStartValid = isValidIpv4(this.state.ip_start); + const isIpEndValid = isValidIpv4(this.state.ip_end); + const isRouterIpValid = isValidIpv4(this.state.router_ip); + const isLeaseTimeValid = isPositiveNumber(this.state.lease_time); + const isDomainValid = isValidHostname(this.state.domain); + return ( -
- {t("DHCP Active")}: {this.state.active.toString()}
-
- {t("Start IP")}: {this.state.ip_start}
-
- {t("End IP")}: {this.state.ip_end}
-
- {t("Router IP")}: {this.state.router_ip}
-
- {t("Lease Time")}: {this.state.lease_time} h
- {t("Domain")}: {this.state.domain}
-
- {t("IPv6 Support")}: {this.state.ipv6_support.toString()}
-
-
+
);
}
}
diff --git a/src/components/settings/DNSInfo.js b/src/components/settings/DNSInfo.js
index 8a6d9b3..5ecabf6 100644
--- a/src/components/settings/DNSInfo.js
+++ b/src/components/settings/DNSInfo.js
@@ -14,17 +14,17 @@ import { api, ignoreCancel, makeCancelable } from "../../utils";
class DNSInfo extends Component {
state = {
- upstream_dns: ["---"],
+ upstream_dns: [],
conditional_forwarding: {
- enabled: "---",
- router_ip: "---",
- domain: "---"
+ enabled: false,
+ router_ip: "",
+ domain: ""
},
options: {
- fqdn_required: "---",
- bogus_priv: "---",
- dnssec: "---",
- listening_type: "---"
+ fqdn_required: false,
+ bogus_priv: false,
+ dnssec: false,
+ listening_type: "single"
}
};
@@ -42,23 +42,7 @@ class DNSInfo extends Component {
.then(res => {
this.setState(res);
})
- .catch(ignoreCancel)
- .catch(() => {
- this.setState({
- upstream_dns: ["-!-"],
- options: {
- fqdn_required: "-!-",
- bogus_priv: "-!-",
- dnssec: "-!-",
- listening_type: "-!-"
- },
- conditional_forwarding: {
- enabled: "-!-",
- router_ip: "-!-",
- domain: "-!-"
- }
- });
- });
+ .catch(ignoreCancel);
}
componentDidMount() {
diff --git a/src/components/settings/FTLInfo.js b/src/components/settings/FTLInfo.js
index d87d00c..71f4bac 100644
--- a/src/components/settings/FTLInfo.js
+++ b/src/components/settings/FTLInfo.js
@@ -14,9 +14,9 @@ import { api, ignoreCancel, makeCancelable } from "../../utils";
class FTLInfo extends Component {
state = {
- filesize: "---",
- queries: "---",
- sqlite_version: "---"
+ filesize: 0,
+ queries: 0,
+ sqlite_version: ""
};
constructor(props) {
@@ -37,14 +37,7 @@ class FTLInfo extends Component {
sqlite_version: res.sqlite_version
});
})
- .catch(ignoreCancel)
- .catch(() => {
- this.setState({
- queries: "-!-",
- filesize: "-!-",
- sqlite_version: "-!-"
- });
- });
+ .catch(ignoreCancel);
}
componentDidMount() {
diff --git a/src/components/settings/NetworkInfo.js b/src/components/settings/NetworkInfo.js
index d4c7ce2..0cd94af 100644
--- a/src/components/settings/NetworkInfo.js
+++ b/src/components/settings/NetworkInfo.js
@@ -8,17 +8,17 @@
* This file is copyright under the latest version of the EUPL.
* Please see LICENSE file for your rights under this license. */
-import React, { Component, Fragment } from "react";
+import React, { Component } from "react";
import { translate } from "react-i18next";
import { api, ignoreCancel, makeCancelable } from "../../utils";
import { Col, Form, FormGroup, Input, Label } from "reactstrap";
class NetworkInfo extends Component {
state = {
- interface: "---",
- ipv4_address: "---",
- ipv6_address: "---",
- hostname: "---"
+ interface: "",
+ ipv4_address: "",
+ ipv6_address: "",
+ hostname: ""
};
constructor(props) {
@@ -40,15 +40,7 @@ class NetworkInfo extends Component {
hostname: res.hostname
});
})
- .catch(ignoreCancel)
- .catch(() => {
- this.setState({
- interface: "-!-",
- ipv4_address: "-!-",
- ipv6_address: "-!-",
- hostname: "-!-"
- });
- });
+ .catch(ignoreCancel);
}
componentDidMount() {
@@ -63,50 +55,48 @@ class NetworkInfo extends Component {
const { t } = this.props;
return (
-