* perf: Slim down loggedInViewer some more * Move locationOptions to apps router * Moved calVideo related handlers to separate router * Moved calendar related handlers to separate router * Rename * Moved deleteCredential to new router * Moved updateProfile to me router * fix unit test * fix e2e test * tweak * missing --------- Co-authored-by: Anik Dhabal Babu <81948346+anikdhabal@users.noreply.github.com> Co-authored-by: unknown <adhabal2002@gmail.com>
54 lines
1.8 KiB
TypeScript
54 lines
1.8 KiB
TypeScript
"use client";
|
|
|
|
import { useState } from "react";
|
|
|
|
import { isDelegationCredential } from "@calcom/lib/delegationCredential/clientAndServer";
|
|
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
|
import { trpc } from "@calcom/trpc/react";
|
|
import type { ButtonProps } from "@calcom/ui/components/button";
|
|
import { DisconnectIntegrationComponent } from "@calcom/ui/components/disconnect-calendar-integration";
|
|
import { showToast } from "@calcom/ui/components/toast";
|
|
|
|
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.credentials.delete.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.calendars.connectedCalendars.invalidate();
|
|
await utils.viewer.apps.integrations.invalidate();
|
|
},
|
|
});
|
|
|
|
// Such a credential is added in-memory and removed when Delegation credential is disabled.
|
|
const disableDisconnect = isDelegationCredential({ credentialId });
|
|
return (
|
|
<DisconnectIntegrationComponent
|
|
onDeletionConfirmation={() => mutation.mutate({ id: credentialId, ...(teamId ? { teamId } : {}) })}
|
|
isModalOpen={modalOpen}
|
|
onModalOpen={() => setModalOpen((prevValue) => !prevValue)}
|
|
disabled={disableDisconnect}
|
|
{...props}
|
|
/>
|
|
);
|
|
}
|