From bc38cdff11a80e3b5ebf873136e37a0d86611a5b Mon Sep 17 00:00:00 2001 From: Shane Melton Date: Wed, 21 Jun 2023 15:11:08 -0700 Subject: [PATCH] [AC-1418] Add api service call to update SM subscription --- .../sm-adjust-subscription.component.ts | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/apps/web/src/app/billing/organizations/secrets-manager/sm-adjust-subscription.component.ts b/apps/web/src/app/billing/organizations/secrets-manager/sm-adjust-subscription.component.ts index 29c343963e6..6edb1e3caed 100644 --- a/apps/web/src/app/billing/organizations/secrets-manager/sm-adjust-subscription.component.ts +++ b/apps/web/src/app/billing/organizations/secrets-manager/sm-adjust-subscription.component.ts @@ -2,6 +2,11 @@ import { Component, EventEmitter, Input, OnDestroy, OnInit, Output } from "@angu import { FormBuilder, Validators } from "@angular/forms"; import { Subject, takeUntil } from "rxjs"; +import { OrganizationApiServiceAbstraction } from "@bitwarden/common/admin-console/abstractions/organization/organization-api.service.abstraction"; +import { OrganizationSubscriptionUpdateRequest } from "@bitwarden/common/billing/models/request/organization-subscription-update.request"; +import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; +import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service"; + export interface SecretsManagerSubscriptionOptions { interval: "year" | "month"; seatCount: number; @@ -64,7 +69,12 @@ export class SecretsManagerAdjustSubscriptionComponent implements OnInit, OnDest return Math.abs((this.formGroup.value.seatLimit ?? 0) * this.options.seatPrice); } - constructor(private formBuilder: FormBuilder) {} + constructor( + private formBuilder: FormBuilder, + private organizationApiService: OrganizationApiServiceAbstraction, + private i18nService: I18nService, + private platformUtilsService: PlatformUtilsService + ) {} ngOnInit() { this.formGroup.valueChanges.pipe(takeUntil(this.destroy$)).subscribe((value) => { @@ -106,7 +116,24 @@ export class SecretsManagerAdjustSubscriptionComponent implements OnInit, OnDest return; } - // TODO: Make the request to update the subscription + const seatAdjustment = this.formGroup.value.seatCount - this.options.seatCount; + const serviceAccountAdjustment = + this.formGroup.value.serviceAccountCount - this.options.serviceAccountCount; + + const request = OrganizationSubscriptionUpdateRequest.forSecretsManager( + seatAdjustment, + serviceAccountAdjustment, + this.formGroup.value.seatLimit, + this.formGroup.value.serviceAccountLimit + ); + + await this.organizationApiService.updateSubscription(this.organizationId, request); + + await this.platformUtilsService.showToast( + "success", + null, + this.i18nService.t("subscriptionUpdated") + ); this.onAdjusted.emit(); };