2021-10-20 15:42:40 +00:00
|
|
|
import { useState } from "react";
|
|
|
|
|
2022-06-03 14:57:50 +00:00
|
|
|
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
2022-03-23 22:00:30 +00:00
|
|
|
import showToast from "@calcom/lib/notification";
|
2022-07-22 17:27:06 +00:00
|
|
|
import { trpc } from "@calcom/trpc/react";
|
2022-03-16 23:36:43 +00:00
|
|
|
import { ButtonBaseProps } from "@calcom/ui/Button";
|
2022-07-28 19:58:26 +00:00
|
|
|
import ConfirmationDialogContent from "@calcom/ui/ConfirmationDialogContent";
|
2022-03-16 23:36:43 +00:00
|
|
|
import { Dialog } from "@calcom/ui/Dialog";
|
|
|
|
|
2021-10-20 15:42:40 +00:00
|
|
|
export default function DisconnectIntegration(props: {
|
|
|
|
/** Integration credential id */
|
|
|
|
id: number;
|
2022-07-15 20:28:24 +00:00
|
|
|
externalId?: string;
|
2021-10-20 15:42:40 +00:00
|
|
|
render: (renderProps: ButtonBaseProps) => JSX.Element;
|
2021-10-30 15:54:21 +00:00
|
|
|
onOpenChange: (isOpen: boolean) => unknown | Promise<unknown>;
|
2021-10-20 15:42:40 +00:00
|
|
|
}) {
|
2022-07-15 20:28:24 +00:00
|
|
|
const { id, externalId = "" } = props;
|
2022-06-03 14:57:50 +00:00
|
|
|
const { t } = useLocale();
|
2021-10-20 15:42:40 +00:00
|
|
|
const [modalOpen, setModalOpen] = useState(false);
|
2022-06-20 17:52:50 +00:00
|
|
|
|
|
|
|
const mutation = trpc.useMutation("viewer.deleteCredential", {
|
|
|
|
onSettled: async () => {
|
|
|
|
await props.onOpenChange(modalOpen);
|
2021-10-20 15:42:40 +00:00
|
|
|
},
|
2022-06-20 17:52:50 +00:00
|
|
|
onSuccess: () => {
|
|
|
|
showToast("Integration deleted successfully", "success");
|
|
|
|
setModalOpen(false);
|
|
|
|
},
|
|
|
|
onError: () => {
|
|
|
|
throw new Error("Something went wrong");
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2021-10-20 15:42:40 +00:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<Dialog open={modalOpen} onOpenChange={setModalOpen}>
|
|
|
|
<ConfirmationDialogContent
|
|
|
|
variety="danger"
|
2022-06-03 14:57:50 +00:00
|
|
|
title={t("remove_app")}
|
|
|
|
confirmBtnText={t("yes_remove_app")}
|
2021-10-20 15:42:40 +00:00
|
|
|
cancelBtnText="Cancel"
|
|
|
|
onConfirm={() => {
|
2022-07-15 20:28:24 +00:00
|
|
|
mutation.mutate({ id, externalId });
|
2021-10-20 15:42:40 +00:00
|
|
|
}}>
|
2022-06-03 14:57:50 +00:00
|
|
|
{t("are_you_sure_you_want_to_remove_this_app")}
|
2021-10-20 15:42:40 +00:00
|
|
|
</ConfirmationDialogContent>
|
|
|
|
</Dialog>
|
|
|
|
{props.render({
|
|
|
|
onClick() {
|
|
|
|
setModalOpen(true);
|
|
|
|
},
|
|
|
|
disabled: modalOpen,
|
|
|
|
loading: mutation.isLoading,
|
|
|
|
})}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|