diff --git a/campaigns.go b/campaigns.go index b6e1b47..5746a52 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.js index a15d5d6..582aa4e 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 {