Skip to content

Commit af324c0

Browse files
committed
giddy up
1 parent 8a28ef2 commit af324c0

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

apps/docs/app/(home)/pricing/_pricing/best-plan.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@ function calculateTotalCost(
2424
return basePrice + overageCost;
2525
}
2626

27+
function findHighestTierPlan(plans: NormalizedPlan[]): NormalizedPlan | null {
28+
const paidPlansWithOverage = plans.filter((p) => p.eventTiers !== null);
29+
if (paidPlansWithOverage.length === 0) {
30+
return null;
31+
}
32+
return paidPlansWithOverage.reduce((max, plan) =>
33+
plan.includedEventsMonthly > max.includedEventsMonthly ? plan : max
34+
);
35+
}
36+
2737
export function selectBestPlan(
2838
monthlyEvents: number,
2939
plans: NormalizedPlan[]
@@ -32,6 +42,11 @@ export function selectBestPlan(
3242
return null;
3343
}
3444

45+
const highestTier = findHighestTierPlan(plans);
46+
47+
if (highestTier && monthlyEvents > highestTier.includedEventsMonthly) {
48+
return highestTier;
49+
}
3550
let bestPlan: NormalizedPlan | null = null;
3651
let bestCost = Number.POSITIVE_INFINITY;
3752

0 commit comments

Comments
 (0)