1
+ import handleCheckout from "@/api/payment/handleCheckout" ;
1
2
import { Button } from "@/components/ui/button" ;
2
- import { SVGProps } from "react" ;
3
- import { useNavigate } from "react-router-dom" ;
3
+ import { useSubscription } from "@/hooks/useSubscription" ;
4
+ import { SVGProps , useEffect , useRef } from "react" ;
5
+ import toast from "react-hot-toast" ;
6
+ import { useLocation , useNavigate } from "react-router-dom" ;
4
7
5
8
export default function Pricing ( ) {
9
+ const { isProUser} = useSubscription ( ) ;
10
+ const sessionUrl = useRef < string > ( "" ) ;
11
+ const { search } = useLocation ( ) ;
12
+ const params = new URLSearchParams ( search ) ;
6
13
const navigate = useNavigate ( ) ;
14
+ useEffect ( ( ) => {
15
+ handleCheckout ( ) . then ( ( redirect_url ) => {
16
+ console . log ( redirect_url ) ;
17
+ sessionUrl . current = redirect_url ;
18
+ } ) . catch ( ( ) => {
19
+ toast . error ( "Error in Generating you session Url" ) ;
20
+ } ) ;
21
+ } , [ ] ) ;
22
+ if ( params . get ( "success" ) == "true" ) {
23
+ toast . success ( "Payment SuccessFul" ) ;
24
+ setTimeout ( ( ) => {
25
+ navigate ( "/test" ) ;
26
+ } , 2000 ) ;
27
+ return (
28
+ < section className = "w-full py-12 bg-gradient-to-r from-gray-50 to-gray-100 dark:from-zinc-900 dark:to-zinc-800 flex items-center justify-center h-screen flex-col sm:flex-row" >
29
+ < CheckIcon /> Redirecting to DashBoard{ " " }
30
+ < span className = "animate-bounce text-xl font-extrabold" > .</ span >
31
+ < span className = "animate-bounce text-xl font-extrabold" > .</ span >
32
+ < span className = "animate-bounce text-xl font-extrabold" > .</ span >
33
+ < span className = "animate-bounce text-xl font-extrabold" > .</ span >
34
+ </ section >
35
+ ) ;
36
+ }
37
+ if ( params . get ( "success" ) == "false" ) {
38
+ toast . error ( "Payment Failed" ) ;
39
+ }
7
40
return (
8
41
< section className = "w-full py-12 bg-gradient-to-r from-gray-50 to-gray-100 dark:from-zinc-900 dark:to-zinc-800 flex items-center justify-center h-screen flex-col sm:flex-row" >
9
- < h1 className = "w-1/2 sm:text-3xl font-bold text-center p-4" > TYPESIGHT comes with only one feature plan to give you the unlimited experience</ h1 >
42
+ < h1 className = "w-1/2 sm:text-3xl font-bold text-center p-4" >
43
+ TYPESIGHT comes with only one feature plan to give you the unlimited
44
+ experience
45
+ </ h1 >
10
46
< div className = "relative flex flex-col p-6 bg-white shadow-lg rounded-lg dark:bg-zinc-850 justify-between border border-purple-500 sm:w-1/3" >
11
47
< div className = "px-3 py-1 text-sm text-white bg-gradient-to-r from-pink-500 to-purple-500 rounded-full inline-block absolute top-0 left-1/2 transform -translate-x-1/2 -translate-y-1/2" >
12
48
Popular
@@ -35,10 +71,10 @@ export default function Pricing() {
35
71
< Button
36
72
className = "w-full bg-gradient-to-r from-pink-500 to-purple-500"
37
73
onClick = { ( ) => {
38
- navigate ( "/test" ) ;
74
+ window . location . href = sessionUrl . current ;
39
75
} }
40
76
>
41
- Get Started
77
+ { isProUser ? "Manage Subscription" : "Subscribe Now" }
42
78
</ Button >
43
79
</ div >
44
80
</ div >
@@ -64,3 +100,4 @@ function CheckIcon(props: JSX.IntrinsicAttributes & SVGProps<SVGSVGElement>) {
64
100
</ svg >
65
101
) ;
66
102
}
103
+
0 commit comments