import { useState } from "react"; import { useMutation } from "react-query"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import showToast from "@calcom/lib/notification"; import { ButtonBaseProps } from "@calcom/ui/Button"; import { Dialog } from "@calcom/ui/Dialog"; import { trpc } from "@lib/trpc"; import ConfirmationDialogContent from "@components/dialog/ConfirmationDialogContent"; export default function DisconnectIntegration(props: { /** Integration credential id */ id: number; externalId?: string; render: (renderProps: ButtonBaseProps) => JSX.Element; onOpenChange: (isOpen: boolean) => unknown | Promise; }) { const { id, externalId = "" } = props; const { t } = useLocale(); const [modalOpen, setModalOpen] = useState(false); const mutation = trpc.useMutation("viewer.deleteCredential", { onSettled: async () => { await props.onOpenChange(modalOpen); }, onSuccess: () => { showToast("Integration deleted successfully", "success"); setModalOpen(false); }, onError: () => { throw new Error("Something went wrong"); }, }); return ( <> { mutation.mutate({ id, externalId }); }}> {t("are_you_sure_you_want_to_remove_this_app")} {props.render({ onClick() { setModalOpen(true); }, disabled: modalOpen, loading: mutation.isLoading, })} ); }