Skip to content
This repository has been archived by the owner on Nov 28, 2022. It is now read-only.

Commit

Permalink
Added send test email button loading states
Browse files Browse the repository at this point in the history
  • Loading branch information
rishabhgrg committed Nov 7, 2019
1 parent 2cde1ea commit c36c7a1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 18 deletions.
30 changes: 18 additions & 12 deletions app/components/gh-post-settings-menu.js
Expand Up @@ -413,18 +413,6 @@ 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'
};
await this.ajax.post(url, options);
},

setEmailSubject(emailSubject) {
// Grab the post and current stored email subject
let post = this.post;
Expand Down Expand Up @@ -560,6 +548,24 @@ export default Component.extend(SettingsMenuMixin, {
this.set('_showThrobbers', true);
}).restartable(),

sendTestEmail: task(function* () {
try {
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'
};
return yield this.ajax.post(url, options);
} catch (error) {
if (error) {
this.notifications.showAPIError(error, {key: 'send.previewEmail'});
}
}
}).drop(),

showError(error) {
// TODO: remove null check once ValidationEngine has been removed
if (error) {
Expand Down
13 changes: 7 additions & 6 deletions app/templates/components/gh-post-settings-menu.hbs
Expand Up @@ -359,12 +359,13 @@
stopEnterKeyDownPropagation=true
data-test-field="email-test"}}

<button type="button" class="gh-btn w-100 mt2"
onclick={{action "sendTestEmail"}} data-test-button="send-test-email">
<span>
Send Test Email
</span>
</button>
{{gh-task-button "Send Test Email"
task=sendTestEmail
successText="Sent"
runningText="Sending..."
class="gh-btn w-100 mt2 gh-btn-icon"
data-test-send-test-mail=true
}}
</div>
</form>
</div>
Expand Down

0 comments on commit c36c7a1

Please sign in to comment.