From dd2c2b9720fe6870283952af0acd81166a23c1dc Mon Sep 17 00:00:00 2001 From: Hinton Date: Tue, 3 May 2022 11:21:42 +0200 Subject: [PATCH] Update Accounts form to use reactive forms and bit-form-field --- jslib | 2 +- .../settings/account.component.html | 79 ++++++++----------- .../settings/account.component.ts | 31 +++++++- src/app/oss.module.ts | 3 +- 4 files changed, 63 insertions(+), 52 deletions(-) diff --git a/jslib b/jslib index 2e2849b4..597e4594 160000 --- a/jslib +++ b/jslib @@ -1 +1 @@ -Subproject commit 2e2849b4def0534f3f72b7a84c3183ab0b1589f2 +Subproject commit 597e45940a3a96946b9d873fcccc6f90994b7716 diff --git a/src/app/organizations/settings/account.component.html b/src/app/organizations/settings/account.component.html index 8995d8aa..4ad37ba7 100644 --- a/src/app/organizations/settings/account.component.html +++ b/src/app/organizations/settings/account.component.html @@ -14,59 +14,46 @@ #form (ngSubmit)="submit()" [appApiAction]="formPromise" - ngNativeValidate + [formGroup]="formData" >
-
- - -
-
- - -
-
- - -
-
- - -
+ + {{ "organizationName" | i18n }} + + + + + {{ "billingEmail" | i18n }} + + + + + {{ "businessName" | i18n }} + + + + + {{ "identifier" | i18n }} + +
- +
- diff --git a/src/app/organizations/settings/account.component.ts b/src/app/organizations/settings/account.component.ts index ec6b2259..43d22d09 100644 --- a/src/app/organizations/settings/account.component.ts +++ b/src/app/organizations/settings/account.component.ts @@ -1,4 +1,5 @@ import { Component, ViewChild, ViewContainerRef } from "@angular/core"; +import { FormBuilder, Validators } from "@angular/forms"; import { ActivatedRoute, Router } from "@angular/router"; import { ModalService } from "jslib-angular/services/modal.service"; @@ -42,7 +43,15 @@ export class AccountComponent { private organizationId: string; + formData = this.formBuilder.group({ + name: ["", [Validators.required]], + billingEmail: ["", [Validators.required, Validators.email]], + businessName: [], + identifier: [], + }); + constructor( + private formBuilder: FormBuilder, private modalService: ModalService, private apiService: ApiService, private i18nService: I18nService, @@ -56,11 +65,25 @@ export class AccountComponent { async ngOnInit() { this.selfHosted = this.platformUtilsService.isSelfHost(); + + if (this.selfHosted) { + this.formData.disable(); + } else { + this.formData.enable(); + } + this.route.parent.parent.params.subscribe(async (params) => { this.organizationId = params.organizationId; try { this.org = await this.apiService.getOrganization(this.organizationId); this.canUseApi = this.org.useApi; + + this.formData.setValue({ + name: this.org.name, + billingEmail: this.org.billingEmail, + businessName: this.org.businessName, + identifier: this.org.identifier, + }); } catch (e) { this.logService.error(e); } @@ -71,10 +94,10 @@ export class AccountComponent { async submit() { try { const request = new OrganizationUpdateRequest(); - request.name = this.org.name; - request.businessName = this.org.businessName; - request.billingEmail = this.org.billingEmail; - request.identifier = this.org.identifier; + request.name = this.formData.get("name").value; + request.businessName = this.formData.get("businessName").value; + request.billingEmail = this.formData.get("billingEmail").value; + request.identifier = this.formData.get("identifier").value; // Backfill pub/priv key if necessary if (!this.org.hasPublicAndPrivateKeys) { diff --git a/src/app/oss.module.ts b/src/app/oss.module.ts index 4be1f094..bea4c1e4 100644 --- a/src/app/oss.module.ts +++ b/src/app/oss.module.ts @@ -53,7 +53,7 @@ import localeZhTw from "@angular/common/locales/zh-Hant"; import { NgModule } from "@angular/core"; import { FormsModule, ReactiveFormsModule } from "@angular/forms"; import { RouterModule } from "@angular/router"; -import { BadgeModule, ButtonModule } from "@bitwarden/components"; +import { BadgeModule, ButtonModule, FormFieldModule } from "@bitwarden/components"; import { InfiniteScrollModule } from "ngx-infinite-scroll"; import { ToastrModule } from "ngx-toastr"; @@ -280,6 +280,7 @@ registerLocaleData(localeZhTw, "zh-TW"); ToastrModule, BadgeModule, ButtonModule, + FormFieldModule, ], declarations: [ PremiumBadgeComponent,