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

Commit

Permalink
Swapped baseUrl input for region selection for bulk email settings
Browse files Browse the repository at this point in the history
no issue

- Mailgun makes it really difficult to find your baseUrl from their UI if you've previously sent emails on a domain
- use a dropdown with flag and region name instead to better match what you can see in their UI
  • Loading branch information
kevinansfield committed Nov 15, 2019
1 parent 52503af commit dfc6efe
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 7 deletions.
29 changes: 28 additions & 1 deletion app/components/gh-members-lab-setting.js
@@ -1,12 +1,26 @@
import Component from '@ember/component';
import {computed} from '@ember/object';
import {inject as service} from '@ember/service';
import {set} from '@ember/object';

const US = {flag: '🇺🇸', name: 'US', baseUrl: 'https://api.mailgun.net/v3'};
const EU = {flag: '🇪🇺', name: 'EU', baseUrl: 'https://api.eu.mailgun.net/v3'};

export default Component.extend({
feature: service(),
config: service(),
mediaQueries: service(),

mailgunRegion: computed('settings.bulkEmailSettings.baseUrl', function () {
if (!this.settings.get('bulkEmailSettings.baseUrl')) {
return US;
}

return [US, EU].find((region) => {
return region.baseUrl === this.settings.get('bulkEmailSettings.baseUrl');
});
}),

blogDomain: computed('config.blogDomain', function () {
let domain = this.config.blogDomain || '';
const host = domain.replace('https://', '').replace('http://', '').split('/');
Expand Down Expand Up @@ -35,7 +49,7 @@ export default Component.extend({

bulkEmailSettings: computed('settings.bulkEmailSettings', function () {
let bulkEmailSettings = this.get('settings.bulkEmailSettings') || {};
const {apiKey = '', baseUrl = '', domain = ''} = bulkEmailSettings;
const {apiKey = '', baseUrl = US.baseUrl, domain = ''} = bulkEmailSettings;
return {apiKey, baseUrl, domain};
}),

Expand All @@ -48,13 +62,26 @@ export default Component.extend({
return this.get('settings.defaultContentVisibility');
}),

init() {
this._super(...arguments);
this.set('mailgunRegions', [US, EU]);
},

actions: {
setDefaultContentVisibility(value) {
this.setDefaultContentVisibility(value);
},
setBulkEmailSettings(key, event) {
let bulkEmailSettings = this.get('settings.bulkEmailSettings') || {};
bulkEmailSettings[key] = event.target.value;
if (!bulkEmailSettings.baseUrl) {
set(bulkEmailSettings, 'baseUrl', US.baseUrl);
}
this.setBulkEmailSettings(bulkEmailSettings);
},
setBulkEmailRegion(region) {
let bulkEmailSettings = this.get('settings.bulkEmailSettings') || {};
set(bulkEmailSettings, 'baseUrl', region.baseUrl);
this.setBulkEmailSettings(bulkEmailSettings);
},
setSubscriptionSettings(key, event) {
Expand Down
1 change: 1 addition & 0 deletions app/controllers/settings/labs.js
Expand Up @@ -53,6 +53,7 @@ export default Controller.extend({
jsonMimeType: null,
yamlExtension: null,
yamlMimeType: null,

init() {
this._super(...arguments);
this.importMimeType = IMPORT_MIME_TYPES;
Expand Down
10 changes: 10 additions & 0 deletions app/styles/components/power-select.css
Expand Up @@ -240,3 +240,13 @@
stroke: var(--blue);
fill: var(--blue);
}

/* Inside settings */
/* TODO: make these general styles? */

.form-group .ember-power-select-trigger {
padding: 6px 12px;
}
.form-group .ember-power-select-selected-item {
margin-left: 0;
}
22 changes: 16 additions & 6 deletions app/templates/components/gh-members-lab-setting.hbs
Expand Up @@ -185,14 +185,24 @@
</div>
<div class="f8 fw4 midgrey mt1">Your members will receive system emails from this address</div>
{{/gh-form-group}}

{{#unless hasBulkEmailConfig}}
{{#gh-form-group}}
<label class="fw6 f8">Mailgun base url</label>
{{gh-text-input
value=(readonly bulkEmailSettings.baseUrl)
input=(action "setBulkEmailSettings" "baseUrl")
class="mt1"
}}
<label class="fw6 f8">Mailgun region</label>
<div class="mt1">
{{#power-select
options=this.mailgunRegions
selected=this.mailgunRegion
onchange=(action "setBulkEmailRegion")
searchEnabled=false
as |region|
}}
{{region.flag}} {{region.name}}
{{/power-select}}
</div>
<a href="https://app.mailgun.com/app/sending/domains" target="_blank" class="mt1 fw4 f8">
Find your Mailgun region next to your domain here &raquo;
</a>
{{/gh-form-group}}
{{#gh-form-group}}
<label class="fw6 f8">Mailgun domain</label>
Expand Down

0 comments on commit dfc6efe

Please sign in to comment.