1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-15 07:43:35 +00:00
Files
browser/apps/web/src/app/auth/settings/account/delete-account-dialog.component.ts
KiruthigaManivannan 36c6dc27e5 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
2024-05-24 08:55:43 +02:00

51 lines
1.7 KiB
TypeScript

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);
}
}