Fix 'send later' switch + date not updating on campaign edit
This commit is contained in:
parent
d0a7c3baf7
commit
649d1b11f0
|
@ -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)
|
||||
|
|
|
@ -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")(
|
||||
<Switch
|
||||
disabled={this.props.formDisabled}
|
||||
checked={this.state.sendLater}
|
||||
|
|
10
queries.sql
10
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
|
||||
|
|
Loading…
Reference in New Issue