Skip to content

Commit 6fcd9f6

Browse files
committed
[PM-18721] handle cross-component submit states
1 parent 7601833 commit 6fcd9f6

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed

apps/web/src/app/auth/settings/emergency-access/takeover/emergency-access-takeover-dialog.component.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
[flow]="inputPasswordFlow"
2424
[masterPasswordPolicyOptions]="masterPasswordPolicyOptions"
2525
(onPasswordFormSubmit)="handlePasswordFormSubmit($event)"
26+
(isSubmitting)="handleIsSubmittingChange($event)"
2627
></auth-input-password>
2728
}
2829
</div>

apps/web/src/app/auth/settings/emergency-access/takeover/emergency-access-takeover-dialog.component.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { CommonModule } from "@angular/common";
22
import { Component, Inject, OnInit, ViewChild } from "@angular/core";
3-
import { BehaviorSubject, firstValueFrom } from "rxjs";
3+
import { BehaviorSubject, combineLatest, firstValueFrom, map } from "rxjs";
44

55
import {
66
InputPasswordComponent,
@@ -65,8 +65,15 @@ export class EmergencyAccessTakeoverDialogComponent implements OnInit {
6565
@ViewChild(InputPasswordComponent)
6666
inputPasswordComponent: InputPasswordComponent | undefined = undefined;
6767

68-
private submittingBehaviorSubject = new BehaviorSubject(false);
69-
submitting$ = this.submittingBehaviorSubject.asObservable();
68+
private parentSubmittingBehaviorSubject = new BehaviorSubject(false);
69+
parentSubmitting$ = this.parentSubmittingBehaviorSubject.asObservable();
70+
71+
private childSubmittingBehaviorSubject = new BehaviorSubject(false);
72+
childSubmitting$ = this.childSubmittingBehaviorSubject.asObservable();
73+
74+
submitting$ = combineLatest([this.parentSubmitting$, this.childSubmitting$]).pipe(
75+
map(([parentIsSubmitting, childIsSubmitting]) => parentIsSubmitting || childIsSubmitting),
76+
);
7077

7178
initializing = true;
7279
inputPasswordFlow = InputPasswordFlow.ChangePasswordDelegation;
@@ -105,7 +112,7 @@ export class EmergencyAccessTakeoverDialogComponent implements OnInit {
105112
};
106113

107114
protected async handlePasswordFormSubmit(passwordInputResult: PasswordInputResult) {
108-
this.submittingBehaviorSubject.next(true);
115+
this.parentSubmittingBehaviorSubject.next(true);
109116

110117
try {
111118
await this.emergencyAccessService.takeover(
@@ -122,12 +129,16 @@ export class EmergencyAccessTakeoverDialogComponent implements OnInit {
122129
message: this.i18nService.t("unexpectedError"),
123130
});
124131
} finally {
125-
this.submittingBehaviorSubject.next(false);
132+
this.parentSubmittingBehaviorSubject.next(false);
126133
}
127134

128135
this.dialogRef.close(EmergencyAccessTakeoverDialogResultTypes.Done);
129136
}
130137

138+
protected handleIsSubmittingChange(isSubmitting: boolean) {
139+
this.childSubmittingBehaviorSubject.next(isSubmitting);
140+
}
141+
131142
/**
132143
* Strongly typed helper to open an EmergencyAccessTakeoverDialogComponent
133144
* @param dialogService Instance of the dialog service that will be used to open the dialog

libs/auth/src/angular/input-password/input-password.component.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Component, EventEmitter, Input, OnInit, Output, ViewChild } from "@angular/core";
22
import { ReactiveFormsModule, FormBuilder, Validators, FormControl } from "@angular/forms";
3-
import { BehaviorSubject, firstValueFrom } from "rxjs";
3+
import { firstValueFrom } from "rxjs";
44

55
import { JslibModule } from "@bitwarden/angular/jslib.module";
66
import {
@@ -115,15 +115,13 @@ interface InputPasswordForm {
115115
],
116116
})
117117
export class InputPasswordComponent implements OnInit {
118-
private submittingBehaviorSubject = new BehaviorSubject(false);
119-
submitting$ = this.submittingBehaviorSubject.asObservable();
120-
121118
@ViewChild(PasswordStrengthV2Component) passwordStrengthComponent:
122119
| PasswordStrengthV2Component
123120
| undefined = undefined;
124121

125122
@Output() onPasswordFormSubmit = new EventEmitter<PasswordInputResult>();
126123
@Output() onSecondaryButtonClick = new EventEmitter<void>();
124+
@Output() isSubmitting = new EventEmitter<boolean>();
127125

128126
@Input({ required: true }) flow!: InputPasswordFlow;
129127

@@ -265,15 +263,14 @@ export class InputPasswordComponent implements OnInit {
265263

266264
submit = async () => {
267265
try {
268-
this.submittingBehaviorSubject.next(true);
266+
this.isSubmitting.emit(true);
269267

270268
this.verifyFlow();
271269

272270
this.formGroup.markAllAsTouched();
273271

274272
if (this.formGroup.invalid) {
275273
this.showErrorSummary = true;
276-
this.submittingBehaviorSubject.next(false);
277274
return;
278275
}
279276

@@ -394,7 +391,7 @@ export class InputPasswordComponent implements OnInit {
394391
} catch (e) {
395392
this.validationService.showError(e);
396393
} finally {
397-
this.submittingBehaviorSubject.next(false);
394+
this.isSubmitting.emit(false);
398395
}
399396
};
400397

@@ -451,7 +448,6 @@ export class InputPasswordComponent implements OnInit {
451448
false,
452449
);
453450
if (!newPasswordVerified) {
454-
this.submittingBehaviorSubject.next(false);
455451
return;
456452
}
457453

0 commit comments

Comments
 (0)