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

Sign in to access your profile and billing

) } return (
{/* Profile Section */}
{session?.image ? ( {session?.name ) : ( )}
{session?.name && (

{session.name}

)}

{session?.email}

{/* Additional Profile Details */}
Organization {organizations?.name || "Personal"}
Member since {session?.createdAt ? new Date(session.createdAt).toLocaleDateString("en-US", { month: "short", year: "numeric", }) : "Recent"}
{/* Billing Section */} {autumn.isLoading || isCheckingStatus ? (
) : (
{hasProProduct ? "Pro Plan" : "Free Plan"} {isPastDue ? ( Past Due ) : isPro ? ( Active ) : null}

{hasProProduct ? "Expanded memory capacity" : "Basic plan"}

{isPastDue && (

Payment Required

Your payment is past due. Please update your payment method to restore access to Pro features.

)} {/* Usage Stats */}
Memories {hasProProduct ? ( Unlimited ) : ( = memoriesLimit ? "text-red-500" : "text-foreground"}`} > {memoriesUsed} / {memoriesLimit} )}
{!hasProProduct && (
= memoriesLimit ? "bg-red-500" : "bg-blue-500" }`} style={{ width: `${Math.min((memoriesUsed / memoriesLimit) * 100, 100)}%`, }} />
)}
{hasProProduct && (
Connections {connectionsUsed} / 10
)} {/* Billing Actions */}
{isPastDue ? ( ) : hasProProduct ? ( ) : ( )}
{!hasProProduct && (
{/* Free Plan */}

Free Plan

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

Pro Plan Recommended

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

$9/month (only for first 100 users) • Cancel anytime. No questions asked.

)}
)}
) }