From b38629b4c96970add83d6dff82fa94db3f5b72a8 Mon Sep 17 00:00:00 2001 From: vinith-kovan <156108204+vinith-kovan@users.noreply.github.com> Date: Wed, 26 Jun 2024 23:16:32 +0530 Subject: [PATCH] [AC-2411] migrate account component (#8854) * migrate account component * account component review comment addressed * account component review comment addressed --------- Co-authored-by: Thomas Rittson <31796059+eliykat@users.noreply.github.com> --- .../settings/account.component.html | 9 +-- .../providers/settings/account.component.html | 50 +++++-------- .../providers/settings/account.component.ts | 74 +++++++++++-------- 3 files changed, 64 insertions(+), 69 deletions(-) diff --git a/apps/web/src/app/admin-console/organizations/settings/account.component.html b/apps/web/src/app/admin-console/organizations/settings/account.component.html index e34972d36e..f453546fca 100644 --- a/apps/web/src/app/admin-console/organizations/settings/account.component.html +++ b/apps/web/src/app/admin-console/organizations/settings/account.component.html @@ -1,9 +1,8 @@ -
@@ -37,9 +36,9 @@

{{ "apiKey" | i18n }}

-

+

{{ "apiKeyDesc" | i18n }} - + {{ "learnMore" | i18n }}

@@ -56,7 +55,7 @@ [formGroup]="collectionManagementFormGroup" >

{{ "collectionManagement" | i18n }}

-

{{ "collectionManagementDesc" | i18n }}

+

{{ "collectionManagementDesc" | i18n }}

{{ "allowAdminAccessToAllCollectionItemsDesc" | i18n }} diff --git a/bitwarden_license/bit-web/src/app/admin-console/providers/settings/account.component.html b/bitwarden_license/bit-web/src/app/admin-console/providers/settings/account.component.html index 10f6d14425..a4e4587755 100644 --- a/bitwarden_license/bit-web/src/app/admin-console/providers/settings/account.component.html +++ b/bitwarden_license/bit-web/src/app/admin-console/providers/settings/account.component.html @@ -2,51 +2,35 @@
- {{ "loading" | i18n }} + {{ "loading" | i18n }}
-
-
-
-
- + +
+
+ + {{ "providerName" | i18n }} + + + + {{ "billingEmail" | i18n }} -
-
- - -
+
-
+
- diff --git a/bitwarden_license/bit-web/src/app/admin-console/providers/settings/account.component.ts b/bitwarden_license/bit-web/src/app/admin-console/providers/settings/account.component.ts index e2b8aeaffd..01e863a826 100644 --- a/bitwarden_license/bit-web/src/app/admin-console/providers/settings/account.component.ts +++ b/bitwarden_license/bit-web/src/app/admin-console/providers/settings/account.component.ts @@ -1,5 +1,7 @@ -import { Component } from "@angular/core"; +import { Component, OnDestroy, OnInit } from "@angular/core"; +import { FormBuilder, Validators } from "@angular/forms"; import { ActivatedRoute, Router } from "@angular/router"; +import { Subject, switchMap, takeUntil } from "rxjs"; import { UserVerificationDialogComponent } from "@bitwarden/auth/angular"; import { ApiService } from "@bitwarden/common/abstractions/api.service"; @@ -19,15 +21,18 @@ import { DialogService } from "@bitwarden/components"; templateUrl: "account.component.html", }) // eslint-disable-next-line rxjs-angular/prefer-takeuntil -export class AccountComponent { +export class AccountComponent implements OnDestroy, OnInit { selfHosted = false; loading = true; provider: ProviderResponse; - formPromise: Promise; taxFormPromise: Promise; + private destroy$ = new Subject(); private providerId: string; - + protected formGroup = this.formBuilder.group({ + providerName: ["" as ProviderResponse["name"]], + providerBillingEmail: ["" as ProviderResponse["billingEmail"], Validators.email], + }); protected enableDeleteProvider$ = this.configService.getFeatureFlag$( FeatureFlag.EnableDeleteProvider, ); @@ -42,39 +47,47 @@ export class AccountComponent { private dialogService: DialogService, private configService: ConfigService, private providerApiService: ProviderApiServiceAbstraction, + private formBuilder: FormBuilder, private router: Router, ) {} async ngOnInit() { this.selfHosted = this.platformUtilsService.isSelfHost(); - // eslint-disable-next-line rxjs-angular/prefer-takeuntil, rxjs/no-async-subscribe - this.route.parent.parent.params.subscribe(async (params) => { - this.providerId = params.providerId; - try { - this.provider = await this.providerApiService.getProvider(this.providerId); - } catch (e) { - this.logService.error(`Handled exception: ${e}`); - } - }); - this.loading = false; + this.route.parent.parent.params + .pipe( + switchMap(async (params) => { + this.providerId = params.providerId; + try { + this.provider = await this.providerApiService.getProvider(this.providerId); + this.formGroup.patchValue({ + providerName: this.provider.name, + providerBillingEmail: this.provider.billingEmail, + }); + } catch (e) { + this.logService.error(`Handled exception: ${e}`); + } finally { + this.loading = false; + } + }), + takeUntil(this.destroy$), + ) + .subscribe(); } - - async submit() { - try { - const request = new ProviderUpdateRequest(); - request.name = this.provider.name; - request.businessName = this.provider.businessName; - request.billingEmail = this.provider.billingEmail; - - this.formPromise = this.providerApiService.putProvider(this.providerId, request).then(() => { - return this.syncService.fullSync(true); - }); - await this.formPromise; - this.platformUtilsService.showToast("success", null, this.i18nService.t("providerUpdated")); - } catch (e) { - this.logService.error(`Handled exception: ${e}`); - } + ngOnDestroy() { + this.destroy$.next(); + this.destroy$.complete(); } + submit = async () => { + const request = new ProviderUpdateRequest(); + request.name = this.formGroup.value.providerName; + request.businessName = this.formGroup.value.providerName; + request.billingEmail = this.formGroup.value.providerBillingEmail; + + await this.providerApiService.putProvider(this.providerId, request); + await this.syncService.fullSync(true); + this.provider = await this.providerApiService.getProvider(this.providerId); + this.platformUtilsService.showToast("success", null, this.i18nService.t("providerUpdated")); + }; async deleteProvider() { const providerClients = await this.apiService.getProviderClients(this.providerId); @@ -105,7 +118,6 @@ export class AccountComponent { } catch (e) { this.logService.error(e); } - await this.router.navigate(["/"]); }