High performance, self-hosted, newsletter and mailing list manager with a modern dashboard. Single binary app.
JavaScript campaigncampaign-managementemail-marketingemail-subscriptionlistmonkmailing-listnewsletternewsletter-managementnewsletter-softwareself-hostedsms-gatewaysmtptransactional-emails
Fix 'send later' switch + date not updating on campaign edit
Kailash Nadh649d1b11f0d4
diff --git a/campaigns.go b/campaigns.goindex b6e1b470..5746a523 100644--- a/campaigns.go+++ b/campaigns.go@@ -22,6 +22,9 @@ import (type campaignReq struct {models.Campaign+ // Indicates if the "send_at" date should be written or set to null.+ SendLater bool `db:"-" json:"send_later"`+// This overrides Campaign.Lists to receive and// write a list of int IDs during creation and updation.// Campaign.Lists is JSONText for sending lists children@@ -271,6 +274,7 @@ func handleUpdateCampaign(c echo.Context) error {o.Body,o.ContentType,o.SendAt,+ o.SendLater,pq.StringArray(normalizeTags(o.Tags)),o.TemplateID,o.ListIDs)diff --git a/frontend/src/Campaign.js b/frontend/src/Campaign.jsindex a15d5d63..582aa4e1 100644--- a/frontend/src/Campaign.js+++ b/frontend/src/Campaign.js@@ -217,14 +217,12 @@ class TheFormDef extends React.PureComponent {}componentWillReceiveProps(nextProps) {- const has = nextProps.isSingle && nextProps.record.send_at !== null- if (!has) {+ if (nextProps.record.send_at === this.props.record.send_at) {return}-- if (this.state.sendLater !== has) {- this.setState({ sendLater: has })- }+ this.setState({+ sendLater: nextProps.isSingle && nextProps.record.send_at !== null+ })}validateEmail = (rule, value, callback) => {@@ -303,7 +301,11 @@ class TheFormDef extends React.PureComponent {cs.ModelCampaigns,cs.Routes.UpdateCampaign,cs.MethodPut,- { ...values, id: this.props.record.id }+ {+ ...values,+ id: this.props.record.id,+ send_at: !this.state.sendLater ? null : values.send_at+ }).then(resp => {notification["success"]({@@ -511,9 +513,7 @@ class TheFormDef extends React.PureComponent {<Form.Item {...formItemLayout} label="Send later?"><Row><Col span={2}>- {getFieldDecorator("send_later", {- defaultChecked: this.props.isSingle- })(+ {getFieldDecorator("send_later")(<Switchdisabled={this.props.formDisabled}checked={this.state.sendLater}diff --git a/queries.sql b/queries.sqlindex 3108f00b..9c8e459c 100644--- a/queries.sql+++ b/queries.sql@@ -463,18 +463,18 @@ WITH camp AS (from_email=(CASE WHEN $4 != '' THEN $4 ELSE from_email END),body=(CASE WHEN $5 != '' THEN $5 ELSE body END),content_type=(CASE WHEN $6 != '' THEN $6::content_type ELSE content_type END),- send_at=(CASE WHEN $7 != '' THEN $7::TIMESTAMP WITH TIME ZONE ELSE send_at END),- tags=(CASE WHEN ARRAY_LENGTH($8::VARCHAR(100)[], 1) > 0 THEN $8 ELSE tags END),- template_id=(CASE WHEN $9 != 0 THEN $9 ELSE template_id END),+ send_at=(CASE WHEN $8 THEN $7::TIMESTAMP WITH TIME ZONE WHEN NOT $8 THEN NULL ELSE send_at END),+ tags=(CASE WHEN ARRAY_LENGTH($9::VARCHAR(100)[], 1) > 0 THEN $9 ELSE tags END),+ template_id=(CASE WHEN $10 != 0 THEN $10 ELSE template_id END),updated_at=NOW()WHERE id = $1 RETURNING id),d AS (-- Reset list relationships- DELETE FROM campaign_lists WHERE campaign_id = $1 AND NOT(list_id = ANY($10))+ DELETE FROM campaign_lists WHERE campaign_id = $1 AND NOT(list_id = ANY($11)))INSERT INTO campaign_lists (campaign_id, list_id, list_name)- (SELECT $1 as campaign_id, id, name FROM lists WHERE id=ANY($10::INT[]))+ (SELECT $1 as campaign_id, id, name FROM lists WHERE id=ANY($11::INT[]))ON CONFLICT (campaign_id, list_id) DO UPDATE SET list_name = EXCLUDED.list_name;-- name: update-campaign-counts