import React, { useState } from "react"; import { useRouter } from "next/router"; import { useTheme } from "next-themes"; import { mutate } from "swr"; import { Dialog, Transition } from "@headlessui/react"; import { Trash2 } from "lucide-react"; // hooks import { TOAST_TYPE, setToast } from "@plane/ui"; import { useUser } from "hooks/store"; // ui 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 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(() => setToast({ type: TOAST_TYPE.ERROR, title: "Error!", message: "Failed to sign out. Please try again.", }) ) .finally(() => setSwitchingAccount(false)); }; const handleDeactivateAccount = async () => { setIsDeactivating(true); await deactivateAccount() .then(() => { setToast({ type: TOAST_TYPE.SUCCESS, title: "Success!", message: "Account deleted successfully.", }); mutate("CURRENT_USER_DETAILS", null); setTheme("system"); router.push("/"); handleClose(); }) .catch((err) => setToast({ type: TOAST_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.
); };