Added test preview email to post email settings

no issue
This commit is contained in:
Rish 2019-11-05 16:10:24 +07:00
parent b23288a41b
commit caff822706
3 changed files with 32 additions and 18 deletions

View File

@ -15,6 +15,7 @@ export default Component.extend(SettingsMenuMixin, {
feature: service(), feature: service(),
store: service(), store: service(),
config: service(), config: service(),
ajax: service(),
ghostPaths: service(), ghostPaths: service(),
notifications: service(), notifications: service(),
slugGenerator: service(), slugGenerator: service(),
@ -27,6 +28,7 @@ export default Component.extend(SettingsMenuMixin, {
_showSettingsMenu: false, _showSettingsMenu: false,
_showThrobbers: false, _showThrobbers: false,
emailTestScratch: '',
canonicalUrlScratch: alias('post.canonicalUrlScratch'), canonicalUrlScratch: alias('post.canonicalUrlScratch'),
customExcerptScratch: alias('post.customExcerptScratch'), customExcerptScratch: alias('post.customExcerptScratch'),
codeinjectionFootScratch: alias('post.codeinjectionFootScratch'), codeinjectionFootScratch: alias('post.codeinjectionFootScratch'),
@ -46,7 +48,7 @@ export default Component.extend(SettingsMenuMixin, {
twitterDescription: or('twitterDescriptionScratch', 'customExcerptScratch', 'seoDescription'), twitterDescription: or('twitterDescriptionScratch', 'customExcerptScratch', 'seoDescription'),
twitterImage: or('post.twitterImage', 'post.featureImage'), twitterImage: or('post.twitterImage', 'post.featureImage'),
twitterTitle: or('twitterTitleScratch', 'seoTitle'), twitterTitle: or('twitterTitleScratch', 'seoTitle'),
emailSubject: alias('emailSubjectScratch', 'post.title'), emailSubject: or('emailSubjectScratch', 'post.title'),
showVisibilityInput: or('session.user.isOwner', 'session.user.isAdmin', 'session.user.isEditor'), showVisibilityInput: or('session.user.isOwner', 'session.user.isAdmin', 'session.user.isEditor'),
@ -411,6 +413,19 @@ export default Component.extend(SettingsMenuMixin, {
}); });
}, },
async sendTestEmail() {
const resourceId = this.post.id;
const testEmail = this.emailTestScratch;
const url = this.get('ghostPaths.url').api('/email_preview/posts', resourceId);
const data = {emails: [testEmail]};
const options = {
data,
dataType: 'json'
};
console.log('Resource id', resourceId, url, options);
await this.ajax.post(url, options);
},
setEmailSubject(emailSubject) { setEmailSubject(emailSubject) {
// Grab the post and current stored email subject // Grab the post and current stored email subject
let post = this.post; let post = this.post;

View File

@ -22,7 +22,7 @@ export default ModalComponent.extend({
const url = this.get('ghostPaths.url').api('/email_preview/posts', resourceId); const url = this.get('ghostPaths.url').api('/email_preview/posts', resourceId);
let htmlData = this.get('previewHtml'); let htmlData = this.get('previewHtml');
if (!htmlData) { if (!htmlData) {
const response = await this.ajax.request(`${url}`); const response = await this.ajax.request(url);
let [emailPreview] = response.email_previews; let [emailPreview] = response.email_previews;
htmlData = emailPreview.html; htmlData = emailPreview.html;
} }

View File

@ -339,22 +339,21 @@
{{/gh-form-group}} {{/gh-form-group}}
<div class="form-group"> <div class="form-group">
<label>Test and Preview</label> <label>Test and Preview</label>
<div class="gh-twitter-preview"> {{gh-text-input
{{#if twitterImage}} class="post-setting-email-test"
<div class="gh-twitter-preview-image" style={{background-image-style twitterImage}}></div> id="email-test"
{{/if}} name="post-setting-email-test"
<div class="gh-twitter-preview-content"> placeholder=(truncate 'noreply@example.com' 40)
<div class="gh-twitter-preview-title">{{twitterTitle}}</div> value=(readonly emailTestScratch)
<div class="gh-twitter-preview-description">{{truncate twitterDescription 155}}</div> input=(action (mut emailTestScratch) value="target.value")
<div class="gh-twitter-preview-footer"> stopEnterKeyDownPropagation=true
<div class="gh-twitter-preview-footer-left"> data-test-field="email-test"}}
{{config.blogDomain}} <button type="button" class="gh-btn gh-btn-icon w-100 mt4 mb4"
</div> onclick={{action "sendTestEmail"}} data-test-button="send-test-email">
<div class="gh-twitter-preview-footer-right"> <span>
</div> Send Test Email
</div> </span>
</div> </button>
</div>
<button type="button" class="gh-btn gh-btn-icon" <button type="button" class="gh-btn gh-btn-icon"
onclick={{action "toggleEmailPreview"}} data-test-button="toggle-email-preview"> onclick={{action "toggleEmailPreview"}} data-test-button="toggle-email-preview">
<span> <span>