2018-02-26 00:11:31 +00:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
|
|
|
|
import { WIFI_SETTINGS_ENDPOINT } from '../constants/Endpoints';
|
2018-03-04 17:36:04 +00:00
|
|
|
import { restComponent } from '../components/RestComponent';
|
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 = {
|
|
|
|
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-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() {
|
2018-03-04 17:53:57 +00:00
|
|
|
const { data, fetched, errorMessage, selectedNetwork } = this.props;
|
2018-02-26 00:11:31 +00:00
|
|
|
return (
|
|
|
|
<SectionContent title="WiFi Settings">
|
2018-03-04 17:36:04 +00:00
|
|
|
<WiFiSettingsForm
|
|
|
|
wifiSettings={data}
|
|
|
|
wifiSettingsFetched={fetched}
|
|
|
|
errorMessage={errorMessage}
|
|
|
|
selectedNetwork={selectedNetwork}
|
2018-03-04 17:53:57 +00:00
|
|
|
deselectNetwork={this.props.deselectNetwork}
|
2018-03-04 17:36:04 +00:00
|
|
|
onSubmit={this.props.saveData}
|
|
|
|
onReset={this.deselectNetworkAndLoadData}
|
|
|
|
handleValueChange={this.props.handleValueChange}
|
|
|
|
handleCheckboxChange={this.props.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);
|