'use client'; import { createClient } from "@/lib/supabase/client"; import { useEffect, useState } from "react"; import { cn } from "@/lib/utils"; import { motion } from "motion/react"; import { setupNewSubscription } from "@/lib/actions/billing"; import { SubmitButton } from "@/components/ui/submit-button"; import { Button } from "@/components/ui/button"; import { siteConfig } from "@/lib/home"; // Create SUBSCRIPTION_PLANS using stripePriceId from siteConfig export const SUBSCRIPTION_PLANS = { FREE: siteConfig.cloudPricingItems.find(item => item.name === 'Free')?.stripePriceId || '', PRO: siteConfig.cloudPricingItems.find(item => item.name === 'Pro')?.stripePriceId || '', ENTERPRISE: siteConfig.cloudPricingItems.find(item => item.name === 'Enterprise')?.stripePriceId || '', }; interface PlanComparisonProps { accountId?: string | null; returnUrl?: string; isManaged?: boolean; onPlanSelect?: (planId: string) => void; className?: string; isCompact?: boolean; // When true, uses vertical stacked layout for modals } // Price display animation component const PriceDisplay = ({ tier, isCompact }: { tier: typeof siteConfig.cloudPricingItems[number]; isCompact?: boolean }) => { return ( {tier.price} ); }; export function PlanComparison({ accountId, returnUrl = typeof window !== 'undefined' ? window.location.href : '', isManaged = true, onPlanSelect, className = "", isCompact = false }: PlanComparisonProps) { const [currentPlanId, setCurrentPlanId] = useState(); useEffect(() => { async function fetchCurrentPlan() { if (accountId) { const supabase = createClient(); const { data } = await supabase .schema('basejump') .from('billing_subscriptions') .select('price_id') .eq('account_id', accountId) .eq('status', 'active') .single(); setCurrentPlanId(data?.price_id || SUBSCRIPTION_PLANS.FREE); } else { setCurrentPlanId(SUBSCRIPTION_PLANS.FREE); } } fetchCurrentPlan(); }, [accountId]); return ( {siteConfig.cloudPricingItems.map((tier) => { const isCurrentPlan = currentPlanId === SUBSCRIPTION_PLANS[tier.name.toUpperCase() as keyof typeof SUBSCRIPTION_PLANS]; return ( {isCompact ? ( // Compact layout for modal <> {tier.name} {tier.isPopular && ( Popular )} {isCurrentPlan && ( Current )} {tier.description} {tier.price !== "$0" ? "/mo" : ""} {tier.hours}/month {tier.features.map((feature, index) => ( {index > 0 && ' • '} {feature} ))} > ) : ( // Standard layout for normal view <> {tier.name} {tier.isPopular && ( Popular )} {isCurrentPlan && ( Current )} {tier.price !== "$0" ? "/month" : ""} {tier.hours}/month {tier.description} {tier.features.map((feature, index) => ( {feature} ))} > )} {isManaged ? ( {isCurrentPlan ? "Current Plan" : (tier.name === "Free" ? tier.buttonText : "Upgrade")} ) : ( onPlanSelect?.(SUBSCRIPTION_PLANS[tier.name.toUpperCase() as keyof typeof SUBSCRIPTION_PLANS])} > {isCurrentPlan ? "Current Plan" : (tier.name === "Free" ? tier.buttonText : "Upgrade")} )} ); })} ); }
{tier.description}