🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.
Refactor PricingCard component to remove dependency on getStripePrices
Bill Yang7ab5bc980f7b
diff --git a/client/src/app/subscribe/components/PricingCard.tsx b/client/src/app/subscribe/components/PricingCard.tsxindex 698fb7ae1..75eec0362 100644--- a/client/src/app/subscribe/components/PricingCard.tsx+++ b/client/src/app/subscribe/components/PricingCard.tsx@@ -13,11 +13,9 @@ import {findPriceForTier,formatEventTier,} from "./utils";-import { getStripePrices } from "../../../lib/stripe";import { trackAdEvent } from "../../../lib/trackAdEvent";export function PricingCard({ isLoggedIn }: { isLoggedIn: boolean }) {- const stripePrices = getStripePrices();const [eventLimitIndex, setEventLimitIndex] = useState<number>(0);const [isAnnual, setIsAnnual] = useState<boolean>(false);const [isLoading, setIsLoading] = useState<boolean>(false);@@ -45,7 +43,7 @@ export function PricingCard({ isLoggedIn }: { isLoggedIn: boolean }) {return;}- const selectedTierPrice = findPriceForTier(eventLimit, isAnnual ? "year" : "month", stripePrices, planType);+ const selectedTierPrice = findPriceForTier(eventLimit, isAnnual ? "year" : "month", planType);if (!selectedTierPrice) {toast.error("Selected pricing plan not found. Please adjust the slider.");@@ -97,10 +95,10 @@ export function PricingCard({ isLoggedIn }: { isLoggedIn: boolean }) {}// Get pricing information for both plans- const standardMonthlyPrice = findPriceForTier(eventLimit, "month", stripePrices, "standard")?.price || 0;- const standardAnnualPrice = findPriceForTier(eventLimit, "year", stripePrices, "standard")?.price || 0;- const proMonthlyPrice = findPriceForTier(eventLimit, "month", stripePrices, "pro")?.price || 0;- const proAnnualPrice = findPriceForTier(eventLimit, "year", stripePrices, "pro")?.price || 0;+ const standardMonthlyPrice = findPriceForTier(eventLimit, "month", "standard")?.price || 0;+ const standardAnnualPrice = findPriceForTier(eventLimit, "year", "standard")?.price || 0;+ const proMonthlyPrice = findPriceForTier(eventLimit, "month", "pro")?.price || 0;+ const proAnnualPrice = findPriceForTier(eventLimit, "year", "pro")?.price || 0;const isCustomTier = eventLimit === "Custom";return (diff --git a/client/src/app/subscribe/components/utils.ts b/client/src/app/subscribe/components/utils.tsindex f6163bced..3f4b9b961 100644--- a/client/src/app/subscribe/components/utils.ts+++ b/client/src/app/subscribe/components/utils.ts@@ -1,18 +1,8 @@// Common utility functions and constants for subscription components-import { STRIPE_TIERS } from "../../../lib/stripe";+import { getStripePrices, STRIPE_TIERS } from "../../../lib/stripe";-export interface StripePrice {- priceId: string;- price: number;- name: string;- interval: string;- limits: {- events: number;- };-}--export const EVENT_TIERS = [STRIPE_TIERS.map(tier => tier.events), "Custom"];+export const EVENT_TIERS = [...STRIPE_TIERS.map(tier => tier.events), "Custom"];export const STANDARD_FEATURES = ["Up to 10 websites",@@ -46,13 +36,14 @@ export const FREE_FEATURES = ["6 month data retention",];+const stripePrices = getStripePrices();+// Find the appropriate price for a tier at current event limitexport function findPriceForTier(eventLimit: number | string,interval: "month" | "year",- stripePrices: StripePrice[],planType: "standard" | "pro" = "standard"-): StripePrice | null {+) {// Check if we have a custom tierif (eventLimit === "Custom") {return null;@@ -73,7 +64,7 @@ export function findPriceForTier();// Find a plan that matches or exceeds the event limit- const matchingPlan = plans.find(plan => plan.limits.events >= eventLimitValue);+ const matchingPlan = plans.find(plan => plan.events >= eventLimitValue);const selectedPlan = matchingPlan || plans[plans.length - 1] || null;// Return the matching plan or the highest tier available@@ -86,5 +77,5 @@ export function formatEventTier(tier: number | string): string {return tier;}- return tier >= 1_000_000 ? `${tier / 1_000_000}M` : `${tier / 1_000}K`;+ return tier >= 1_000_000 ? `${tier / 1_000_000}M` : `${tier / 1_000}k`;}diff --git a/client/src/lib/stripe.ts b/client/src/lib/stripe.tsindex 84321ee19..3edbeeb8a 100644--- a/client/src/lib/stripe.ts+++ b/client/src/lib/stripe.ts@@ -1,4 +1,13 @@-const STRIPE_PRICES = [+export interface StripePrice {+ priceId: string;+ price: number;+ name: string;+ interval: string;+ events: number;+ shortName: string;+}++const STRIPE_PRICES: StripePrice[] = [// Standard tiers{price: 19,