import { useRouter } from "next/navigation"; import { t } from "@lingui/core/macro"; import { useMutation } from "@tanstack/react-query"; import { useState } from "react"; import { authClient } from "@kan/auth/client"; import Button from "~/components/Button"; import { useModal } from "~/providers/modal"; import { usePopup } from "~/providers/popup"; import { api } from "~/utils/api"; export function DeleteAccountConfirmation() { const { closeModal } = useModal(); const { showPopup } = usePopup(); const router = useRouter(); const utils = api.useUtils(); const [isAcknowledgmentChecked, setIsAcknowledgmentChecked] = useState(false); const deleteAccountMutation = useMutation({ mutationFn: () => authClient.deleteUser(), onSuccess: async () => { closeModal(); showPopup({ header: t`Account deleted`, message: t`Your account has been deleted.`, icon: "success", }); utils.invalidate(); router.push("/"); }, onError: () => { closeModal(); showPopup({ header: t`Error deleting account`, message: t`Please try again later, or contact customer support.`, icon: "error", }); }, }); const handleDeleteAccount = () => { deleteAccountMutation.mutate(); }; return (

{t`Are you sure you want to delete your account?`}

{t`Keep in mind that this action is irreversible.`}

{t`This will result in the permanent deletion of all data associated with your account.`}

setIsAcknowledgmentChecked(!isAcknowledgmentChecked) } />

{t`I acknowledge that all of my account data will be permanently deleted and want to proceed.`}

); }