Skip to content

Commit

Permalink
NPE when trying to delete an empty email (#2326)
Browse files Browse the repository at this point in the history
* NPE when trying to delete an empty email

* Check if email is verified to consider it for domain deletion
  • Loading branch information
amontenegro authored Aug 14, 2024
1 parent 1b927db commit 6575e43
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/app/cdk/side-bar/modals/modal-email/modal-email.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -469,20 +469,22 @@ export class ModalEmailComponent implements OnInit, OnDestroy {
this.setNextEmailAsPrimary()
}
const i = this.emails.findIndex((value) => value.putCode === controlKey)
const domain = this.emails[i].value.split('@')[1]
const domain = (this.emails[i].value && this.emails[i].value.includes('@')) ? this.emails[i].value.split('@')[1] : null
this.emails.splice(i, 1)
this.emailsForm.removeControl(controlKey)

const remainingEmailsHaveDomain = this.emails.find(
(email) => email.value.split('@')[1] === domain
)
if (!remainingEmailsHaveDomain) {
this.verifiedDomains = this.verifiedDomains.filter(
(d) => d.value !== domain
if(domain) {
const remainingEmailsHaveDomain = this.emails.find(
(email) => (email) ? (email.verified && email.value.split('@')[1] === domain) : false
)
this.emailsForm.removeControl('domain-' + domain)
} else {
this.updateDomainVisibility(domain)
if (!remainingEmailsHaveDomain) {
this.verifiedDomains = this.verifiedDomains.filter(
(d) => d.value !== domain
)
this.emailsForm.removeControl('domain-' + domain)
} else {
this.updateDomainVisibility(domain)
}
}
}
}
Expand Down

0 comments on commit 6575e43

Please sign in to comment.