"use client"; import { useState } from "react"; import { useRouter } from "next/navigation"; import { useTranslations } from "next-intl"; import { toast } from "sonner"; import { Button } from "@/design-system/base/button"; import { Modal } from "@/design-system/overlay/modal"; import { actionDeleteAccount } from "@/modules/auth/auth-action"; interface DeleteAccountButtonProps { username: string; } export function DeleteAccountButton({ username }: DeleteAccountButtonProps) { const t = useTranslations("user_profile"); const router = useRouter(); const [showModal, setShowModal] = useState(false); const [confirmUsername, setConfirmUsername] = useState(""); const [loading, setLoading] = useState(false); const handleDelete = async () => { if (confirmUsername !== username) { toast.error(t("deleteAccount.usernameMismatch")); return; } setLoading(true); try { const result = await actionDeleteAccount(); if (result.success) { toast.success(t("deleteAccount.success")); router.push("/"); } else { toast.error(result.message || t("deleteAccount.failed")); } } catch { toast.error(t("deleteAccount.failed")); } finally { setLoading(false); setShowModal(false); } }; return ( <> setShowModal(false)}>

{t("deleteAccount.title")}

{t("deleteAccount.warning")}

  • {t("deleteAccount.warningDecks")}
  • {t("deleteAccount.warningCards")}
  • {t("deleteAccount.warningHistory")}
  • {t("deleteAccount.warningPermanent")}
setConfirmUsername(e.target.value)} className="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-red-500" placeholder={username} />
); }