diff --git a/apps/web/src/app/settings/domain-rules.component.html b/apps/web/src/app/settings/domain-rules.component.html index be6ac851c4..18091bcc3a 100644 --- a/apps/web/src/app/settings/domain-rules.component.html +++ b/apps/web/src/app/settings/domain-rules.component.html @@ -1,109 +1,89 @@ - {{ "domainRulesDesc" | i18n }} - - {{ "customEqDomains" | i18n }} - + {{ "domainRulesDesc" | i18n }} + + {{ "customEqDomains" | i18n }} + - {{ "loading" | i18n }} + {{ "loading" | i18n }} - - - - {{ - "customDomainX" | i18n: i + 1 - }} + + + + {{ "customDomainX" | i18n: i + 1 }} - + - - + > - + {{ "newCustomDomain" | i18n }} - {{ "newCustomDomainDesc" | i18n }} + {{ "newCustomDomainDesc" | i18n }} - - - {{ "save" | i18n }} + + {{ "save" | i18n }} - {{ "globalEqDomains" | i18n }} - + {{ "globalEqDomains" | i18n }} + - {{ "loading" | i18n }} + {{ "loading" | i18n }} - 0"> - - - {{ d.domains }} - - - - - - - - - {{ "exclude" | i18n }} - - - - {{ "include" | i18n }} - - - - {{ "customize" | i18n }} - - - + 0"> + + + {{ d.domains }} + + + + + + {{ "exclude" | i18n }} + + + + {{ "include" | i18n }} + + + + {{ "customize" | i18n }} + + - - - - - {{ "save" | i18n }} + + + + {{ "save" | i18n }} diff --git a/apps/web/src/app/settings/domain-rules.component.ts b/apps/web/src/app/settings/domain-rules.component.ts index 6c9394d591..27049c0f65 100644 --- a/apps/web/src/app/settings/domain-rules.component.ts +++ b/apps/web/src/app/settings/domain-rules.component.ts @@ -1,4 +1,5 @@ import { Component, OnInit } from "@angular/core"; +import { FormArray, FormBuilder, FormControl, FormGroup } from "@angular/forms"; import { ApiService } from "@bitwarden/common/abstractions/api.service"; import { UpdateDomainsRequest } from "@bitwarden/common/models/request/update-domains.request"; @@ -15,12 +16,15 @@ export class DomainRulesComponent implements OnInit { custom: string[] = []; global: any[] = []; formPromise: Promise; - + formGroup: FormGroup<{ customDomain: FormArray> }> = this.formBuilder.group({ + customDomain: this.formBuilder.array([]), + }); constructor( private apiService: ApiService, private i18nService: I18nService, private platformUtilsService: PlatformUtilsService, private logService: LogService, + private formBuilder: FormBuilder, ) {} async ngOnInit() { @@ -38,8 +42,21 @@ export class DomainRulesComponent implements OnInit { }; }); } + this.patch(); + } + patch() { + const control = this.formGroup.get("customDomain"); + control.clear(); + this.custom.forEach((val, index) => { + control.insert(index, this.patchValues(val)); + }); + this.formGroup.updateValueAndValidity(); + } + patchValues(customDomain: string) { + return this.formBuilder.group({ + domain: [customDomain], + }); } - toggleExcluded(globalDomain: any) { globalDomain.excluded = !globalDomain.excluded; } @@ -47,17 +64,22 @@ export class DomainRulesComponent implements OnInit { customize(globalDomain: any) { globalDomain.excluded = true; this.custom.push(globalDomain.domains); + this.patch(); } remove(index: number) { this.custom.splice(index, 1); + this.patch(); } add() { this.custom.push(""); + this.patch(); } - async submit() { + submit = async () => { + const customDomainValues = this.formGroup.get("customDomain").value; + this.custom = customDomainValues.map((d) => d.domain); const request = new UpdateDomainsRequest(); request.excludedGlobalEquivalentDomains = this.global .filter((d) => d.excluded) @@ -72,14 +94,9 @@ export class DomainRulesComponent implements OnInit { request.equivalentDomains = null; } - try { - this.formPromise = this.apiService.putSettingsDomains(request); - await this.formPromise; - this.platformUtilsService.showToast("success", null, this.i18nService.t("domainsUpdated")); - } catch (e) { - this.logService.error(e); - } - } + await this.apiService.putSettingsDomains(request); + this.platformUtilsService.showToast("success", null, this.i18nService.t("domainsUpdated")); + }; indexTrackBy(index: number, obj: any): any { return index;
{{ "domainRulesDesc" | i18n }}
+
- {{ "loading" | i18n }} + {{ "loading" | i18n }}