diff --git a/browser/main/modals/PreferencesModal/InfoTab.js b/browser/main/modals/PreferencesModal/InfoTab.js index d4b2a408..88cc935b 100644 --- a/browser/main/modals/PreferencesModal/InfoTab.js +++ b/browser/main/modals/PreferencesModal/InfoTab.js @@ -16,7 +16,10 @@ class InfoTab extends React.Component { super(props) this.state = { - config: this.props.config + config: this.props.config, + subscriptionFormStatus: 'idle', + subscriptionFormErrorMessage: null, + subscriptionFormEmail: '' } } @@ -31,6 +34,48 @@ class InfoTab extends React.Component { 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 = { amaEnabled: this.state.config.amaEnabled @@ -134,6 +179,40 @@ class InfoTab extends React.Component {
+ Thanks for the subscription! ++
+ {this.state.subscriptionFormErrorMessage} ++ )} + +