diff --git a/src/app/admin/users/AdminUserActions.tsx b/src/app/admin/users/AdminUserActions.tsx index 22238ed..8fd9852 100644 --- a/src/app/admin/users/AdminUserActions.tsx +++ b/src/app/admin/users/AdminUserActions.tsx @@ -24,6 +24,8 @@ export function AdminUserActions({ user }: { user: UserData }) { const [resetUrl, setResetUrl] = useState(null) const [lotteryReset, setLotteryReset] = useState(false) const [error, setError] = useState('') + const [deleteConfirm, setDeleteConfirm] = useState('') + const [deleteError, setDeleteError] = useState('') async function handleSave() { setLoading(true) @@ -80,10 +82,28 @@ export function AdminUserActions({ user }: { user: UserData }) { } } + async function handleDelete() { + if (deleteConfirm !== user.username) { + setDeleteError('Username does not match.') + return + } + setLoading(true) + setDeleteError('') + const res = await fetch(`/api/admin/users/${user.id}`, { method: 'DELETE' }) + const data = await res.json() + setLoading(false) + if (!res.ok) { + setDeleteError(data.error ?? 'Delete failed.') + } else { + setOpen(false) + router.refresh() + } + } + return ( <> + + +
+ + {open && ( +
+

+ This will permanently delete your account, + all trade history, positions, and portfolio data. This cannot be undone. +

+

+ Any fund investments you hold will be forfeited to the fund. +

+
+ + setConfirm(e.target.value)} + placeholder={username} + autoComplete="off" + className="w-full bg-surface border border-red-500/30 focus:border-red-500 rounded-lg px-3 py-2 text-sm focus:outline-none" + /> +
+ + {error &&

{error}

} + + +
+ )} + + ) +} diff --git a/src/app/profile/[username]/page.tsx b/src/app/profile/[username]/page.tsx index f7b01eb..e67150f 100644 --- a/src/app/profile/[username]/page.tsx +++ b/src/app/profile/[username]/page.tsx @@ -9,6 +9,7 @@ import Link from 'next/link' import { TrendingUp, TrendingDown, Coins, Building2 } from 'lucide-react' import ChangePasswordForm from './ChangePasswordForm' import AccountSettingsForm from './AccountSettingsForm' +import CloseAccountForm from './CloseAccountForm' import { PriceChart } from '@/components/PriceChart' export const dynamic = 'force-dynamic' @@ -327,6 +328,7 @@ export default async function ProfilePage({ params }: Props) { currentDisplayUsername={user.displayUsername ?? null} /> + )}