Skip to content

Commit

Permalink
[SG-753] Keep email after hint component is launched in browser (#3883)
Browse files Browse the repository at this point in the history
* Keep email after hint component is launched in browser

* Use query params instead of state for consistency
  • Loading branch information
differsthecat authored Oct 25, 2022
1 parent 6217960 commit 85e2715
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 deletions.
4 changes: 3 additions & 1 deletion apps/browser/src/popup/accounts/hint.component.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<form #form (ngSubmit)="submit()" [appApiAction]="formPromise">
<header>
<div class="left">
<button type="button" routerLink="/login">{{ "cancel" | i18n }}</button>
<button type="button" routerLink="/login" [queryParams]="{ email: emailSent }">
{{ "cancel" | i18n }}
</button>
</div>
<h1 class="center">
<span class="title">{{ "passwordHint" | i18n }}</span>
Expand Down
32 changes: 28 additions & 4 deletions apps/browser/src/popup/accounts/hint.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Component } from "@angular/core";
import { Router } from "@angular/router";
import { Component, OnInit } from "@angular/core";
import { ActivatedRoute, Router } from "@angular/router";
import { Subject, takeUntil } from "rxjs";

import { HintComponent as BaseHintComponent } from "@bitwarden/angular/components/hint.component";
import { ApiService } from "@bitwarden/common/abstractions/api.service";
Expand All @@ -11,14 +12,37 @@ import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUti
selector: "app-hint",
templateUrl: "hint.component.html",
})
export class HintComponent extends BaseHintComponent {
export class HintComponent extends BaseHintComponent implements OnInit {
emailSent: string;
private destroy$ = new Subject<void>();

constructor(
router: Router,
platformUtilsService: PlatformUtilsService,
i18nService: I18nService,
apiService: ApiService,
logService: LogService
logService: LogService,
private route: ActivatedRoute
) {
super(router, i18nService, apiService, platformUtilsService, logService);

super.onSuccessfulSubmit = async () => {
this.router.navigate([this.successRoute], { queryParams: { email: this.emailSent } });
};
}
ngOnInit() {
this.route?.queryParams.pipe(takeUntil(this.destroy$)).subscribe((params) => {
if (params) {
const queryParamsEmail = params["email"];
if (queryParamsEmail != null && queryParamsEmail.indexOf("@") > -1) {
this.emailSent = this.email = queryParamsEmail;
}
}
});
}

ngOnDestroy(): void {
this.destroy$.next();
this.destroy$.complete();
}
}
7 changes: 6 additions & 1 deletion apps/browser/src/popup/accounts/login.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,12 @@ <h1 class="center">
</div>
</div>
<div class="box-footer">
<button type="button" class="btn link" routerLink="/hint">
<button
type="button"
class="btn link"
routerLink="/hint"
[queryParams]="{ email: loggedEmail }"
>
<b>{{ "getMasterPasswordHint" | i18n }}</b>
</button>
</div>
Expand Down

0 comments on commit 85e2715

Please sign in to comment.