re-enable submit button in finally block

This commit is contained in:
2021-09-07 16:02:09 +02:00
parent d21a5986a8
commit 356c8c0bbd
6 changed files with 98 additions and 64 deletions

View File

@ -56,23 +56,29 @@ export class TenantDetailsComponent implements OnInit {
}
async saveTenant() {
this.submitButton.disabled = true
this.messageService.add("saveTenant")
this.messageService.add(JSON.stringify(this.tenant, undefined, 4))
if (this.tenant.id == 0) {
this.messageService.add("about to insert new tenant")
this.account = {
"id": 0,
"description": `account_${this.tenant.firstname}_${this.tenant.lastname}`
try {
this.submitButton.disabled = true
this.messageService.add("saveTenant")
this.messageService.add(JSON.stringify(this.tenant, undefined, 4))
if (this.tenant.id == 0) {
this.messageService.add("about to insert new tenant")
this.account = {
"id": 0,
"description": `account_${this.tenant.firstname}_${this.tenant.lastname}`
}
this.account = await this.accountService.postAccount(this.account)
this.tenant.account = this.account.id
this.tenant = await this.tenantService.postTenant(this.tenant)
this.messageService.add(`Successfully added account with id ${this.account.id} and tenant with id ${this.tenant.id}`)
} else {
this.messageService.add("about to update existing tenant")
this.tenant = await this.tenantService.putTenant(this.tenant)
this.messageService.add(`Successfully changed tenant with id ${this.tenant.id}`)
}
this.account = await this.accountService.postAccount(this.account)
this.tenant.account = this.account.id
this.tenant = await this.tenantService.postTenant(this.tenant)
this.messageService.add(`Successfully added account with id ${this.account.id} and tenant with id ${this.tenant.id}`)
} else {
this.messageService.add("about to update existing tenant")
this.router.navigate(['/tenants'])
} finally {
this.submitButton.disabled = false
}
this.router.navigate(['/tenants'])
}
ngOnInit(): void {