-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: handle campaign validation via post meta field
- Loading branch information
Showing
5 changed files
with
67 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const validateCampaign = campaign => { | ||
const { recipients, settings, status } = campaign || {}; | ||
const { list_id: listId } = recipients || {}; | ||
const { from_name: senderName, reply_to: senderEmail } = settings || {}; | ||
let canPublish = true; | ||
if ( 'sent' === status || 'sending' === status ) { | ||
canPublish = false; | ||
} | ||
if ( ! listId ) { | ||
canPublish = false; | ||
} | ||
if ( ! senderName || ! senderName.length || ! senderEmail || ! senderEmail.length ) { | ||
canPublish = false; | ||
} | ||
return canPublish; | ||
}; | ||
|
||
export const getEditPostPayload = campaign => ( { | ||
meta: { | ||
// This meta field does not have to be registered on the back end, | ||
// as it is not used there. | ||
is_ready_to_send: validateCampaign( campaign ), | ||
}, | ||
} ); |