Skip to content

Commit

Permalink
Use mithril props for disabling 'send test mail' button while waiting…
Browse files Browse the repository at this point in the history
… for response.
  • Loading branch information
askvortsov1 committed Mar 20, 2020
1 parent 4e2538e commit ca3639b
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions js/src/admin/components/MailPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default class MailPage extends Page {
super.init();

this.saving = false;
this.sendingTest = false;
this.sendingTest = m.prop(false);
this.refresh();
}

Expand Down Expand Up @@ -127,7 +127,7 @@ export default class MailPage extends Page {
type: 'button',
className: 'Button Button--primary',
children: app.translator.trans('core.admin.email.send_test_mail_button'),
disabled: this.sendingTestEmail(),
disabled: this.sendingTest(),
onclick: () => this.sendTestEmail()
})
]
Expand Down Expand Up @@ -162,16 +162,11 @@ export default class MailPage extends Page {
return this.fields.some(key => this.values[key]() !== app.data.settings[key]);
}

sendingTestEmail() {
return this.sendingTest;
}

sendTestEmail() {
if (this.saving || this.sendingTest) return;
if (this.saving || this.sendingTest()) return;

this.sendingTest = true;
this.sendingTest = m.prop(true);
const settings = {};
console.log(this.sendingTest);

this.fields.forEach(key => settings[key] = this.values[key]());

Expand All @@ -180,15 +175,13 @@ export default class MailPage extends Page {
url: app.forum.attribute('apiUrl') + '/mail/test',
data: settings
}).then(response => {
this.sendingTest = false;
this.sendingTest = m.prop(false);
app.alerts.show(new Alert({
type: 'success',
children: app.translator.trans('core.admin.email.send_test_mail_success')
}));
this.sendingTest = false;
console.log(this.sendingTest);
}).catch(error => {
this.sendingTest = false;
this.sendingTest = m.prop(false)
const response = JSON.parse(error.responseText)['message'];
if (Array.isArray(response)) {
response.forEach(errorMessage => {
Expand All @@ -210,7 +203,7 @@ export default class MailPage extends Page {
onsubmit(e) {
e.preventDefault();

if (this.saving || this.sendingTest) return;
if (this.saving || this.sendingTest()) return;

this.saving = true;
app.alerts.dismiss(this.successAlert);
Expand Down

0 comments on commit ca3639b

Please sign in to comment.