Skip to content

Commit debac33

Browse files
committed
feat: autumn migration (supermemoryai#902)
1 parent 35c6060 commit debac33

13 files changed

Lines changed: 139 additions & 220 deletions

File tree

apps/web/app/auth/connect/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ function AuthConnectContent() {
169169
setIsUpgrading(true)
170170
const safeSuccessUrl = `${window.location.origin}${window.location.pathname}?callback=${encodeURIComponent(callback ?? "")}&client=${encodeURIComponent(validClient ?? "")}`
171171
await autumn.attach({
172-
productId: "api_pro",
172+
planId: "api_pro",
173173
successUrl: safeSuccessUrl,
174174
})
175175
} catch (err) {

apps/web/components/add-document/connections.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ interface ConnectContentProps {
226226
export function ConnectContent({ selectedProject }: ConnectContentProps) {
227227
const queryClient = useQueryClient()
228228
const autumn = useCustomer()
229-
const isProUser = hasActivePlan(autumn.customer?.products, "api_pro")
229+
const isProUser = hasActivePlan(autumn.data?.subscriptions, "api_pro")
230230
const [connectingProvider, setConnectingProvider] =
231231
useState<ConnectorProvider | null>(null)
232232
const [gdriveSyncScope, setGdriveSyncScope] =
@@ -244,7 +244,7 @@ export function ConnectContent({ selectedProject }: ConnectContentProps) {
244244
setIsUpgrading(true)
245245
try {
246246
await autumn.attach({
247-
productId: "api_pro",
247+
planId: "api_pro",
248248
successUrl: window.location.href,
249249
})
250250
} catch (error) {
@@ -254,9 +254,9 @@ export function ConnectContent({ selectedProject }: ConnectContentProps) {
254254
}
255255
}
256256

257-
const connectionsFeature = autumn.customer?.features?.connections
258-
const connectionsUsed = connectionsFeature?.usage ?? 0
259-
const connectionsLimit = connectionsFeature?.included_usage ?? 10
257+
const connectionsBalance = autumn.data?.balances?.connections
258+
const connectionsUsed = connectionsBalance?.usage ?? 0
259+
const connectionsLimit = connectionsBalance?.granted ?? 10
260260
const canAddConnection = connectionsUsed < connectionsLimit
261261

262262
// Fetch connections

apps/web/components/add-document/index.tsx

Lines changed: 16 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { toast } from "sonner"
1616
import { useDocumentMutations } from "../../hooks/use-document-mutations"
1717
import { useCustomer } from "autumn-js/react"
1818
import { useTokenUsage } from "@/hooks/use-token-usage"
19-
import { tokensToCredits, formatUsageNumber } from "@/lib/billing-utils"
19+
import { formatUsageNumber } from "@/lib/billing-utils"
2020
import { SpaceSelector } from "../space-selector"
2121
import { useIsMobile } from "@hooks/use-mobile"
2222
import { addDocumentParam } from "@/lib/search-params"
@@ -127,11 +127,8 @@ export function AddDocument({
127127
const autumn = useCustomer()
128128
const {
129129
tokensUsed,
130-
tokensLimit,
131-
tokensPercent,
132130
searchesUsed,
133-
searchesLimit,
134-
searchesPercent,
131+
planUsagePct,
135132
hasPaidPlan,
136133
isLoading: isLoadingUsage,
137134
} = useTokenUsage(autumn)
@@ -298,72 +295,46 @@ export function AddDocument({
298295
dmSansClassName(),
299296
)}
300297
>
301-
Credits
298+
Plan usage
302299
</span>
303300
<span
304301
className={cn(
305-
"text-sm font-medium",
302+
"text-sm font-medium tabular-nums",
306303
hasPaidPlan ? "text-[#4BA0FA]" : "text-[#737373]",
307304
dmSansClassName(),
308305
)}
309306
>
310307
{isLoadingUsage
311308
? "…"
312-
: `${tokensToCredits(tokensUsed)} / ${tokensToCredits(tokensLimit)}`}
309+
: `${planUsagePct < 1 && planUsagePct > 0 ? "< 1" : Math.round(planUsagePct)}% used`}
313310
</span>
314311
</div>
315312
<div className="h-2 w-full rounded-[40px] bg-[#2E353D] p-px overflow-hidden">
316313
<div
317314
className="h-full rounded-[40px]"
318315
style={{
319-
width: `${tokensPercent}%`,
316+
width: `${planUsagePct}%`,
320317
background:
321-
tokensPercent > 80
318+
planUsagePct > 80
322319
? "#ef4444"
323320
: hasPaidPlan
324321
? "linear-gradient(to right, #4BA0FA 80%, #002757 100%)"
325322
: "#0054AD",
326323
}}
324+
title={`${formatUsageNumber(tokensUsed)} tokens · ${formatUsageNumber(searchesUsed)} queries`}
327325
/>
328326
</div>
329-
</div>
330-
331-
<div className="flex flex-col gap-2">
332-
<div className="flex justify-between items-center">
333-
<span
327+
{!isLoadingUsage && (
328+
<p
334329
className={cn(
335-
"text-[#FAFAFA] text-sm font-medium",
330+
"text-xs text-[#737373] tabular-nums",
336331
dmSansClassName(),
337332
)}
338333
>
339-
Search Queries
340-
</span>
341-
<span
342-
className={cn(
343-
"text-sm font-medium",
344-
hasPaidPlan ? "text-[#4BA0FA]" : "text-[#737373]",
345-
dmSansClassName(),
346-
)}
347-
>
348-
{isLoadingUsage
349-
? "…"
350-
: `${formatUsageNumber(searchesUsed)} / ${formatUsageNumber(searchesLimit)}`}
351-
</span>
352-
</div>
353-
<div className="h-2 w-full rounded-[40px] bg-[#2E353D] p-px overflow-hidden">
354-
<div
355-
className="h-full rounded-[40px]"
356-
style={{
357-
width: `${searchesPercent}%`,
358-
background:
359-
searchesPercent > 80
360-
? "#ef4444"
361-
: hasPaidPlan
362-
? "linear-gradient(to right, #4BA0FA 80%, #002757 100%)"
363-
: "#0054AD",
364-
}}
365-
/>
366-
</div>
334+
{formatUsageNumber(tokensUsed)} tokens ·{" "}
335+
{formatUsageNumber(searchesUsed)} queries
336+
</p>
337+
)}
367338
</div>
368339

369340
{!hasPaidPlan && (
@@ -373,7 +344,7 @@ export function AddDocument({
373344
setIsUpgrading(true)
374345
try {
375346
await autumn.attach({
376-
productId: "api_pro",
347+
planId: "api_pro",
377348
successUrl: "https://app.supermemory.ai/settings#account",
378349
})
379350
window.location.reload()

apps/web/components/integrations-view.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ export function IntegrationsView() {
170170
const [, setAddDoc] = useQueryState("add", addDocumentParam)
171171
const { org } = useAuth()
172172
const autumn = useCustomer()
173-
const hasProProduct = hasActivePlan(autumn.customer?.products, "api_pro")
173+
const hasProProduct = hasActivePlan(autumn.data?.subscriptions, "api_pro")
174174

175175
const { data: connections = [] } = useQuery({
176176
queryKey: ["connections"],

apps/web/components/integrations/plugins-detail.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ export function PluginsDetail() {
386386
})
387387
const [keyCopied, setKeyCopied] = useState(false)
388388

389-
const hasProProduct = hasActivePlan(autumn.customer?.products, "api_pro")
389+
const hasProProduct = hasActivePlan(autumn.data?.subscriptions, "api_pro")
390390

391391
const { data: pluginsData } = useQuery({
392392
queryFn: async () => {
@@ -496,7 +496,7 @@ export function PluginsDetail() {
496496
const handleUpgrade = async () => {
497497
try {
498498
await autumn.attach({
499-
productId: "api_pro",
499+
planId: "api_pro",
500500
successUrl: "https://app.supermemory.ai/?view=integrations",
501501
})
502502
window.location.reload()

0 commit comments

Comments
 (0)