Fix logic for email address text field * Update the state of the button for every change to the email in the textfield so it is disabled as soon as the email is not valid or new anymore. * Make empty string the default value of the textfield email instead of undefined if serviceuser has no email set. * Make empty string a valid email if serviceuser already has an email set. To make it possible to remove email from serviceuser. Change-Id: I1cc5ae58d97db64af58ac95e895cffe11efe967d
diff --git a/web/gr-serviceuser-detail.ts b/web/gr-serviceuser-detail.ts index e2d4f94..befa4dd 100644 --- a/web/gr-serviceuser-detail.ts +++ b/web/gr-serviceuser-detail.ts
@@ -88,7 +88,7 @@ fullName?: String; @property({type: String}) - email?: String; + email = ''; @property({type: Array}) availableOwners?: Array<GroupInfo>; @@ -273,7 +273,7 @@ type="text" class="wide" .value="${this.email}" - .placeholder="${this.serviceUser?.email}" + .placeholder="${this.serviceUser.email ?? ''}" ?disabled="${this.changingPrefs}" @input="${this.emailChanged}" /> @@ -345,7 +345,7 @@ this.computeStatusButtonText(); this.loading = false; this.fullName = this.serviceUser?.name; - this.email = this.serviceUser?.email; + this.email = this.serviceUser.email ?? ''; this.owner = this.getCurrentOwnerGroup() ?? NOT_FOUND_MESSAGE; }); } @@ -457,11 +457,11 @@ : NOT_FOUND_MESSAGE; } - private isEmailValid(email: String) { - if (!email) { - return false; + private isNewValidEmail(email: String) { + if (!this.serviceUser.email) { + return email.includes('@'); } - return email.includes('@'); + return email !== this.serviceUser.email && (email.includes('@') || email.length === 0); } private getGroupSuggestions(input: String) { @@ -506,11 +506,8 @@ } private emailChanged() { - const newEmail = this.serviceUserEmailInput.value; - if (this.isEmailValid(newEmail)) { - this.email = this.serviceUserEmailInput.value; - this.computePrefsChanged(); - } + this.email = this.serviceUserEmailInput.value; + this.computePrefsChanged(); } private ownerChanged() { @@ -530,7 +527,7 @@ if ( this.owner === this.getCurrentOwnerGroup() && - this.email === this.serviceUser.email && + !this.isNewValidEmail(this.email) && this.fullName === this.serviceUser.name ) { this.prefsChanged = false; @@ -548,7 +545,7 @@ } private applyNewEmail() { - if (!this.isEmailValid(this.email ?? '')) { + if (!this.isNewValidEmail(this.email)) { return; } return this.pluginRestApi.put(