diff --git a/src/app/layouts/navbar.component.ts b/src/app/layouts/navbar.component.ts index 41585ef448..d93ec65d27 100644 --- a/src/app/layouts/navbar.component.ts +++ b/src/app/layouts/navbar.component.ts @@ -1,5 +1,6 @@ -import { Component, OnInit } from "@angular/core"; +import { Component, NgZone, OnInit } from "@angular/core"; +import { BroadcasterService } from "jslib-common/abstractions/broadcaster.service"; import { I18nService } from "jslib-common/abstractions/i18n.service"; import { MessagingService } from "jslib-common/abstractions/messaging.service"; import { OrganizationService } from "jslib-common/abstractions/organization.service"; @@ -31,7 +32,9 @@ export class NavbarComponent implements OnInit { private providerService: ProviderService, private syncService: SyncService, private organizationService: OrganizationService, - private i18nService: I18nService + private i18nService: I18nService, + private broadcasterService: BroadcasterService, + private ngZone: NgZone ) { this.selfHosted = this.platformUtilsService.isSelfHost(); } @@ -49,8 +52,24 @@ export class NavbarComponent implements OnInit { } this.providers = await this.providerService.getAll(); + this.organizations = await this.buildOrganizations(); + + this.broadcasterService.subscribe(this.constructor.name, async (message: any) => { + this.ngZone.run(async () => { + switch (message.command) { + case "organizationCreated": + if (this.organizations.length < 1) { + this.organizations = await this.buildOrganizations(); + } + break; + } + }); + }); + } + + async buildOrganizations() { const allOrgs = await this.organizationService.getAll(); - this.organizations = allOrgs + return allOrgs .filter((org) => OrgNavigationPermissionsService.canAccessAdmin(org)) .sort(Utils.getSortFunction(this.i18nService, "name")); } diff --git a/src/app/settings/organization-plans.component.ts b/src/app/settings/organization-plans.component.ts index 7096aef184..73da459ebf 100644 --- a/src/app/settings/organization-plans.component.ts +++ b/src/app/settings/organization-plans.component.ts @@ -5,6 +5,7 @@ import { ApiService } from "jslib-common/abstractions/api.service"; import { CryptoService } from "jslib-common/abstractions/crypto.service"; import { I18nService } from "jslib-common/abstractions/i18n.service"; import { LogService } from "jslib-common/abstractions/log.service"; +import { MessagingService } from "jslib-common/abstractions/messaging.service"; import { OrganizationService } from "jslib-common/abstractions/organization.service"; import { PlatformUtilsService } from "jslib-common/abstractions/platformUtils.service"; import { PolicyService } from "jslib-common/abstractions/policy.service"; @@ -68,7 +69,8 @@ export class OrganizationPlansComponent implements OnInit { private syncService: SyncService, private policyService: PolicyService, private organizationService: OrganizationService, - private logService: LogService + private logService: LogService, + private messagingService: MessagingService ) { this.selfHosted = platformUtilsService.isSelfHost(); } @@ -298,6 +300,7 @@ export class OrganizationPlansComponent implements OnInit { this.formPromise = doSubmit(); const organizationId = await this.formPromise; this.onSuccess.emit({ organizationId: organizationId }); + this.messagingService.send("organizationCreated", organizationId); } catch (e) { this.logService.error(e); }