Fork of the excellent esp8266-react - https://github.com/rjwats/esp8266-react
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
1.7 KiB

  1. import React, { Component } from 'react';
  2. import PropTypes from 'prop-types';
  3. import { WIFI_SETTINGS_ENDPOINT } from '../constants/Endpoints';
  4. import { restComponent } from '../components/RestComponent';
  5. import SectionContent from '../components/SectionContent';
  6. import WiFiSettingsForm from '../forms/WiFiSettingsForm';
  7. class WiFiSettings extends Component {
  8. constructor(props) {
  9. super(props);
  10. this.deselectNetworkAndLoadData = this.deselectNetworkAndLoadData.bind(this);
  11. }
  12. componentDidMount() {
  13. const { selectedNetwork } = this.props;
  14. if (selectedNetwork) {
  15. var wifiSettings = {
  16. ssid:selectedNetwork.ssid,
  17. password:"",
  18. hostname:"esp8266-react",
  19. static_ip_config:false,
  20. }
  21. this.props.setData(wifiSettings);
  22. } else {
  23. this.props.loadData();
  24. }
  25. }
  26. deselectNetworkAndLoadData() {
  27. this.props.deselectNetwork();
  28. this.props.loadData();
  29. }
  30. render() {
  31. const { data, fetched, errorMessage, selectedNetwork } = this.props;
  32. return (
  33. <SectionContent title="WiFi Settings">
  34. <WiFiSettingsForm
  35. wifiSettings={data}
  36. wifiSettingsFetched={fetched}
  37. errorMessage={errorMessage}
  38. selectedNetwork={selectedNetwork}
  39. deselectNetwork={this.props.deselectNetwork}
  40. onSubmit={this.props.saveData}
  41. onReset={this.deselectNetworkAndLoadData}
  42. handleValueChange={this.props.handleValueChange}
  43. handleCheckboxChange={this.props.handleCheckboxChange}
  44. />
  45. </SectionContent>
  46. )
  47. }
  48. }
  49. WiFiSettings.propTypes = {
  50. deselectNetwork: PropTypes.func,
  51. selectedNetwork: PropTypes.object
  52. };
  53. export default restComponent(WIFI_SETTINGS_ENDPOINT, WiFiSettings);