import { ClipboardCopyIcon } from "@heroicons/react/solid"; import { Trans } from "next-i18next"; import Link from "next/link"; import { useState } from "react"; import { Toaster } from "react-hot-toast"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import showToast from "@calcom/lib/notification"; import { Button, Loader, Tooltip } from "@calcom/ui"; /** TODO: Maybe extract this into a package to prevent circular dependencies */ import { trpc } from "@calcom/web/lib/trpc"; export interface IZapierSetupProps { inviteLink: string; } const ZAPIER = "zapier"; export default function ZapierSetup(props: IZapierSetupProps) { const [newApiKey, setNewApiKey] = useState(""); const { t } = useLocale(); const utils = trpc.useContext(); const integrations = trpc.useQuery(["viewer.integrations", { variant: "other" }]); // @ts-ignore const oldApiKey = trpc.useQuery(["viewer.apiKeys.findKeyOfType", { appId: ZAPIER }]); const deleteApiKey = trpc.useMutation("viewer.apiKeys.delete"); const zapierCredentials: { credentialIds: number[] } | undefined = integrations.data?.items.find( (item: { type: string }) => item.type === "zapier_other" ); const [credentialId] = zapierCredentials?.credentialIds || [false]; const showContent = integrations.data && integrations.isSuccess && credentialId; const isCalDev = process.env.NEXT_PUBLIC_WEBAPP_URL === "https://app.cal.dev"; async function createApiKey() { const event = { note: "Zapier", expiresAt: null, appId: ZAPIER }; // @ts-ignore const apiKey = await utils.client.mutation("viewer.apiKeys.create", event); if (oldApiKey.data) { deleteApiKey.mutate({ id: oldApiKey.data.id, }); } setNewApiKey(apiKey); } if (integrations.isLoading) { return (