1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-21 18:53:29 +00:00

PM-2165 Migrate delete account dialog (#8503)

* PM-2165 Migrate delete account dialog

* PM-2165 Addressed Review comments

* PM-2165 Removed legacy user verfication component and used new one

* PM-2165 Added invalidSecret to form input
This commit is contained in:
KiruthigaManivannan
2024-05-24 12:25:43 +05:30
committed by GitHub
parent f2fcf5ce2e
commit 36c6dc27e5
6 changed files with 48 additions and 61 deletions

View File

@@ -0,0 +1,50 @@
import { DialogRef } from "@angular/cdk/dialog";
import { Component } from "@angular/core";
import { FormBuilder } from "@angular/forms";
import { AccountApiService } from "@bitwarden/common/auth/abstractions/account-api.service";
import { Verification } from "@bitwarden/common/auth/types/verification";
import { ErrorResponse } from "@bitwarden/common/models/response/error.response";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
import { DialogService } from "@bitwarden/components";
@Component({
templateUrl: "delete-account-dialog.component.html",
})
export class DeleteAccountDialogComponent {
deleteForm = this.formBuilder.group({
verification: undefined as Verification | undefined,
});
invalidSecret: boolean = false;
constructor(
private i18nService: I18nService,
private platformUtilsService: PlatformUtilsService,
private formBuilder: FormBuilder,
private accountApiService: AccountApiService,
private dialogRef: DialogRef,
) {}
submit = async () => {
try {
const verification = this.deleteForm.get("verification").value;
await this.accountApiService.deleteAccount(verification);
this.dialogRef.close();
this.platformUtilsService.showToast(
"success",
this.i18nService.t("accountDeleted"),
this.i18nService.t("accountDeletedDesc"),
);
} catch (e) {
if (e instanceof ErrorResponse && e.statusCode === 400) {
this.invalidSecret = true;
}
throw e;
}
};
static open(dialogService: DialogService) {
return dialogService.open(DeleteAccountDialogComponent);
}
}