From 12b698b11dfd40ad951dc3243e14edefe9cd6a04 Mon Sep 17 00:00:00 2001 From: cyprain-okeke <108260115+cyprain-okeke@users.noreply.github.com> Date: Wed, 18 Dec 2024 16:31:16 +0100 Subject: [PATCH] organization status changed code changes (#12249) * organization status changed code changes * Remove the stop so a reconnect can be made --- apps/web/src/app/app.component.ts | 14 ++++++++++++++ .../adjust-payment-dialog.component.ts | 1 - libs/common/src/enums/notification-type.enum.ts | 1 + .../src/models/response/notification.response.ts | 14 ++++++++++++++ libs/common/src/services/notifications.service.ts | 5 +++++ 5 files changed, 34 insertions(+), 1 deletion(-) diff --git a/apps/web/src/app/app.component.ts b/apps/web/src/app/app.component.ts index a1ebd141e1..1075655af9 100644 --- a/apps/web/src/app/app.component.ts +++ b/apps/web/src/app/app.component.ts @@ -243,6 +243,20 @@ export class AppComponent implements OnDestroy, OnInit { // eslint-disable-next-line @typescript-eslint/no-floating-promises this.router.navigate(["/remove-password"]); break; + case "syncOrganizationStatusChanged": { + const { organizationId, enabled } = message; + const organizations = await firstValueFrom(this.organizationService.organizations$); + const organization = organizations.find((org) => org.id === organizationId); + + if (organization) { + const updatedOrganization = { + ...organization, + enabled: enabled, + }; + await this.organizationService.upsert(updatedOrganization); + } + break; + } default: break; } diff --git a/apps/web/src/app/billing/shared/adjust-payment-dialog/adjust-payment-dialog.component.ts b/apps/web/src/app/billing/shared/adjust-payment-dialog/adjust-payment-dialog.component.ts index 1cc9f5b4e0..b8826f0626 100644 --- a/apps/web/src/app/billing/shared/adjust-payment-dialog/adjust-payment-dialog.component.ts +++ b/apps/web/src/app/billing/shared/adjust-payment-dialog/adjust-payment-dialog.component.ts @@ -76,7 +76,6 @@ export class AdjustPaymentDialogComponent { } }); await response; - await new Promise((resolve) => setTimeout(resolve, 10000)); this.toastService.showToast({ variant: "success", title: null, diff --git a/libs/common/src/enums/notification-type.enum.ts b/libs/common/src/enums/notification-type.enum.ts index c5853cbe2c..69cbdff9dd 100644 --- a/libs/common/src/enums/notification-type.enum.ts +++ b/libs/common/src/enums/notification-type.enum.ts @@ -22,4 +22,5 @@ export enum NotificationType { AuthRequestResponse = 16, SyncOrganizations = 17, + SyncOrganizationStatusChanged = 18, } diff --git a/libs/common/src/models/response/notification.response.ts b/libs/common/src/models/response/notification.response.ts index af79b883f0..473e6fc1d1 100644 --- a/libs/common/src/models/response/notification.response.ts +++ b/libs/common/src/models/response/notification.response.ts @@ -42,6 +42,9 @@ export class NotificationResponse extends BaseResponse { case NotificationType.AuthRequestResponse: this.payload = new AuthRequestPushNotification(payload); break; + case NotificationType.SyncOrganizationStatusChanged: + this.payload = new OrganizationStatusPushNotification(payload); + break; default: break; } @@ -112,3 +115,14 @@ export class AuthRequestPushNotification extends BaseResponse { this.userId = this.getResponseProperty("UserId"); } } + +export class OrganizationStatusPushNotification extends BaseResponse { + organizationId: string; + enabled: boolean; + + constructor(response: any) { + super(response); + this.organizationId = this.getResponseProperty("OrganizationId"); + this.enabled = this.getResponseProperty("Enabled"); + } +} diff --git a/libs/common/src/services/notifications.service.ts b/libs/common/src/services/notifications.service.ts index e240886cf2..6f7c5c9f26 100644 --- a/libs/common/src/services/notifications.service.ts +++ b/libs/common/src/services/notifications.service.ts @@ -218,6 +218,11 @@ export class NotificationsService implements NotificationsServiceAbstraction { }); } break; + case NotificationType.SyncOrganizationStatusChanged: + if (isAuthenticated) { + await this.syncService.fullSync(true); + } + break; default: break; }