From 36c6dc27e5fc707b6539c340e8d8c0016d43587c Mon Sep 17 00:00:00 2001 From: KiruthigaManivannan <162679756+KiruthigaManivannan@users.noreply.github.com> Date: Fri, 24 May 2024 12:25:43 +0530 Subject: [PATCH] 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 --- .../settings/account/account.component.html | 3 +- .../settings/account/account.component.ts | 11 +++--- .../delete-account-dialog.component.html | 21 ++++++++++ ....ts => delete-account-dialog.component.ts} | 29 ++++++++------ .../account/delete-account.component.html | 39 ------------------- .../src/app/shared/loose-components.module.ts | 6 +-- 6 files changed, 48 insertions(+), 61 deletions(-) create mode 100644 apps/web/src/app/auth/settings/account/delete-account-dialog.component.html rename apps/web/src/app/auth/settings/account/{delete-account.component.ts => delete-account-dialog.component.ts} (59%) delete mode 100644 apps/web/src/app/auth/settings/account/delete-account.component.html diff --git a/apps/web/src/app/auth/settings/account/account.component.html b/apps/web/src/app/auth/settings/account/account.component.html index a521061194..c176469371 100644 --- a/apps/web/src/app/auth/settings/account/account.component.html +++ b/apps/web/src/app/auth/settings/account/account.component.html @@ -15,13 +15,12 @@ - - diff --git a/apps/web/src/app/auth/settings/account/account.component.ts b/apps/web/src/app/auth/settings/account/account.component.ts index e005298030..bd49eb36af 100644 --- a/apps/web/src/app/auth/settings/account/account.component.ts +++ b/apps/web/src/app/auth/settings/account/account.component.ts @@ -8,7 +8,7 @@ import { DialogService } from "@bitwarden/components"; import { PurgeVaultComponent } from "../../../vault/settings/purge-vault.component"; import { DeauthorizeSessionsComponent } from "./deauthorize-sessions.component"; -import { DeleteAccountComponent } from "./delete-account.component"; +import { DeleteAccountDialogComponent } from "./delete-account-dialog.component"; @Component({ selector: "app-account", @@ -17,8 +17,6 @@ import { DeleteAccountComponent } from "./delete-account.component"; export class AccountComponent { @ViewChild("deauthorizeSessionsTemplate", { read: ViewContainerRef, static: true }) deauthModalRef: ViewContainerRef; - @ViewChild("deleteAccountTemplate", { read: ViewContainerRef, static: true }) - deleteModalRef: ViewContainerRef; showChangeEmail = true; @@ -41,7 +39,8 @@ export class AccountComponent { await lastValueFrom(dialogRef.closed); }; - async deleteAccount() { - await this.modalService.openViewRef(DeleteAccountComponent, this.deleteModalRef); - } + deleteAccount = async () => { + const dialogRef = DeleteAccountDialogComponent.open(this.dialogService); + await lastValueFrom(dialogRef.closed); + }; } diff --git a/apps/web/src/app/auth/settings/account/delete-account-dialog.component.html b/apps/web/src/app/auth/settings/account/delete-account-dialog.component.html new file mode 100644 index 0000000000..93fec807ba --- /dev/null +++ b/apps/web/src/app/auth/settings/account/delete-account-dialog.component.html @@ -0,0 +1,21 @@ +
+ + +

{{ "deleteAccountDesc" | i18n }}

+ {{ "deleteAccountWarning" | i18n }} + +
+ + + + +
+
diff --git a/apps/web/src/app/auth/settings/account/delete-account.component.ts b/apps/web/src/app/auth/settings/account/delete-account-dialog.component.ts similarity index 59% rename from apps/web/src/app/auth/settings/account/delete-account.component.ts rename to apps/web/src/app/auth/settings/account/delete-account-dialog.component.ts index daee917401..b3dd8fbe61 100644 --- a/apps/web/src/app/auth/settings/account/delete-account.component.ts +++ b/apps/web/src/app/auth/settings/account/delete-account-dialog.component.ts @@ -1,43 +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 { LogService } from "@bitwarden/common/platform/abstractions/log.service"; import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service"; +import { DialogService } from "@bitwarden/components"; @Component({ - selector: "app-delete-account", - templateUrl: "delete-account.component.html", + templateUrl: "delete-account-dialog.component.html", }) -export class DeleteAccountComponent { - formPromise: Promise; - +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 logService: LogService, + private dialogRef: DialogRef, ) {} - async submit() { + submit = async () => { try { const verification = this.deleteForm.get("verification").value; - this.formPromise = this.accountApiService.deleteAccount(verification); - await this.formPromise; + await this.accountApiService.deleteAccount(verification); + this.dialogRef.close(); this.platformUtilsService.showToast( "success", this.i18nService.t("accountDeleted"), this.i18nService.t("accountDeletedDesc"), ); } catch (e) { - this.logService.error(e); + if (e instanceof ErrorResponse && e.statusCode === 400) { + this.invalidSecret = true; + } + throw e; } + }; + + static open(dialogService: DialogService) { + return dialogService.open(DeleteAccountDialogComponent); } } diff --git a/apps/web/src/app/auth/settings/account/delete-account.component.html b/apps/web/src/app/auth/settings/account/delete-account.component.html deleted file mode 100644 index c2fbbe9e2c..0000000000 --- a/apps/web/src/app/auth/settings/account/delete-account.component.html +++ /dev/null @@ -1,39 +0,0 @@ - diff --git a/apps/web/src/app/shared/loose-components.module.ts b/apps/web/src/app/shared/loose-components.module.ts index ce5f442bd2..cf273ee682 100644 --- a/apps/web/src/app/shared/loose-components.module.ts +++ b/apps/web/src/app/shared/loose-components.module.ts @@ -33,7 +33,7 @@ import { ChangeAvatarComponent } from "../auth/settings/account/change-avatar.co import { ChangeEmailComponent } from "../auth/settings/account/change-email.component"; import { DangerZoneComponent } from "../auth/settings/account/danger-zone.component"; import { DeauthorizeSessionsComponent } from "../auth/settings/account/deauthorize-sessions.component"; -import { DeleteAccountComponent } from "../auth/settings/account/delete-account.component"; +import { DeleteAccountDialogComponent } from "../auth/settings/account/delete-account-dialog.component"; import { ProfileComponent } from "../auth/settings/account/profile.component"; import { EmergencyAccessAttachmentsComponent } from "../auth/settings/emergency-access/attachments/emergency-access-attachments.component"; import { EmergencyAccessConfirmComponent } from "../auth/settings/emergency-access/confirm/emergency-access-confirm.component"; @@ -130,7 +130,7 @@ import { SharedModule } from "./shared.module"; ChangeEmailComponent, CollectionsComponent, DeauthorizeSessionsComponent, - DeleteAccountComponent, + DeleteAccountDialogComponent, DomainRulesComponent, EmergencyAccessAddEditComponent, EmergencyAccessAttachmentsComponent, @@ -203,7 +203,7 @@ import { SharedModule } from "./shared.module"; ChangeEmailComponent, CollectionsComponent, DeauthorizeSessionsComponent, - DeleteAccountComponent, + DeleteAccountDialogComponent, DomainRulesComponent, DynamicAvatarComponent, EmergencyAccessAddEditComponent,