[AC-1423] Switch to AddonProductType enum instead of boolean

This commit is contained in:
Shane Melton 2023-06-21 17:38:49 -07:00
parent 5ca5b97a30
commit 204f64b4e7
No known key found for this signature in database
4 changed files with 23 additions and 13 deletions

View File

@ -70,10 +70,8 @@
<ng-template body> <ng-template body>
<ng-container *ngIf="subscription"> <ng-container *ngIf="subscription">
<tr bitRow *ngFor="let i of lineItems"> <tr bitRow *ngFor="let i of lineItems">
<td bitCell [ngClass]="{ 'tw-pl-20': i.addonSubscriptionItem }"> <td bitCell [ngClass]="{ 'tw-pl-20': i.addonProduct != null }">
<span *ngIf="!i.addonSubscriptionItem" <span *ngIf="i.addonProduct == null">{{ productName(i.bitwardenProduct) }} -</span>
>{{ productName(i.bitwardenProduct) }} -</span
>
{{ i.name }} {{ i.quantity > 1 ? "&times;" + i.quantity : "" }} @ {{ i.name }} {{ i.quantity > 1 ? "&times;" + i.quantity : "" }} @
{{ i.amount | currency : "$" }} {{ i.amount | currency : "$" }}
</td> </td>

View File

@ -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( function sortSubscriptionItems(
a: BillingSubscriptionItemResponse, a: BillingSubscriptionItemResponse,
b: BillingSubscriptionItemResponse b: BillingSubscriptionItemResponse
) { ) {
if (a.bitwardenProduct == b.bitwardenProduct) { if (a.bitwardenProduct == b.bitwardenProduct) {
// sort addon items to the bottom // Both are addon products, sort by enum value
if (a.addonSubscriptionItem == b.addonSubscriptionItem) { if (a.addonProduct != null && b.addonProduct != null) {
return 0; return a.addonProduct - b.addonProduct;
} }
if (a.addonSubscriptionItem) { // 'a' is not an addon product, sort it to the bottom
return 1; 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; return a.bitwardenProduct - b.bitwardenProduct;
} }

View File

@ -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,
}

View File

@ -1,4 +1,5 @@
import { BaseResponse } from "../../../models/response/base.response"; import { BaseResponse } from "../../../models/response/base.response";
import { AddonProductType } from "../../enums/addon-product-type.enum";
import { BitwardenProductType } from "../../enums/bitwarden-product-type.enum"; import { BitwardenProductType } from "../../enums/bitwarden-product-type.enum";
export class SubscriptionResponse extends BaseResponse { export class SubscriptionResponse extends BaseResponse {
@ -63,7 +64,7 @@ export class BillingSubscriptionItemResponse extends BaseResponse {
quantity: number; quantity: number;
interval: string; interval: string;
sponsoredSubscriptionItem: boolean; sponsoredSubscriptionItem: boolean;
addonSubscriptionItem: boolean; addonProduct?: AddonProductType;
bitwardenProduct: BitwardenProductType; bitwardenProduct: BitwardenProductType;
constructor(response: any) { constructor(response: any) {
@ -73,7 +74,7 @@ export class BillingSubscriptionItemResponse extends BaseResponse {
this.quantity = this.getResponseProperty("Quantity"); this.quantity = this.getResponseProperty("Quantity");
this.interval = this.getResponseProperty("Interval"); this.interval = this.getResponseProperty("Interval");
this.sponsoredSubscriptionItem = this.getResponseProperty("SponsoredSubscriptionItem"); this.sponsoredSubscriptionItem = this.getResponseProperty("SponsoredSubscriptionItem");
this.addonSubscriptionItem = this.getResponseProperty("AddonSubscriptionItem"); this.addonProduct = this.getResponseProperty("AddonProduct");
this.bitwardenProduct = this.getResponseProperty("BitwardenProduct"); this.bitwardenProduct = this.getResponseProperty("BitwardenProduct");
} }
} }