11import { FormEvent , useEffect , useRef , useState } from 'react'
22import { useQueryClient } from '@tanstack/react-query'
3+ import { useRouter } from 'next/router'
34import { Icon } from '~/components/Icon'
45import { LocalLoader } from '~/components/Loaders'
56import { FreeCard } from '~/components/SubscribeCards/FreeCard'
@@ -8,38 +9,15 @@ import { SubscribeEnterpriseCard } from '~/components/SubscribeCards/SubscribeEn
89import { SubscribeProCard } from '~/components/SubscribeCards/SubscribeProCard'
910import { useAuthContext } from '~/containers/Subscribtion/auth'
1011import { useSubscribe } from '~/hooks/useSubscribe'
11- import { AccountInfo } from './AccountInfo'
12- import { AccountStatus } from './components/AccountStatus'
13- import { EmailChangeModal } from './components/EmailChangeModal'
14- import { EmailVerificationWarning } from './components/EmailVerificationWarning'
1512import { ReturnModal } from './components/ReturnModal'
1613import { TrialActivation } from './components/TrialActivation'
1714import { SignIn } from './SignIn'
1815
1916export function SubscribeHome ( { returnUrl, isTrial } : { returnUrl ?: string ; isTrial ?: boolean } ) {
20- const { isAuthenticated, loaders, user, changeEmail, addEmail, resendVerification } = useAuthContext ( )
17+ const router = useRouter ( )
18+ const { isAuthenticated, loaders, user } = useAuthContext ( )
2119 const { subscription, isSubscriptionFetching, apiSubscription } = useSubscribe ( )
22- const [ showEmailForm , setShowEmailForm ] = useState ( false )
23- const [ newEmail , setNewEmail ] = useState ( '' )
2420 const [ billingInterval , setBillingInterval ] = useState < 'year' | 'month' > ( 'month' )
25- const isWalletUser = user ?. email ?. includes ( '@defillama.com' )
26- const handleEmailChange = async ( e : FormEvent < HTMLFormElement > ) => {
27- e . preventDefault ( )
28- if ( isWalletUser ) {
29- await addEmail ( newEmail )
30- } else {
31- changeEmail ( newEmail )
32- }
33- setNewEmail ( '' )
34- setShowEmailForm ( false )
35- }
36-
37- const handleResendVerification = ( ) => {
38- if ( user ?. email ) {
39- resendVerification ( user . email )
40- }
41- }
42-
4321 const isSubscribed = subscription ?. status === 'active'
4422 const [ isClient , setIsClient ] = useState ( false )
4523
@@ -125,6 +103,13 @@ export function SubscribeHome({ returnUrl, isTrial }: { returnUrl?: string; isTr
125103 { billingInterval === 'year' ? '/year' : '/month' }
126104 </ button >
127105 < p className = "mt-2 text-center text-xs text-[#8a8c90]" > Cancel anytime • Crypto and Card payments</ p >
106+ < button
107+ onClick = { ( ) => router . push ( '/account' ) }
108+ className = "mt-3 flex w-full items-center justify-center gap-2 text-sm text-[#8a8c90] transition-colors hover:text-white"
109+ >
110+ < Icon name = "settings" height = { 14 } width = { 14 } />
111+ Manage Account
112+ </ button >
128113 </ div >
129114 ) : (
130115 < div className = "mx-auto w-full max-w-[400px] lg:hidden" >
@@ -237,18 +222,21 @@ export function SubscribeHome({ returnUrl, isTrial }: { returnUrl?: string; isTr
237222 />
238223 ) }
239224
240- < EmailChangeModal
241- isOpen = { showEmailForm }
242- onClose = { ( ) => setShowEmailForm ( false ) }
243- onSubmit = { handleEmailChange }
244- email = { newEmail }
245- onEmailChange = { setNewEmail }
246- isLoading = { isWalletUser ? loaders . addEmail : loaders . changeEmail }
247- isWalletUser = { isWalletUser }
248- />
249225 { isAuthenticated && isSubscribed ? (
250- < div className = "mx-auto mt-6 w-full max-w-[1200px]" >
251- < AccountInfo />
226+ < div className = "mx-auto mt-6 flex w-full max-w-[600px] flex-col items-center gap-4" >
227+ < div className = "flex flex-col items-center gap-4 rounded-xl border border-[#39393E] bg-[#1a1b1f] p-8 text-center" >
228+ < div className = "flex h-16 w-16 items-center justify-center rounded-full bg-green-500/10" >
229+ < Icon name = "check" height = { 32 } width = { 32 } className = "text-green-400" />
230+ </ div >
231+ < h2 className = "text-2xl font-bold text-white" > You're subscribed!</ h2 >
232+ < p className = "text-[#8a8c90]" > Manage your subscription and view your account details.</ p >
233+ < button
234+ onClick = { ( ) => router . push ( '/account' ) }
235+ className = "rounded-lg bg-[#5C5CF9] px-8 py-3 font-medium text-white transition-colors hover:bg-[#4A4AF0]"
236+ >
237+ Go to Account
238+ </ button >
239+ </ div >
252240 </ div >
253241 ) : (
254242 < div className = "relative" >
@@ -314,28 +302,18 @@ export function SubscribeHome({ returnUrl, isTrial }: { returnUrl?: string; isTr
314302 </ span >
315303 </ div >
316304
317- { isAuthenticated && ! isSubscribed && (
318- < div className = "relative z-10 mt-8 w-full" >
319- < h3 className = "mb-4 flex items-center gap-2 text-lg font-semibold text-white" >
320- < Icon name = "users" height = { 18 } width = { 18 } className = "text-[#5C5CF9]" />
321- Manage Account
322- </ h3 >
323- < AccountStatus
324- user = { user }
325- isVerified = { user ?. verified }
326- isSubscribed = { isSubscribed }
327- subscription = { subscription }
328- onEmailChange = { ( ) => setShowEmailForm ( true ) }
329- />
330- { ! user ?. verified && ! isWalletUser && user ?. email && (
331- < div className = "mt-4" >
332- < EmailVerificationWarning
333- email = { user . email }
334- onResendVerification = { handleResendVerification }
335- isLoading = { loaders . resendVerification }
336- />
337- </ div >
338- ) }
305+ { isAuthenticated && (
306+ < div className = "relative z-10 mt-6 flex flex-col items-center gap-3 rounded-xl border border-[#39393E] bg-[#1a1b1f]/50 p-6 backdrop-blur-sm" >
307+ < Icon name = "user" height = { 24 } width = { 24 } className = "text-[#5C5CF9]" />
308+ < p className = "text-center text-[#b4b7bc]" >
309+ Already a subscriber or need to manage your account?
310+ </ p >
311+ < button
312+ onClick = { ( ) => router . push ( '/account' ) }
313+ className = "rounded-lg border border-[#5C5CF9]/30 bg-[#5C5CF9]/10 px-6 py-2.5 font-medium text-[#5C5CF9] transition-all hover:border-[#5C5CF9]/50 hover:bg-[#5C5CF9]/20"
314+ >
315+ Go to Account
316+ </ button >
339317 </ div >
340318 ) }
341319 </ div >
0 commit comments