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 { AlertTriangle } from "lucide-react"; // mobx store import { useMobxStore } from "lib/mobx/store-provider"; // ui import { Button } from "@plane/ui"; // hooks import useToast from "hooks/use-toast"; // services import { AuthService } from "services/auth.service"; type Props = { isOpen: boolean; onClose: () => void; }; const authService = new AuthService(); export const DeactivateAccountModal: React.FC = (props) => { const { isOpen, onClose } = props; // states const [switchingAccount, setSwitchingAccount] = useState(false); const [isDeactivating, setIsDeactivating] = useState(false); const { user: { deactivateAccount }, } = useMobxStore(); const router = useRouter(); const { setTheme } = useTheme(); const { setToastAlert } = useToast(); const handleClose = () => { setSwitchingAccount(false); setIsDeactivating(false); onClose(); }; const handleSwitchAccount = async () => { setSwitchingAccount(true); await authService .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 handleDeleteAccount = async () => { setIsDeactivating(true); await deactivateAccount() .then(() => { setToastAlert({ type: "success", title: "Success!", message: "Account deleted successfully.", }); handleClose(); router.push("/"); }) .catch((err) => setToastAlert({ type: "error", title: "Error!", message: err?.error, }) ) .finally(() => setIsDeactivating(false)); }; return (
Deactivate account?
  • Deactivate 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.
); };