Skip to content

Commit

Permalink
Fix to delete multiple access codes
Browse files Browse the repository at this point in the history
  • Loading branch information
jggoebel committed Nov 9, 2023
1 parent e3335ac commit a079754
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,22 +309,26 @@ export class AppComponent implements OnInit {
this.accesscodes.splice(acIndex, 1);
}

public deleteAccessCode(a: string) {
public deleteAccessCode(a: string): Promise<ServerResponse> {
// Wrap the observable in a Promise
return new Promise((resolve, reject) => {
this.userService.deleteAccessCode(a).subscribe({
next: (s: ServerResponse) => {
this.accessCodeSuccessAlert = s.message + ' deleted.';
this.accessCodeSuccessClosed = false;
this._removeAccessCode(a);
setTimeout(() => (this.accessCodeSuccessClosed = true), 2000);
resolve(s); // Resolve the Promise with the success response
},
error: (s: ServerResponse) => {
// failure
this.accessCodeDangerAlert = s.message;
this.accessCodeDangerClosed = false;
setTimeout(() => (this.accessCodeDangerClosed = true), 2000);
reject(s); // Reject the Promise with the error response
},
});
}
});
}

public doSaveSettings() {
this.settingsService.update(this.settingsForm.value).subscribe({
Expand Down Expand Up @@ -385,12 +389,13 @@ export class AppComponent implements OnInit {
public accessCodeSelectedForDeletion(a: string[]) {
this.selectedAccesscodesForDeletion = a;
}
public deleteAccessCodes() {
this.selectedAccesscodesForDeletion.forEach((element) =>
this.deleteAccessCode(element),
);
public async deleteAccessCodes() {
for (const element of this.selectedAccesscodesForDeletion) {
await this.deleteAccessCode(element);
}
this.alertDeleteAccessCodeModal = false;
}

public enableDarkMode() {
document.body.classList.add('darkmode');
}
Expand Down

0 comments on commit a079754

Please sign in to comment.