Fix 'send later' switch + date not updating on campaign edit

This commit is contained in:
Kailash Nadh 2019-08-26 23:45:18 +05:30
parent d0a7c3baf7
commit 649d1b11f0
3 changed files with 19 additions and 15 deletions

View File

@ -22,6 +22,9 @@ import (
type campaignReq struct { type campaignReq struct {
models.Campaign 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 // This overrides Campaign.Lists to receive and
// write a list of int IDs during creation and updation. // write a list of int IDs during creation and updation.
// Campaign.Lists is JSONText for sending lists children // Campaign.Lists is JSONText for sending lists children
@ -271,6 +274,7 @@ func handleUpdateCampaign(c echo.Context) error {
o.Body, o.Body,
o.ContentType, o.ContentType,
o.SendAt, o.SendAt,
o.SendLater,
pq.StringArray(normalizeTags(o.Tags)), pq.StringArray(normalizeTags(o.Tags)),
o.TemplateID, o.TemplateID,
o.ListIDs) o.ListIDs)

View File

@ -217,14 +217,12 @@ class TheFormDef extends React.PureComponent {
} }
componentWillReceiveProps(nextProps) { componentWillReceiveProps(nextProps) {
const has = nextProps.isSingle && nextProps.record.send_at !== null if (nextProps.record.send_at === this.props.record.send_at) {
if (!has) {
return return
} }
this.setState({
if (this.state.sendLater !== has) { sendLater: nextProps.isSingle && nextProps.record.send_at !== null
this.setState({ sendLater: has }) })
}
} }
validateEmail = (rule, value, callback) => { validateEmail = (rule, value, callback) => {
@ -303,7 +301,11 @@ class TheFormDef extends React.PureComponent {
cs.ModelCampaigns, cs.ModelCampaigns,
cs.Routes.UpdateCampaign, cs.Routes.UpdateCampaign,
cs.MethodPut, 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 => { .then(resp => {
notification["success"]({ notification["success"]({
@ -511,9 +513,7 @@ class TheFormDef extends React.PureComponent {
<Form.Item {...formItemLayout} label="Send later?"> <Form.Item {...formItemLayout} label="Send later?">
<Row> <Row>
<Col span={2}> <Col span={2}>
{getFieldDecorator("send_later", { {getFieldDecorator("send_later")(
defaultChecked: this.props.isSingle
})(
<Switch <Switch
disabled={this.props.formDisabled} disabled={this.props.formDisabled}
checked={this.state.sendLater} checked={this.state.sendLater}

View File

@ -463,18 +463,18 @@ WITH camp AS (
from_email=(CASE WHEN $4 != '' THEN $4 ELSE from_email END), from_email=(CASE WHEN $4 != '' THEN $4 ELSE from_email END),
body=(CASE WHEN $5 != '' THEN $5 ELSE body END), body=(CASE WHEN $5 != '' THEN $5 ELSE body END),
content_type=(CASE WHEN $6 != '' THEN $6::content_type ELSE content_type 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), 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($8::VARCHAR(100)[], 1) > 0 THEN $8 ELSE tags END), tags=(CASE WHEN ARRAY_LENGTH($9::VARCHAR(100)[], 1) > 0 THEN $9 ELSE tags END),
template_id=(CASE WHEN $9 != 0 THEN $9 ELSE template_id END), template_id=(CASE WHEN $10 != 0 THEN $10 ELSE template_id END),
updated_at=NOW() updated_at=NOW()
WHERE id = $1 RETURNING id WHERE id = $1 RETURNING id
), ),
d AS ( d AS (
-- Reset list relationships -- 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) 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; ON CONFLICT (campaign_id, list_id) DO UPDATE SET list_name = EXCLUDED.list_name;
-- name: update-campaign-counts -- name: update-campaign-counts