From 2c52a065368212ee203bec5653758e3ec1c2b31c Mon Sep 17 00:00:00 2001 From: giancarlo Date: Sat, 1 Jun 2024 15:59:39 +0700 Subject: [PATCH] Update pricing table and billing configuration Updated the pricing table component to display all line items for a plan, removed condition to exclude primary plan. Adjusted the type of a billing package in the sample configuration to be "metered" instead of "flat". Made related changes in line-item-details component to handle the changes in billing type and to fix the layout. --- apps/web/config/billing.sample.config.ts | 9 ++- apps/web/public/locales/en/billing.json | 1 + .../src/components/line-item-details.tsx | 55 +++++++++++++------ .../gateway/src/components/pricing-table.tsx | 8 +-- 4 files changed, 51 insertions(+), 22 deletions(-) diff --git a/apps/web/config/billing.sample.config.ts b/apps/web/config/billing.sample.config.ts index 23bac72b0..b33b62ec3 100644 --- a/apps/web/config/billing.sample.config.ts +++ b/apps/web/config/billing.sample.config.ts @@ -33,7 +33,14 @@ export default createBillingSchema({ id: 'price_1NNwYHI1i3VnbZTqI2UzaHIe', name: 'Addon 2', cost: 9.99, - type: 'flat' as const, + type: 'metered' as const, + unit: 'GB', + tiers: [ + { + cost: 0.5, + upTo: 'unlimited', + }, + ], }, ], }, diff --git a/apps/web/public/locales/en/billing.json b/apps/web/public/locales/en/billing.json index 6727aea00..7cf727a41 100644 --- a/apps/web/public/locales/en/billing.json +++ b/apps/web/public/locales/en/billing.json @@ -39,6 +39,7 @@ "includedUpTo": "Up to {{upTo}} {{unit}} included in the plan", "fromPreviousTierUpTo": "for each {{unit}} for the next {{ upTo }} {{ unit }}", "andAbove": "above {{ previousTier }} {{ unit }}", + "forEveryUnit": "for every {{ unit }}", "setupFee": "plus a {{ setupFee }} setup fee", "perUnitIncluded": "({{included}} included)", "featuresLabel": "Features", diff --git a/packages/billing/gateway/src/components/line-item-details.tsx b/packages/billing/gateway/src/components/line-item-details.tsx index 0e3c2973a..26ed4c4b9 100644 --- a/packages/billing/gateway/src/components/line-item-details.tsx +++ b/packages/billing/gateway/src/components/line-item-details.tsx @@ -5,9 +5,9 @@ import { LineItemSchema } from '@kit/billing'; import { formatCurrency } from '@kit/shared/utils'; import { If } from '@kit/ui/if'; import { Trans } from '@kit/ui/trans'; +import { cn } from '@kit/ui/utils'; -const className = - 'flex text-secondary-foreground items-center justify-between text-sm'; +const className = 'flex text-secondary-foreground items-center text-sm'; export function LineItemDetails( props: React.PropsWithChildren<{ @@ -62,7 +62,7 @@ export function LineItemDetails( const FlatFee = () => (
-
+
@@ -72,21 +72,23 @@ export function LineItemDetails( - - - } > + ( + ) - + - + + {formatCurrency(props?.currency.toLowerCase(), item.cost)}
@@ -185,6 +187,10 @@ export function LineItemDetails( return ; case 'metered': { + if (item.cost > 0) { + return ; + } + return ; } } @@ -203,8 +209,9 @@ function Tiers({ const unit = item.unit; const tiers = item.tiers?.map((tier, index) => { + const tiersLength = item.tiers?.length ?? 0; const previousTier = item.tiers?.[index - 1]; - const isNoLimit = tier.upTo === 'unlimited'; + const isLastTier = tier.upTo === 'unlimited'; const previousTierFrom = previousTier?.upTo === 'unlimited' @@ -223,20 +230,36 @@ function Tiers({ > - - + {formatCurrency(currency.toLowerCase(), tier.cost)} - - - + 1}> + + + + + + + + + + - + @@ -260,5 +283,5 @@ function Tiers({ ); }); - return
{tiers}
; + return
{tiers}
; } diff --git a/packages/billing/gateway/src/components/pricing-table.tsx b/packages/billing/gateway/src/components/pricing-table.tsx index b49608ba0..b15fb665f 100644 --- a/packages/billing/gateway/src/components/pricing-table.tsx +++ b/packages/billing/gateway/src/components/pricing-table.tsx @@ -152,9 +152,7 @@ function PricingItem( // we want to exclude the primary plan from the list of line items // since we are displaying the primary line item separately as the main price - const lineItemsToDisplay = props.plan.lineItems.filter((item) => { - return item.id !== lineItem?.id; - }); + const lineItemsToDisplay = props.plan.lineItems; return (
- + }