Handle case for metered line items in the Plan Picker by displaying t… (#107)
* Handle case for metered line items in the Plan Picker by displaying the cost of the lower tier as "Starting at {price}/{unit}"
This commit is contained in:
committed by
GitHub
parent
f3ff0e7bb3
commit
41193e5697
@@ -40,6 +40,8 @@
|
|||||||
"includedUpTo": "Up to {{upTo}} {{unit}} included in the plan",
|
"includedUpTo": "Up to {{upTo}} {{unit}} included in the plan",
|
||||||
"fromPreviousTierUpTo": "for each {{unit}} for the next {{ upTo }} {{ unit }}",
|
"fromPreviousTierUpTo": "for each {{unit}} for the next {{ upTo }} {{ unit }}",
|
||||||
"andAbove": "above {{ previousTier }} {{ unit }}",
|
"andAbove": "above {{ previousTier }} {{ unit }}",
|
||||||
|
"startingAtPriceUnit": "Starting at {{price}}/{{unit}}",
|
||||||
|
"priceUnit": "{{price}}/{{unit}}",
|
||||||
"forEveryUnit": "for every {{ unit }}",
|
"forEveryUnit": "for every {{ unit }}",
|
||||||
"setupFee": "plus a {{ setupFee }} setup fee",
|
"setupFee": "plus a {{ setupFee }} setup fee",
|
||||||
"perUnitIncluded": "({{included}} included)",
|
"perUnitIncluded": "({{included}} included)",
|
||||||
|
|||||||
@@ -239,6 +239,28 @@ export function PlanPicker(
|
|||||||
throw new Error(`Base line item was not found`);
|
throw new Error(`Base line item was not found`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const shouldDisplayTier =
|
||||||
|
primaryLineItem.type === 'metered' &&
|
||||||
|
Array.isArray(primaryLineItem.tiers) &&
|
||||||
|
primaryLineItem.tiers.length > 0;
|
||||||
|
|
||||||
|
const isMultiTier =
|
||||||
|
Array.isArray(primaryLineItem.tiers) &&
|
||||||
|
primaryLineItem.tiers.length > 1;
|
||||||
|
|
||||||
|
const lowestTier = primaryLineItem.tiers?.reduce(
|
||||||
|
(acc, curr) => {
|
||||||
|
if (acc && acc.cost < curr.cost) {
|
||||||
|
return acc;
|
||||||
|
}
|
||||||
|
|
||||||
|
return curr;
|
||||||
|
},
|
||||||
|
primaryLineItem.tiers[0],
|
||||||
|
);
|
||||||
|
|
||||||
|
const tierTranslationKey = isMultiTier ? 'billing:startingAtPriceUnit' : 'billing:priceUnit';
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<RadioGroupItemLabel
|
<RadioGroupItemLabel
|
||||||
selected={selected}
|
selected={selected}
|
||||||
@@ -318,16 +340,34 @@ export function PlanPicker(
|
|||||||
}
|
}
|
||||||
>
|
>
|
||||||
<div>
|
<div>
|
||||||
<Price key={plan.id}>
|
<If
|
||||||
<span>
|
condition={shouldDisplayTier}
|
||||||
{formatCurrency({
|
fallback={
|
||||||
currencyCode:
|
<Price key={plan.id}>
|
||||||
product.currency.toLowerCase(),
|
<span>
|
||||||
value: primaryLineItem.cost,
|
{formatCurrency({
|
||||||
locale,
|
currencyCode:
|
||||||
})}
|
product.currency.toLowerCase(),
|
||||||
</span>
|
value: primaryLineItem.cost,
|
||||||
</Price>
|
locale,
|
||||||
|
})}
|
||||||
|
</span>
|
||||||
|
</Price>
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<Trans
|
||||||
|
i18nKey={tierTranslationKey}
|
||||||
|
values={{
|
||||||
|
price: formatCurrency({
|
||||||
|
currencyCode:
|
||||||
|
product.currency.toLowerCase(),
|
||||||
|
value: lowestTier?.cost ?? 0,
|
||||||
|
locale,
|
||||||
|
}),
|
||||||
|
unit: primaryLineItem.unit,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</If>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<span className={'text-muted-foreground'}>
|
<span className={'text-muted-foreground'}>
|
||||||
|
|||||||
Reference in New Issue
Block a user