esp8266-react-framework/interface/src/containers/WiFiSettings.js

70 lines
1.9 KiB
JavaScript
Raw Normal View History

import React, { Component } from 'react';
import PropTypes from 'prop-types';
2019-08-09 17:21:28 +00:00
import { WIFI_SETTINGS_ENDPOINT } from '../constants/Endpoints';
2018-03-04 17:36:04 +00:00
import { restComponent } from '../components/RestComponent';
2019-08-09 17:21:28 +00:00
import LoadingNotification from '../components/LoadingNotification';
import SectionContent from '../components/SectionContent';
import WiFiSettingsForm from '../forms/WiFiSettingsForm';
class WiFiSettings extends Component {
constructor(props) {
super(props);
this.deselectNetworkAndLoadData = this.deselectNetworkAndLoadData.bind(this);
}
componentDidMount() {
2018-03-04 17:53:57 +00:00
const { selectedNetwork } = this.props;
if (selectedNetwork) {
var wifiSettings = {
2019-08-09 17:21:28 +00:00
ssid: selectedNetwork.ssid,
password: "",
hostname: "esp8266-react",
static_ip_config: false,
}
2018-03-04 17:36:04 +00:00
this.props.setData(wifiSettings);
2018-03-04 17:53:57 +00:00
} else {
2018-03-04 17:36:04 +00:00
this.props.loadData();
}
}
2018-03-04 17:36:04 +00:00
deselectNetworkAndLoadData() {
2018-03-04 17:53:57 +00:00
this.props.deselectNetwork();
2018-03-04 17:36:04 +00:00
this.props.loadData();
}
render() {
2019-08-09 17:21:28 +00:00
const { data, fetched, errorMessage, saveData, loadData, handleValueChange, handleCheckboxChange, selectedNetwork, deselectNetwork } = this.props;
return (
<SectionContent title="WiFi Settings">
2019-08-09 17:21:28 +00:00
<LoadingNotification
onReset={loadData}
fetched={fetched}
errorMessage={errorMessage}
render={() =>
<WiFiSettingsForm
wifiSettings={data}
selectedNetwork={selectedNetwork}
deselectNetwork={deselectNetwork}
onSubmit={saveData}
onReset={this.deselectNetworkAndLoadData}
handleValueChange={handleValueChange}
handleCheckboxChange={handleCheckboxChange}
/>
}
/>
</SectionContent>
)
}
}
WiFiSettings.propTypes = {
deselectNetwork: PropTypes.func,
selectedNetwork: PropTypes.object
};
2018-03-04 17:36:04 +00:00
export default restComponent(WIFI_SETTINGS_ENDPOINT, WiFiSettings);