From 07c6ed3df226c42bfb66984842a86c7f3bcfaa84 Mon Sep 17 00:00:00 2001 From: Christopher Ng Date: Tue, 20 Jul 2021 01:44:03 +0000 Subject: [PATCH] Improve UX Signed-off-by: Christopher Ng --- .../PersonalInfo/EmailSection/Email.vue | 29 ++++++++++++------- .../EmailSection/EmailSection.vue | 10 +++---- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/apps/settings/src/components/PersonalInfo/EmailSection/Email.vue b/apps/settings/src/components/PersonalInfo/EmailSection/Email.vue index 7ae01908013..2c6d34b44f3 100644 --- a/apps/settings/src/components/PersonalInfo/EmailSection/Email.vue +++ b/apps/settings/src/components/PersonalInfo/EmailSection/Email.vue @@ -135,7 +135,10 @@ export default { }, deleteDisabled() { - return !this.containsNoWhitespace(this.email) + if (this.primary) { + return this.email === '' + } + return this.email !== '' && !this.isValid() }, deleteEmailLabel() { @@ -146,6 +149,12 @@ export default { }, }, + mounted() { + if (this.initialEmail === '') { + this.$nextTick(() => this.$refs.email?.focus()) + } + }, + methods: { onEmailChange(e) { this.$emit('update:email', e.target.value) @@ -154,16 +163,16 @@ export default { }, debounceEmailChange: debounce(async function() { - if ((this.$refs.email?.checkValidity() && this.containsNoWhitespace(this.email)) || this.email === '') { + if (this.$refs.email?.checkValidity() || this.email === '') { if (this.primary) { await this.updatePrimaryEmail() } else { - if (this.initialEmail && this.email === '') { - await this.deleteAdditionalEmail() - } else if (this.initialEmail === '') { - await this.addAdditionalEmail() - } else { - await this.updateAdditionalEmail() + if (this.email) { + if (this.initialEmail === '') { + await this.addAdditionalEmail() + } else { + await this.updateAdditionalEmail() + } } } } @@ -218,8 +227,8 @@ export default { } }, - containsNoWhitespace(string) { - return /^\S+$/.test(string) + isValid() { + return /^\S+$/.test(this.email) }, handleDeleteAdditionalEmail(status) { diff --git a/apps/settings/src/components/PersonalInfo/EmailSection/EmailSection.vue b/apps/settings/src/components/PersonalInfo/EmailSection/EmailSection.vue index bcd5973f626..57e9ac60357 100644 --- a/apps/settings/src/components/PersonalInfo/EmailSection/EmailSection.vue +++ b/apps/settings/src/components/PersonalInfo/EmailSection/EmailSection.vue @@ -25,12 +25,12 @@ class="section" @submit.stop.prevent="() => {}"> -