\ No newline at end of file
diff --git a/ghost/admin/app/components/modal-post-preview/browser.js b/ghost/admin/app/components/modal-post-preview/browser.js
new file mode 100644
index 0000000000..c19a5f3c52
--- /dev/null
+++ b/ghost/admin/app/components/modal-post-preview/browser.js
@@ -0,0 +1,12 @@
+import Component from '@glimmer/component';
+import copyTextToClipboard from 'ghost-admin/utils/copy-text-to-clipboard';
+import {task} from 'ember-concurrency-decorators';
+import {timeout} from 'ember-concurrency';
+
+export default class ModalPostPreviewBrowserComponent extends Component {
+ @task
+ *copyPreviewUrl() {
+ copyTextToClipboard(this.args.post.previewUrl);
+ yield timeout(this.isTesting ? 50 : 3000);
+ }
+}
diff --git a/ghost/admin/app/components/modal-post-preview/desktop.hbs b/ghost/admin/app/components/modal-post-preview/desktop.hbs
deleted file mode 100644
index 9e6e183b0e..0000000000
--- a/ghost/admin/app/components/modal-post-preview/desktop.hbs
+++ /dev/null
@@ -1,5 +0,0 @@
-
-
-
-
-
\ No newline at end of file
diff --git a/ghost/admin/app/components/modal-post-preview/email.hbs b/ghost/admin/app/components/modal-post-preview/email.hbs
index 363cb50033..124c3a1be1 100644
--- a/ghost/admin/app/components/modal-post-preview/email.hbs
+++ b/ghost/admin/app/components/modal-post-preview/email.hbs
@@ -1,4 +1,4 @@
-
+
@@ -10,4 +10,26 @@
+
+
+ Send a preview newsletter
+
+
+
+ {{#if this.sendPreviewEmailError}}
+
{{this.sendPreviewEmailError}}
+ {{/if}}
+
+
\ No newline at end of file
diff --git a/ghost/admin/app/components/modal-post-preview/email.js b/ghost/admin/app/components/modal-post-preview/email.js
index 9bfdd22752..8f9d087a24 100644
--- a/ghost/admin/app/components/modal-post-preview/email.js
+++ b/ghost/admin/app/components/modal-post-preview/email.js
@@ -1,6 +1,9 @@
import Component from '@glimmer/component';
+import validator from 'validator';
import {action} from '@ember/object';
+import {htmlSafe} from '@ember/string';
import {inject as service} from '@ember/service';
+import {task} from 'ember-concurrency-decorators';
import {timeout} from 'ember-concurrency';
import {tracked} from '@glimmer/tracking';
@@ -24,6 +27,15 @@ export default class ModalPostPreviewEmailComponent extends Component {
@tracked html = '';
@tracked subject = '';
+ @tracked emailPreviewAddress = '';
+ @tracked sendPreviewEmailError = '';
+
+ get mailgunIsEnabled() {
+ return this.config.get('mailgunIsConfigured') ||
+ this.settings.get('mailgunApiKey') &&
+ this.settings.get('mailgunDomain') &&
+ this.settings.get('mailgunBaseUrl');
+ }
@action
async renderEmailPreview(iframe) {
@@ -38,6 +50,46 @@ export default class ModalPostPreviewEmailComponent extends Component {
}
}
+ @task({drop: true})
+ *sendPreviewEmailTask() {
+ try {
+ const resourceId = this.post.id;
+ const testEmail = this.emailPreviewAddress.trim();
+
+ if (!validator.isEmail(testEmail)) {
+ this.sendPreviewEmailError = 'Please enter a valid email';
+ return false;
+ }
+ if (!this.mailgunIsEnabled) {
+ this.sendPreviewEmailError = 'Please verify your email settings';
+ return false;
+ }
+ this.sendPreviewEmailError = '';
+
+ const url = this.ghostPaths.url.api('/email_preview/posts', resourceId);
+ const data = {emails: [testEmail]};
+ const options = {
+ data,
+ dataType: 'json'
+ };
+
+ return yield this.ajax.post(url, options);
+ } catch (error) {
+ if (error) {
+ let message = 'Email could not be sent, verify mail settings';
+
+ // grab custom error message if present
+ if (
+ error.payload && error.payload.errors
+ && error.payload.errors[0] && error.payload.errors[0].message) {
+ message = htmlSafe(error.payload.errors[0].message);
+ }
+
+ this.sendPreviewEmailError = message;
+ }
+ }
+ }
+
async _fetchEmailData() {
let {html, subject} = this;
let {post} = this.args;
diff --git a/ghost/admin/app/components/modal-post-preview/social.hbs b/ghost/admin/app/components/modal-post-preview/social.hbs
index e69de29bb2..94fdf9b012 100644
--- a/ghost/admin/app/components/modal-post-preview/social.hbs
+++ b/ghost/admin/app/components/modal-post-preview/social.hbs
@@ -0,0 +1,42 @@
+
+