+
+
-
+
diff --git a/apps/web/src/app/auth/settings/account/profile.component.ts b/apps/web/src/app/auth/settings/account/profile.component.ts
index 1b7d7f378a..64c5687c0b 100644
--- a/apps/web/src/app/auth/settings/account/profile.component.ts
+++ b/apps/web/src/app/auth/settings/account/profile.component.ts
@@ -1,4 +1,5 @@
import { ViewChild, ViewContainerRef, Component, OnDestroy, OnInit } from "@angular/core";
+import { FormControl, FormGroup } from "@angular/forms";
import { Subject, takeUntil } from "rxjs";
import { ModalService } from "@bitwarden/angular/services/modal.service";
@@ -6,7 +7,6 @@ import { ApiService } from "@bitwarden/common/abstractions/api.service";
import { UpdateProfileRequest } from "@bitwarden/common/auth/models/request/update-profile.request";
import { ProfileResponse } from "@bitwarden/common/models/response/profile.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 { StateService } from "@bitwarden/common/platform/abstractions/state.service";
@@ -21,16 +21,19 @@ export class ProfileComponent implements OnInit, OnDestroy {
profile: ProfileResponse;
fingerprintMaterial: string;
- formPromise: Promise
;
@ViewChild("avatarModalTemplate", { read: ViewContainerRef, static: true })
avatarModalRef: ViewContainerRef;
private destroy$ = new Subject();
+ protected formGroup = new FormGroup({
+ name: new FormControl(null),
+ email: new FormControl(null),
+ });
+
constructor(
private apiService: ApiService,
private i18nService: I18nService,
private platformUtilsService: PlatformUtilsService,
- private logService: LogService,
private stateService: StateService,
private modalService: ModalService,
) {}
@@ -39,6 +42,15 @@ export class ProfileComponent implements OnInit, OnDestroy {
this.profile = await this.apiService.getProfile();
this.loading = false;
this.fingerprintMaterial = await this.stateService.getUserId();
+ this.formGroup.get("name").setValue(this.profile.name);
+ this.formGroup.get("email").setValue(this.profile.email);
+
+ this.formGroup
+ .get("name")
+ .valueChanges.pipe(takeUntil(this.destroy$))
+ .subscribe((name) => {
+ this.profile.name = name;
+ });
}
async ngOnDestroy() {
@@ -46,7 +58,7 @@ export class ProfileComponent implements OnInit, OnDestroy {
this.destroy$.complete();
}
- async openChangeAvatar() {
+ openChangeAvatar = async () => {
const modalOpened = await this.modalService.openViewRef(
ChangeAvatarComponent,
this.avatarModalRef,
@@ -57,16 +69,14 @@ export class ProfileComponent implements OnInit, OnDestroy {
});
},
);
- }
+ };
- async submit() {
- try {
- const request = new UpdateProfileRequest(this.profile.name, this.profile.masterPasswordHint);
- this.formPromise = this.apiService.putProfile(request);
- await this.formPromise;
- this.platformUtilsService.showToast("success", null, this.i18nService.t("accountUpdated"));
- } catch (e) {
- this.logService.error(e);
- }
- }
+ submit = async () => {
+ const request = new UpdateProfileRequest(
+ this.formGroup.get("name").value,
+ this.profile.masterPasswordHint,
+ );
+ await this.apiService.putProfile(request);
+ this.platformUtilsService.showToast("success", null, this.i18nService.t("accountUpdated"));
+ };
}