1
0
mirror of https://github.com/bitwarden/browser synced 2026-02-11 22:13:32 +00:00

feat(pricing): adds support for hidden discount amounts

Allows hiding the formatted amount for discounts in the cart summary.

This is useful for scenarios where the discount amount is displayed
elsewhere or is not relevant to the user.

Updates the storybook to include a story demonstrating this feature.
This commit is contained in:
Stephon Brown
2026-01-28 16:23:31 -05:00
parent 59c2c6efa0
commit 076724276c
2 changed files with 36 additions and 0 deletions

View File

@@ -57,6 +57,8 @@ export default {
return "Your next charge is for";
case "dueOn":
return "due on";
case "specialOfferDiscount":
return "Special Offer Discount";
default:
return key;
}
@@ -342,6 +344,36 @@ export const WithAmountDiscount: Story = {
},
};
export const WithAmountDiscountHidden: Story = {
name: "Amount Discount (Hidden Formatted Amount)",
args: {
cart: {
passwordManager: {
seats: {
quantity: 5,
translationKey: "members",
cost: 50.0,
},
},
secretsManager: {
seats: {
quantity: 3,
translationKey: "members",
cost: 30.0,
},
},
cadence: "annually",
discount: {
type: DiscountTypes.AmountOff,
value: 50.0,
translationKey: "specialOfferDiscount",
hideFormattedAmount: true,
},
estimatedTax: 95.0,
} satisfies Cart,
},
};
export const WithHiddenBreakdown: Story = {
name: "Hidden Cost Breakdown",
args: {

View File

@@ -11,11 +11,15 @@ export type Discount = {
type: DiscountType;
value: number;
translationKey?: string;
hideFormattedAmount?: boolean;
};
export const getLabel = (i18nService: I18nService, discount: Discount): string => {
switch (discount.type) {
case DiscountTypes.AmountOff: {
if (discount.hideFormattedAmount) {
return i18nService.t(discount.translationKey ?? "discount");
}
const formattedAmount = new Intl.NumberFormat("en-US", {
style: "currency",
currency: "USD",