@@ -38,7 +38,7 @@ import type { Account } from "@3rdweb-sdk/react/hooks/useApi";
3838import { zodResolver } from "@hookform/resolvers/zod" ;
3939import { useMutation } from "@tanstack/react-query" ;
4040import { REGEXP_ONLY_DIGITS_AND_CHARS } from "input-otp" ;
41- import { EllipsisIcon , ExternalLinkIcon } from "lucide-react" ;
41+ import { CircleXIcon , EllipsisIcon , ExternalLinkIcon } from "lucide-react" ;
4242import Link from "next/link" ;
4343import { useState } from "react" ;
4444import { useForm } from "react-hook-form" ;
@@ -64,6 +64,7 @@ export function AccountSettingsPageUI(props: {
6464 defaultTeamSlug : string ;
6565 defaultTeamName : string ;
6666 redirectToBillingPortal : BillingBillingPortalAction ;
67+ cancelSubscriptions : ( ) => Promise < void > ;
6768} ) {
6869 return (
6970 < div className = "flex flex-col gap-8" >
@@ -89,6 +90,7 @@ export function AccountSettingsPageUI(props: {
8990 defaultTeamSlug = { props . defaultTeamSlug }
9091 defaultTeamName = { props . defaultTeamName }
9192 redirectToBillingPortal = { props . redirectToBillingPortal }
93+ cancelSubscriptions = { props . cancelSubscriptions }
9294 />
9395 </ div >
9496 ) ;
@@ -207,6 +209,7 @@ function DeleteAccountCard(props: {
207209 defaultTeamSlug : string ;
208210 defaultTeamName : string ;
209211 redirectToBillingPortal : BillingBillingPortalAction ;
212+ cancelSubscriptions : ( ) => Promise < void > ;
210213} ) {
211214 const title = "Delete Account" ;
212215 const description = (
@@ -230,6 +233,10 @@ function DeleteAccountCard(props: {
230233 } ,
231234 } ) ;
232235
236+ const cancelSubscriptions = useMutation ( {
237+ mutationFn : props . cancelSubscriptions ,
238+ } ) ;
239+
233240 function handleDelete ( ) {
234241 deleteAccount . mutate ( ) ;
235242 }
@@ -264,25 +271,47 @@ function DeleteAccountCard(props: {
264271 < Alert variant = "destructive" >
265272 < AlertTitle > Failed to delete account</ AlertTitle >
266273 < 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 >
286315 </ AlertDescription >
287316 </ Alert >
288317 </ div >
0 commit comments