Skip to content

Commit 0527ee2

Browse files
committed
[TOOL-3630] Dashboard: Add cancel subscriptions option in delete account flow (#6429)
1 parent 834ed83 commit 0527ee2

File tree

3 files changed

+62
-20
lines changed

3 files changed

+62
-20
lines changed

apps/dashboard/src/app/account/settings/AccountSettingsPage.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,16 @@ export function AccountSettingsPage(props: {
3636
client={props.client}
3737
defaultTeamSlug={props.defaultTeamSlug}
3838
defaultTeamName={props.defaultTeamName}
39+
cancelSubscriptions={async () => {
40+
const res = await apiServerProxy({
41+
method: "DELETE",
42+
pathname: `/v1/teams/${props.defaultTeamSlug}/subscriptions`,
43+
});
44+
45+
if (!res.ok) {
46+
throw new Error(res.error);
47+
}
48+
}}
3949
onAccountDeleted={async () => {
4050
await doLogout();
4151
if (activeWallet) {

apps/dashboard/src/app/account/settings/AccountSettingsPageUI.stories.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ function Variants() {
143143
onAccountDeleted={() => {
144144
console.log("Account deleted");
145145
}}
146+
cancelSubscriptions={async () => {
147+
await new Promise((resolve) => setTimeout(resolve, 1000));
148+
}}
146149
/>
147150
<Toaster richColors />
148151
</div>

apps/dashboard/src/app/account/settings/AccountSettingsPageUI.tsx

Lines changed: 49 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import type { Account } from "@3rdweb-sdk/react/hooks/useApi";
3838
import { zodResolver } from "@hookform/resolvers/zod";
3939
import { useMutation } from "@tanstack/react-query";
4040
import { REGEXP_ONLY_DIGITS_AND_CHARS } from "input-otp";
41-
import { EllipsisIcon, ExternalLinkIcon } from "lucide-react";
41+
import { CircleXIcon, EllipsisIcon, ExternalLinkIcon } from "lucide-react";
4242
import Link from "next/link";
4343
import { useState } from "react";
4444
import { 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

Comments
 (0)