Skip to content

Commit

Permalink
Fix 'send_at' option on the UI and bug in starting scheduled campaigns
Browse files Browse the repository at this point in the history
  • Loading branch information
knadh committed Jan 19, 2020
1 parent 32a543b commit 6681f18
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
11 changes: 9 additions & 2 deletions frontend/src/Campaign.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 => {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/constants.js
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
5 changes: 3 additions & 2 deletions queries.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down

0 comments on commit 6681f18

Please sign in to comment.