@@ -3,6 +3,8 @@ import { Card } from "@/components/ui/card";
33import { Switch } from "@/components/ui/switch" ;
44import { CheckIcon } from "lucide-react" ;
55import { useState } from "react" ;
6+ import { useAuth } from "@/hooks/useAuth" ;
7+ import { SignInButton } from "@clerk/nextjs" ;
68
79interface PlanCardProps {
810 plan : {
@@ -17,16 +19,23 @@ interface PlanCardProps {
1719
1820export function PlanCard ( { plan, onSelect } : PlanCardProps ) {
1921 const [ isAnnual , setIsAnnual ] = useState ( false ) ;
22+ const [ isLoading ] = useState ( false ) ;
23+ const { isAuthenticated } = useAuth ( ) ;
2024 const annualPrice = Math . round ( plan . price * 12 * 0.8 ) ; // 20% discount
2125
26+ const handleSelectPlan = async ( ) => {
27+ if ( isLoading ) return ;
28+ if ( isAuthenticated ) {
29+ onSelect ( isAnnual ) ;
30+ }
31+ } ;
32+
2233 return (
2334 < Card className = "p-8 rounded-2xl shadow-xl transition-all duration-300 ease-out hover:shadow-md hover:shadow-purple-600/50 border border-gray-200 dark:border-gray-700 transform hover:scale-102 hover:brightness-110" >
24- { /* Plan Name */ }
2535 < h2 className = "text-3xl font-extrabold mb-4 text-gray-900 dark:text-white" >
2636 { plan . name }
2737 </ h2 >
2838
29- { /* Pricing & Toggle */ }
3039 < div className = "flex items-center justify-between mb-6" >
3140 < span className = "text-4xl font-bold text-gray-900 dark:text-white" >
3241 ${ isAnnual ? annualPrice : plan . price }
@@ -42,7 +51,6 @@ export function PlanCard({ plan, onSelect }: PlanCardProps) {
4251 </ div >
4352 </ div >
4453
45- { /* Features List */ }
4654 < ul className = "mb-6 space-y-2" >
4755 { plan . features . map ( ( feature ) => (
4856 < li
@@ -55,13 +63,21 @@ export function PlanCard({ plan, onSelect }: PlanCardProps) {
5563 ) ) }
5664 </ ul >
5765
58- { /* Select Plan Button */ }
59- < Button
60- className = "w-full py-3 rounded-lg bg-gradient-to-r from-blue-600 to-blue-500 text-white font-medium tracking-wide shadow-lg transition-all hover:scale-105 hover:shadow-xl dark:from-blue-500 dark:to-blue-400"
61- onClick = { ( ) => onSelect ( isAnnual ) }
62- >
63- Select Plan
64- </ Button >
66+ { isAuthenticated ? (
67+ < Button
68+ className = "w-full py-3 rounded-lg bg-gradient-to-r from-blue-600 to-blue-500 text-white font-medium tracking-wide shadow-lg transition-all hover:scale-105 hover:shadow-xl dark:from-blue-500 dark:to-blue-400"
69+ onClick = { handleSelectPlan }
70+ disabled = { isLoading }
71+ >
72+ { isLoading ? "Loading..." : "Select Plan" }
73+ </ Button >
74+ ) : (
75+ < SignInButton mode = "modal" >
76+ < Button className = "w-full py-3 rounded-lg bg-gradient-to-r from-blue-600 to-blue-500 text-white font-medium tracking-wide shadow-lg transition-all hover:scale-105 hover:shadow-xl dark:from-blue-500 dark:to-blue-400" >
77+ Sign in to Select
78+ </ Button >
79+ </ SignInButton >
80+ ) }
6581 </ Card >
6682 ) ;
6783}
0 commit comments