import React from 'react' import CSSModules from 'browser/lib/CSSModules' import styles from './InfoTab.styl' import ConfigManager from 'browser/main/lib/ConfigManager' import { store } from 'browser/main/store' import AwsMobileAnalyticsConfig from 'browser/main/lib/AwsMobileAnalyticsConfig' import _ from 'lodash' import i18n from 'browser/lib/i18n' const electron = require('electron') const { shell, remote } = electron const appVersion = remote.app.getVersion() class InfoTab extends React.Component { constructor(props) { super(props) this.state = { config: this.props.config, subscriptionFormStatus: 'idle', subscriptionFormErrorMessage: null, subscriptionFormEmail: '' } } componentDidMount() { const { autoUpdateEnabled, amaEnabled } = ConfigManager.get() this.setState({ config: { autoUpdateEnabled, amaEnabled } }) } handleLinkClick(e) { shell.openExternal(e.currentTarget.href) e.preventDefault() } handleConfigChange(e) { const newConfig = { amaEnabled: this.refs.amaEnabled.checked, autoUpdateEnabled: this.refs.autoUpdateEnabled.checked } this.setState({ config: newConfig }) } handleSubscriptionFormSubmit(e) { e.preventDefault() this.setState({ subscriptionFormStatus: 'sending', subscriptionFormErrorMessage: null }) fetch( 'https://boostmails.boostio.co/api/public/lists/5f434dccd05f3160b41c0d49/subscriptions', { headers: { Accept: 'application/json', 'Content-Type': 'application/json' }, method: 'POST', body: JSON.stringify({ email: this.state.subscriptionFormEmail }) } ) .then(response => { if (response.status >= 400) { return response.text().then(text => { throw new Error(text) }) } this.setState({ subscriptionFormStatus: 'done' }) }) .catch(error => { this.setState({ subscriptionFormStatus: 'idle', subscriptionFormErrorMessage: error.message }) }) } handleSubscriptionFormEmailChange(e) { this.setState({ subscriptionFormEmail: e.target.value }) } handleSaveButtonClick(e) { const newConfig = this.state.config if (!newConfig.amaEnabled) { AwsMobileAnalyticsConfig.recordDynamicCustomEvent('DISABLE_AMA') this.setState({ amaMessage: i18n.__('We hope we will gain your trust') }) } else { this.setState({ amaMessage: i18n.__("Thank's for trusting us") }) } _.debounce(() => { this.setState({ amaMessage: '' }) }, 3000)() ConfigManager.set(newConfig) store.dispatch({ type: 'SET_CONFIG', config: newConfig }) } infoMessage() { const { amaMessage } = this.state return amaMessage ?
{amaMessage}
: null } render() { return (Thanks for the subscription!
{this.state.subscriptionFormErrorMessage})}