diff --git a/apps/dashboard/src/components/dashboard-account-settings/settings/delete-account-section.tsx b/apps/dashboard/src/components/dashboard-account-settings/settings/delete-account-section.tsx new file mode 100644 index 000000000..463b77147 --- /dev/null +++ b/apps/dashboard/src/components/dashboard-account-settings/settings/delete-account-section.tsx @@ -0,0 +1,93 @@ +'use client'; + +import { + Accordion, + AccordionContent, + AccordionItem, + AccordionTrigger, +} from "@/components/ui/accordion"; +import { Button } from "@/components/ui/button"; +import { useState } from "react"; +import { useStackApp, useUser } from "@stackframe/stack"; +import { Section } from "../section"; + +export function DeleteAccountSection(props?: { mockMode?: boolean }) { + const user = useUser({ or: props?.mockMode ? 'return-null' : 'redirect' }); + const app = useStackApp(); + const project = app.useProject(); + const [deleting, setDeleting] = useState(false); + + const showDeleteSection = props?.mockMode || project.config.clientUserDeletionEnabled; + + if (!showDeleteSection) { + return null; + } + + const handleDeleteAccount = async () => { + if (props?.mockMode) { + alert("Mock mode: Account deletion clicked"); + setDeleting(false); + return; + } + + if (user) { + await user.delete(); + await app.redirectToHome(); + } + }; + + return ( + + + + + + Danger zone + + + {!deleting ? ( + + + Once you delete your account, there is no going back. Please be certain. + + setDeleting(true)} + className="rounded-xl w-full" + > + Delete account + + + ) : ( + + + Are you sure you want to delete your account? This action is IRREVERSIBLE and will delete ALL associated data. + + + + Yes, delete account + + setDeleting(false)} + className="border-black/[0.08] dark:border-white/[0.08] hover:bg-zinc-50 dark:hover:bg-zinc-900 rounded-xl flex-1 text-xs" + > + Cancel + + + + )} + + + + + + ); +} diff --git a/apps/dashboard/src/components/dashboard-account-settings/settings/settings-page.tsx b/apps/dashboard/src/components/dashboard-account-settings/settings/settings-page.tsx new file mode 100644 index 000000000..6d0570582 --- /dev/null +++ b/apps/dashboard/src/components/dashboard-account-settings/settings/settings-page.tsx @@ -0,0 +1,15 @@ +import { PageLayout } from "../page-layout"; +import { DeleteAccountSection } from "./delete-account-section"; +import { SignOutSection } from "./sign-out-section"; + + +export function SettingsPage(props?: { + mockMode?: boolean, +}) { + return ( + + + + + ); +} diff --git a/apps/dashboard/src/components/dashboard-account-settings/settings/sign-out-section.tsx b/apps/dashboard/src/components/dashboard-account-settings/settings/sign-out-section.tsx new file mode 100644 index 000000000..652793ae7 --- /dev/null +++ b/apps/dashboard/src/components/dashboard-account-settings/settings/sign-out-section.tsx @@ -0,0 +1,34 @@ +'use client'; + +import { Button } from "@/components/ui/button"; +import { useUser } from "@stackframe/stack"; +import { Section } from "../section"; + +export function SignOutSection(props?: { mockMode?: boolean }) { + const user = useUser({ or: props?.mockMode ? "return-null" : "throw" }); + + const handleSignOut = async () => { + if (props?.mockMode) { + alert("Mock mode: Sign out clicked"); + return; + } + if (user) { + await user.signOut(); + } + }; + + return ( + + + Sign out + + + ); +}
+ Once you delete your account, there is no going back. Please be certain. +
+ Are you sure you want to delete your account? This action is IRREVERSIBLE and will delete ALL associated data. +