-
Notifications
You must be signed in to change notification settings - Fork 66
show unique features only #2139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,11 +3,53 @@ import { Button } from "zudoku/components"; | |
| import { Link } from "zudoku/router"; | ||
| import { FeatureItem } from "../../components/FeatureItem"; | ||
| import { QuotaItem } from "../../components/QuotaItem"; | ||
| import type { Plan } from "../../types/PlanType"; | ||
| import type { Plan, PlanPhase } from "../../types/PlanType"; | ||
| import { categorizeRateCards } from "../../utils/categorizeRateCards"; | ||
| import { formatDuration } from "../../utils/formatDuration"; | ||
| import { formatPrice } from "../../utils/formatPrice"; | ||
| import { getPriceFromPlan } from "../../utils/getPriceFromPlan"; | ||
|
|
||
| const PhaseSection = ({ | ||
| phase, | ||
| currency, | ||
| showName, | ||
| excludeKeys, | ||
| }: { | ||
| phase: PlanPhase; | ||
| currency?: string; | ||
| showName: boolean; | ||
| excludeKeys: Set<string>; | ||
| }) => { | ||
| const { quotas, features } = categorizeRateCards(phase.rateCards, currency); | ||
|
|
||
| const filteredQuotas = quotas.filter((q) => !excludeKeys.has(q.key)); | ||
| const filteredFeatures = features.filter((f) => !excludeKeys.has(f.key)); | ||
|
|
||
| if (filteredQuotas.length === 0 && filteredFeatures.length === 0) return null; | ||
|
|
||
| return ( | ||
| <div className="space-y-2"> | ||
| {showName && ( | ||
| <div className="text-sm font-medium text-card-foreground"> | ||
| {phase.name} | ||
| {phase.duration && ( | ||
| <span className="text-muted-foreground font-normal"> | ||
| {" "} | ||
| — {formatDuration(phase.duration)} | ||
| </span> | ||
| )} | ||
| </div> | ||
| )} | ||
| {filteredQuotas.map((quota) => ( | ||
| <QuotaItem key={quota.key} quota={quota} /> | ||
| ))} | ||
| {filteredFeatures.map((feature) => ( | ||
| <FeatureItem key={feature.key} feature={feature} /> | ||
| ))} | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export const PricingCard = ({ | ||
| plan, | ||
| isPopular = false, | ||
|
|
@@ -17,17 +59,13 @@ export const PricingCard = ({ | |
| isPopular?: boolean; | ||
| isSubscribed?: boolean; | ||
| }) => { | ||
| const defaultPhase = plan.phases.at(-1); | ||
| if (!defaultPhase) return null; | ||
| if (plan.phases.length === 0) return null; | ||
|
|
||
| const { quotas, features } = categorizeRateCards( | ||
| defaultPhase.rateCards, | ||
| plan.currency, | ||
| ); | ||
| const price = getPriceFromPlan(plan); | ||
| const isFree = price.monthly === 0; | ||
|
|
||
| const isCustom = plan.metadata?.isCustom === true; | ||
| const hasMultiplePhases = plan.phases.length > 1; | ||
|
|
||
| return ( | ||
| <div | ||
|
|
@@ -81,22 +119,23 @@ export const PricingCard = ({ | |
| )} | ||
| </div> | ||
|
|
||
| <div className="space-y-4 mb-6 grow"> | ||
| {quotas.length > 0 && ( | ||
| <div className="space-y-2"> | ||
| {quotas.map((quota) => ( | ||
| <QuotaItem key={quota.key} quota={quota} /> | ||
| ))} | ||
| </div> | ||
| )} | ||
|
|
||
| {features.length > 0 && ( | ||
| <div className="space-y-2"> | ||
| {features.map((feature) => ( | ||
| <FeatureItem key={feature.key} feature={feature} /> | ||
| ))} | ||
| </div> | ||
| )} | ||
| <div className="space-y-4 mb-6 grow"> | ||
| {plan.phases.map((phase, index) => { | ||
| const laterKeys = new Set( | ||
| plan.phases | ||
| .slice(index + 1) | ||
| .flatMap((p) => p.rateCards.map((rc) => rc.featureKey ?? rc.key)), | ||
| ); | ||
|
Comment on lines
+123
to
+128
|
||
| return ( | ||
| <PhaseSection | ||
| key={phase.key} | ||
| phase={phase} | ||
| currency={plan.currency} | ||
| showName={hasMultiplePhases} | ||
| excludeKeys={laterKeys} | ||
| /> | ||
| ); | ||
| })} | ||
| </div> | ||
|
|
||
| {isSubscribed ? ( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,7 +20,9 @@ export const categorizeRateCards = ( | |
| rc.price?.type === "tiered" && | ||
| rc.price.tiers | ||
| ) { | ||
| const overageTier = rc.price.tiers.find((t) => t.unitPrice?.amount); | ||
| const overageTier = rc.price.tiers.find( | ||
| (t) => t.unitPrice?.amount && parseFloat(t.unitPrice.amount) > 0, | ||
| ); | ||
|
Comment on lines
+23
to
+25
|
||
| if (overageTier?.unitPrice) { | ||
| const amount = parseFloat(overageTier.unitPrice.amount); | ||
| overagePrice = `${formatPrice(amount, currency)}/unit`; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
| import { formatPrice } from "./formatPrice.js"; | ||
|
|
||
| describe("formatPrice", () => { | ||
| it("formats whole numbers without decimals", () => { | ||
| expect(formatPrice(10, "USD")).toBe("$10"); | ||
| }); | ||
|
|
||
| it("formats two decimal places for standard amounts", () => { | ||
| expect(formatPrice(0.01, "USD")).toBe("$0.01"); | ||
| expect(formatPrice(9.99, "USD")).toBe("$9.99"); | ||
| }); | ||
|
|
||
| it("preserves extra decimal places beyond two", () => { | ||
| expect(formatPrice(0.005, "USD")).toBe("$0.005"); | ||
| expect(formatPrice(0.001, "USD")).toBe("$0.001"); | ||
| }); | ||
|
|
||
| it("formats zero without decimals", () => { | ||
| expect(formatPrice(0, "USD")).toBe("$0"); | ||
| }); | ||
|
|
||
| it("defaults to USD when no currency is provided", () => { | ||
| expect(formatPrice(10)).toBe("$10"); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,8 @@ | ||
| export const formatPrice = (amount: number, currency?: string) => | ||
| new Intl.NumberFormat(undefined, { | ||
| style: "currency", | ||
| currency: currency || "USD", | ||
| minimumFractionDigits: 0, | ||
| currency: currency ?? "USD", | ||
| minimumFractionDigits: 2, | ||
| maximumFractionDigits: 6, | ||
| trailingZeroDisplay: "stripIfInteger", | ||
| }).format(amount); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
plan.metadatais typed asRecord<string, unknown>and elsewhere in this plugin metadata flags are treated as strings (e.g.zuplo_most_popular === "true"). Checkingplan.metadata?.isCustom === truewill never match if the API sends string values, so the “Custom / Contact Sales” UI may not appear. Consider checking for a string value (e.g.=== "true") and/or falling back to a plan key convention (like the enterprise check used inSwitchPlanModal).