import { useAuth } from "@lib/auth-context" import { fetchConnectionsFeature, fetchMemoriesFeature, fetchSubscriptionStatus, } from "@lib/queries" import { Button } from "@ui/components/button" import { HeadingH3Bold } from "@ui/text/heading/heading-h3-bold" import { useCustomer } from "autumn-js/react" import { AlertTriangle, CheckCircle, LoaderIcon, X } from "lucide-react" import { motion } from "motion/react" import Link from "next/link" import { useEffect, useState } from "react" import { analytics } from "@/lib/analytics" export function BillingView() { const autumn = useCustomer() const { user } = useAuth() const [isLoading, setIsLoading] = useState(false) useEffect(() => { analytics.billingViewed() }, []) const { data: status = { consumer_pro: { allowed: false, status: null }, }, isLoading: isCheckingStatus, } = fetchSubscriptionStatus(autumn, !autumn.isLoading) const proStatus = status.consumer_pro const proProductStatus = proStatus?.status const isPastDue = proProductStatus === "past_due" const hasProProduct = proProductStatus !== null const { data: memoriesCheck } = fetchMemoriesFeature( autumn, !autumn.isLoading && !isCheckingStatus, ) const memoriesUsed = memoriesCheck?.usage ?? 0 const memoriesLimit = memoriesCheck?.included_usage ?? 0 const { data: connectionsCheck } = fetchConnectionsFeature( autumn, !autumn.isLoading && !isCheckingStatus, ) const connectionsUsed = connectionsCheck?.usage ?? 0 // Handle upgrade const handleUpgrade = async () => { analytics.upgradeInitiated() setIsLoading(true) try { await autumn.attach({ productId: "consumer_pro", successUrl: "https://app.supermemory.ai/", }) analytics.upgradeCompleted() window.location.reload() } catch (error) { console.error(error) setIsLoading(false) } } // Handle manage billing const handleManageBilling = async () => { analytics.billingPortalOpened() await autumn.openBillingPortal({ returnUrl: "https://app.supermemory.ai", }) } if (user?.isAnonymous) { return (

Sign in to unlock premium features

) } if (hasProProduct) { return (
Pro Plan {isPastDue ? ( Past Due ) : ( Active )}

{isPastDue ? "Your payment is past due. Please update your payment method to restore access." : "You're enjoying expanded memory capacity with supermemory Pro!"}

{isPastDue && (

Payment Required

Your payment method failed or payment is past due. Update your payment information to restore access to all Pro features.

)} {/* Current Usage */}

Current Usage

Memories Unlimited
Connections {connectionsUsed} / 10
) } return ( {/* Current Usage - Free Plan */}
Current Plan: Free
Memories = memoriesLimit ? "text-red-500" : "text-foreground"}`} > {memoriesUsed} / {memoriesLimit}
= memoriesLimit ? "bg-red-500" : "bg-blue-500" }`} style={{ width: `${Math.min((memoriesUsed / memoriesLimit) * 100, 100)}%`, }} />
{/* Comparison */}
Upgrade to Pro
{/* Free Plan */}

Free Plan

  • 200 memories
  • No connections
  • Basic search
{/* Pro Plan */}

Pro Plan Recommended

  • Unlimited memories
  • 10 connections
  • Advanced search
  • Priority support

Cancel anytime. No questions asked.

) }