Files
calendar/packages/features/apps/components/DisconnectIntegration.tsx
T
a4519e705d fix: No option to install/disconnect app from app detail page (#17997)
* fix: No option to install/disconnect app from app detail page

* Fix types

* fix: Install button showing up even after it is installed for all targers

* chore: Simplified installOrDisconnectAppButton making it easy to read

---------

Co-authored-by: Hariom <hariombalhara@gmail.com>
Co-authored-by: Peer Richelsen <peeroke@gmail.com>
2025-02-26 00:08:59 +05:30

49 lines
1.4 KiB
TypeScript

"use client";
import { useState } from "react";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { trpc } from "@calcom/trpc/react";
import type { ButtonProps } from "@calcom/ui";
import { DisconnectIntegrationComponent, showToast } from "@calcom/ui";
export default function DisconnectIntegration(props: {
credentialId: number;
teamId?: number | null;
label?: string;
trashIcon?: boolean;
isGlobal?: boolean;
onSuccess?: () => void;
buttonProps?: ButtonProps;
}) {
const { t } = useLocale();
const { onSuccess, credentialId, teamId } = props;
const [modalOpen, setModalOpen] = useState(false);
const utils = trpc.useUtils();
const mutation = trpc.viewer.deleteCredential.useMutation({
onSuccess: () => {
showToast(t("app_removed_successfully"), "success");
setModalOpen(false);
onSuccess && onSuccess();
},
onError: () => {
showToast(t("error_removing_app"), "error");
setModalOpen(false);
},
async onSettled() {
await utils.viewer.connectedCalendars.invalidate();
await utils.viewer.integrations.invalidate();
},
});
return (
<DisconnectIntegrationComponent
onDeletionConfirmation={() => mutation.mutate({ id: credentialId, ...(teamId ? { teamId } : {}) })}
isModalOpen={modalOpen}
onModalOpen={() => setModalOpen((prevValue) => !prevValue)}
{...props}
/>
);
}