From 0527ee26b7415e98f7d094ce92650292139cced4 Mon Sep 17 00:00:00 2001 From: MananTank Date: Thu, 6 Mar 2025 15:59:30 +0000 Subject: [PATCH] [TOOL-3630] Dashboard: Add cancel subscriptions option in delete account flow (#6429) --- .../account/settings/AccountSettingsPage.tsx | 10 +++ .../AccountSettingsPageUI.stories.tsx | 3 + .../settings/AccountSettingsPageUI.tsx | 69 +++++++++++++------ 3 files changed, 62 insertions(+), 20 deletions(-) diff --git a/apps/dashboard/src/app/account/settings/AccountSettingsPage.tsx b/apps/dashboard/src/app/account/settings/AccountSettingsPage.tsx index ad87d155268..ce61faae3ff 100644 --- a/apps/dashboard/src/app/account/settings/AccountSettingsPage.tsx +++ b/apps/dashboard/src/app/account/settings/AccountSettingsPage.tsx @@ -36,6 +36,16 @@ export function AccountSettingsPage(props: { client={props.client} defaultTeamSlug={props.defaultTeamSlug} defaultTeamName={props.defaultTeamName} + cancelSubscriptions={async () => { + const res = await apiServerProxy({ + method: "DELETE", + pathname: `/v1/teams/${props.defaultTeamSlug}/subscriptions`, + }); + + if (!res.ok) { + throw new Error(res.error); + } + }} onAccountDeleted={async () => { await doLogout(); if (activeWallet) { diff --git a/apps/dashboard/src/app/account/settings/AccountSettingsPageUI.stories.tsx b/apps/dashboard/src/app/account/settings/AccountSettingsPageUI.stories.tsx index 382f2dbcdc2..e7c61cbd5b3 100644 --- a/apps/dashboard/src/app/account/settings/AccountSettingsPageUI.stories.tsx +++ b/apps/dashboard/src/app/account/settings/AccountSettingsPageUI.stories.tsx @@ -143,6 +143,9 @@ function Variants() { onAccountDeleted={() => { console.log("Account deleted"); }} + cancelSubscriptions={async () => { + await new Promise((resolve) => setTimeout(resolve, 1000)); + }} /> diff --git a/apps/dashboard/src/app/account/settings/AccountSettingsPageUI.tsx b/apps/dashboard/src/app/account/settings/AccountSettingsPageUI.tsx index 4508dfca1be..bb6d873bfcc 100644 --- a/apps/dashboard/src/app/account/settings/AccountSettingsPageUI.tsx +++ b/apps/dashboard/src/app/account/settings/AccountSettingsPageUI.tsx @@ -38,7 +38,7 @@ import type { Account } from "@3rdweb-sdk/react/hooks/useApi"; import { zodResolver } from "@hookform/resolvers/zod"; import { useMutation } from "@tanstack/react-query"; import { REGEXP_ONLY_DIGITS_AND_CHARS } from "input-otp"; -import { EllipsisIcon, ExternalLinkIcon } from "lucide-react"; +import { CircleXIcon, EllipsisIcon, ExternalLinkIcon } from "lucide-react"; import Link from "next/link"; import { useState } from "react"; import { useForm } from "react-hook-form"; @@ -64,6 +64,7 @@ export function AccountSettingsPageUI(props: { defaultTeamSlug: string; defaultTeamName: string; redirectToBillingPortal: BillingBillingPortalAction; + cancelSubscriptions: () => Promise; }) { return (
@@ -89,6 +90,7 @@ export function AccountSettingsPageUI(props: { defaultTeamSlug={props.defaultTeamSlug} defaultTeamName={props.defaultTeamName} redirectToBillingPortal={props.redirectToBillingPortal} + cancelSubscriptions={props.cancelSubscriptions} />
); @@ -207,6 +209,7 @@ function DeleteAccountCard(props: { defaultTeamSlug: string; defaultTeamName: string; redirectToBillingPortal: BillingBillingPortalAction; + cancelSubscriptions: () => Promise; }) { const title = "Delete Account"; const description = ( @@ -230,6 +233,10 @@ function DeleteAccountCard(props: { }, }); + const cancelSubscriptions = useMutation({ + mutationFn: props.cancelSubscriptions, + }); + function handleDelete() { deleteAccount.mutate(); } @@ -264,25 +271,47 @@ function DeleteAccountCard(props: { Failed to delete account - - Your default team "{props.defaultTeamName}" has active - subscriptions. These subscriptions have to be cancelled - first before deleting account - - - Reach out to support to help you cancel them - - +
+ + Your default team "{props.defaultTeamName}" has active + subscriptions. These subscriptions have to be cancelled + before deleting account + +
+ +
+ + + +