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