import { useState, Fragment, FC } from "react"; import { useRouter } from "next/router"; import { mutate } from "swr"; import { Dialog, Transition } from "@headlessui/react"; import { IApiToken } from "@plane/types"; // services import { Button, TOAST_TYPE, setToast } from "@plane/ui"; import { API_TOKENS_LIST } from "@/constants/fetch-keys"; import { APITokenService } from "@/services/api_token.service"; // ui // types // fetch-keys type Props = { isOpen: boolean; onClose: () => void; tokenId: string; }; const apiTokenService = new APITokenService(); export const DeleteApiTokenModal: FC = (props) => { const { isOpen, onClose, tokenId } = props; // states const [deleteLoading, setDeleteLoading] = useState(false); // router const router = useRouter(); const { workspaceSlug } = router.query; const handleClose = () => { onClose(); setDeleteLoading(false); }; const handleDeletion = () => { if (!workspaceSlug) return; setDeleteLoading(true); apiTokenService .deleteApiToken(workspaceSlug.toString(), tokenId) .then(() => { setToast({ type: TOAST_TYPE.SUCCESS, title: "Success!", message: "Token deleted successfully.", }); mutate( API_TOKENS_LIST(workspaceSlug.toString()), (prevData) => (prevData ?? []).filter((token) => token.id !== tokenId), false ); handleClose(); }) .catch((err) => setToast({ type: TOAST_TYPE.ERROR, title: "Error", message: err?.message ?? "Something went wrong. Please try again.", }) ) .finally(() => setDeleteLoading(false)); }; return (

Are you sure you want to delete the token?

Any application using this token will no longer have the access to Plane data. This action cannot be undone.

); };