Skip to content

Commit

Permalink
Autogenerate subscriber name from e-mail on the UI if it's empty. Closes
Browse files Browse the repository at this point in the history
  • Loading branch information
knadh committed Oct 20, 2021
1 parent 0f896c1 commit bc9252f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions frontend/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ export default class Utils {
// https://stackoverflow.com/a/12034334
escapeHTML = (html) => html.replace(/[&<>"'`=/]/g, (s) => htmlEntities[s]);

titleCase = (str) => str[0].toUpperCase() + str.substr(1).toLowerCase();

// UI shortcuts.
confirm = (msg, onConfirm, onCancel) => {
Dialog.confirm({
Expand Down
12 changes: 12 additions & 0 deletions frontend/src/views/SubscriberForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,18 @@ export default Vue.extend({
},
onSubmit() {
// If there is no name, auto-generate one from the e-mail.
if (!this.form.name) {
let name = '';
[name] = this.form.email.toLowerCase().split('@');
if (name.includes('.')) {
this.form.name = name.split('.').map((c) => this.$utils.titleCase(c)).join(' ');
} else {
this.form.name = this.$utils.titleCase(name);
}
}
if (this.isEditing) {
this.updateSubscriber();
return;
Expand Down

0 comments on commit bc9252f

Please sign in to comment.