From c79785e09b4af0ca453663c07359e10b1ef03521 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Mon, 16 Nov 2020 19:05:41 +0100 Subject: subscription form seemingly working --- .../app/views/viewer/forms/subscription.actions.js | 8 ++------ .../frontend/app/views/viewer/forms/subscription.form.js | 16 ++++++++++++---- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/animism-align/frontend/app/views/viewer/forms/subscription.actions.js b/animism-align/frontend/app/views/viewer/forms/subscription.actions.js index bf7a30e..f1257b2 100644 --- a/animism-align/frontend/app/views/viewer/forms/subscription.actions.js +++ b/animism-align/frontend/app/views/viewer/forms/subscription.actions.js @@ -10,10 +10,6 @@ export const subscribe = email => { body: data, }) .then(res => res.json()) - .then(res => { - return res - }) - .catch(err => { - return err - }) + .then(res => res) + .catch(err => err) } diff --git a/animism-align/frontend/app/views/viewer/forms/subscription.form.js b/animism-align/frontend/app/views/viewer/forms/subscription.form.js index 9c84614..956941b 100644 --- a/animism-align/frontend/app/views/viewer/forms/subscription.form.js +++ b/animism-align/frontend/app/views/viewer/forms/subscription.form.js @@ -12,6 +12,7 @@ const initialState = { email: "", agreed: false, subscribed: false, + success: false, loading: false, } @@ -47,13 +48,16 @@ export default class SubscriptionForm extends Component { if (ENV_PRODUCTION) { this.setState({ loading: true }) subscriptionActions.subscribe(this.state.email) - .then(() => { - this.setState({ loading: false, subscribed: true }) + .then(res => { + this.setState({ loading: false, subscribed: true, success: res.ok }) + }) + .catch(err => { + this.setState({ loading: false, subscribed: true, success: false }) }) } else { this.setState({ loading: true }) setTimeout(() => { - this.setState({ loading: false, subscribed: true }) + this.setState({ loading: false, subscribed: true, success: true }) }, 1000) } } @@ -107,7 +111,11 @@ export default class SubscriptionForm extends Component {
- Thanks! You will receive an email soon confirming your subscription. + {this.state.success ? ( + "Thanks! You will receive an email soon confirming your subscription." + ) : ( + "Sorry, there was a problem adding your subscription." + )}
-- cgit v1.2.3-70-g09d2