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 <jsnider@bitwarden.com>
Co-authored-by: Todd Martin <tmartin@bitwarden.com>
This commit is contained in:
KiruthigaManivannan 2024-06-19 21:12:16 +05:30 committed by GitHub
parent 97002c8852
commit 7e3ba087ec
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 66 additions and 48 deletions

View File

@ -1,44 +1,23 @@
<form #form (ngSubmit)="submit()" [appApiAction]="formPromise" class="container" ngNativeValidate> <form [bitSubmit]="submit" [formGroup]="formGroup">
<div class="row justify-content-md-center mt-5"> <bit-form-field>
<div class="col-5"> <bit-label>{{ "emailAddress" | i18n }}</bit-label>
<p class="lead text-center mb-4">{{ "passwordHint" | i18n }}</p>
<div class="card d-block">
<div class="card-body">
<div class="form-group">
<label for="email">{{ "emailAddress" | i18n }}</label>
<input <input
id="email" bitInput
class="form-control"
type="text"
name="Email"
[(ngModel)]="email"
required
appAutofocus appAutofocus
inputmode="email" inputmode="email"
appInputVerbatim="false" appInputVerbatim="false"
type="email"
formControlName="email"
/> />
<small class="form-text text-muted">{{ "enterEmailToGetHint" | i18n }}</small> <bit-hint>{{ "enterEmailToGetHint" | i18n }}</bit-hint>
</div> </bit-form-field>
<hr /> <hr />
<div class="d-flex"> <div class="tw-flex tw-gap-2">
<button <button type="submit" bitButton bitFormButton buttonType="primary" [block]="true">
type="submit" {{ "submit" | i18n }}
class="btn btn-primary btn-block btn-submit"
[disabled]="form.loading"
>
<span [hidden]="form.loading">{{ "submit" | i18n }}</span>
<i
class="bwi bwi-spinner bwi-spin"
title="{{ 'loading' | i18n }}"
aria-hidden="true"
></i>
</button> </button>
<a routerLink="/login" class="btn btn-outline-secondary btn-block ml-2 mt-0"> <a bitButton buttonType="secondary" routerLink="/login" [block]="true">
{{ "cancel" | i18n }} {{ "cancel" | i18n }}
</a> </a>
</div> </div>
</div>
</div>
</div>
</div>
</form> </form>

View File

@ -1,4 +1,5 @@
import { Component } from "@angular/core"; import { Component } from "@angular/core";
import { FormBuilder, Validators } from "@angular/forms";
import { Router } from "@angular/router"; import { Router } from "@angular/router";
import { HintComponent as BaseHintComponent } from "@bitwarden/angular/auth/components/hint.component"; 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", templateUrl: "hint.component.html",
}) })
export class HintComponent extends BaseHintComponent { export class HintComponent extends BaseHintComponent {
formGroup = this.formBuilder.group({
email: ["", [Validators.email, Validators.required]],
});
get emailFormControl() {
return this.formGroup.controls.email;
}
constructor( constructor(
router: Router, router: Router,
i18nService: I18nService, i18nService: I18nService,
@ -20,7 +29,24 @@ export class HintComponent extends BaseHintComponent {
platformUtilsService: PlatformUtilsService, platformUtilsService: PlatformUtilsService,
logService: LogService, logService: LogService,
loginEmailService: LoginEmailServiceAbstraction, loginEmailService: LoginEmailServiceAbstraction,
private formBuilder: FormBuilder,
) { ) {
super(router, i18nService, apiService, platformUtilsService, logService, loginEmailService); 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();
};
} }

View File

@ -111,12 +111,6 @@ const routes: Routes = [
component: SetPasswordComponent, component: SetPasswordComponent,
data: { titleId: "setMasterPassword" } satisfies DataProperties, data: { titleId: "setMasterPassword" } satisfies DataProperties,
}, },
{
path: "hint",
component: HintComponent,
canActivate: [UnauthGuard],
data: { titleId: "passwordHint" } satisfies DataProperties,
},
{ {
path: "lock", path: "lock",
component: LockComponent, 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", path: "remove-password",
component: RemovePasswordComponent, component: RemovePasswordComponent,