diff --git a/libs/importer/src/components/import.component.ts b/libs/importer/src/components/import.component.ts index 557ed86f84..438076c934 100644 --- a/libs/importer/src/components/import.component.ts +++ b/libs/importer/src/components/import.component.ts @@ -196,27 +196,10 @@ export class ImportComponent implements OnInit, OnDestroy { return this.showLastPassToggle && this.formGroup.controls.lastPassType.value === "direct"; } - ngOnInit() { + async ngOnInit() { this.setImportOptions(); - this.organizations$ = concat( - this.organizationService.memberOrganizations$.pipe( - canAccessImportExport(this.i18nService), - map((orgs) => orgs.sort(Utils.getSortFunction(this.i18nService, "name"))), - ), - ); - - combineLatest([ - this.policyService.policyAppliesToActiveUser$(PolicyType.PersonalOwnership), - this.organizations$, - ]) - .pipe(takeUntil(this.destroy$)) - .subscribe(([policyApplies, orgs]) => { - this._importBlockedByPolicy = policyApplies; - if (policyApplies && orgs.length == 0) { - this.formGroup.disable(); - } - }); + await this.initializeOrganizations(); if (this.organizationId) { this.formGroup.controls.vaultSelector.patchValue(this.organizationId); @@ -257,6 +240,37 @@ export class ImportComponent implements OnInit, OnDestroy { .subscribe((value) => { this.format = value; }); + + await this.handlePolicies(); + } + + private async initializeOrganizations() { + this.organizations$ = concat( + this.organizationService.memberOrganizations$.pipe( + canAccessImportExport(this.i18nService), + map((orgs) => orgs.sort(Utils.getSortFunction(this.i18nService, "name"))), + ), + ); + } + + private async handlePolicies() { + combineLatest([ + this.policyService.policyAppliesToActiveUser$(PolicyType.PersonalOwnership), + this.organizations$, + ]) + .pipe(takeUntil(this.destroy$)) + .subscribe(([policyApplies, orgs]) => { + this._importBlockedByPolicy = policyApplies; + if (policyApplies && orgs.length == 0) { + this.formGroup.disable(); + } + + // If there are orgs the user has access to import into set + // the default value to the first org in the collection. + if (policyApplies && orgs.length > 0) { + this.formGroup.controls.vaultSelector.setValue(orgs[0].id); + } + }); } submit = async () => { @@ -291,7 +305,7 @@ export class ImportComponent implements OnInit, OnDestroy { } } - if (this.importBlockedByPolicy) { + if (this.importBlockedByPolicy && this.organizationId == null) { this.platformUtilsService.showToast( "error", null,