import { useQueryClient } from '@tanstack/react-query' import { useRef, useState } from 'react' import { DestructiveConfirmation } from '@/components/destructive-confirmation' import { Button } from '@/components/ui/button' import { deleteOwnAccount } from '@/lib/api/account' import { tt } from '@/lib/i18n' import { AccountRow } from './account-page' export function DeleteAccountPanel() { const queryClient = useQueryClient() const triggerRef = useRef(null) const [open, setOpen] = useState(false) const [pending, setPending] = useState(false) const [error, setError] = useState(null) const [deleted, setDeleted] = useState(false) async function erase() { setPending(true) setError(null) try { await deleteOwnAccount() } catch (cause) { setError(cause instanceof Error ? tt(cause.message) : tt('Unable to delete account.')) setPending(false) return } queryClient.clear() setDeleted(true) setPending(false) setOpen(false) // Navigate away from all private UI. The server has already invalidated credentials. window.location.replace('/auth/account-deleted') } return ( <> { setError(null) setOpen(true) }} > {tt('Delete account')} } description={tt( 'Permanently delete your Realmroot account. This cannot be undone. Your personal Agents and access will also be revoked.', )} label={tt('Delete account')} value={tt('Permanent')} /> setOpen(false)} onConfirm={() => void erase()} error={ error ? (

{error}

) : null } /> ) }