diff --git a/frontend/.env.example b/frontend/.env.example index 3545db7e..6500b295 100644 --- a/frontend/.env.example +++ b/frontend/.env.example @@ -1,3 +1,4 @@ +NEXT_PUBLIC_ENV_MODE="LOCAL" #production, or staging NEXT_PUBLIC_SUPABASE_URL="" NEXT_PUBLIC_SUPABASE_ANON_KEY="" NEXT_PUBLIC_BACKEND_URL="" diff --git a/frontend/src/app/(dashboard)/layout.tsx b/frontend/src/app/(dashboard)/layout.tsx index bcb712ad..03976416 100644 --- a/frontend/src/app/(dashboard)/layout.tsx +++ b/frontend/src/app/(dashboard)/layout.tsx @@ -39,7 +39,7 @@ export default function DashboardLayout({ diff --git a/frontend/src/components/billing/pricing-alert.tsx b/frontend/src/components/billing/pricing-alert.tsx index 52d79c79..c124fb45 100644 --- a/frontend/src/components/billing/pricing-alert.tsx +++ b/frontend/src/components/billing/pricing-alert.tsx @@ -10,6 +10,9 @@ import { setupNewSubscription } from "@/lib/actions/billing" import { SubmitButton } from "@/components/ui/submit-button" import { siteConfig } from "@/lib/home" import { isLocalMode } from "@/lib/config" +import { createClient } from "@/lib/supabase/client" +import { useEffect, useState } from "react" +import { SUBSCRIPTION_PLANS } from "./plan-comparison" interface PricingAlertProps { open: boolean @@ -20,9 +23,46 @@ interface PricingAlertProps { export function PricingAlert({ open, onOpenChange, closeable = true, accountId }: PricingAlertProps) { const returnUrl = typeof window !== 'undefined' ? window.location.href : ''; + const [hasActiveSubscription, setHasActiveSubscription] = useState(false); + const [isLoading, setIsLoading] = useState(true); - // Skip rendering in local development mode - if (isLocalMode() || !open) return null; + // Check if user has an active subscription + useEffect(() => { + async function checkSubscription() { + if (!accountId) { + setHasActiveSubscription(false); + setIsLoading(false); + return; + } + + try { + const supabase = createClient(); + const { data } = await supabase + .schema('basejump') + .from('billing_subscriptions') + .select('price_id') + .eq('account_id', accountId) + .eq('status', 'active') + .single(); + + // Check if the user has a paid subscription (not free tier) + const isPaidSubscription = data?.price_id && + data.price_id !== SUBSCRIPTION_PLANS.FREE; + + setHasActiveSubscription(isPaidSubscription); + } catch (error) { + console.error("Error checking subscription:", error); + setHasActiveSubscription(false); + } finally { + setIsLoading(false); + } + } + + checkSubscription(); + }, [accountId]); + + // Skip rendering in local development mode or if user has an active subscription + if (isLocalMode() || !open || hasActiveSubscription || isLoading) return null; // Filter plans to show only Pro and Enterprise const premiumPlans = siteConfig.cloudPricingItems.filter(plan =>