From 6681f189fc8b74e61d0c99f4bd653dcf75bb5685 Mon Sep 17 00:00:00 2001 From: Kailash Nadh Date: Sun, 19 Jan 2020 20:46:25 +0530 Subject: [PATCH] Fix 'send_at' option on the UI and bug in starting scheduled campaigns --- frontend/src/Campaign.js | 11 +++++++++-- frontend/src/constants.js | 2 +- queries.sql | 5 +++-- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/frontend/src/Campaign.js b/frontend/src/Campaign.js index c235282..fc0a7f2 100644 --- a/frontend/src/Campaign.js +++ b/frontend/src/Campaign.js @@ -217,6 +217,8 @@ class TheFormDef extends React.PureComponent { } componentWillReceiveProps(nextProps) { + // On initial load, toggle the send_later switch if the record + // has a "send_at" date. if (nextProps.record.send_at === this.props.record.send_at) { return } @@ -260,6 +262,12 @@ class TheFormDef extends React.PureComponent { values.body = this.props.body values.content_type = this.props.contentType + if (values.send_at) { + values.send_later = true + } else { + values.send_later = false + } + // Create a new campaign. this.setState({ loading: true }) if (!this.props.isSingle) { @@ -303,8 +311,7 @@ class TheFormDef extends React.PureComponent { cs.MethodPut, { ...values, - id: this.props.record.id, - send_at: !this.state.sendLater ? null : values.send_at + id: this.props.record.id } ) .then(resp => { diff --git a/frontend/src/constants.js b/frontend/src/constants.js index 06b95c1..f682e39 100644 --- a/frontend/src/constants.js +++ b/frontend/src/constants.js @@ -1,4 +1,4 @@ -export const DateFormat = "ddd D MMM YYYY, hh:MM A" +export const DateFormat = "ddd D MMM YYYY, hh:mm A" // Data types. export const ModelUsers = "users" diff --git a/queries.sql b/queries.sql index 9c8e459..2ae18d0 100644 --- a/queries.sql +++ b/queries.sql @@ -411,8 +411,9 @@ u AS ( -- For each campaign above, update the to_send count. UPDATE campaigns AS ca SET to_send = co.to_send, - max_subscriber_id = co.max_subscriber_id, - started_at=(CASE WHEN ca.started_at IS NULL THEN NOW() ELSE ca.started_at END) + status = (CASE WHEN status != 'running' THEN 'running' ELSE status END), + max_subscriber_id = co.max_subscriber_id, + started_at=(CASE WHEN ca.started_at IS NULL THEN NOW() ELSE ca.started_at END) FROM (SELECT * FROM counts) co WHERE ca.id = co.campaign_id )