import React, { useState } from "react"; import { useRouter } from "next/router"; import { mutate } from "swr"; import { useTheme } from "next-themes"; import { Dialog, Transition } from "@headlessui/react"; import { Trash2 } from "lucide-react"; // hooks import { useUser } from "hooks/store"; import useToast from "hooks/use-toast"; type Props = { isOpen: boolean; onClose: () => void; }; export const SwitchOrDeleteAccountModal: React.FC = (props) => { const { isOpen, onClose } = props; // states const [switchingAccount, setSwitchingAccount] = useState(false); const [isDeactivating, setIsDeactivating] = useState(false); // router const router = useRouter(); // store hooks const { deactivateAccount, signOut } = useUser(); const { resolvedTheme, setTheme } = useTheme(); const { setToastAlert } = useToast(); const handleClose = () => { setSwitchingAccount(false); setIsDeactivating(false); onClose(); }; const handleSwitchAccount = async () => { setSwitchingAccount(true); await signOut() .then(() => { mutate("CURRENT_USER_DETAILS", null); setTheme("system"); router.push("/"); handleClose(); }) .catch(() => setToastAlert({ type: "error", title: "Error!", message: "Failed to sign out. Please try again.", }) ) .finally(() => setSwitchingAccount(false)); }; const handleDeactivateAccount = async () => { setIsDeactivating(true); await deactivateAccount() .then(() => { setToastAlert({ type: "success", title: "Success!", message: "Account deleted successfully.", }); mutate("CURRENT_USER_DETAILS", null); setTheme("system"); router.push("/"); handleClose(); }) .catch((err) => setToastAlert({ type: "error", title: "Error!", message: err?.error, }) ) .finally(() => setIsDeactivating(false)); }; 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.
); };