From 204f64b4e7f76cf43a7dbc6161332553047592df Mon Sep 17 00:00:00 2001 From: Shane Melton Date: Wed, 21 Jun 2023 17:38:49 -0700 Subject: [PATCH] [AC-1423] Switch to AddonProductType enum instead of boolean --- ...ganization-subscription-cloud.component.html | 6 ++---- ...organization-subscription-cloud.component.ts | 17 ++++++++++------- .../billing/enums/addon-product-type.enum.ts | 8 ++++++++ .../models/response/subscription.response.ts | 5 +++-- 4 files changed, 23 insertions(+), 13 deletions(-) create mode 100644 libs/common/src/billing/enums/addon-product-type.enum.ts diff --git a/apps/web/src/app/billing/organizations/organization-subscription-cloud.component.html b/apps/web/src/app/billing/organizations/organization-subscription-cloud.component.html index 20dc22597f5..f6d78864574 100644 --- a/apps/web/src/app/billing/organizations/organization-subscription-cloud.component.html +++ b/apps/web/src/app/billing/organizations/organization-subscription-cloud.component.html @@ -70,10 +70,8 @@ - - {{ productName(i.bitwardenProduct) }} - + + {{ productName(i.bitwardenProduct) }} - {{ i.name }} {{ i.quantity > 1 ? "×" + i.quantity : "" }} @ {{ i.amount | currency : "$" }} diff --git a/apps/web/src/app/billing/organizations/organization-subscription-cloud.component.ts b/apps/web/src/app/billing/organizations/organization-subscription-cloud.component.ts index ae455e6354f..7e8fed21d74 100644 --- a/apps/web/src/app/billing/organizations/organization-subscription-cloud.component.ts +++ b/apps/web/src/app/billing/organizations/organization-subscription-cloud.component.ts @@ -349,22 +349,25 @@ export class OrganizationSubscriptionCloudComponent implements OnInit, OnDestroy } /** - * Helper to sort subscription items by product type and then by addon status + * Helper to sort subscription items by product type and then by addon product type */ function sortSubscriptionItems( a: BillingSubscriptionItemResponse, b: BillingSubscriptionItemResponse ) { if (a.bitwardenProduct == b.bitwardenProduct) { - // sort addon items to the bottom - if (a.addonSubscriptionItem == b.addonSubscriptionItem) { - return 0; + // Both are addon products, sort by enum value + if (a.addonProduct != null && b.addonProduct != null) { + return a.addonProduct - b.addonProduct; } - if (a.addonSubscriptionItem) { - return 1; + // 'a' is not an addon product, sort it to the bottom + if (a.addonProduct == null) { + return -1; } - return -1; + + // 'a' is an addon product, sort it to the top + return 1; } return a.bitwardenProduct - b.bitwardenProduct; } diff --git a/libs/common/src/billing/enums/addon-product-type.enum.ts b/libs/common/src/billing/enums/addon-product-type.enum.ts new file mode 100644 index 00000000000..2e93a10f3e4 --- /dev/null +++ b/libs/common/src/billing/enums/addon-product-type.enum.ts @@ -0,0 +1,8 @@ +/** + * Used to identify the various types of "addon" products that can be added + * to an existing product subscription. + */ +export enum AddonProductType { + PasswordManager_Storage = 0, + SecretsManager_ServiceAccounts = 1, +} diff --git a/libs/common/src/billing/models/response/subscription.response.ts b/libs/common/src/billing/models/response/subscription.response.ts index f966a3e9bfa..216d33b28f3 100644 --- a/libs/common/src/billing/models/response/subscription.response.ts +++ b/libs/common/src/billing/models/response/subscription.response.ts @@ -1,4 +1,5 @@ import { BaseResponse } from "../../../models/response/base.response"; +import { AddonProductType } from "../../enums/addon-product-type.enum"; import { BitwardenProductType } from "../../enums/bitwarden-product-type.enum"; export class SubscriptionResponse extends BaseResponse { @@ -63,7 +64,7 @@ export class BillingSubscriptionItemResponse extends BaseResponse { quantity: number; interval: string; sponsoredSubscriptionItem: boolean; - addonSubscriptionItem: boolean; + addonProduct?: AddonProductType; bitwardenProduct: BitwardenProductType; constructor(response: any) { @@ -73,7 +74,7 @@ export class BillingSubscriptionItemResponse extends BaseResponse { this.quantity = this.getResponseProperty("Quantity"); this.interval = this.getResponseProperty("Interval"); this.sponsoredSubscriptionItem = this.getResponseProperty("SponsoredSubscriptionItem"); - this.addonSubscriptionItem = this.getResponseProperty("AddonSubscriptionItem"); + this.addonProduct = this.getResponseProperty("AddonProduct"); this.bitwardenProduct = this.getResponseProperty("BitwardenProduct"); } }