From 7e3ba087ecae764994e09cdc2fca0a5309a114e2 Mon Sep 17 00:00:00 2001 From: KiruthigaManivannan <162679756+KiruthigaManivannan@users.noreply.github.com> Date: Wed, 19 Jun 2024 21:12:16 +0530 Subject: [PATCH] PM-4950 Migrate Hint Component (#9303) * PM-4950 Migrate Hint Component * PM-4950 Updated Anon layout changes * PM-4950 Addressed review comments * PM-4950 - Tweak form control + add comment. * PM-4950 - Address PR feedback * PM-4950 - Move canActivate up a level. * PM-4950 - Consolidate route under AnonLayoutWrapperComponent path from merging in main. --------- Co-authored-by: Jared Snider <116684653+JaredSnider-Bitwarden@users.noreply.github.com> Co-authored-by: Jared Snider Co-authored-by: Todd Martin --- apps/web/src/app/auth/hint.component.html | 63 ++++++++--------------- apps/web/src/app/auth/hint.component.ts | 26 ++++++++++ apps/web/src/app/oss-routing.module.ts | 25 ++++++--- 3 files changed, 66 insertions(+), 48 deletions(-) diff --git a/apps/web/src/app/auth/hint.component.html b/apps/web/src/app/auth/hint.component.html index 786643d947..9f4d76d840 100644 --- a/apps/web/src/app/auth/hint.component.html +++ b/apps/web/src/app/auth/hint.component.html @@ -1,44 +1,23 @@ -
-
-
-

{{ "passwordHint" | i18n }}

-
-
-
- - - {{ "enterEmailToGetHint" | i18n }} -
-
-
- - - {{ "cancel" | i18n }} - -
-
-
-
+ + + {{ "emailAddress" | i18n }} + + {{ "enterEmailToGetHint" | i18n }} + +
+
+ + + {{ "cancel" | i18n }} +
diff --git a/apps/web/src/app/auth/hint.component.ts b/apps/web/src/app/auth/hint.component.ts index 116b0f3f83..91e9ca5ceb 100644 --- a/apps/web/src/app/auth/hint.component.ts +++ b/apps/web/src/app/auth/hint.component.ts @@ -1,4 +1,5 @@ import { Component } from "@angular/core"; +import { FormBuilder, Validators } from "@angular/forms"; import { Router } from "@angular/router"; import { HintComponent as BaseHintComponent } from "@bitwarden/angular/auth/components/hint.component"; @@ -13,6 +14,14 @@ import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/pl templateUrl: "hint.component.html", }) export class HintComponent extends BaseHintComponent { + formGroup = this.formBuilder.group({ + email: ["", [Validators.email, Validators.required]], + }); + + get emailFormControl() { + return this.formGroup.controls.email; + } + constructor( router: Router, i18nService: I18nService, @@ -20,7 +29,24 @@ export class HintComponent extends BaseHintComponent { platformUtilsService: PlatformUtilsService, logService: LogService, loginEmailService: LoginEmailServiceAbstraction, + private formBuilder: FormBuilder, ) { super(router, i18nService, apiService, platformUtilsService, logService, loginEmailService); } + + ngOnInit(): void { + super.ngOnInit(); + this.emailFormControl.setValue(this.email); + } + + // Wrapper method to call super.submit() since properties (e.g., submit) cannot use super directly + // This is because properties are assigned per type and generally don't have access to the prototype + async superSubmit() { + await super.submit(); + } + + submit = async () => { + this.email = this.emailFormControl.value; + await this.superSubmit(); + }; } diff --git a/apps/web/src/app/oss-routing.module.ts b/apps/web/src/app/oss-routing.module.ts index 7a57f7a1ce..e7236348a6 100644 --- a/apps/web/src/app/oss-routing.module.ts +++ b/apps/web/src/app/oss-routing.module.ts @@ -111,12 +111,6 @@ const routes: Routes = [ component: SetPasswordComponent, data: { titleId: "setMasterPassword" } satisfies DataProperties, }, - { - path: "hint", - component: HintComponent, - canActivate: [UnauthGuard], - data: { titleId: "passwordHint" } satisfies DataProperties, - }, { path: "lock", component: LockComponent, @@ -338,6 +332,25 @@ const routes: Routes = [ }, ], }, + { + path: "hint", + canActivate: [unauthGuardFn()], + children: [ + { + path: "", + component: HintComponent, + data: { + pageTitle: "passwordHint", + titleId: "passwordHint", + } satisfies DataProperties & AnonLayoutWrapperData, + }, + { + path: "", + component: EnvironmentSelectorComponent, + outlet: "environment-selector", + }, + ], + }, { path: "remove-password", component: RemovePasswordComponent,