"use client" import { dmSans125ClassName } from "@/lib/fonts" import { cn } from "@lib/utils" import { useAuth } from "@lib/auth-context" import { Avatar, AvatarFallback, AvatarImage } from "@ui/components/avatar" import { useTokenUsage } from "@/hooks/use-token-usage" import { formatUsageNumber, tokensToCredits } from "@/lib/billing-utils" import { Dialog, DialogContent, DialogTrigger, DialogClose, } from "@ui/components/dialog" import { authClient } from "@lib/auth" import { Popover, PopoverContent, PopoverTrigger } from "@ui/components/popover" import { useCustomer } from "autumn-js/react" import { Check, X, Trash2, LoaderIcon, Settings, ChevronDown, Building2, } from "lucide-react" import { useState } from "react" function SectionTitle({ children }: { children: React.ReactNode }) { return (

{children}

) } function SettingsCard({ children }: { children: React.ReactNode }) { return (
{children}
) } function PlanFeatureRow({ icon, text, variant = "muted", }: { icon: "check" | "x" text: string variant?: "muted" | "highlight" }) { return (
{icon === "check" ? ( ) : ( )} {text}
) } export default function Account() { const { user, org, setActiveOrg } = useAuth() const autumn = useCustomer() const [isUpgrading, setIsUpgrading] = useState(false) const [deleteConfirmText, setDeleteConfirmText] = useState("") const [isDeleteDialogOpen, setIsDeleteDialogOpen] = useState(false) const [switchingOrgId, setSwitchingOrgId] = useState(null) const { data: allOrgs } = authClient.useListOrganizations() const handleOrgSwitch = async (orgSlug: string, orgId: string) => { if (orgId === org?.id) return setSwitchingOrgId(orgId) try { await setActiveOrg(orgSlug) window.location.reload() } catch (error) { console.error("Failed to switch organization:", error) setSwitchingOrgId(null) } } const { tokensUsed, tokensLimit, tokensPercent, searchesUsed, searchesLimit, searchesPercent, currentPlan, hasPaidPlan, isLoading: isCheckingStatus, daysRemaining, } = useTokenUsage(autumn) const planDisplayNames: Record = { free: "Free", pro: "Pro", scale: "Scale", enterprise: "Enterprise", } // Handlers const handleUpgrade = async () => { setIsUpgrading(true) try { await autumn.attach({ productId: "api_pro", successUrl: "https://app.supermemory.ai/settings#account", }) window.location.reload() } catch (error) { console.error(error) setIsUpgrading(false) } } const handleDeleteAccount = () => { if (deleteConfirmText !== "DELETE") return // TODO: Implement account deletion API call console.log("Delete account requested") setIsDeleteDialogOpen(false) setDeleteConfirmText("") } const isDeleteEnabled = deleteConfirmText === "DELETE" // Format member since date const memberSince = user?.createdAt ? new Date(user.createdAt).toLocaleDateString("en-US", { month: "short", year: "numeric", }) : "—" return (
Profile Details
{/* Avatar + Name/Email */}
{user?.name?.charAt(0) ?? "U"}

{user?.name ?? "—"}

{user?.email ?? "—"}

Organization

{org?.name ?? "Personal"} {allOrgs && allOrgs.length > 1 && ( {allOrgs.map((organization) => { const isCurrent = organization.id === org?.id const isSwitching = switchingOrgId === organization.id return ( ) })} )}

Member since

{memberSince}

Billing & Subscription
{hasPaidPlan ? ( <>

{planDisplayNames[currentPlan]} plan

ACTIVE

Expanded memory with connections and more

{/* Credits Usage Progress */}

Credits Used

{tokensToCredits(tokensUsed)} /{" "} {tokensToCredits(tokensLimit)}
80 ? "#ef4444" : "linear-gradient(to right, #4BA0FA 80%, #002757 100%)", }} />
{/* Search Queries Progress */}

Search Queries

{formatUsageNumber(searchesUsed)} /{" "} {formatUsageNumber(searchesLimit)}
80 ? "#ef4444" : "linear-gradient(to right, #4BA0FA 80%, #002757 100%)", }} />
{/* Days remaining indicator */} {daysRemaining !== null && (

Resets in {daysRemaining} day {daysRemaining !== 1 ? "s" : ""}

)}
{/* Free plan card */}

Free plan

{/* Current plan card - highlighted */}

{planDisplayNames[currentPlan]} plan

ACTIVE
) : ( <>

Free Plan

You are on basic plan

{/* Credits Usage Progress */}

Credits Used

{tokensToCredits(tokensUsed)} /{" "} {tokensToCredits(tokensLimit)}

80 ? "#ef4444" : "#0054AD", }} />
{/* Search Queries Progress */}

Search Queries

{formatUsageNumber(searchesUsed)} /{" "} {formatUsageNumber(searchesLimit)}

80 ? "#ef4444" : "#0054AD", }} />
{/* Days remaining indicator */} {daysRemaining !== null && (

Resets in {daysRemaining} day {daysRemaining !== 1 ? "s" : ""}

)}
{/* Free plan card */}

Free plan

{/* Pro plan card */}
{/* Header with badge */}

Pro plan

RECOMMENDED
{/* Inset highlight */}
)}
Delete Account

Permanently delete all your data and cancel any active subscriptions

{ setIsDeleteDialogOpen(open) if (!open) setDeleteConfirmText("") }} >
{/* Header */}

Delete account?

This will permanently delete your memories, conversations, settings and cancel any active subscriptions.

{/* Confirmation input */}

Type DELETE to confirm:

setDeleteConfirmText(e.target.value)} placeholder="DELETE" className={cn( "w-full px-4 py-3 bg-transparent", "text-[#FAFAFA] placeholder:text-[#737373]", "text-[14px] tracking-[-0.14px]", "outline-none", dmSans125ClassName(), )} />
{/* Footer */}
{/* Modal inset highlight */}
) }