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:
@@ -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: {
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user