@@ -5,6 +5,7 @@ import Modal, { type ModalProps } from "@/components/common/modal";
5
5
import { Button } from "@/components/ui/button" ;
6
6
import type { PricingPlanInterval , PricingType } from "@/prisma/enums" ;
7
7
import { api } from "@/trpc/react" ;
8
+ import type { TypeZodStripePortalMutationSchema } from "@/trpc/routers/billing-router/schema" ;
8
9
import type { RouterOutputs } from "@/trpc/shared" ;
9
10
import { useRouter } from "next/navigation" ;
10
11
import { useState } from "react" ;
@@ -61,14 +62,16 @@ function Plans({ products, subscription }: PricingProps) {
61
62
await checkoutWithStripe ( price ) ;
62
63
} ;
63
64
64
- const handleBillingPortal = async ( ) => {
65
- await stripePortal ( ) ;
65
+ const handleBillingPortal = async (
66
+ data : TypeZodStripePortalMutationSchema ,
67
+ ) => {
68
+ await stripePortal ( data ) ;
66
69
} ;
67
70
68
71
const loading = checkoutLoading || stripePortalLoading ;
69
72
70
73
return (
71
- < div >
74
+ < div className = "flex flex-col items-center justify-center" >
72
75
< div className = "inline-flex h-10 items-center justify-center rounded-md bg-muted p-1 text-muted-foreground" >
73
76
{ intervals . includes ( "month" ) && (
74
77
< PricingButton
@@ -112,7 +115,17 @@ function Plans({ products, subscription }: PricingProps) {
112
115
subscribed = { ! ! subscription }
113
116
onClick = { ( ) => {
114
117
if ( subscription ) {
115
- return handleBillingPortal ( ) ;
118
+ return handleBillingPortal ( {
119
+ ...( active
120
+ ? {
121
+ type : "cancel" ,
122
+ subscription : subscription . id ,
123
+ }
124
+ : {
125
+ type : "update" ,
126
+ subscription : subscription . id ,
127
+ } ) ,
128
+ } ) ;
116
129
}
117
130
return handleStripeCheckout ( {
118
131
priceId : price . id ,
@@ -122,7 +135,6 @@ function Plans({ products, subscription }: PricingProps) {
122
135
loading = { loading }
123
136
subscribedUnitAmount = { subscription ?. price . unitAmount }
124
137
unitAmount = { unitAmount }
125
- variant = { active ? "default" : "secondary" }
126
138
/>
127
139
) ;
128
140
} ) }
0 commit comments