import { json, type LoaderFunctionArgs } from "@remix-run/node"; import { useLoaderData, useFetcher, useNavigate } from "@remix-run/react"; import { requireUser } from "~/services/session.server"; import { Card } from "~/components/ui/card"; import { Button } from "~/components/ui/button"; import { Input } from "~/components/ui/input"; import { Label } from "~/components/ui/label"; import { AlertTriangle } from "lucide-react"; import { useState } from "react"; import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, } from "~/components/ui/alert-dialog"; import { SettingSection } from "~/components/setting-section"; interface SuccessDataResponse { success: boolean; } interface ErrorDataResponse { error: string; } export const loader = async ({ request }: LoaderFunctionArgs) => { const user = await requireUser(request); return json({ user, }); }; export default function AccountSettings() { const { user } = useLoaderData(); const fetcher = useFetcher(); const navigate = useNavigate(); const [showDeleteDialog, setShowDeleteDialog] = useState(false); const [confirmText, setConfirmText] = useState(""); const isDeleting = fetcher.state === "submitting"; const handleDeleteAccount = () => { fetcher.submit( {}, { method: "DELETE", action: "/api/v1/user/delete", }, ); }; // Redirect to login after successful deletion if (fetcher.data && "success" in fetcher.data && fetcher.data.success) { setTimeout(() => { navigate("/login"); }, 1000); } const canDelete = confirmText === user.email; return (
<> {/* Account Information */}

Account Information

{user.email}

{user.name && (

{user.name}

)} {user.displayName && (

{user.displayName}

)}

{new Date(user.createdAt).toLocaleDateString()}

{/* Danger Zone */}

Danger Zone

Delete Account

Permanently delete your account and all associated data. This action cannot be undone.

  • All your memories and conversations will be deleted
  • All integration connections will be removed
  • All API keys and webhooks will be revoked
  • Your workspace and all its data will be permanently lost
  • Active subscriptions will be cancelled immediately
{/* Delete Confirmation Dialog */} Are you absolutely sure?

This action cannot be undone. This will permanently delete your account and remove all your data from our servers.

setConfirmText(e.target.value)} placeholder="Enter your email" className="mt-2" autoComplete="off" />
{ setConfirmText(""); }} disabled={isDeleting} > Cancel {isDeleting ? "Deleting..." : "Delete Account Permanently"}
{/* Success Message */} {fetcher.data && "success" in fetcher.data && fetcher.data.success && (
Account deleted successfully. Redirecting...
)} {/* Error Message */} {fetcher.data && "error" in fetcher.data && (
{fetcher.data.error}
)}
); }