"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 { 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: null, }, isLoading: isCheckingStatus, } = fetchSubscriptionStatus(autumn, !autumn.isLoading) const isPro = status.consumer_pro 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 ? (
) : (
{isPro ? "Pro Plan" : "Free Plan"} {isPro && ( Active )}

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

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

Free Plan

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

Pro Plan Recommended

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

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

)}
)}
) }