// react import React, { useState } from "react"; // next import { useRouter } from "next/router"; // hooks import useToast from "hooks/use-toast"; // services import { AuthService } from "services/auth.service"; // headless ui import { Dialog, Transition } from "@headlessui/react"; // icons import { Trash2 } from "lucide-react"; import { UserService } from "services/user.service"; import { useTheme } from "next-themes"; import { mutate } from "swr"; type Props = { isOpen: boolean; onClose: () => void; }; const authService = new AuthService(); const userService = new UserService(); const DeleteAccountModal: React.FC = (props) => { const { isOpen, onClose } = props; const [isDeleteLoading, setIsDeleteLoading] = useState(false); const router = useRouter(); const { setTheme } = useTheme(); const { setToastAlert } = useToast(); const handleSignOut = async () => { await authService .signOut() .then(() => { mutate("CURRENT_USER_DETAILS", null); setTheme("system"); router.push("/"); }) .catch(() => setToastAlert({ type: "error", title: "Error!", message: "Failed to sign out. Please try again.", }) ); }; const handleDeleteAccount = async () => { setIsDeleteLoading(true); await userService .deleteAccount() .then(() => { setToastAlert({ type: "success", title: "Success!", message: "Account deleted successfully.", }); mutate("CURRENT_USER_DETAILS", null); setTheme("system"); router.push("/"); }) .catch((err) => setToastAlert({ type: "error", title: "Error!", message: err?.data?.error, }) ); setIsDeleteLoading(false); }; const handleClose = () => { onClose(); }; return (
Not the right workspace?
  • Delete this account if you have another and won’t use this account.
  • Switch to another account if you’d like to come back to this account another time.
Switch account
); }; export default DeleteAccountModal;