@@ -8,15 +8,18 @@ import {
8
8
} from "@/components/ui/card" ;
9
9
import { cn } from "@/lib/utils" ;
10
10
import type { PricingPlanInterval } from "@/prisma/enums" ;
11
+ import { useState } from "react" ;
11
12
12
- interface PricingCardProps extends Omit < ButtonProps , "children" > {
13
+ interface PricingCardProps {
13
14
title : string ;
14
15
description ?: string | null ;
15
16
price : string ;
16
17
interval : PricingPlanInterval ;
17
- subscribed : boolean ;
18
18
subscribedUnitAmount ?: bigint | null ;
19
19
unitAmount : number ;
20
+ // biome-ignore lint/suspicious/noExplicitAny: <explanation>
21
+ handleClick : ( ) => Promise < any > ;
22
+ isSubmitting : boolean ;
20
23
}
21
24
22
25
const humanizedInterval : Record < PricingPlanInterval , string > = {
@@ -31,11 +34,12 @@ export function PricingCard({
31
34
title,
32
35
interval,
33
36
price,
34
- subscribed,
35
37
subscribedUnitAmount : subscribedUnitAmount_ ,
36
38
unitAmount,
37
- ...rest
39
+ handleClick,
40
+ isSubmitting,
38
41
} : PricingCardProps ) {
42
+ const [ isLoading , setIsLoading ] = useState ( false ) ;
39
43
const subscribedUnitAmount = subscribedUnitAmount_
40
44
? Number ( subscribedUnitAmount_ )
41
45
: null ;
@@ -56,12 +60,15 @@ export function PricingCard({
56
60
</ CardHeader >
57
61
< CardFooter >
58
62
< Button
59
- { ...rest }
60
- className = { cn (
61
- rest . className ,
62
- ! active && "bg-teal-500 hover:bg-teal-500/80" ,
63
- ) }
63
+ className = { cn ( ! active && "bg-teal-500 hover:bg-teal-500/80" ) }
64
64
{ ...( active && { variant : "destructive" } ) }
65
+ onClick = { async ( ) => {
66
+ setIsLoading ( true ) ;
67
+ await handleClick ( ) ;
68
+ setIsLoading ( false ) ;
69
+ } }
70
+ loading = { isLoading }
71
+ { ...( ! isLoading && { disabled : isSubmitting } ) }
65
72
>
66
73
{ subscribedUnitAmount
67
74
? unitAmount < subscribedUnitAmount
0 commit comments