@@ -38,7 +38,7 @@ import type { Account } from "@3rdweb-sdk/react/hooks/useApi";
38
38
import { zodResolver } from "@hookform/resolvers/zod" ;
39
39
import { useMutation } from "@tanstack/react-query" ;
40
40
import { REGEXP_ONLY_DIGITS_AND_CHARS } from "input-otp" ;
41
- import { EllipsisIcon , ExternalLinkIcon } from "lucide-react" ;
41
+ import { CircleXIcon , EllipsisIcon , ExternalLinkIcon } from "lucide-react" ;
42
42
import Link from "next/link" ;
43
43
import { useState } from "react" ;
44
44
import { useForm } from "react-hook-form" ;
@@ -64,6 +64,7 @@ export function AccountSettingsPageUI(props: {
64
64
defaultTeamSlug : string ;
65
65
defaultTeamName : string ;
66
66
redirectToBillingPortal : BillingBillingPortalAction ;
67
+ cancelSubscriptions : ( ) => Promise < void > ;
67
68
} ) {
68
69
return (
69
70
< div className = "flex flex-col gap-8" >
@@ -89,6 +90,7 @@ export function AccountSettingsPageUI(props: {
89
90
defaultTeamSlug = { props . defaultTeamSlug }
90
91
defaultTeamName = { props . defaultTeamName }
91
92
redirectToBillingPortal = { props . redirectToBillingPortal }
93
+ cancelSubscriptions = { props . cancelSubscriptions }
92
94
/>
93
95
</ div >
94
96
) ;
@@ -207,6 +209,7 @@ function DeleteAccountCard(props: {
207
209
defaultTeamSlug : string ;
208
210
defaultTeamName : string ;
209
211
redirectToBillingPortal : BillingBillingPortalAction ;
212
+ cancelSubscriptions : ( ) => Promise < void > ;
210
213
} ) {
211
214
const title = "Delete Account" ;
212
215
const description = (
@@ -230,6 +233,10 @@ function DeleteAccountCard(props: {
230
233
} ,
231
234
} ) ;
232
235
236
+ const cancelSubscriptions = useMutation ( {
237
+ mutationFn : props . cancelSubscriptions ,
238
+ } ) ;
239
+
233
240
function handleDelete ( ) {
234
241
deleteAccount . mutate ( ) ;
235
242
}
@@ -264,25 +271,47 @@ function DeleteAccountCard(props: {
264
271
< Alert variant = "destructive" >
265
272
< AlertTitle > Failed to delete account</ AlertTitle >
266
273
< AlertDescription >
267
- < span className = "mb-1 block" >
268
- Your default team "{ props . defaultTeamName } " has active
269
- subscriptions. These subscriptions have to be cancelled
270
- first before deleting account
271
- </ span >
272
- < span className = "mb-4 block" >
273
- Reach out to support to help you cancel them
274
- </ span >
275
- < Button
276
- variant = "default"
277
- asChild
278
- size = "sm"
279
- className = "gap-2"
280
- >
281
- < Link href = "/support/create-ticket" >
282
- Contact Support
283
- < ExternalLinkIcon className = "size-4" />
284
- </ Link >
285
- </ Button >
274
+ < div className = "mb-4" >
275
+ < span className = "block" >
276
+ Your default team "{ props . defaultTeamName } " has active
277
+ subscriptions. These subscriptions have to be cancelled
278
+ before deleting account
279
+ </ span >
280
+ </ div >
281
+
282
+ < div className = "flex flex-col gap-3 lg:flex-row" >
283
+ < Button
284
+ variant = "default"
285
+ size = "sm"
286
+ className = "gap-2"
287
+ onClick = { ( ) => {
288
+ const promise = cancelSubscriptions . mutateAsync ( ) ;
289
+ toast . promise ( promise , {
290
+ success : "Subscriptions cancelled successfully" ,
291
+ error : "Failed to cancel subscriptions" ,
292
+ } ) ;
293
+ } }
294
+ >
295
+ { cancelSubscriptions . isPending ? (
296
+ < Spinner className = "size-4" />
297
+ ) : (
298
+ < CircleXIcon className = "size-4" />
299
+ ) }
300
+ Cancel subscriptions
301
+ </ Button >
302
+
303
+ < Button
304
+ variant = "outline"
305
+ asChild
306
+ size = "sm"
307
+ className = "gap-2"
308
+ >
309
+ < Link href = "/support/create-ticket" target = "_blank" >
310
+ Contact Support
311
+ < ExternalLinkIcon className = "size-4" />
312
+ </ Link >
313
+ </ Button >
314
+ </ div >
286
315
</ AlertDescription >
287
316
</ Alert >
288
317
</ div >
0 commit comments