1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
|
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 (
<motion.div
animate={{ opacity: 1, scale: 1 }}
className="text-center py-8"
initial={{ opacity: 0, scale: 0.9 }}
transition={{ type: "spring", damping: 20 }}
>
<p className="text-muted-foreground mb-4">
Sign in to unlock premium features
</p>
<motion.div whileHover={{ scale: 1.05 }} whileTap={{ scale: 0.95 }}>
<Button
asChild
className="bg-muted hover:bg-muted/80 text-foreground border-border"
size="sm"
>
<Link href="/login">Sign in</Link>
</Button>
</motion.div>
</motion.div>
)
}
if (hasProProduct) {
return (
<motion.div
animate={{ opacity: 1, y: 0 }}
className="space-y-6"
initial={{ opacity: 0, y: 10 }}
>
<div className="space-y-3">
<HeadingH3Bold className="text-foreground flex items-center gap-2">
Pro Plan
{isPastDue ? (
<span className="text-xs bg-red-500/20 text-red-600 dark:text-red-400 px-2 py-0.5 rounded-full">
Past Due
</span>
) : (
<span className="text-xs bg-green-500/20 text-green-600 dark:text-green-400 px-2 py-0.5 rounded-full">
Active
</span>
)}
</HeadingH3Bold>
<p className="text-sm text-muted-foreground">
{isPastDue
? "Your payment is past due. Please update your payment method to restore access."
: "You're enjoying expanded memory capacity with supermemory Pro!"}
</p>
</div>
{isPastDue && (
<div className="p-4 bg-red-500/10 border border-red-500/20 rounded-lg flex items-start gap-3">
<AlertTriangle className="h-5 w-5 text-red-600 dark:text-red-400 flex-shrink-0 mt-0.5" />
<div className="flex-1">
<p className="text-sm text-red-600 dark:text-red-400 font-medium mb-1">
Payment Required
</p>
<p className="text-xs text-red-600/80 dark:text-red-400/80">
Your payment method failed or payment is past due. Update your
payment information to restore access to all Pro features.
</p>
</div>
</div>
)}
{/* Current Usage */}
<div className="space-y-3">
<h4 className="text-sm font-medium text-foreground">Current Usage</h4>
<div className="space-y-2">
<div className="flex justify-between items-center">
<span className="text-sm text-muted-foreground">Memories</span>
<span className="text-sm text-foreground">Unlimited</span>
</div>
</div>
<div className="space-y-2">
<div className="flex justify-between items-center">
<span className="text-sm text-muted-foreground">Connections</span>
<span className="text-sm text-foreground">
{connectionsUsed} / 10
</span>
</div>
</div>
</div>
<Button
onClick={handleManageBilling}
size="sm"
variant="default"
className={isPastDue ? "bg-red-600 hover:bg-red-700 text-white" : ""}
>
{isPastDue ? "Pay Past Due" : "Manage Billing"}
</Button>
</motion.div>
)
}
return (
<motion.div
animate={{ opacity: 1, y: 0 }}
className="space-y-6"
initial={{ opacity: 0, y: 10 }}
>
{/* Current Usage - Free Plan */}
<div className="space-y-3">
<HeadingH3Bold className="text-foreground">
Current Plan: Free
</HeadingH3Bold>
<div className="space-y-2">
<div className="flex justify-between items-center">
<span className="text-sm text-muted-foreground">Memories</span>
<span
className={`text-sm ${memoriesUsed >= memoriesLimit ? "text-red-500" : "text-foreground"}`}
>
{memoriesUsed} / {memoriesLimit}
</span>
</div>
<div className="w-full bg-muted-foreground/50 rounded-full h-2">
<div
className={`h-2 rounded-full transition-all ${
memoriesUsed >= memoriesLimit ? "bg-red-500" : "bg-blue-500"
}`}
style={{
width: `${Math.min((memoriesUsed / memoriesLimit) * 100, 100)}%`,
}}
/>
</div>
</div>
</div>
{/* Comparison */}
<div className="space-y-4">
<HeadingH3Bold className="text-foreground">
Upgrade to Pro
</HeadingH3Bold>
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
{/* Free Plan */}
<div className="p-4 bg-muted/50 rounded-lg border border-border">
<h4 className="font-medium text-foreground mb-3">Free Plan</h4>
<ul className="space-y-2">
<li className="flex items-center gap-2 text-sm text-muted-foreground">
<CheckCircle className="h-4 w-4 text-green-500" />
200 memories
</li>
<li className="flex items-center gap-2 text-sm text-muted-foreground">
<X className="h-4 w-4 text-red-500" />
No connections
</li>
<li className="flex items-center gap-2 text-sm text-muted-foreground">
<CheckCircle className="h-4 w-4 text-green-500" />
Basic search
</li>
</ul>
</div>
{/* Pro Plan */}
<div className="p-4 bg-gradient-to-br from-blue-500/10 to-purple-500/10 rounded-lg border border-blue-500/20">
<h4 className="font-medium text-foreground mb-3 flex items-center gap-2">
Pro Plan
<span className="text-xs bg-blue-500/20 text-blue-600 dark:text-blue-400 px-2 py-0.5 rounded-full">
Recommended
</span>
</h4>
<ul className="space-y-2">
<li className="flex items-center gap-2 text-sm text-white/90">
<CheckCircle className="h-4 w-4 text-green-400" />
Unlimited memories
</li>
<li className="flex items-center gap-2 text-sm text-foreground">
<CheckCircle className="h-4 w-4 text-green-500" />
10 connections
</li>
<li className="flex items-center gap-2 text-sm text-foreground">
<CheckCircle className="h-4 w-4 text-green-500" />
Advanced search
</li>
<li className="flex items-center gap-2 text-sm text-foreground">
<CheckCircle className="h-4 w-4 text-green-500" />
Priority support
</li>
</ul>
</div>
</div>
<Button
className="bg-blue-600 hover:bg-blue-700 text-white border-0 w-full"
disabled={isLoading || isCheckingStatus}
onClick={handleUpgrade}
>
{isLoading || isCheckingStatus ? (
<>
<LoaderIcon className="h-4 w-4 animate-spin mr-2" />
Upgrading...
</>
) : (
<div>Upgrade to Pro - $9/month (only for first 100 users)</div>
)}
</Button>
<p className="text-xs text-muted-foreground text-center">
Cancel anytime. No questions asked.
</p>
</div>
</motion.div>
)
}
|